Search in sources :

Example 6 with EnableFeature

use of org.keycloak.testsuite.arquillian.annotation.EnableFeature 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 7 with EnableFeature

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

the class PartialImportTest method testEverythingOverwriteWithServiceAccounts.

@EnableFeature(value = UPLOAD_SCRIPTS, skipRestart = true)
@Test
public void testEverythingOverwriteWithServiceAccounts() throws IOException {
    setOverwrite();
    importEverything(true);
    PartialImportResults results = doImport();
    assertEquals(NUM_ENTITIES * (NUM_RESOURCE_TYPES + 1), 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 8 with EnableFeature

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

the class PartialImportTest method testEverythingSkipWithServiceAccounts.

@EnableFeature(value = UPLOAD_SCRIPTS, skipRestart = true)
@Test
public void testEverythingSkipWithServiceAccounts() throws IOException {
    setSkip();
    importEverything(true);
    PartialImportResults results = doImport();
    assertEquals(NUM_ENTITIES * (NUM_RESOURCE_TYPES + 1), 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 9 with EnableFeature

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

the class LoginTest method loginSuccessfulWithDynamicScope.

@Test
@EnableFeature(value = Profile.Feature.DYNAMIC_SCOPES, skipRestart = true)
public void loginSuccessfulWithDynamicScope() {
    ProfileAssume.assumeFeatureEnabled(DYNAMIC_SCOPES);
    ClientScopeRepresentation clientScope = new ClientScopeRepresentation();
    clientScope.setName("dynamic");
    clientScope.setAttributes(new HashMap<String, String>() {

        {
            put(ClientScopeModel.IS_DYNAMIC_SCOPE, "true");
            put(ClientScopeModel.DYNAMIC_SCOPE_REGEXP, "dynamic:*");
        }
    });
    clientScope.setProtocol(OIDCLoginProtocol.LOGIN_PROTOCOL);
    Response response = testRealm().clientScopes().create(clientScope);
    String scopeId = ApiUtil.getCreatedId(response);
    getCleanup().addClientScopeId(scopeId);
    response.close();
    ClientResource testApp = ApiUtil.findClientByClientId(testRealm(), "test-app");
    ClientRepresentation testAppRep = testApp.toRepresentation();
    testApp.update(testAppRep);
    testApp.addOptionalClientScope(scopeId);
    oauth.scope("dynamic:scope");
    oauth.doLogin("login@test.com", "password");
    events.expectLogin().user(userId).assertEvent();
}
Also used : Response(javax.ws.rs.core.Response) ClientScopeRepresentation(org.keycloak.representations.idm.ClientScopeRepresentation) ClientResource(org.keycloak.admin.client.resource.ClientResource) Matchers.containsString(org.hamcrest.Matchers.containsString) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest) EnableFeature(org.keycloak.testsuite.arquillian.annotation.EnableFeature)

Example 10 with EnableFeature

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

the class ClientSettingsTest method alwaysDisplayInAccountConsole.

@Test
@EnableFeature(value = Profile.Feature.ACCOUNT2, skipRestart = true)
public void alwaysDisplayInAccountConsole() {
    refreshPageAndWaitForLoad();
    newClient = createClientRep("always-display-in-console", OIDC);
    createClient(newClient);
    newClient.setRedirectUris(TEST_REDIRECT_URIs);
    newClient.setAlwaysDisplayInConsole(true);
    assertFalse(clientSettingsPage.form().isAlwaysDisplayInConsole());
    clientSettingsPage.form().setAlwaysDisplayInConsole(true);
    clientSettingsPage.form().setRedirectUris(TEST_REDIRECT_URIs);
    clientSettingsPage.form().save();
    assertTrue(clientSettingsPage.form().isAlwaysDisplayInConsole());
    ClientRepresentation found = findClientByClientId(newClient.getClientId());
    assertNotNull("Client " + newClient.getClientId() + " was not found.", found);
    assertClientSettingsEqual(newClient, found);
    clientSettingsPage.form().setAccessType(BEARER_ONLY);
    assertFalse(clientSettingsPage.form().isAlwaysDisplayInConsoleVisible());
    // check if the switch is displayed when change the Client to SAML and bearer-only flag is set to on (bearer-only
    // is not applicable for SAML but it's technically present in the Client representation and therefore can affect
    // the visibility of the switch)
    clientSettingsPage.form().setProtocol(SAML);
    assertTrue(clientSettingsPage.form().isAlwaysDisplayInConsoleVisible());
}
Also used : ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) Test(org.junit.Test) EnableFeature(org.keycloak.testsuite.arquillian.annotation.EnableFeature)

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