Search in sources :

Example 6 with ModelKeyManagerForTest

use of org.wso2.carbon.apimgt.impl.factory.ModelKeyManagerForTest in project carbon-apimgt by wso2.

the class AbstractKeyManagerTestCase method testCanHandleTokenWithConfigurationJWT.

@Test
public void testCanHandleTokenWithConfigurationJWT() throws APIManagementException {
    KeyManagerConfiguration keyManagerConfiguration = new KeyManagerConfiguration();
    keyManagerConfiguration.addParameter(APIConstants.KeyManager.TOKEN_FORMAT_STRING, "[{\"enable\": true,\"type\": \"JWT\",\"value\": {\"body\": {\"iss\": \"https://localhost:9443\"}}}]");
    KeyManager keyManager = new ModelKeyManagerForTest();
    keyManager.loadConfiguration(keyManagerConfiguration);
    assertTrue(keyManager.canHandleToken("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9" + ".eyJpc3MiOiJodHRwczovL2xvY2FsaG9zdDo5NDQzIiwiaWF0IjoxNTkwMTM0NzIyLCJleHAiOjE2MjE2NzA3MjAsImF1ZC" + "I6Ind3dy5leGFtcGxlLmNvbSIsInN1YiI6Impyb2NrZXRAZXhhbXBsZS5jb20iLCJFbWFpbCI6ImJlZUBleGFtcGxlLmNvb" + "SJ9.HIxL7_WqeLPkxYdROAwRyL0YEY1YNJRfLghsaHEc7C4"));
    assertFalse(keyManager.canHandleToken("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL2xvY2FsaG9zdDo5NDQ0IiwiaWF0IjoxN" + "TkwMTM0NzIyLCJleHAiOjE2MjE2NzA3MjAsImF1ZCI6Ind3dy5leGFtcGxlLmNvbSIsInN1YiI6Impyb2NrZXRAZXhhb" + "XBsZS5jb20iLCJFbWFpbCI6ImJlZUBleGFtcGxlLmNvbSJ9.QjwcCl7Xs0zmioqsr85VQmW5lgRnkfba-v8OgKwhKyA"));
}
Also used : ModelKeyManagerForTest(org.wso2.carbon.apimgt.impl.factory.ModelKeyManagerForTest) KeyManager(org.wso2.carbon.apimgt.api.model.KeyManager) KeyManagerConfiguration(org.wso2.carbon.apimgt.api.model.KeyManagerConfiguration) Test(org.junit.Test) ModelKeyManagerForTest(org.wso2.carbon.apimgt.impl.factory.ModelKeyManagerForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 7 with ModelKeyManagerForTest

use of org.wso2.carbon.apimgt.impl.factory.ModelKeyManagerForTest in project carbon-apimgt by wso2.

the class AbstractKeyManagerTestCase method testCanHandleToken.

@Test
public void testCanHandleToken() throws APIManagementException {
    KeyManagerConfiguration keyManagerConfiguration = new KeyManagerConfiguration();
    KeyManager keyManager = new ModelKeyManagerForTest();
    keyManager.loadConfiguration(keyManagerConfiguration);
    assertTrue(keyManager.canHandleToken(UUID.randomUUID().toString()));
}
Also used : ModelKeyManagerForTest(org.wso2.carbon.apimgt.impl.factory.ModelKeyManagerForTest) KeyManager(org.wso2.carbon.apimgt.api.model.KeyManager) KeyManagerConfiguration(org.wso2.carbon.apimgt.api.model.KeyManagerConfiguration) Test(org.junit.Test) ModelKeyManagerForTest(org.wso2.carbon.apimgt.impl.factory.ModelKeyManagerForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 8 with ModelKeyManagerForTest

use of org.wso2.carbon.apimgt.impl.factory.ModelKeyManagerForTest in project carbon-apimgt by wso2.

the class AbstractKeyManagerTestCase method testCanHandleTokenWithConfigurationJWTAndOpaue.

@Test
public void testCanHandleTokenWithConfigurationJWTAndOpaue() throws APIManagementException {
    KeyManagerConfiguration keyManagerConfiguration = new KeyManagerConfiguration();
    keyManagerConfiguration.addParameter(APIConstants.KeyManager.TOKEN_FORMAT_STRING, "[{\"enable\": true,\"type\": \"JWT\",\"value\": {\"body\": {\"iss\": \"https://localhost:9443\"}}}," + "{\"enable\": true,\"type\": \"REFERENCE\",\"value\": \"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0" + "-9a-fA-F]{3}-[89ab][0-9a-fA-F]{3}-[0-9a-fA-F]{12}\"}]");
    KeyManager keyManager = new ModelKeyManagerForTest();
    keyManager.loadConfiguration(keyManagerConfiguration);
    assertTrue(keyManager.canHandleToken("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9" + ".eyJpc3MiOiJodHRwczovL2xvY2FsaG9zdDo5NDQzIiwiaWF0IjoxNTkwMTM0NzIyLCJleHAiOjE2MjE2NzA3MjAsImF1ZC" + "I6Ind3dy5leGFtcGxlLmNvbSIsInN1YiI6Impyb2NrZXRAZXhhbXBsZS5jb20iLCJFbWFpbCI6ImJlZUBleGFtcGxlLmNvb" + "SJ9.HIxL7_WqeLPkxYdROAwRyL0YEY1YNJRfLghsaHEc7C4"));
    assertTrue(keyManager.canHandleToken(UUID.randomUUID().toString()));
}
Also used : ModelKeyManagerForTest(org.wso2.carbon.apimgt.impl.factory.ModelKeyManagerForTest) KeyManager(org.wso2.carbon.apimgt.api.model.KeyManager) KeyManagerConfiguration(org.wso2.carbon.apimgt.api.model.KeyManagerConfiguration) Test(org.junit.Test) ModelKeyManagerForTest(org.wso2.carbon.apimgt.impl.factory.ModelKeyManagerForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

Test (org.junit.Test)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 KeyManager (org.wso2.carbon.apimgt.api.model.KeyManager)8 KeyManagerConfiguration (org.wso2.carbon.apimgt.api.model.KeyManagerConfiguration)8 ModelKeyManagerForTest (org.wso2.carbon.apimgt.impl.factory.ModelKeyManagerForTest)8