Search in sources :

Example 1 with PartialImportResult

use of org.keycloak.partialimport.PartialImportResult in project keycloak by keycloak.

the class PartialImportTest method testAddClientsWithServiceAccountsAndAuthorization.

@EnableFeature(value = UPLOAD_SCRIPTS, skipRestart = true)
@Test
public void testAddClientsWithServiceAccountsAndAuthorization() throws IOException {
    setFail();
    addClients(true);
    PartialImportResults results = doImport();
    assertEquals(NUM_ENTITIES * 2, results.getAdded());
    for (PartialImportResult result : results.getResults()) {
        if (result.getResourceType().equals(ResourceType.CLIENT)) {
            String id = result.getId();
            ClientResource clientRsc = testRealmResource().clients().get(id);
            ClientRepresentation client = clientRsc.toRepresentation();
            assertTrue(client.getName().startsWith(CLIENT_PREFIX));
            Assert.assertTrue(client.isServiceAccountsEnabled());
            if (ProfileAssume.isFeatureEnabled(AUTHORIZATION)) {
                Assert.assertTrue(client.getAuthorizationServicesEnabled());
                AuthorizationResource authRsc = clientRsc.authorization();
                ResourceServerRepresentation authRep = authRsc.exportSettings();
                Assert.assertNotNull(authRep);
                Assert.assertEquals(2, authRep.getResources().size());
                Assert.assertEquals(3, authRep.getPolicies().size());
            } else {
                Assert.assertNull(client.getAuthorizationServicesEnabled());
            }
        } else {
            UserResource userRsc = testRealmResource().users().get(result.getId());
            Assert.assertTrue(userRsc.toRepresentation().getUsername().startsWith(ServiceAccountConstants.SERVICE_ACCOUNT_USER_PREFIX + CLIENT_PREFIX));
        }
    }
}
Also used : PartialImportResult(org.keycloak.partialimport.PartialImportResult) PartialImportResults(org.keycloak.partialimport.PartialImportResults) ResourceServerRepresentation(org.keycloak.representations.idm.authorization.ResourceServerRepresentation) UserResource(org.keycloak.admin.client.resource.UserResource) ClientResource(org.keycloak.admin.client.resource.ClientResource) AuthorizationResource(org.keycloak.admin.client.resource.AuthorizationResource) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) AbstractAuthTest(org.keycloak.testsuite.AbstractAuthTest) Test(org.junit.Test) EnableFeature(org.keycloak.testsuite.arquillian.annotation.EnableFeature)

Example 2 with PartialImportResult

use of org.keycloak.partialimport.PartialImportResult in project keycloak by keycloak.

the class PartialImportTest method testAddRealmRoles.

@Test
public void testAddRealmRoles() {
    setFail();
    addRealmRoles();
    PartialImportResults results = doImport();
    assertEquals(NUM_ENTITIES, results.getAdded());
    for (PartialImportResult result : results.getResults()) {
        String name = result.getResourceName();
        RoleResource roleRsc = testRealmResource().roles().get(name);
        RoleRepresentation role = roleRsc.toRepresentation();
        assertTrue(role.getName().startsWith(REALM_ROLE_PREFIX));
    }
}
Also used : RoleRepresentation(org.keycloak.representations.idm.RoleRepresentation) PartialImportResult(org.keycloak.partialimport.PartialImportResult) PartialImportResults(org.keycloak.partialimport.PartialImportResults) RoleResource(org.keycloak.admin.client.resource.RoleResource) AbstractAuthTest(org.keycloak.testsuite.AbstractAuthTest) Test(org.junit.Test)

Example 3 with PartialImportResult

use of org.keycloak.partialimport.PartialImportResult in project keycloak by keycloak.

the class PartialImportTest method testAddProviders.

@Test
public void testAddProviders() {
    setFail();
    addProviders();
    PartialImportResults results = doImport();
    assertEquals(IDP_ALIASES.length, results.getAdded());
    for (PartialImportResult result : results.getResults()) {
        String id = result.getId();
        IdentityProviderResource idpRsc = testRealmResource().identityProviders().get(id);
        IdentityProviderRepresentation idp = idpRsc.toRepresentation();
        Map<String, String> config = idp.getConfig();
        assertTrue(Arrays.asList(IDP_ALIASES).contains(config.get("clientId")));
    }
}
Also used : PartialImportResult(org.keycloak.partialimport.PartialImportResult) IdentityProviderResource(org.keycloak.admin.client.resource.IdentityProviderResource) PartialImportResults(org.keycloak.partialimport.PartialImportResults) IdentityProviderRepresentation(org.keycloak.representations.idm.IdentityProviderRepresentation) AbstractAuthTest(org.keycloak.testsuite.AbstractAuthTest) Test(org.junit.Test)

Example 4 with PartialImportResult

use of org.keycloak.partialimport.PartialImportResult in project keycloak by keycloak.

the class PartialImportTest method testAddUsersWithTermsAndConditions.

