Search in sources :

Example 6 with KeyValidationInfo

use of org.wso2.micro.gateway.tests.common.KeyValidationInfo in project product-microgateway by wso2.

the class HTTP2RequestsWithHTTP2BackEndTestCase method setup.

@BeforeClass
public void setup() throws Exception {
    String label = "http2TestLabel";
    String project = "http2TestProject";
    // get mock APIM Instance
    MockAPIPublisher pub = MockAPIPublisher.getInstance();
    API api = new API();
    api.setName("PizzaShackAPI");
    api.setContext("/pizzashack");
    api.setEndpoint("https://localhost:8443");
    api.setVersion("1.0.0");
    api.setProvider("admin");
    // Register API with label
    pub.addApi(label, api);
    API api2 = new API();
    api2.setName("PizzaShackAPINew");
    api2.setContext("/pizzashack1");
    api2.setEndpoint(getMockServiceURLHttp("/echo"));
    api2.setVersion("2.0.0");
    api2.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");
    String configPath = "confs/http2-test.conf";
    super.init(label, project, configPath);
    jwtTokenProd = getJWT(api, application, "Unlimited", TestConstant.KEY_TYPE_PRODUCTION, 3600);
    boolean isOpen2 = Utils.isPortOpen(MOCK_HTTP2_SERVER_PORT);
    Assert.assertFalse(isOpen2, "Port: " + MOCK_HTTP2_SERVER_PORT + " already in use.");
    mockHttp2Server = new MockHttp2Server(MOCK_HTTP2_SERVER_PORT, true);
    mockHttp2Server.start();
}
Also used : MockHttp2Server(org.wso2.micro.gateway.tests.common.HTTP2Server.MockHttp2Server) 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 7 with KeyValidationInfo

use of org.wso2.micro.gateway.tests.common.KeyValidationInfo in project product-microgateway by wso2.

the class APIInvokeWithOAuthTestCase 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(2);
    // 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");
    info.setTokenType(TestConstant.KEY_TYPE_PRODUCTION);
    // 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.setTokenType(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);
    // generate apis with CLI and start the micro gateway server
    super.init(label, project);
}
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 8 with KeyValidationInfo

use of org.wso2.micro.gateway.tests.common.KeyValidationInfo in project product-microgateway by wso2.

the class DistributedThrottlingTestCase method start.

