Search in sources :

Example 21 with Scope

use of org.wso2.carbon.apimgt.keymgt.model.entity.Scope in project carbon-apimgt by wso2.

the class DefaultScopeRegistrationImplTest method testRegisterScope.

@Test
public void testRegisterScope() throws KeyManagementException {
    DefaultScopeRegistrationServiceStub defaultScopeRegistrationServiceStub = Mockito.mock(DefaultScopeRegistrationServiceStub.class);
    DefaultScopeRegistrationImpl defaultScopeRegistration = new DefaultScopeRegistrationImpl(defaultScopeRegistrationServiceStub);
    Scope scopeInfo = new Scope();
    scopeInfo.setName("abc");
    scopeInfo.setDescription("cde");
    Mockito.when(defaultScopeRegistrationServiceStub.registerScope(getScopeInfo(scopeInfo))).thenReturn(Response.builder().status(201).headers(new HashMap<>()).body(new Gson().toJson(scopeInfo), feign.Util.UTF_8).build());
    Scope scope = new Scope();
    scope.setName("abc");
    scope.setDescription("cde");
    Assert.assertTrue(defaultScopeRegistration.registerScope(scope));
}
Also used : Scope(org.wso2.carbon.apimgt.core.models.Scope) HashMap(java.util.HashMap) Gson(com.google.gson.Gson) Test(org.testng.annotations.Test)

Example 22 with Scope

use of org.wso2.carbon.apimgt.keymgt.model.entity.Scope in project carbon-apimgt by wso2.

the class APIDefinitionFromSwagger20TestCase method testAddNewScopeToNonExistingSecurityDefinition.

@Test()
public void testAddNewScopeToNonExistingSecurityDefinition() throws IOException, APIManagementException {
    APIDefinitionFromSwagger20 apiDefinitionFromSwagger20 = new APIDefinitionFromSwagger20();
    String sampleApi = IOUtils.toString(this.getClass().getResourceAsStream(File.separator + "swagger" + File.separator + "swaggerWithOutAuthorization.yaml"));
    Scope scope = new Scope();
    scope.setName("apim:api_delete");
    scope.setDescription("Delete API");
    String scopeAddedSwagger = apiDefinitionFromSwagger20.addScopeToSwaggerDefinition(sampleApi, scope);
    Map<String, String> scopes = apiDefinitionFromSwagger20.getScopesFromSecurityDefinition(scopeAddedSwagger);
    Assert.assertTrue(scopes.containsKey("apim:api_delete"));
}
Also used : Scope(org.wso2.carbon.apimgt.core.models.Scope) Test(org.testng.annotations.Test)

Example 23 with Scope

use of org.wso2.carbon.apimgt.keymgt.model.entity.Scope in project carbon-apimgt by wso2.

the class APIDefinitionFromSwagger20TestCase method testAddNewScopeToExistingOauthSecurity.

@Test()
public void testAddNewScopeToExistingOauthSecurity() throws IOException, APIManagementException {
    APIDefinitionFromSwagger20 apiDefinitionFromSwagger20 = new APIDefinitionFromSwagger20();
    String filePath = "src" + File.separator + "test" + File.separator + "resources" + File.separator + "swagger" + File.separator + "swaggerWithAuthorization.yaml";
    File file = Paths.get(filePath).toFile();
    String sampleApi = IOUtils.toString(new FileInputStream(file));
    Scope scope = new Scope();
    scope.setName("apim:api_delete");
    scope.setDescription("Delete API");
    String scopeAddedSwagger = apiDefinitionFromSwagger20.addScopeToSwaggerDefinition(sampleApi, scope);
    Map<String, String> scopes = apiDefinitionFromSwagger20.getScopesFromSecurityDefinition(scopeAddedSwagger);
    Assert.assertTrue(scopes.containsKey("apim:api_delete"));
}
Also used : Scope(org.wso2.carbon.apimgt.core.models.Scope) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.testng.annotations.Test)

Example 24 with Scope

use of org.wso2.carbon.apimgt.keymgt.model.entity.Scope in project carbon-apimgt by wso2.

the class APIPublisherImplTestCase method testDeleteScopeToApi.

