Search in sources :

Example 21 with ApplicationDTO

use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationDTO in project product-microgateway by wso2.

the class EtcdSupportTestCase method start.

@BeforeClass
public void start() throws Exception {
    String label = "etcdLabel";
    String project = "etcdProject";
    // get mock APIM Instance
    MockAPIPublisher pub = MockAPIPublisher.getInstance();
    API api = new API();
    api.setName("PizzaShackAPI");
    api.setContext("/pizzashack");
    api.setProdEndpoint(getMockServiceURLHttp("/echo/prod"));
    api.setSandEndpoint(getMockServiceURLHttp("/echo/sand"));
    api.setVersion("1.0.0");
    api.setProvider("admin");
    // Register API with label
    pub.addApi(label, api);
    // Define application info
    ApplicationDTO application = new ApplicationDTO();
    application.setName("jwtApp");
    application.setTier("Unlimited");
    application.setId((int) (Math.random() * 1000));
    // Register a production token with key validation info
    KeyValidationInfo info = new KeyValidationInfo();
    info.setApi(api);
    info.setApplication(application);
    info.setAuthorized(true);
    info.setKeyType(TestConstant.KEY_TYPE_PRODUCTION);
    info.setSubscriptionTier("Unlimited");
    jwtTokenProd = getJWT(api, application, "Unlimited", TestConstant.KEY_TYPE_PRODUCTION, 3600);
    jwtTokenSand = getJWT(api, application, "Unlimited", TestConstant.KEY_TYPE_SANDBOX, 3600);
    encodeValuesToBase64();
    prepareConfigValues();
    prepareCLIParameters();
    initializeEtcdServer();
    String[] args = { etcdUrlParameter, etcdUsernameParameter, etcdPasswordParameter, pizzaShackProdParameter, pizzaShackSandParameter, etcdTimerParameter, etcdBasePathParameter };
    super.init(project, new String[] { "serviceDiscovery/etcd_test.yaml" }, args);
}
Also used : ApplicationDTO(org.wso2.micro.gateway.tests.common.model.ApplicationDTO) API(org.wso2.micro.gateway.tests.common.model.API) MockAPIPublisher(org.wso2.micro.gateway.tests.common.MockAPIPublisher) KeyValidationInfo(org.wso2.micro.gateway.tests.common.KeyValidationInfo) BeforeClass(org.testng.annotations.BeforeClass)

Example 22 with ApplicationDTO

use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationDTO in project product-microgateway by wso2.

the class CookieAuthTestCase method start.

@BeforeClass
public void start() throws Exception {
    String label = "apimTestLabel";
    String project = "apimTestProject";
    // get mock APIM Instance
    MockAPIPublisher pub = MockAPIPublisher.getInstance();
    API api = new API();
    api.setName("PizzaShackAPI");
    api.setContext("/pizzashack");
    api.setProdEndpoint(getMockServiceURLHttp("/echo/prod"));
    api.setSandEndpoint(getMockServiceURLHttp("/echo/sand"));
    api.setVersion("1.0.0");
    api.setProvider("admin");
    // Register API with label
    pub.addApi(label, api);
    // Define application info
    ApplicationDTO application = new ApplicationDTO();
    application.setName("jwtApp");
    application.setTier("Unlimited");
    application.setId((int) (Math.random() * 1000));
    // Register a production token with key validation info
    KeyValidationInfo info = new KeyValidationInfo();
    info.setApi(api);
    info.setApplication(application);
    info.setAuthorized(true);
    info.setKeyType(TestConstant.KEY_TYPE_PRODUCTION);
    info.setSubscriptionTier("Unlimited");
    // Register a production token with key validation info
    prodToken = pub.getAndRegisterAccessToken(info);
    // Register a sandbox token with key validation info
    KeyValidationInfo infoSand = new KeyValidationInfo();
    infoSand.setApi(api);
    infoSand.setApplication(application);
    infoSand.setAuthorized(true);
    infoSand.setKeyType(TestConstant.KEY_TYPE_SANDBOX);
    infoSand.setSubscriptionTier("Unlimited");
    sandToken = pub.getAndRegisterAccessToken(infoSand);
    jwtTokenProd = getJWT(api, application, "Unlimited", TestConstant.KEY_TYPE_PRODUCTION, 3600);
    jwtTokenSand = getJWT(api, application, "Unlimited", TestConstant.KEY_TYPE_SANDBOX, 3600);
    expiringJwtTokenProd = getJWT(api, application, "Unlimited", TestConstant.KEY_TYPE_PRODUCTION, 1);
    String configPath = "confs/default-test-config.conf";
    String cookie;
    if (Utils.getOSName().toLowerCase().contains("windows")) {
        cookie = "--Cookie=\"" + jwtTokenProd + "\"";
    } else {
        cookie = "--Cookie=" + jwtTokenProd;
    }
    String[] args = { cookie };
    super.init(label, project, args, configPath);
}
Also used : ApplicationDTO(org.wso2.micro.gateway.tests.common.model.ApplicationDTO) API(org.wso2.micro.gateway.tests.common.model.API) MockAPIPublisher(org.wso2.micro.gateway.tests.common.MockAPIPublisher) KeyValidationInfo(org.wso2.micro.gateway.tests.common.KeyValidationInfo) BeforeClass(org.testng.annotations.BeforeClass)

