From 6fb607cccfb8a2991372efad4570c3b551c38393 Mon Sep 17 00:00:00 2001 From: Tharsanan1 Date: Mon, 16 Oct 2023 13:45:20 +0530 Subject: [PATCH] Add test --- .../server/RevokedTokenRedisClient.java | 4 --- .../common-controller-web-server-service.yaml | 4 +-- .../gateway-components/common-log-conf.yaml | 2 +- test/cucumber-tests/scripts/setup-hosts.sh | 1 + .../wso2/apk/integration/api/BaseSteps.java | 8 +++-- .../resources/tests/api/RevokedToken.feature | 34 +++++++++++++++++++ 6 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 test/cucumber-tests/src/test/resources/tests/api/RevokedToken.feature diff --git a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/server/RevokedTokenRedisClient.java b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/server/RevokedTokenRedisClient.java index 9918cef1a0..91c26e142c 100644 --- a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/server/RevokedTokenRedisClient.java +++ b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/server/RevokedTokenRedisClient.java @@ -244,8 +244,4 @@ private static SSLSocketFactory createSslSocketFactory(String redisCaCertPath) t } } - public static void main(String[] args) throws EnforcerException { - retrieveAndSubscribe(); - } - } diff --git a/helm-charts/templates/data-plane/gateway-components/common-controller/common-controller-web-server-service.yaml b/helm-charts/templates/data-plane/gateway-components/common-controller/common-controller-web-server-service.yaml index 859d309906..a51c9d2388 100644 --- a/helm-charts/templates/data-plane/gateway-components/common-controller/common-controller-web-server-service.yaml +++ b/helm-charts/templates/data-plane/gateway-components/common-controller/common-controller-web-server-service.yaml @@ -27,6 +27,6 @@ spec: ports: - name: web-server protocol: TCP - port: 8443 - targetPort: 8443 + port: 9543 + targetPort: 9543 {{- end -}} diff --git a/helm-charts/templates/data-plane/gateway-components/common-log-conf.yaml b/helm-charts/templates/data-plane/gateway-components/common-log-conf.yaml index a1aa824ecb..098cd0bf6e 100644 --- a/helm-charts/templates/data-plane/gateway-components/common-log-conf.yaml +++ b/helm-charts/templates/data-plane/gateway-components/common-log-conf.yaml @@ -36,6 +36,6 @@ data: authKeyHeader = "stsAuthKey" [commoncontroller.webServer] - port = 8443 + port = 9543 {{- end -}} diff --git a/test/cucumber-tests/scripts/setup-hosts.sh b/test/cucumber-tests/scripts/setup-hosts.sh index 8eb4dc657e..bb49d699c4 100644 --- a/test/cucumber-tests/scripts/setup-hosts.sh +++ b/test/cucumber-tests/scripts/setup-hosts.sh @@ -10,6 +10,7 @@ kubectl wait --timeout=15m -n apk-integration-test deployment/apk-test-setup-wso IP=$(kubectl get svc apk-test-setup-wso2-apk-gateway-service -n apk-integration-test --output jsonpath='{.status.loadBalancer.ingress[0].ip}') sudo echo "$IP localhost" | sudo tee -a /etc/hosts sudo echo "$IP idp.am.wso2.com" | sudo tee -a /etc/hosts +sudo echo "$IP apk-test-setup-wso2-apk-common-controller-service.apk-integration-test.svc" | sudo tee -a /etc/hosts sudo echo "$IP api.am.wso2.com" | sudo tee -a /etc/hosts sudo echo "$IP default.gw.wso2.com" | sudo tee -a /etc/hosts sudo echo "$IP org1.gw.wso2.com" | sudo tee -a /etc/hosts diff --git a/test/cucumber-tests/src/test/java/org/wso2/apk/integration/api/BaseSteps.java b/test/cucumber-tests/src/test/java/org/wso2/apk/integration/api/BaseSteps.java index bb2673f86c..4938e8534d 100644 --- a/test/cucumber-tests/src/test/java/org/wso2/apk/integration/api/BaseSteps.java +++ b/test/cucumber-tests/src/test/java/org/wso2/apk/integration/api/BaseSteps.java @@ -118,6 +118,7 @@ public void theResponseStatusCodeShouldBe(int expectedStatusCode) throws IOExcep @Then("I send {string} request to {string} with body {string}") public void sendHttpRequest(String httpMethod, String url, String body) throws IOException { + body = Utils.resolveVariables(body, sharedContext.getValueStore()); if (sharedContext.getResponse() instanceof CloseableHttpResponse) { ((CloseableHttpResponse) sharedContext.getResponse()).close(); } @@ -141,6 +142,7 @@ public void sendHttpRequest(String httpMethod, String url, String body) throws I // It will send request using a new thread and forget about the response @Then("I send {string} async request to {string} with body {string}") public void sendAsyncHttpRequest(String httpMethod, String url, String body) throws IOException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { + String finalBody = Utils.resolveVariables(body, sharedContext.getValueStore()); if (sharedContext.getResponse() instanceof CloseableHttpResponse) { ((CloseableHttpResponse) sharedContext.getResponse()).close(); } @@ -150,11 +152,11 @@ public void sendAsyncHttpRequest(String httpMethod, String url, String body) thr if (CurlOption.HttpMethod.GET.toString().toLowerCase().equals(httpMethod.toLowerCase())) { simpleHTTPClient.doGet(url, sharedContext.getHeaders()); } else if (CurlOption.HttpMethod.POST.toString().toLowerCase().equals(httpMethod.toLowerCase())) { - simpleHTTPClient.doPost(url, sharedContext.getHeaders(), body, null); + simpleHTTPClient.doPost(url, sharedContext.getHeaders(), finalBody, null); } else if (CurlOption.HttpMethod.PUT.toString().toLowerCase().equals(httpMethod.toLowerCase())) { - simpleHTTPClient.doPut(url, sharedContext.getHeaders(), body, null); + simpleHTTPClient.doPut(url, sharedContext.getHeaders(), finalBody, null); } else if (CurlOption.HttpMethod.DELETE.toString().toLowerCase().equals(httpMethod.toLowerCase())) { - simpleHTTPClient.doPut(url, sharedContext.getHeaders(), body, null); + simpleHTTPClient.doPut(url, sharedContext.getHeaders(), finalBody, null); } else if (CurlOption.HttpMethod.OPTIONS.toString().toLowerCase().equals(httpMethod.toLowerCase())) { simpleHTTPClient.doOptions(url, sharedContext.getHeaders(), null, null); } diff --git a/test/cucumber-tests/src/test/resources/tests/api/RevokedToken.feature b/test/cucumber-tests/src/test/resources/tests/api/RevokedToken.feature new file mode 100644 index 0000000000..3efca46b7e --- /dev/null +++ b/test/cucumber-tests/src/test/resources/tests/api/RevokedToken.feature @@ -0,0 +1,34 @@ +Feature: Token revocation + Scenario: Testing token revocation + Given The system is ready + And I have a valid subscription + When I use the APK Conf file "artifacts/apk-confs/jwt_basic_conf.yaml" + And the definition file "artifacts/definitions/employees_api.json" + And make the API deployment request + Then the response status code should be 200 + Then I set headers + |Authorization|bearer ${accessToken}| + And I send "GET" request to "https://default.gw.wso2.com:9095/jwt-basic/3.14/employee/" with body "" + And I eventually receive 200 response code, not accepting + |429| + |401| + Then I set headers + |stsAuthKey|2jrmypak391zsqz974ugdddebf812ofx1b9t1oq27530ir02tc815eemrx435qvcp41ucgy7v5uuawzi4qcmjrx0k1zgox2s28cr| + And I send "GET" request to "https://default.gw.wso2.com:9095/jwt-basic/3.14/employee/" with body "" + And the response status code should be 200 + And I send "POST" request to "https://apk-test-setup-wso2-apk-common-controller-service.apk-integration-test.svc:9543/revoke" with body "{\"token\": \"${accessToken}\"}" + And the response status code should be 200 + And I wait for 5 seconds + And I send "GET" request to "https://default.gw.wso2.com:9095/jwt-basic/3.14/employee/" with body "" + And the response status code should be 401 + + + Scenario Outline: Undeploy API + Given The system is ready + And I have a valid subscription + When I undeploy the API whose ID is "" + Then the response status code should be + + Examples: + | apiID | expectedStatusCode | + | jwt-basic-test | 202 |