@BeforeClass
private void start() throws Exception {
    String label = "apimTestLabel";
    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));
    SubscriptionPolicy subscriptionPolicy = new SubscriptionPolicy();
    subscriptionPolicy.setPolicyName("10MinSubPolicy");
    subscriptionPolicy.setRequestCount(10);
    pub.addSubscriptionPolicy(subscriptionPolicy);
    SubscriptionPolicy subPolicyContinueOnLimit = new SubscriptionPolicy();
    subPolicyContinueOnLimit.setPolicyName("allowOnLimitExceed");
    subPolicyContinueOnLimit.setRequestCount(10);
    subPolicyContinueOnLimit.setStopOnQuotaReach(false);
    pub.addSubscriptionPolicy(subPolicyContinueOnLimit);
    ApplicationPolicy applicationPolicy = new ApplicationPolicy();
    applicationPolicy.setPolicyName("10MinAppPolicy");
    applicationPolicy.setRequestCount(10);
    pub.addApplicationPolicy(applicationPolicy);
    ApplicationDTO application2 = new ApplicationDTO();
    application2.setName("jwtApp2");
    application2.setTier(applicationPolicy.getPolicyName());
    application2.setId((int) (Math.random() * 1000));
    ApplicationDTO application3 = new ApplicationDTO();
    application3.setName("jwtApp3");
    application3.setTier("Unlimited");
    application3.setId((int) (Math.random() * 1000));
    // Register a token with key validation info
    jwtToken = getJWT(api, application, subscriptionPolicy.getPolicyName(), TestConstant.KEY_TYPE_PRODUCTION, 3600);
    jwtToken2 = getJWT(api, application2, "Unlimited", TestConstant.KEY_TYPE_PRODUCTION, 3600);
    continueOnQuotaToken = getJWT(api, application3, subPolicyContinueOnLimit.getPolicyName(), TestConstant.KEY_TYPE_PRODUCTION, 3600);
    KeyValidationInfo info = new KeyValidationInfo();
    info.setApi(api);
    info.setApplication(application);
    info.setAuthorized(true);
    info.setKeyType(TestConstant.KEY_TYPE_PRODUCTION);
    info.setSubscriptionTier(subscriptionPolicy.getPolicyName());
    info.setTokenType(TestConstant.TOKEN_TYPE_SUBSCRIPTION_THROTTLING);
    token1 = pub.getAndRegisterAccessToken(info);
    KeyValidationInfo info2 = new KeyValidationInfo();
    info2.setApi(api);
    info2.setApplication(application2);
    info2.setAuthorized(true);
    info2.setKeyType(TestConstant.KEY_TYPE_PRODUCTION);
    info2.setSubscriptionTier("Unlimited");
    info2.setTokenType(TestConstant.TOKEN_TYPE_APPLICATION_THROTTLING);
    token2 = pub.getAndRegisterAccessToken(info2);
    ApplicationDTO appWithNonExistPolicy = new ApplicationDTO();
    appWithNonExistPolicy.setName("appWithNonExistPolicy");
    appWithNonExistPolicy.setTier("AppPolicyNotExist");
    appWithNonExistPolicy.setId((int) (Math.random() * 1000));
    noSubPolicyJWT = getJWT(api, application, "SubPolicyNotExist", TestConstant.KEY_TYPE_PRODUCTION, 3600);
    noAppPolicyJWT = getJWT(api, appWithNonExistPolicy, "Unlimited", TestConstant.KEY_TYPE_PRODUCTION, 3600);
    KeyValidationInfo info3 = new KeyValidationInfo();
    info3.setApi(api);
    info3.setApplication(application);
    info3.setAuthorized(true);
    info3.setKeyType(TestConstant.KEY_TYPE_PRODUCTION);
    info3.setSubscriptionTier("SubPolicyNotExist");
    noSubPolicyToken = pub.getAndRegisterAccessToken(info3);
    info3.setApplication(appWithNonExistPolicy);
    info.setSubscriptionTier(subscriptionPolicy.getPolicyName());
    noAppPolicyToken = pub.getAndRegisterAccessToken(info3);
    binaryTestServer1 = new BinaryTestServer();
    binaryTestServer2 = new BinaryTestServer();
    String streamDefinition = readFromInputStream(getClass().getClassLoader().getResourceAsStream("distributedThrottling/stream-definition.json"));
    binaryTestServer1.addStreamDefinition(streamDefinition);
    binaryTestServer2.addStreamDefinition(streamDefinition);
    binaryTestServer1.startServer(9611, 9711);
    binaryTestServer2.startServer(9612, 9712);
    // generate apis with CLI and start the micro gateway server
    init(label, project);
}
Also used : ApplicationDTO(org.wso2.micro.gateway.tests.common.model.ApplicationDTO) SubscriptionPolicy(org.wso2.micro.gateway.tests.common.model.SubscriptionPolicy) ApplicationPolicy(org.wso2.micro.gateway.tests.common.model.ApplicationPolicy) 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 9 with KeyValidationInfo

use of org.wso2.micro.gateway.tests.common.KeyValidationInfo in project product-microgateway by wso2.

the class ThrottlingTestCase method start.