Example 23 with ApplicationDTO

use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationDTO in project product-microgateway by wso2.

the class ScopesTestCase method start.

@BeforeClass
public void start() throws Exception {
    String project = "scopesProject";
    // Define application info
    ApplicationDTO application = new ApplicationDTO();
    application.setName("jwtApp");
    application.setTier("Unlimited");
    application.setId((int) (Math.random() * 1000));
    jwtTokenProd = TokenUtil.getBasicJWT(application, new JSONObject(), TestConstant.KEY_TYPE_PRODUCTION, 3600);
    Map<String, String> claimMap = new HashMap<>();
    claimMap.put("scope", "write:pets");
    jwtTokenProdWithScopes = TokenUtil.getJwtWithCustomClaims(application, new JSONObject(), TestConstant.KEY_TYPE_PRODUCTION, 3600, claimMap);
    claimMap.put("scope", "write:petsNew");
    jwtTokenProdWithSingleScope = TokenUtil.getJwtWithCustomClaims(application, new JSONObject(), TestConstant.KEY_TYPE_PRODUCTION, 3600, claimMap);
    claimMap.put("scope", "write:petsNew read:pets");
    jwtTokenProdWithMultipleScope = TokenUtil.getJwtWithCustomClaims(application, new JSONObject(), TestConstant.KEY_TYPE_PRODUCTION, 3600, claimMap);
    basicAuthToken = generateBasicAuthToken("generalUser1", "password");
    basicAuthTokenWithSingleScope = generateBasicAuthToken("generalUser2", "password");
    basicAuthTokenWithMultipleScopes = generateBasicAuthToken("generalUser3", "password");
    basicAuthTokenWithScopes = generateBasicAuthToken("generalUser4", "password");
    // generate apis with CLI and start the micro gateway server
    super.init(project, new String[] { "common_api.yaml", "security/disable_security.yaml" });
}
Also used : ApplicationDTO(org.wso2.micro.gateway.tests.common.model.ApplicationDTO) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) BeforeClass(org.testng.annotations.BeforeClass)

Example 24 with ApplicationDTO

use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationDTO in project product-microgateway by wso2.

the class JWTGenerationTestCase method start.

@BeforeClass
public void start() throws Exception {
    String project = "jwtGeneratorProject";
    // Define application info
    ApplicationDTO application = new ApplicationDTO();
    application.setName("jwtApp");
    application.setTier("Unlimited");
    application.setId((int) (Math.random() * 1000));
    // Create map with custom claims
    Map<String, String> customClaims = new HashMap<>();
    customClaims.put("claim1", "testValue1");
    customClaims.put("claim2", "testValue2");
    jwtTokenProd = TokenUtil.getJwtWithCustomClaims(application, new JSONObject(), TestConstant.KEY_TYPE_PRODUCTION, 3600, customClaims);
    // Create map with backendJwt claim
    Map<String, String> jwtClaim = new HashMap<>();
    jwtClaim.put("backendJwt", jwtTokenProd);
    jwtWithBackendJwtClaim = TokenUtil.getJwtWithCustomClaims(application, new JSONObject(), TestConstant.KEY_TYPE_PRODUCTION, 3600, jwtClaim);
    // generate apis with CLI and start the micro gateway server
    super.init(project, new String[] { "jwtGeneration/jwt_generation.yaml", "mgw-JwtGenerator.jar" }, null, "confs/jwt-generator-test-config.conf");
}
Also used : ApplicationDTO(org.wso2.micro.gateway.tests.common.model.ApplicationDTO) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) BeforeClass(org.testng.annotations.BeforeClass)

