Search in sources :

Example 16 with EnableFeature

use of org.keycloak.testsuite.arquillian.annotation.EnableFeature in project keycloak by keycloak.

the class PartialImportTest method testAddClientsOverwriteWithServiceAccountsAndAuthorization.

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

Example 17 with EnableFeature

use of org.keycloak.testsuite.arquillian.annotation.EnableFeature in project keycloak by keycloak.

the class PartialImportTest method testAddClientsOverwriteServiceAccountsWithNoServiceAccounts.

@EnableFeature(value = UPLOAD_SCRIPTS, skipRestart = true)
@Test
public void testAddClientsOverwriteServiceAccountsWithNoServiceAccounts() throws IOException {
    addClients(true);
    setOverwrite();
    PartialImportResults results = doImport();
    assertEquals(NUM_ENTITIES * 2, results.getAdded());
    // check the service accounts are there
    for (int i = 0; i < NUM_ENTITIES; i++) {
        List<UserRepresentation> l = testRealmResource().users().search(ServiceAccountConstants.SERVICE_ACCOUNT_USER_PREFIX + CLIENT_PREFIX + i);
        Assert.assertEquals(1, l.size());
    }
    // re-import without service accounts enabled
    piRep = new PartialImportRepresentation();
    addClients(false);
    setOverwrite();
    results = doImport();
    assertEquals(NUM_ENTITIES, results.getOverwritten());
    // check the service accounts have been removed
    for (int i = 0; i < NUM_ENTITIES; i++) {
        List<UserRepresentation> l = testRealmResource().users().search(ServiceAccountConstants.SERVICE_ACCOUNT_USER_PREFIX + CLIENT_PREFIX + i);
        Assert.assertEquals(0, l.size());
    }
}
Also used : PartialImportRepresentation(org.keycloak.representations.idm.PartialImportRepresentation) PartialImportResults(org.keycloak.partialimport.PartialImportResults) UserRepresentation(org.keycloak.representations.idm.UserRepresentation) AbstractAuthTest(org.keycloak.testsuite.AbstractAuthTest) Test(org.junit.Test) EnableFeature(org.keycloak.testsuite.arquillian.annotation.EnableFeature)

Example 18 with EnableFeature

use of org.keycloak.testsuite.arquillian.annotation.EnableFeature in project keycloak by keycloak.

the class UndeployedScriptMapperNotAvailableTest method testMapperNotRecognizedWhenDisabled.

@Test
@EnableFeature(value = SCRIPTS, skipRestart = true, executeAsLast = false)
public void testMapperNotRecognizedWhenDisabled() throws Exception {
    ClientResource app = findClientResourceByClientId(adminClient.realm("test"), "test-app");
    {
        ProtocolMapperRepresentation mapper = createScriptMapper("test-script-mapper1", "computed-via-script", "computed-via-script", "String", true, true, "'hello_' + user.username", false);
        mapper.setProtocolMapper("script-mapper-a.js");
        app.getProtocolMappers().createMapper(mapper).close();
    }
    deployer.undeploy(SCRIPT_DEPLOYMENT_NAME);
    reconnectAdminClient();
    ClientResource cl = findClientResourceByClientId(adminClient.realm("test"), "test-app");
    assertTrue(cl.getProtocolMappers().getMappers().isEmpty());
    assertTrue(cl.getProtocolMappers().getMappersPerProtocol(cl.toRepresentation().getProtocol()).isEmpty());
}
Also used : ProtocolMapperRepresentation(org.keycloak.representations.idm.ProtocolMapperRepresentation) ClientResource(org.keycloak.admin.client.resource.ClientResource) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest) EnableFeature(org.keycloak.testsuite.arquillian.annotation.EnableFeature)

Example 19 with EnableFeature

use of org.keycloak.testsuite.arquillian.annotation.EnableFeature in project keycloak by keycloak.

the class FineGrainAdminUnitTest method testWithTokenExchange.

/**
 * KEYCLOAK-7406
 *
 * @throws Exception
 */
@Test
@UncaughtServerErrorExpected
@AuthServerContainerExclude(AuthServer.REMOTE)
@EnableFeature(value = Profile.Feature.TOKEN_EXCHANGE, skipRestart = true)
public void testWithTokenExchange() throws Exception {
    String exchanged = checkTokenExchange(true);
    Assert.assertNotNull(exchanged);
    try (Keycloak client = Keycloak.getInstance(getAuthServerContextRoot() + "/auth", AuthRealm.MASTER, Constants.ADMIN_CLI_CLIENT_ID, exchanged, TLSUtils.initializeTLS())) {
        Assert.assertNotNull(client.realm("master").roles().get("offline_access"));
    }
}
Also used : Keycloak(org.keycloak.admin.client.Keycloak) AuthServerContainerExclude(org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude) AbstractKeycloakTest(org.keycloak.testsuite.AbstractKeycloakTest) Test(org.junit.Test) EnableFeature(org.keycloak.testsuite.arquillian.annotation.EnableFeature) UncaughtServerErrorExpected(org.keycloak.testsuite.arquillian.annotation.UncaughtServerErrorExpected)

Aggregations

Test (org.junit.Test)19 EnableFeature (org.keycloak.testsuite.arquillian.annotation.EnableFeature)19 ClientScopeRepresentation (org.keycloak.representations.idm.ClientScopeRepresentation)9 ClientResource (org.keycloak.admin.client.resource.ClientResource)7 PartialImportResults (org.keycloak.partialimport.PartialImportResults)6 ClientRepresentation (org.keycloak.representations.idm.ClientRepresentation)6 AbstractAuthTest (org.keycloak.testsuite.AbstractAuthTest)6 Response (javax.ws.rs.core.Response)5 AbstractKeycloakTest (org.keycloak.testsuite.AbstractKeycloakTest)4 OAuthClient (org.keycloak.testsuite.util.OAuthClient)3 ClientErrorException (javax.ws.rs.ClientErrorException)2 RealmResource (org.keycloak.admin.client.resource.RealmResource)2 AccessToken (org.keycloak.representations.AccessToken)2 ProtocolMapperRepresentation (org.keycloak.representations.idm.ProtocolMapperRepresentation)2 AbstractTestRealmKeycloakTest (org.keycloak.testsuite.AbstractTestRealmKeycloakTest)2 AuthServerContainerExclude (org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude)2 HashMap (java.util.HashMap)1 HttpResponse (org.apache.http.HttpResponse)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Matchers.isEmptyOrNullString (org.hamcrest.Matchers.isEmptyOrNullString)1