Skip to content

Commit

Permalink
Fix test cases with scope
Browse files Browse the repository at this point in the history
  • Loading branch information
chashikajw committed Oct 16, 2023
1 parent 7024a8e commit bdf318b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,19 @@ public void iHaveValidSubscription() throws Exception {
headers.put(Constants.REQUEST_HEADERS.HOST, Constants.DEFAULT_IDP_HOST);
headers.put(Constants.REQUEST_HEADERS.AUTHORIZATION, "Basic NDVmMWM1YzgtYTkyZS0xMWVkLWFmYTEtMDI0MmFjMTIwMDAyOjRmYmQ2MmVjLWE5MmUtMTFlZC1hZmExLTAyNDJhYzEyMDAwMg==");

HttpResponse httpResponse = httpClient.doPost(Utils.getTokenEndpointURL(), headers, "grant_type=client_credentials&scope=" + Constants.API_CREATE_SCOPE,
Constants.CONTENT_TYPES.APPLICATION_X_WWW_FORM_URLENCODED);
sharedContext.setAccessToken(Utils.extractToken(httpResponse));
sharedContext.addStoreValue("accessToken", sharedContext.getAccessToken());
}

@Given("I have a valid subscription without api deploy/undeploy permission")
public void iHaveValidSubscriptionWithAPICreateScope() throws Exception {

Map<String, String> headers = new HashMap<>();
headers.put(Constants.REQUEST_HEADERS.HOST, Constants.DEFAULT_IDP_HOST);
headers.put(Constants.REQUEST_HEADERS.AUTHORIZATION, "Basic NDVmMWM1YzgtYTkyZS0xMWVkLWFmYTEtMDI0MmFjMTIwMDAyOjRmYmQ2MmVjLWE5MmUtMTFlZC1hZmExLTAyNDJhYzEyMDAwMg==");

HttpResponse httpResponse = httpClient.doPost(Utils.getTokenEndpointURL(), headers, "grant_type=client_credentials",
Constants.CONTENT_TYPES.APPLICATION_X_WWW_FORM_URLENCODED);
sharedContext.setAccessToken(Utils.extractToken(httpResponse));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import java.util.Date;
import java.util.UUID;

import org.wso2.apk.integration.utils.Constants;

public class JWTGeneratorSteps {

private final SharedContext sharedContext;
Expand All @@ -47,7 +49,7 @@ public void generateTokenFromIdp1(String kid) throws IOException, CertificateExc
.expirationTime(new Date(new Date().getTime() + 60 * 1000))
.jwtID(UUID.randomUUID().toString())
.claim("azp", UUID.randomUUID().toString())
.claim("scope", "default")
.claim("scope", Constants.API_CREATE_SCOPE)
.build();
SignedJWT signedJWT = new SignedJWT(
new JWSHeader.Builder(JWSAlgorithm.RS256).keyID(kid).build(),
Expand All @@ -74,7 +76,7 @@ public void generateTokenFromIdp1WithOrganization(String organization) throws IO
.expirationTime(new Date(new Date().getTime() + 60 * 1000))
.jwtID(UUID.randomUUID().toString())
.claim("azp", UUID.randomUUID().toString())
.claim("scope", "default")
.claim("scope", Constants.API_CREATE_SCOPE)
.claim("organization", organization)
.build();
SignedJWT signedJWT = new SignedJWT(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class Constants {
public static final String DEFAULT_API_DEPLOYER = "api/deployer/1.0.0/";
public static final String ACCESS_TOKEN = "accessToken";
public static final String EMPTY_STRING = "";
public static final String API_CREATE_SCOPE = "apk:api_create";
public static final String SPACE_STRING = " ";
public static final String SUBSCRIPTION_BASIC_AUTH_TOKEN =
"Basic NDVmMWM1YzgtYTkyZS0xMWVkLWFmYTEtMDI0MmFjMTIwMDAyOjRmYmQ2MmVjLWE5MmUtMTFlZC1hZmExLTAyNDJhYzEyMDAwMg==";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
Feature: API Deployment
Scenario: Deploying an API without api create scope
Given The system is ready
And I have a valid subscription without api deploy/undeploy permission
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 403

Scenario: Deploying an API
Given The system is ready
And I have a valid subscription
Expand All @@ -17,6 +25,12 @@ Feature: API Deployment
Then the response status code should be 400
And the response body should contain
|"#/corsConfiguration/corsConfigurationEnabled: expected type: Boolean, found: String"|

Scenario Outline: Undeploy an API without api create scope
Given The system is ready
And I have a valid subscription without api deploy/undeploy permission
When I undeploy the API whose ID is "<apiID>"
Then the response status code should be 403

Scenario Outline: Undeploy an API
Given The system is ready
Expand Down

0 comments on commit bdf318b

Please sign in to comment.