@Test
public void testAddUsersWithTermsAndConditions() {
    assertAdminEvents.clear();
    setFail();
    addUsersWithTermsAndConditions();
    PartialImportResults results = doImport();
    assertEquals(NUM_ENTITIES, results.getAdded());
    // Need to do this way as admin events from partial import are unsorted
    Set<String> userIds = new HashSet<>();
    for (int i = 0; i < NUM_ENTITIES; i++) {
        AdminEventRepresentation adminEvent = assertAdminEvents.poll();
        Assert.assertEquals(realmId, adminEvent.getRealmId());
        Assert.assertEquals(OperationType.CREATE.name(), adminEvent.getOperationType());
        Assert.assertTrue(adminEvent.getResourcePath().startsWith("users/"));
        String userId = adminEvent.getResourcePath().substring(6);
        userIds.add(userId);
    }
    assertAdminEvents.assertEmpty();
    for (PartialImportResult result : results.getResults()) {
        String id = result.getId();
        UserResource userRsc = testRealmResource().users().get(id);
        UserRepresentation user = userRsc.toRepresentation();
        assertTrue(user.getUsername().startsWith(USER_PREFIX));
        Assert.assertTrue(userIds.contains(id));
    }
}
Also used : PartialImportResult(org.keycloak.partialimport.PartialImportResult) AdminEventRepresentation(org.keycloak.representations.idm.AdminEventRepresentation) PartialImportResults(org.keycloak.partialimport.PartialImportResults) UserResource(org.keycloak.admin.client.resource.UserResource) HashSet(java.util.HashSet) UserRepresentation(org.keycloak.representations.idm.UserRepresentation) AbstractAuthTest(org.keycloak.testsuite.AbstractAuthTest) Test(org.junit.Test)

Example 5 with PartialImportResult

use of org.keycloak.partialimport.PartialImportResult in project keycloak by keycloak.

the class PartialImportTest method testAddUsers.

@Test
public void testAddUsers() {
    assertAdminEvents.clear();
    setFail();
    addUsers();
    PartialImportResults results = doImport();
    assertEquals(NUM_ENTITIES, results.getAdded());
    // Need to do this way as admin events from partial import are unsorted
    Set<String> userIds = new HashSet<>();
    for (int i = 0; i < NUM_ENTITIES; i++) {
        AdminEventRepresentation adminEvent = assertAdminEvents.poll();
        Assert.assertEquals(realmId, adminEvent.getRealmId());
        Assert.assertEquals(OperationType.CREATE.name(), adminEvent.getOperationType());
        Assert.assertTrue(adminEvent.getResourcePath().startsWith("users/"));
        String userId = adminEvent.getResourcePath().substring(6);
        userIds.add(userId);
    }
    assertAdminEvents.assertEmpty();
    for (PartialImportResult result : results.getResults()) {
        String id = result.getId();
        UserResource userRsc = testRealmResource().users().get(id);
        UserRepresentation user = userRsc.toRepresentation();
        Assert.assertThat(user.getUsername(), startsWith(USER_PREFIX));
        Assert.assertThat(userIds, hasItem(id));
    }
}
Also used : PartialImportResult(org.keycloak.partialimport.PartialImportResult) AdminEventRepresentation(org.keycloak.representations.idm.AdminEventRepresentation) PartialImportResults(org.keycloak.partialimport.PartialImportResults) UserResource(org.keycloak.admin.client.resource.UserResource) HashSet(java.util.HashSet) UserRepresentation(org.keycloak.representations.idm.UserRepresentation) AbstractAuthTest(org.keycloak.testsuite.AbstractAuthTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 PartialImportResult (org.keycloak.partialimport.PartialImportResult)6 PartialImportResults (org.keycloak.partialimport.PartialImportResults)6 AbstractAuthTest (org.keycloak.testsuite.AbstractAuthTest)6 UserResource (org.keycloak.admin.client.resource.UserResource)3 HashSet (java.util.HashSet)2 ClientResource (org.keycloak.admin.client.resource.ClientResource)2 AdminEventRepresentation (org.keycloak.representations.idm.AdminEventRepresentation)2 ClientRepresentation (org.keycloak.representations.idm.ClientRepresentation)2 UserRepresentation (org.keycloak.representations.idm.UserRepresentation)2 AuthorizationResource (org.keycloak.admin.client.resource.AuthorizationResource)1 IdentityProviderResource (org.keycloak.admin.client.resource.IdentityProviderResource)1 RoleResource (org.keycloak.admin.client.resource.RoleResource)1 IdentityProviderRepresentation (org.keycloak.representations.idm.IdentityProviderRepresentation)1 RoleRepresentation (org.keycloak.representations.idm.RoleRepresentation)1 ResourceServerRepresentation (org.keycloak.representations.idm.authorization.ResourceServerRepresentation)1 EnableFeature (org.keycloak.testsuite.arquillian.annotation.EnableFeature)1