Search in sources :

Example 1 with MockAPIPublisher

use of org.wso2.micro.gateway.tests.common.MockAPIPublisher 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 2 with MockAPIPublisher

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

the class AuthenticationFailureTestCase method setup.

@BeforeClass
public void setup() 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);
    String response = IOUtils.toString(new FileInputStream(getClass().getClassLoader().getResource("keyManager/invalid_subscription.xml").getPath()));
    KeyValidationInfo info = new KeyValidationInfo();
    info.setStringResponse(response);
    info.setTokenType(TestConstant.TOKEN_TYPE_INVALID_SUBSCRIPTION);
    invalidSubscriptionToken = pub.getAndRegisterAccessToken(info);
    String response1 = IOUtils.toString(new FileInputStream(getClass().getClassLoader().getResource("keyManager/unauthorized.xml").getPath()));
    KeyValidationInfo info1 = new KeyValidationInfo();
    info1.setTokenType(TestConstant.TOKEN_TYPE_INVALID_SCOPES);
    info1.setStringResponse(response1);
    invalidScopeToken = pub.getAndRegisterAccessToken(info1);
    KeyValidationInfo info2 = new KeyValidationInfo();
    info2.setTokenType(TestConstant.TOKEN_TYPE_NO_CLIENT_ID);
    info2.setStringResponse(response1);
    noClientIdToken = pub.getAndRegisterAccessToken(info2);
    String configPath = "confs/mutualSSL-test.conf";
    super.init(label, project, configPath);
}
Also used : 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) FileInputStream(java.io.FileInputStream) BeforeClass(org.testng.annotations.BeforeClass)

Example 3 with MockAPIPublisher

use of org.wso2.micro.gateway.tests.common.MockAPIPublisher 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 4 with MockAPIPublisher

use of org.wso2.micro.gateway.tests.common.MockAPIPublisher 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)

Example 5 with MockAPIPublisher

use of org.wso2.micro.gateway.tests.common.MockAPIPublisher 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)

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 JSONObject (org.json.JSONObject)1 MockHttp2Server (org.wso2.micro.gateway.tests.common.HTTP2Server.MockHttp2Server)1