@BeforeClass
public void start() throws Exception {
    String label = "apimTestLabel";
    String project = "ThrottlingProject";
    // get mock APIM Instance
    MockAPIPublisher pub = MockAPIPublisher.getInstance();
    API api = new API();
    api.setName("PizzaShackAPI");
    api.setContext("/pizzashack");
    api.setEndpoint(getMockServiceURLHttp("/echo"));
    api.setVersion("1.0.0");
    api.setProvider("admin");
    // Register API with label
    pub.addApi(label, api);
    // Define application(Unlimited) info
    ApplicationDTO application = new ApplicationDTO();
    application.setName("jwtApp");
    application.setTier("Unlimited");
    application.setId((int) (Math.random() * 1000));
    ApplicationPolicy applicationPolicy = new ApplicationPolicy();
    applicationPolicy.setPolicyName("5MinAppPolicy");
    applicationPolicy.setRequestCount(5);
    pub.addApplicationPolicy(applicationPolicy);
    // Define 10req application
    ApplicationDTO application2 = new ApplicationDTO();
    application2.setName("jwtApp2");
    application2.setTier(applicationPolicy.getPolicyName());
    application2.setId((int) (Math.random() * 1000));
    SubscriptionPolicy subscriptionPolicy = new SubscriptionPolicy();
    subscriptionPolicy.setPolicyName("5MinSubPolicy");
    subscriptionPolicy.setRequestCount(5);
    pub.addSubscriptionPolicy(subscriptionPolicy);
    SubscriptionPolicy subPolicyContinueOnLimit = new SubscriptionPolicy();
    subPolicyContinueOnLimit.setPolicyName("allowOnLimitExceed");
    subPolicyContinueOnLimit.setRequestCount(10);
    subPolicyContinueOnLimit.setStopOnQuotaReach(false);
    pub.addSubscriptionPolicy(subPolicyContinueOnLimit);
    ApplicationDTO application3 = new ApplicationDTO();
    application3.setName("jwtApp3");
    application3.setTier("Unlimited");
    application3.setId((int) (Math.random() * 1000));
    // Register a token with key validation info
    jwtToken = getJWT(api, application, subscriptionPolicy.getPolicyName(), TestConstant.KEY_TYPE_PRODUCTION, 3600);
    jwtToken2 = getJWT(api, application2, "Unlimited", TestConstant.KEY_TYPE_PRODUCTION, 3600);
    continueOnQuotaToken = getJWT(api, application3, subPolicyContinueOnLimit.getPolicyName(), TestConstant.KEY_TYPE_PRODUCTION, 3600);
    KeyValidationInfo info = new KeyValidationInfo();
    info.setApi(api);
    info.setApplication(application);
    info.setAuthorized(true);
    info.setKeyType(TestConstant.KEY_TYPE_PRODUCTION);
    info.setTokenType(TestConstant.TOKEN_TYPE_5_MIN_SUB);
    info.setSubscriptionTier(subscriptionPolicy.getPolicyName());
    token1 = pub.getAndRegisterAccessToken(info);
    KeyValidationInfo info2 = new KeyValidationInfo();
    info2.setApi(api);
    info2.setApplication(application2);
    info2.setAuthorized(true);
    info2.setKeyType(TestConstant.KEY_TYPE_PRODUCTION);
    info2.setTokenType(TestConstant.TOKEN_TYPE_5_MIN_APP);
    info2.setSubscriptionTier("Unlimited");
    token2 = pub.getAndRegisterAccessToken(info2);
    ApplicationDTO appWithNonExistPolicy = new ApplicationDTO();
    appWithNonExistPolicy.setName("appWithNonExistPolicy");
    appWithNonExistPolicy.setTier("AppPolicyNotExist");
    appWithNonExistPolicy.setId((int) (Math.random() * 1000));
    noSubPolicyJWT = getJWT(api, application, "SubPolicyNotExist", TestConstant.KEY_TYPE_PRODUCTION, 3600);
    noAppPolicyJWT = getJWT(api, appWithNonExistPolicy, "Unlimited", TestConstant.KEY_TYPE_PRODUCTION, 3600);
    KeyValidationInfo info3 = new KeyValidationInfo();
    info3.setApi(api);
    info3.setApplication(application);
    info3.setAuthorized(true);
    info3.setKeyType(TestConstant.KEY_TYPE_PRODUCTION);
    info3.setSubscriptionTier("SubPolicyNotExist");
    info3.setTokenType(TestConstant.TOKEN_TYPE_INVALID_SUB_POLICY);
    noSubPolicyToken = pub.getAndRegisterAccessToken(info3);
    info3.setApplication(appWithNonExistPolicy);
    info3.setSubscriptionTier(subscriptionPolicy.getPolicyName());
    info3.setTokenType(TestConstant.TOKEN_TYPE_INVALID_APP_POLICY);
    noAppPolicyToken = pub.getAndRegisterAccessToken(info3);
    // generate apis with CLI and start the micro gateway server
    super.init(label, project);
}
Also used : ApplicationDTO(org.wso2.micro.gateway.tests.common.model.ApplicationDTO) SubscriptionPolicy(org.wso2.micro.gateway.tests.common.model.SubscriptionPolicy) ApplicationPolicy(org.wso2.micro.gateway.tests.common.model.ApplicationPolicy) 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)8 KeyValidationInfo (org.wso2.micro.gateway.tests.common.KeyValidationInfo)8 MockAPIPublisher (org.wso2.micro.gateway.tests.common.MockAPIPublisher)8 API (org.wso2.micro.gateway.tests.common.model.API)8 ApplicationDTO (org.wso2.micro.gateway.tests.common.model.ApplicationDTO)7 ApplicationPolicy (org.wso2.micro.gateway.tests.common.model.ApplicationPolicy)2 SubscriptionPolicy (org.wso2.micro.gateway.tests.common.model.SubscriptionPolicy)2 FileInputStream (java.io.FileInputStream)1 Cache (javax.cache.Cache)1 JSONObject (org.json.JSONObject)1 APIKeyValidationInfoDTO (org.wso2.carbon.apimgt.impl.dto.APIKeyValidationInfoDTO)1 MockHttp2Server (org.wso2.micro.gateway.tests.common.HTTP2Server.MockHttp2Server)1