我使用 SoapUI Groovy 脚本为 ZAPI 生成 JWT 令牌。
笔记 :
库版本应该是 lib 文件夹中的“commons-lang-2.6.jar”和“commons-codec-1.11.jar”。
在 bin -> ext 文件夹中添加“jwt-generator.jar”和“zfj-cloud-rest-client-3.0.jar”。
jwt 生成器
JWT 令牌将根据输入的 API url 创建。例如:
字符串 createCycleUri = zephyrBaseUrl + "/public/rest/api/1.0/cycle";
在生成 jwt 令牌之前提及 api HTTP 方法类型。
String jwt = jwtGenerator.generateJWT("POST", uri, expirationInSec);
站点始终针对任何 ZAPI api 进行修复。这将采用 JWT 令牌。
https://prod-api.zephyr4jiracloud.com/connect
文件中提到了这一点。
https://zfjcloud.docs.apiary.io/#
- 如果您使用以下文档中提到的 JIRA api,将使用您创建的站点 url。这将需要基本的身份验证。
https://getzephyr.docs.apiary.io/#
例如:
https://newapi.atlassian.net
时髦的:
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import com.thed.zephyr.cloud.rest.ZFJCloudRestClient;
import com.thed.zephyr.cloud.rest.client.JwtGenerator;
def site = context.expand( '${#Project#Site}' )
def zapiAccessKey = context.expand( '${#Project#zapiAccessKey}' )
def secretID = context.expand( '${#Project#secretID}' )
def user = context.expand( '${#Project#user}' )
// Replace Zephyr BaseUrl with the <ZAPI_CLOUD_URL> shared with ZAPI Cloud Installation
String zephyrBaseUrl = site;
// zephyr accessKey , we can get from Addons >> zapi section
String accessKey = zapiAccessKey;
// zephyr secretKey , we can get from Addons >> zapi section
String secretKey = secretID;
// Jira UserName
String userName = user;
ZFJCloudRestClient client = ZFJCloudRestClient.restBuilder(zephyrBaseUrl, accessKey, secretKey, userName).build();
JwtGenerator jwtGenerator = client.getJwtGenerator();
// API to which the JWT token has to be generated
String createCycleUri = zephyrBaseUrl + "/public/rest/api/1.0/cycle";
URI uri = new URI(createCycleUri);
int expirationInSec = 3600;
String jwt = jwtGenerator.generateJWT("POST", uri, expirationInSec);
log.info "JWT Token : " + jwt
//Store token in property.
context.testCase.testSuite.project.setPropertyValue('JWT_Token', jwt)