Search in sources :

Example 1 with PartialImportResults

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

the class PartialImportTest method testAddClientsSkipWithServiceAccountsAndAuthorization.

@EnableFeature(value = UPLOAD_SCRIPTS, skipRestart = true)
@Test
public void testAddClientsSkipWithServiceAccountsAndAuthorization() throws IOException {
    addClients(true);
    setSkip();
    PartialImportResults results = doImport();
    assertEquals(NUM_ENTITIES * 2, results.getAdded());
    results = doImport();
    assertEquals(NUM_ENTITIES * 2, results.getSkipped());
}
Also used : PartialImportResults(org.keycloak.partialimport.PartialImportResults) AbstractAuthTest(org.keycloak.testsuite.AbstractAuthTest) Test(org.junit.Test) EnableFeature(org.keycloak.testsuite.arquillian.annotation.EnableFeature)

Example 2 with PartialImportResults

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

the class PartialImportTest method importEverything.

private void importEverything(boolean withServiceAccounts) throws IOException {
    addUsers();
    addGroups();
    addClients(withServiceAccounts);
    addProviders();
    addRealmRoles();
    addClientRoles();
    PartialImportResults results = doImport();
    assertNull(results.getErrorMessage());
    if (withServiceAccounts) {
        assertEquals(NUM_ENTITIES * (NUM_RESOURCE_TYPES + 1), results.getAdded());
    } else {
        assertEquals(NUM_ENTITIES * NUM_RESOURCE_TYPES, results.getAdded());
    }
}
Also used : PartialImportResults(org.keycloak.partialimport.PartialImportResults)

Example 3 with PartialImportResults

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

the class PartialImportTest method testOverwriteExistingInternalClient.

// KEYCLOAK-6058
@Test
public void testOverwriteExistingInternalClient() {
    setOverwrite();
    ClientRepresentation client = adminClient.realm(MASTER).clients().findByClientId("security-admin-console").get(0);
    ClientRepresentation client2 = adminClient.realm(MASTER).clients().findByClientId("master-realm").get(0);
    piRep.setClients(Arrays.asList(client, client2));
    PartialImportResults result = doImport();
    Assert.assertEquals(0, result.getOverwritten());
}
Also used : PartialImportResults(org.keycloak.partialimport.PartialImportResults) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) AbstractAuthTest(org.keycloak.testsuite.AbstractAuthTest) Test(org.junit.Test)

Example 4 with PartialImportResults

use of org.keycloak.partialimport.PartialImportResults 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 5 with PartialImportResults

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

the class PartialImportTest method testEverythingSkip.

@Test
public void testEverythingSkip() throws IOException {
    setSkip();
    importEverything(false);
    PartialImportResults results = doImport();
    assertEquals(NUM_ENTITIES * NUM_RESOURCE_TYPES, results.getSkipped());
}
Also used : PartialImportResults(org.keycloak.partialimport.PartialImportResults) AbstractAuthTest(org.keycloak.testsuite.AbstractAuthTest) Test(org.junit.Test)

Aggregations

PartialImportResults (org.keycloak.partialimport.PartialImportResults)21 Test (org.junit.Test)17 AbstractAuthTest (org.keycloak.testsuite.AbstractAuthTest)17 PartialImportResult (org.keycloak.partialimport.PartialImportResult)6 EnableFeature (org.keycloak.testsuite.arquillian.annotation.EnableFeature)6 UserRepresentation (org.keycloak.representations.idm.UserRepresentation)4 UserResource (org.keycloak.admin.client.resource.UserResource)3 ClientRepresentation (org.keycloak.representations.idm.ClientRepresentation)3 HashSet (java.util.HashSet)2 ClientResource (org.keycloak.admin.client.resource.ClientResource)2 AdminEventRepresentation (org.keycloak.representations.idm.AdminEventRepresentation)2 RoleRepresentation (org.keycloak.representations.idm.RoleRepresentation)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 PartialImportRepresentation (org.keycloak.representations.idm.PartialImportRepresentation)1 RealmRepresentation (org.keycloak.representations.idm.RealmRepresentation)1 ResourceServerRepresentation (org.keycloak.representations.idm.authorization.ResourceServerRepresentation)1