From 3b5031dcf89512c689c7425f66348521c005c028 Mon Sep 17 00:00:00 2001 From: CrowleyRajapakse Date: Mon, 4 Mar 2024 17:01:06 +0530 Subject: [PATCH] adding initial apk agent integration tests --- .../confs/instance-1/deployment.toml | 3 + .../integration/api/APIDeploymentSteps.java | 143 ++++++++++++++++++ .../wso2/apk/integration/api/BaseSteps.java | 40 ++--- .../apk/integration/api/SharedContext.java | 87 +++++++++-- .../wso2/apk/integration/utils/Constants.java | 1 + .../org/wso2/apk/integration/utils/Utils.java | 102 +++++++++++++ .../utils/clients/SimpleHTTPClient.java | 2 +- .../src/test/resources/testng.xml | 2 +- .../resources/tests/api/Deployment.feature | 36 +++-- 9 files changed, 360 insertions(+), 56 deletions(-) diff --git a/test/apim-apk-agent-test/apim-cp-helm-chart/confs/instance-1/deployment.toml b/test/apim-apk-agent-test/apim-cp-helm-chart/confs/instance-1/deployment.toml index 8c26d8543a..0cf2510df9 100644 --- a/test/apim-apk-agent-test/apim-cp-helm-chart/confs/instance-1/deployment.toml +++ b/test/apim-apk-agent-test/apim-cp-helm-chart/confs/instance-1/deployment.toml @@ -140,6 +140,9 @@ allow_refresh_tokens = true iat_validity_period = "1h" {{- end }} +[oauth.endpoints] +oauth2_jwks_url = "https://apim-wso2am-cp-1-service:9443/oauth2/jwks" + #[apim.publisher] #{{- if .Values.wso2.apim.configurations.publisher.supportedDocumentTypes }} #supported_document_types = {{ toJson .Values.wso2.apim.configurations.publisher.supportedDocumentTypes }} diff --git a/test/apim-apk-agent-test/cucumber-tests/src/test/java/org/wso2/apk/integration/api/APIDeploymentSteps.java b/test/apim-apk-agent-test/cucumber-tests/src/test/java/org/wso2/apk/integration/api/APIDeploymentSteps.java index 7f5c74dc6b..9c9dc8644f 100644 --- a/test/apim-apk-agent-test/cucumber-tests/src/test/java/org/wso2/apk/integration/api/APIDeploymentSteps.java +++ b/test/apim-apk-agent-test/cucumber-tests/src/test/java/org/wso2/apk/integration/api/APIDeploymentSteps.java @@ -136,6 +136,149 @@ public void make_a_api_revision_deployment_request() throws Exception { Thread.sleep(3000); } + @When("make the Change Lifecycle request") + public void make_a_change_lifecycle_request() throws Exception { + String apiUUID = sharedContext.getApiUUID(); + String payload = ""; + + Map headers = new HashMap<>(); + headers.put(Constants.REQUEST_HEADERS.AUTHORIZATION, "Bearer " + sharedContext.getPublisherAccessToken()); + headers.put(Constants.REQUEST_HEADERS.HOST, Constants.DEFAULT_API_HOST); + + HttpResponse response = sharedContext.getHttpClient().doPost(Utils.getAPIChangeLifecycleURL(apiUUID), + headers, payload, Constants.CONTENT_TYPES.APPLICATION_JSON); + + sharedContext.setResponse(response); + Thread.sleep(3000); + } + + @When("make the Application Creation request") + public void make_application_creation_request() throws Exception { + logger.info("Creating an application"); + String payload = "{\"name\":\"PetstoreApp\",\"throttlingPolicy\":\"10PerMin\",\"description\":\"test app\",\"tokenType\":\"JWT\",\"groups\":null,\"attributes\":{}}"; + + Map headers = new HashMap<>(); + headers.put(Constants.REQUEST_HEADERS.AUTHORIZATION, "Bearer " + sharedContext.getDevportalAccessToken()); + headers.put(Constants.REQUEST_HEADERS.HOST, Constants.DEFAULT_API_HOST); + + HttpResponse response = sharedContext.getHttpClient().doPost(Utils.getApplicationCreateURL(), + headers, payload, Constants.CONTENT_TYPES.APPLICATION_JSON); + + sharedContext.setResponse(response); + sharedContext.setResponseBody(SimpleHTTPClient.responseEntityBodyToString(sharedContext.getResponse())); + logger.info("Response: " + sharedContext.getResponseBody()); + sharedContext.setApplicationUUID(Utils.extractApplicationID(sharedContext.getResponseBody())); + Thread.sleep(3000); + } + + @When("I have a KeyManager") + public void i_have_a_key_manager() throws Exception { + Map headers = new HashMap<>(); + headers.put(Constants.REQUEST_HEADERS.AUTHORIZATION, "Bearer " + sharedContext.getDevportalAccessToken()); + headers.put(Constants.REQUEST_HEADERS.HOST, Constants.DEFAULT_API_HOST); + + HttpResponse response = sharedContext.getHttpClient().doGet(Utils.getKeyManagerURL(), + headers); + + sharedContext.setResponse(response); + sharedContext.setResponseBody(SimpleHTTPClient.responseEntityBodyToString(sharedContext.getResponse())); + sharedContext.setKeyManagerUUID(Utils.extractKeyManagerID(sharedContext.getResponseBody())); + Thread.sleep(3000); + } + + @When("make the Generate Keys request") + public void make_generate_keys_request() throws Exception { + String applicationUUID = sharedContext.getApplicationUUID(); + String keyManagerUUID = sharedContext.getKeyManagerUUID(); + logger.info("Key Manager UUID: " + keyManagerUUID); + logger.info("Application UUID: " + applicationUUID); + String payload = "{\"keyType\":\"PRODUCTION\",\"grantTypesToBeSupported\":[\"password\",\"client_credentials\"]," + + "\"callbackUrl\":\"\",\"additionalProperties\":{\"application_access_token_expiry_time\":\"N/A\"," + + "\"user_access_token_expiry_time\":\"N/A\",\"refresh_token_expiry_time\":\"N/A\"," + + "\"id_token_expiry_time\":\"N/A\",\"pkceMandatory\":\"false\",\"pkceSupportPlain\":\"false\"," + + "\"bypassClientCredentials\":\"false\"},\"keyManager\":\"" + keyManagerUUID +"\"," + + "\"validityTime\":3600,\"scopes\":[\"default\"]}"; + + Map headers = new HashMap<>(); + headers.put(Constants.REQUEST_HEADERS.AUTHORIZATION, "Bearer " + sharedContext.getDevportalAccessToken()); + headers.put(Constants.REQUEST_HEADERS.HOST, Constants.DEFAULT_API_HOST); + + logger.info("Payload: " + payload); + + HttpResponse response = sharedContext.getHttpClient().doPost(Utils.getGenerateKeysURL(applicationUUID), + headers, payload, Constants.CONTENT_TYPES.APPLICATION_JSON); + + sharedContext.setResponse(response); + sharedContext.setResponseBody(SimpleHTTPClient.responseEntityBodyToString(sharedContext.getResponse())); + sharedContext.setConsumerSecret(Utils.extractKeys(sharedContext.getResponseBody(), "consumerSecret")); + sharedContext.setConsumerKey(Utils.extractKeys(sharedContext.getResponseBody(), "consumerKey")); + Thread.sleep(3000); + } + + @When("make the Subscription request") + public void make_subscription_request() throws Exception { + String applicationUUID = sharedContext.getApplicationUUID(); + String apiUUID = sharedContext.getApiUUID(); + logger.info("API UUID: " + apiUUID); + logger.info("Application UUID: " + applicationUUID); + String payload = "{\"apiId\":\"" + apiUUID + "\",\"applicationId\":\"" + applicationUUID + "\",\"throttlingPolicy\":\"Gold\"}"; + + Map headers = new HashMap<>(); + headers.put(Constants.REQUEST_HEADERS.AUTHORIZATION, "Bearer " + sharedContext.getDevportalAccessToken()); + headers.put(Constants.REQUEST_HEADERS.HOST, Constants.DEFAULT_API_HOST); + + HttpResponse response = sharedContext.getHttpClient().doPost(Utils.getSubscriptionURL(), + headers, payload, Constants.CONTENT_TYPES.APPLICATION_JSON); + + sharedContext.setResponse(response); + sharedContext.setResponseBody(SimpleHTTPClient.responseEntityBodyToString(sharedContext.getResponse())); + Thread.sleep(3000); + } + + @When("I get oauth keys for application") + public void get_oauth_keys_for_application() throws Exception { + String applicationUUID = sharedContext.getApplicationUUID(); + + Map headers = new HashMap<>(); + headers.put(Constants.REQUEST_HEADERS.AUTHORIZATION, "Bearer " + sharedContext.getDevportalAccessToken()); + headers.put(Constants.REQUEST_HEADERS.HOST, Constants.DEFAULT_API_HOST); + + HttpResponse response = sharedContext.getHttpClient().doGet(Utils.getOauthKeysURL(applicationUUID), + headers); + + sharedContext.setResponse(response); + sharedContext.setResponseBody(SimpleHTTPClient.responseEntityBodyToString(sharedContext.getResponse())); + sharedContext.setOauthKeyUUID(Utils.extractOAuthMappingID(sharedContext.getResponseBody())); + Thread.sleep(3000); + } + + @When("make the Access Token Generation request") + public void make_access_token_generation_request() throws Exception { + String applicationUUID = sharedContext.getApplicationUUID(); + String oauthKeyUUID = sharedContext.getOauthKeyUUID(); + String consumerKey = sharedContext.getConsumerKey(); + String consumerSecret = sharedContext.getConsumerSecret(); + logger.info("Oauth Key UUID: " + oauthKeyUUID); + logger.info("Application UUID: " + applicationUUID); + String payload = "{\"consumerSecret\":\"" + consumerSecret + "\",\"validityPeriod\":3600,\"revokeToken\":null," + + "\"scopes\":[\"write:pets\",\"read:pets\"],\"additionalProperties\":{\"id_token_expiry_time\":3600," + + "\"application_access_token_expiry_time\":3600,\"user_access_token_expiry_time\":3600,\"bypassClientCredentials\":false," + + "\"pkceMandatory\":false,\"pkceSupportPlain\":false,\"refresh_token_expiry_time\":86400}}"; + + Map headers = new HashMap<>(); + headers.put(Constants.REQUEST_HEADERS.AUTHORIZATION, "Bearer " + sharedContext.getDevportalAccessToken()); + headers.put(Constants.REQUEST_HEADERS.HOST, Constants.DEFAULT_API_HOST); + + HttpResponse response = sharedContext.getHttpClient().doPost(Utils.getAccessTokenGenerationURL(applicationUUID, oauthKeyUUID), + headers, payload, Constants.CONTENT_TYPES.APPLICATION_JSON); + + sharedContext.setResponse(response); + sharedContext.setResponseBody(SimpleHTTPClient.responseEntityBodyToString(sharedContext.getResponse())); + sharedContext.setApiAccessToken(Utils.extractKeys(sharedContext.getResponseBody(), "accessToken")); + logger.info("Access Token: " + sharedContext.getApiAccessToken()); + Thread.sleep(3000); + } + @When("make the API Deployment request") public void make_a_api_deployment_request() throws Exception { diff --git a/test/apim-apk-agent-test/cucumber-tests/src/test/java/org/wso2/apk/integration/api/BaseSteps.java b/test/apim-apk-agent-test/cucumber-tests/src/test/java/org/wso2/apk/integration/api/BaseSteps.java index 04db3306a9..ddd50abab7 100644 --- a/test/apim-apk-agent-test/cucumber-tests/src/test/java/org/wso2/apk/integration/api/BaseSteps.java +++ b/test/apim-apk-agent-test/cucumber-tests/src/test/java/org/wso2/apk/integration/api/BaseSteps.java @@ -113,11 +113,13 @@ public void theResponseBodyShouldContain(DataTable dataTable) throws IOException public void theResponseStatusCodeShouldBe(int expectedStatusCode) throws IOException { int actualStatusCode = sharedContext.getResponse().getStatusLine().getStatusCode(); + ((CloseableHttpResponse)sharedContext.getResponse()).close(); Assert.assertEquals(actualStatusCode, expectedStatusCode); } @Then("I send {string} request to {string} with body {string}") public void sendHttpRequest(String httpMethod, String url, String body) throws IOException { + sharedContext.addHeader("Authorization", "Bearer " + sharedContext.getApiAccessToken()); body = Utils.resolveVariables(body, sharedContext.getValueStore()); if (sharedContext.getResponse() instanceof CloseableHttpResponse) { ((CloseableHttpResponse) sharedContext.getResponse()).close(); @@ -316,8 +318,8 @@ public void decode_header_and_validate(String header,String jwksEndpoint, DataTa } } - @Given("I have a DCR application for Publisher") - public void iHaveADCRApplicationForPublisher() throws Exception { + @Given("I have a DCR application") + public void iHaveADCRApplication() throws Exception { Map headers = new HashMap<>(); headers.put(Constants.REQUEST_HEADERS.HOST, Constants.DEFAULT_IDP_HOST); @@ -331,39 +333,21 @@ public void iHaveADCRApplicationForPublisher() throws Exception { " \"saasApp\":true\n" + " }", Constants.CONTENT_TYPES.APPLICATION_JSON); - sharedContext.setPublisherBasicAuthToken(Utils.extractBasicToken(httpResponse)); - sharedContext.addStoreValue("publisherBasicAuthToken", sharedContext.getPublisherBasicAuthToken()); + sharedContext.setBasicAuthToken(Utils.extractBasicToken(httpResponse)); + sharedContext.addStoreValue("publisherBasicAuthToken", sharedContext.getBasicAuthToken()); } - @Given("I have a DCR application for Devportal") - public void iHaveADCRApplicationForDevportal() throws Exception { - - Map headers = new HashMap<>(); - headers.put(Constants.REQUEST_HEADERS.HOST, Constants.DEFAULT_IDP_HOST); - headers.put(Constants.REQUEST_HEADERS.AUTHORIZATION, "Basic YWRtaW46YWRtaW4="); - - HttpResponse httpResponse = httpClient.doPost(Utils.getDCREndpointURL(), headers, "{\n" + - " \"callbackUrl\":\"www.google.lk\",\n" + - " \"clientName\":\"rest_api_publisher\",\n" + - " \"owner\":\"admin\",\n" + - " \"grantType\":\"client_credentials password refresh_token\",\n" + - " \"saasApp\":true\n" + - " }", - Constants.CONTENT_TYPES.APPLICATION_JSON); - sharedContext.setDevportalBasicAuthToken(Utils.extractBasicToken(httpResponse)); - sharedContext.addStoreValue("devportalBasicAuthToken", sharedContext.getDevportalBasicAuthToken()); - } @Given("I have a valid Publisher access token") public void iHaveValidPublisherAccessToken() throws Exception { Map headers = new HashMap<>(); - String basicAuthHeader = "Basic " + sharedContext.getPublisherBasicAuthToken(); + String basicAuthHeader = "Basic " + sharedContext.getBasicAuthToken(); logger.info("Basic Auth Header: " + basicAuthHeader); headers.put(Constants.REQUEST_HEADERS.HOST, Constants.DEFAULT_IDP_HOST); headers.put(Constants.REQUEST_HEADERS.AUTHORIZATION, basicAuthHeader); - HttpResponse httpResponse = httpClient.doPost(Utils.getTokenEndpointURL(), headers, "grant_type=password&username=admin&password=admin&scope=apim:api_view apim:api_create", + HttpResponse httpResponse = httpClient.doPost(Utils.getTokenEndpointURL(), headers, "grant_type=password&username=admin&password=admin&scope=apim:api_view apim:api_create apim:api_publish", Constants.CONTENT_TYPES.APPLICATION_X_WWW_FORM_URLENCODED); logger.info("Response: " + httpResponse); sharedContext.setPublisherAccessToken(Utils.extractToken(httpResponse)); @@ -372,16 +356,18 @@ public void iHaveValidPublisherAccessToken() throws Exception { @Given("I have a valid Devportal access token") public void iHaveValidDevportalAccessToken() throws Exception { + logger.info("Basic Auth Header: " + sharedContext.getBasicAuthToken()); Map headers = new HashMap<>(); - String basicAuthHeader = "Basic " + sharedContext.getDevportalBasicAuthToken(); + String basicAuthHeader = "Basic " + sharedContext.getBasicAuthToken(); headers.put(Constants.REQUEST_HEADERS.HOST, Constants.DEFAULT_IDP_HOST); headers.put(Constants.REQUEST_HEADERS.AUTHORIZATION, basicAuthHeader); - HttpResponse httpResponse = httpClient.doPost(Utils.getTokenEndpointURL(), headers, "grant_type=password&username=admin&password=admin&scope=apim:api_view apim:api_create", - Constants.CONTENT_TYPES.APPLICATION_JSON); + HttpResponse httpResponse = httpClient.doPost(Utils.getTokenEndpointURL(), headers, "grant_type=password&username=admin&password=admin&scope=apim:app_manage apim:sub_manage apim:subscribe", + Constants.CONTENT_TYPES.APPLICATION_X_WWW_FORM_URLENCODED); sharedContext.setDevportalAccessToken(Utils.extractToken(httpResponse)); sharedContext.addStoreValue("devportalAccessToken", sharedContext.getDevportalAccessToken()); + logger.info("Devportal Access Token: " + sharedContext.getDevportalAccessToken()); } // @Given("I have a valid subscription without api deploy permission") diff --git a/test/apim-apk-agent-test/cucumber-tests/src/test/java/org/wso2/apk/integration/api/SharedContext.java b/test/apim-apk-agent-test/cucumber-tests/src/test/java/org/wso2/apk/integration/api/SharedContext.java index e3878ce627..acf781838a 100644 --- a/test/apim-apk-agent-test/cucumber-tests/src/test/java/org/wso2/apk/integration/api/SharedContext.java +++ b/test/apim-apk-agent-test/cucumber-tests/src/test/java/org/wso2/apk/integration/api/SharedContext.java @@ -33,12 +33,17 @@ public class SharedContext { private SimpleHTTPClient httpClient; private String publisherAccessToken; private String devportalAccessToken; - private String publisherBasicAuthToken; - private String devportalBasicAuthToken; + private String basicAuthToken; private HttpResponse response; private String responseBody; private String apiUUID; private String revisionUUID; + private String applicationUUID; + private String keyManagerUUID; + private String oauthKeyUUID; + private String consumerSecret; + private String consumerKey; + private String apiAccessToken; private HashMap valueStore = new HashMap<>(); private HashMap headers = new HashMap<>(); @@ -69,24 +74,14 @@ public void setDevportalAccessToken(String accessToken) { this.devportalAccessToken = accessToken; } - public String getPublisherBasicAuthToken() { + public String getBasicAuthToken() { - return publisherBasicAuthToken; + return basicAuthToken; } - public void setPublisherBasicAuthToken(String basicAuthToken) { + public void setBasicAuthToken(String basicAuthToken) { - this.publisherBasicAuthToken = basicAuthToken; - } - - public String getDevportalBasicAuthToken() { - - return devportalBasicAuthToken; - } - - public void setDevportalBasicAuthToken(String basicAuthToken) { - - this.devportalBasicAuthToken = basicAuthToken; + this.basicAuthToken = basicAuthToken; } public HttpResponse getResponse() { @@ -148,4 +143,64 @@ public void setRevisionUUID(String revisionUUID) { this.revisionUUID = revisionUUID; } + + public String getApplicationUUID() { + + return applicationUUID; + } + + public void setApplicationUUID(String applicationUUID) { + + this.applicationUUID = applicationUUID; + } + + public String getKeyManagerUUID() { + + return keyManagerUUID; + } + + public void setKeyManagerUUID(String keyManagerUUID) { + + this.keyManagerUUID = keyManagerUUID; + } + + public String getOauthKeyUUID() { + + return oauthKeyUUID; + } + + public void setOauthKeyUUID(String oauthKeyUUID) { + + this.oauthKeyUUID = oauthKeyUUID; + } + + public String getConsumerSecret() { + + return consumerSecret; + } + + public void setConsumerSecret(String consumerSecret) { + + this.consumerSecret = consumerSecret; + } + + public String getConsumerKey() { + + return consumerKey; + } + + public void setConsumerKey(String consumerKey) { + + this.consumerKey = consumerKey; + } + + public String getApiAccessToken() { + + return apiAccessToken; + } + + public void setApiAccessToken(String apiAccessToken) { + + this.apiAccessToken = apiAccessToken; + } } diff --git a/test/apim-apk-agent-test/cucumber-tests/src/test/java/org/wso2/apk/integration/utils/Constants.java b/test/apim-apk-agent-test/cucumber-tests/src/test/java/org/wso2/apk/integration/utils/Constants.java index bb26958e14..07905c3076 100644 --- a/test/apim-apk-agent-test/cucumber-tests/src/test/java/org/wso2/apk/integration/utils/Constants.java +++ b/test/apim-apk-agent-test/cucumber-tests/src/test/java/org/wso2/apk/integration/utils/Constants.java @@ -26,6 +26,7 @@ public class Constants { public static final String DEFAULT_DCR_EP = "client-registration/v0.17/register"; public static final String DEFAULT_API_CONFIGURATOR = "api/configurator/1.0.0/"; public static final String DEFAULT_API_DEPLOYER = "api/am/publisher/v4/"; + public static final String DEFAULT_DEVPORTAL = "api/am/devportal/v3/"; public static final String ACCESS_TOKEN = "accessToken"; public static final String EMPTY_STRING = ""; public static final String API_CREATE_SCOPE = "apk:api_create"; diff --git a/test/apim-apk-agent-test/cucumber-tests/src/test/java/org/wso2/apk/integration/utils/Utils.java b/test/apim-apk-agent-test/cucumber-tests/src/test/java/org/wso2/apk/integration/utils/Utils.java index 0023c1ea17..6b040e9460 100644 --- a/test/apim-apk-agent-test/cucumber-tests/src/test/java/org/wso2/apk/integration/utils/Utils.java +++ b/test/apim-apk-agent-test/cucumber-tests/src/test/java/org/wso2/apk/integration/utils/Utils.java @@ -36,6 +36,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; @@ -78,6 +79,41 @@ public static String getAPIRevisionURL(String apiUUID) { + Constants.DEFAULT_API_DEPLOYER + "apis/" + apiUUID + "/revisions"; } + public static String getAPIChangeLifecycleURL(String apiUUID) { + return "https://" + Constants.DEFAULT_API_HOST + ":" + Constants.DEFAULT_GW_PORT + "/" + + Constants.DEFAULT_API_DEPLOYER + "apis/change-lifecycle?action=Publish&apiId=" + apiUUID; + } + + public static String getApplicationCreateURL() { + return "https://" + Constants.DEFAULT_API_HOST + ":" + Constants.DEFAULT_GW_PORT + "/" + + Constants.DEFAULT_DEVPORTAL + "applications"; + } + + public static String getGenerateKeysURL(String applicationId) { + return "https://" + Constants.DEFAULT_API_HOST + ":" + Constants.DEFAULT_GW_PORT + "/" + + Constants.DEFAULT_DEVPORTAL + "applications/" + applicationId + "/generate-keys"; + } + + public static String getOauthKeysURL(String applicationId) { + return "https://" + Constants.DEFAULT_API_HOST + ":" + Constants.DEFAULT_GW_PORT + "/" + + Constants.DEFAULT_DEVPORTAL + "applications/" + applicationId + "/oauth-keys"; + } + + public static String getKeyManagerURL() { + return "https://" + Constants.DEFAULT_API_HOST + ":" + Constants.DEFAULT_GW_PORT + "/" + + Constants.DEFAULT_DEVPORTAL+ "key-managers"; + } + + public static String getSubscriptionURL() { + return "https://" + Constants.DEFAULT_API_HOST + ":" + Constants.DEFAULT_GW_PORT + "/" + + Constants.DEFAULT_DEVPORTAL + "subscriptions"; + } + + public static String getAccessTokenGenerationURL(String applicationId, String oauthKeyId) { + return "https://" + Constants.DEFAULT_API_HOST + ":" + Constants.DEFAULT_GW_PORT + "/" + + Constants.DEFAULT_DEVPORTAL + "applications/" + applicationId + "/oauth-keys/" + oauthKeyId + "/generate-token"; + } + public static String getAPIRevisionDeploymentURL(String apiUUID, String revisionId) { return "https://" + Constants.DEFAULT_API_HOST + ":" + Constants.DEFAULT_GW_PORT + "/" @@ -105,6 +141,72 @@ public static String extractID(String payload) throws IOException { } } + public static String extractApplicationID(String payload) throws IOException { + + JSONParser parser = new JSONParser(); + try { + // Parse the JSON string + JSONObject jsonObject = (JSONObject) parser.parse(payload); + + // Get the value of the "applicationId" attribute + String idValue = (String) jsonObject.get("applicationId"); + return idValue; + } catch (ParseException e) { + throw new IOException("Error while parsing the JSON payload: " + e.getMessage()); + } + } + + public static String extractKeyManagerID(String payload) throws IOException { + + JSONParser parser = new JSONParser(); + try { + // Parse the JSON string + JSONObject jsonObject = (JSONObject) parser.parse(payload); + + // Get the value of the "id" attribute + JSONArray idValue = (JSONArray)jsonObject.get("list"); + JSONObject keyManager = (JSONObject) idValue.get(0); + String keyManagerId = (String) keyManager.get("id"); + return keyManagerId; + } catch (ParseException e) { + throw new IOException("Error while parsing the JSON payload: " + e.getMessage()); + } + } + + public static String extractOAuthMappingID(String payload) throws IOException { + + JSONParser parser = new JSONParser(); + try { + // Parse the JSON string + JSONObject jsonObject = (JSONObject) parser.parse(payload); + + // Get the value of the "id" attribute + JSONArray idValue = (JSONArray)jsonObject.get("list"); + JSONObject keyManager = (JSONObject) idValue.get(0); + String keyManagerId = (String) keyManager.get("keyMappingId"); + return keyManagerId; + } catch (ParseException e) { + throw new IOException("Error while parsing the JSON payload: " + e.getMessage()); + } + } + + public static String extractKeys(String payload, String key) throws IOException { + + JSONParser parser = new JSONParser(); + try { + // Parse the JSON string + JSONObject jsonObject = (JSONObject) parser.parse(payload); + + // Get the value of the "applicationId" attribute + String idValue = (String) jsonObject.get(key); + return idValue; + } catch (ParseException e) { + throw new IOException("Error while parsing the JSON payload: " + e.getMessage()); + } + } + + + public static String extractToken(HttpResponse response) throws IOException { int responseCode = response.getStatusLine().getStatusCode(); diff --git a/test/apim-apk-agent-test/cucumber-tests/src/test/java/org/wso2/apk/integration/utils/clients/SimpleHTTPClient.java b/test/apim-apk-agent-test/cucumber-tests/src/test/java/org/wso2/apk/integration/utils/clients/SimpleHTTPClient.java index 4a3595646c..fcccd12763 100644 --- a/test/apim-apk-agent-test/cucumber-tests/src/test/java/org/wso2/apk/integration/utils/clients/SimpleHTTPClient.java +++ b/test/apim-apk-agent-test/cucumber-tests/src/test/java/org/wso2/apk/integration/utils/clients/SimpleHTTPClient.java @@ -75,7 +75,7 @@ public class SimpleHTTPClient { protected Log log = LogFactory.getLog(getClass()); private CloseableHttpClient client; private HttpUriRequest lastRequest; - private static final int EVENTUAL_SUCCESS_RESPONSE_TIMEOUT_IN_SECONDS = 10; + private static final int EVENTUAL_SUCCESS_RESPONSE_TIMEOUT_IN_SECONDS = 20; public SimpleHTTPClient() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException { diff --git a/test/apim-apk-agent-test/cucumber-tests/src/test/resources/testng.xml b/test/apim-apk-agent-test/cucumber-tests/src/test/resources/testng.xml index feff098cf4..959bf28869 100644 --- a/test/apim-apk-agent-test/cucumber-tests/src/test/resources/testng.xml +++ b/test/apim-apk-agent-test/cucumber-tests/src/test/resources/testng.xml @@ -17,7 +17,7 @@ --> - + diff --git a/test/apim-apk-agent-test/cucumber-tests/src/test/resources/tests/api/Deployment.feature b/test/apim-apk-agent-test/cucumber-tests/src/test/resources/tests/api/Deployment.feature index 45002e28f3..b97e0ba257 100644 --- a/test/apim-apk-agent-test/cucumber-tests/src/test/resources/tests/api/Deployment.feature +++ b/test/apim-apk-agent-test/cucumber-tests/src/test/resources/tests/api/Deployment.feature @@ -1,7 +1,8 @@ Feature: API Deployment - Scenario: Import an API + Background: Given The system is ready - And I have a DCR application for Publisher + Scenario: Import an API, Create Application, Generate Keys, Subscribe to an API + And I have a DCR application And I have a valid Publisher access token When I use the Payload file "artifacts/payloads/api1.json" And I use the OAS URL "https://petstore3.swagger.io/api/v3/openapi.json" @@ -10,16 +11,29 @@ Feature: API Deployment And the response body should contain "SwaggerPetstore" And make the API Revision Deployment request Then the response status code should be 201 + And make the Change Lifecycle request + Then the response status code should be 200 + And I have a valid Devportal access token + And make the Application Creation request + Then the response status code should be 201 + And the response body should contain "PetstoreApp" + And I have a KeyManager + And make the Generate Keys request + Then the response status code should be 200 + And the response body should contain "consumerKey" + And the response body should contain "consumerSecret" + And make the Subscription request + Then the response status code should be 201 + And the response body should contain "Gold" + And I get oauth keys for application + Then the response status code should be 200 + And make the Access Token Generation request + Then the response status code should be 200 + And the response body should contain "accessToken" + And I send "GET" request to "https://default.gw.wso2.com:9095/petstore/1.0.0/pet/5" with body "" + And I eventually receive 200 response code, not accepting + |429| -# Scenario: Deploying an API -# Given The system is ready -# And I have a valid subscription -# When I use the APK Conf file "artifacts/apk-confs/cors_API.apk-conf" -# And the definition file "artifacts/definitions/cors_api.yaml" -# And make the API deployment request -# Then the response status code should be 200 -# And the response body should contain "cors-api-adff3dbc-2787-11ee-be56-0242ac120002" -# # Scenario Outline: Undeploy an API # Given The system is ready # And I have a valid subscription