Example 25 with ApplicationDTO

use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationDTO in project product-microgateway by wso2.

the class JWTRevocationSupportTestCase method start.

@BeforeClass
public void start() throws Exception {
    initializeEtcdServer();
    String configPath = "";
    String label = "apimTestLabel";
    String project = "apimTestProject";
    // get mock APIM Instance
    MockAPIPublisher pub = MockAPIPublisher.getInstance();
    API api = new API();
    api.setName("PizzaShackAPI");
    api.setContext("/pizzashack");
    api.setProdEndpoint(getMockServiceURLHttp("/echo/prod"));
    api.setSandEndpoint(getMockServiceURLHttp("/echo/sand"));
    api.setVersion("1.0.0");
    api.setProvider("admin");
    // Register API with label
    pub.addApi(label, api);
    // Define application info
    ApplicationDTO application = new ApplicationDTO();
    application.setName("jwtApp");
    application.setTier("Unlimited");
    application.setId((int) (Math.random() * 1000));
    // Register a production token with key validation info
    KeyValidationInfo info = new KeyValidationInfo();
    info.setApi(api);
    info.setApplication(application);
    info.setAuthorized(true);
    info.setKeyType(TestConstant.KEY_TYPE_PRODUCTION);
    info.setSubscriptionTier("Unlimited");
    // Generate the relevant JWT tokens
    jwtTokenProd = getJWT(api, application, "Unlimited", TestConstant.KEY_TYPE_PRODUCTION, 3600);
    // Extract the JWT token
    int firstDotSeparatorIndex = jwtTokenProd.indexOf('.');
    int secondSeparatorIndex = jwtTokenProd.indexOf('.', firstDotSeparatorIndex + 1);
    String JWTToken = jwtTokenProd.substring(firstDotSeparatorIndex + 1, secondSeparatorIndex);
    byte[] decodedJwt = Base64.decodeBase64(JWTToken.getBytes());
    JSONObject jsonObject = new JSONObject(new String(decodedJwt));
    jti = jsonObject.get("jti").toString();
    // prepareConfigValues();
    // uncomment to run this test case only
    // Initialize the JMS message broker
    // broker = new EmbeddedBroker();
    // startMessageBroker();
    configPath = "confs/default-test-config.conf";
    super.init(label, project, configPath);
    // Send Extracted JTI to the jwtRevocation Topic
    publishMessage();
}
Also used : ApplicationDTO(org.wso2.micro.gateway.tests.common.model.ApplicationDTO) JSONObject(org.json.JSONObject) API(org.wso2.micro.gateway.tests.common.model.API) MockAPIPublisher(org.wso2.micro.gateway.tests.common.MockAPIPublisher) KeyValidationInfo(org.wso2.micro.gateway.tests.common.KeyValidationInfo) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

BeforeClass (org.testng.annotations.BeforeClass)17 ApplicationDTO (org.wso2.micro.gateway.tests.common.model.ApplicationDTO)17 Application (org.wso2.carbon.apimgt.core.models.Application)11 ApplicationDTO (org.wso2.carbon.apimgt.rest.api.store.dto.ApplicationDTO)11 ArrayList (java.util.ArrayList)10 JSONObject (org.json.JSONObject)10 HashMap (java.util.HashMap)9 Application (org.wso2.carbon.apimgt.api.model.Application)8 API (org.wso2.micro.gateway.tests.common.model.API)8 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)7 ExportedApplication (org.wso2.carbon.apimgt.rest.api.store.v1.models.ExportedApplication)7 KeyValidationInfo (org.wso2.micro.gateway.tests.common.KeyValidationInfo)7 MockAPIPublisher (org.wso2.micro.gateway.tests.common.MockAPIPublisher)7 Test (org.junit.Test)6 APIConsumer (org.wso2.carbon.apimgt.api.APIConsumer)6 ApplicationKeysDTO (org.wso2.carbon.apimgt.rest.api.store.dto.ApplicationKeysDTO)6 ApplicationDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationDTO)6 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)5 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)5 ApplicationCreationResponse (org.wso2.carbon.apimgt.core.workflow.ApplicationCreationResponse)5