@Test(description = "Delete existing Scope of API")
public void testDeleteScopeToApi() throws APIManagementException, IOException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    API api = SampleTestObjectCreator.createDefaultAPI().build();
    String uuid = api.getId();
    Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api);
    GatewaySourceGenerator gatewaySourceGenerator = Mockito.mock(GatewaySourceGenerator.class);
    APIGateway gateway = Mockito.mock(APIGateway.class);
    IdentityProvider identityProvider = Mockito.mock(IdentityProvider.class);
    KeyManager keyManager = Mockito.mock(KeyManager.class);
    APIPublisherImpl apiPublisher = getApiPublisherImpl(identityProvider, apiDAO, gatewaySourceGenerator, gateway, keyManager);
    String oldSwagger = IOUtils.toString(new FileInputStream("src" + File.separator + "test" + File.separator + "resources" + File.separator + "swagger" + File.separator + "swaggerWithAuthorization" + ".yaml"));
    Scope scope = new Scope("apim:api_create", "apim:api_create");
    Mockito.when(apiDAO.getApiSwaggerDefinition(uuid)).thenReturn(oldSwagger);
    Mockito.when(keyManager.deleteScope(scope.getName())).thenReturn(true);
    apiPublisher.deleteScopeFromApi(api.getId(), scope.getName());
}
Also used : Scope(org.wso2.carbon.apimgt.core.models.Scope) API(org.wso2.carbon.apimgt.core.models.API) IdentityProvider(org.wso2.carbon.apimgt.core.api.IdentityProvider) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) KeyManager(org.wso2.carbon.apimgt.core.api.KeyManager) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) FileInputStream(java.io.FileInputStream) GatewaySourceGenerator(org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator) Test(org.testng.annotations.Test)

Example 25 with Scope

use of org.wso2.carbon.apimgt.keymgt.model.entity.Scope in project carbon-apimgt by wso2.

the class APIPublisherImplTestCase method testUpdateSwagger20DefinitionWithDifferentSwagger.

@Test(description = "Save swagger definition for API")
public void testUpdateSwagger20DefinitionWithDifferentSwagger() throws APIManagementException, IOException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    API api = SampleTestObjectCreator.createDefaultAPI().build();
    String uuid = api.getId();
    Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api);
    GatewaySourceGenerator gatewaySourceGenerator = Mockito.mock(GatewaySourceGenerator.class);
    APIGateway gateway = Mockito.mock(APIGateway.class);
    IdentityProvider identityProvider = Mockito.mock(IdentityProvider.class);
    KeyManager keyManager = Mockito.mock(KeyManager.class);
    APIPublisherImpl apiPublisher = getApiPublisherImpl(identityProvider, apiDAO, gatewaySourceGenerator, gateway, keyManager);
    Mockito.when(identityProvider.getRoleName(SampleTestObjectCreator.DEVELOPER_ROLE_ID)).thenReturn(DEVELOPER_ROLE);
    Mockito.when(identityProvider.getRoleName(SampleTestObjectCreator.ADMIN_ROLE_ID)).thenReturn(ADMIN_ROLE);
    String oldSwagger = IOUtils.toString(new FileInputStream("src" + File.separator + "test" + File.separator + "resources" + File.separator + "swagger" + File.separator + "swaggerWithAuthorization" + ".yaml"));
    Mockito.when(apiDAO.getApiSwaggerDefinition(uuid)).thenReturn(oldSwagger);
    Mockito.when(keyManager.retrieveScope("apim:api_create")).thenReturn(new Scope("apim:api_create", "Create " + "API"));
    apiPublisher.saveSwagger20Definition(uuid, SampleTestObjectCreator.apiDefinition);
    Mockito.verify(apiDAO, Mockito.times(1)).updateApiDefinition(uuid, SampleTestObjectCreator.apiDefinition, USER);
}
Also used : Scope(org.wso2.carbon.apimgt.core.models.Scope) API(org.wso2.carbon.apimgt.core.models.API) IdentityProvider(org.wso2.carbon.apimgt.core.api.IdentityProvider) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) KeyManager(org.wso2.carbon.apimgt.core.api.KeyManager) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) FileInputStream(java.io.FileInputStream) GatewaySourceGenerator(org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator) Test(org.testng.annotations.Test)

Aggregations

HashMap (java.util.HashMap)122 ArrayList (java.util.ArrayList)119 Scope (org.wso2.carbon.apimgt.api.model.Scope)97 Test (org.testng.annotations.Test)78 Connection (java.sql.Connection)66 IdentityOAuth2Exception (org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception)64 Map (java.util.Map)63 SQLException (java.sql.SQLException)61 PreparedStatement (java.sql.PreparedStatement)59 HashSet (java.util.HashSet)59 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)50 ResultSet (java.sql.ResultSet)45 Scope (org.wso2.carbon.apimgt.core.models.Scope)41 List (java.util.List)39 URITemplate (org.wso2.carbon.apimgt.api.model.URITemplate)39 Scope (org.wso2.carbon.identity.oauth2.bean.Scope)39 AccessTokenDO (org.wso2.carbon.identity.oauth2.model.AccessTokenDO)39 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)38 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)33 LinkedHashSet (java.util.LinkedHashSet)32