Search in sources :

Example 1 with KeyValidationInfo

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

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

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

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

use of org.wso2.micro.gateway.tests.common.KeyValidationInfo in project carbon-apimgt by wso2.

the class APIKeyMgtUtil method getFromKeyManagerCache.

/**
 * Get the KeyValidationInfo object from cache, for a given cache-Key
 *
 * @param cacheKey Key for the Cache Entry
 * @return APIKeyValidationInfoDTO
 * @throws APIKeyMgtException
 */
public static APIKeyValidationInfoDTO getFromKeyManagerCache(String cacheKey) {
    APIKeyValidationInfoDTO info = null;
    boolean cacheEnabledKeyMgt = APIKeyMgtDataHolder.getKeyCacheEnabledKeyMgt();
    Cache cache = getKeyManagerCache();
    // We only fetch from cache if KeyMgtValidationInfoCache is enabled.
    if (cacheEnabledKeyMgt) {
        info = (APIKeyValidationInfoDTO) cache.get(cacheKey);
        // If key validation information is not null then only we proceed with cached object
        if (info != null) {
            if (log.isDebugEnabled()) {
                log.debug("Found cached access token for : " + cacheKey + ".");
            }
        }
    }
    return info;
}
Also used : APIKeyValidationInfoDTO(org.wso2.carbon.apimgt.impl.dto.APIKeyValidationInfoDTO) Cache(javax.cache.Cache)

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