Skip to content

Commit

Permalink
added UI tests for client scope
Browse files Browse the repository at this point in the history
  • Loading branch information
vramik committed Dec 4, 2015
1 parent 1dd3fc5 commit 1b936a1
Show file tree
Hide file tree
Showing 9 changed files with 202 additions and 34 deletions.
Expand Up @@ -76,9 +76,9 @@ <h2><span>{{client.clientId}}</span> {{:: 'scope-mappings' | translate}} </h2>
</div> </div>
<div class="row" data-ng-show="targetClient"> <div class="row" data-ng-show="targetClient">
<div class="col-md-3"> <div class="col-md-3">
<label class="control-label" for="client-available">{{:: 'available-roles' | translate}}</label> <label class="control-label" for="available-client">{{:: 'available-roles' | translate}}</label>
<kc-tooltip>{{:: 'assign.available-roles.tooltip' | translate}}</kc-tooltip> <kc-tooltip>{{:: 'assign.available-roles.tooltip' | translate}}</kc-tooltip>
<select id="client-available" class="form-control" multiple size="5" <select id="available-client" class="form-control" multiple size="5"
ng-multiple="true" ng-multiple="true"
ng-model="selectedClientRoles" ng-model="selectedClientRoles"
ng-options="r.name for r in clientRoles"> ng-options="r.name for r in clientRoles">
Expand All @@ -88,9 +88,9 @@ <h2><span>{{client.clientId}}</span> {{:: 'scope-mappings' | translate}} </h2>
</button> </button>
</div> </div>
<div class="col-md-3"> <div class="col-md-3">
<label class="control-label" for="client-assigned">{{:: 'assigned-roles' | translate}}</label> <label class="control-label" for="assigned-client">{{:: 'assigned-roles' | translate}}</label>
<kc-tooltip>{{:: 'client.assigned-roles.tooltip' | translate}}</kc-tooltip> <kc-tooltip>{{:: 'client.assigned-roles.tooltip' | translate}}</kc-tooltip>
<select id="client-assigned" class="form-control" multiple size=5 <select id="assigned-client" class="form-control" multiple size=5
ng-multiple="true" ng-multiple="true"
ng-model="selectedClientMappings" ng-model="selectedClientMappings"
ng-options="r.name for r in clientMappings"> ng-options="r.name for r in clientMappings">
Expand Down
Expand Up @@ -65,9 +65,9 @@ <h2><span>{{client.clientId}}</span> {{:: 'service-accounts' | translate}} </h2>
</div> </div>
<div class="row" data-ng-show="targetClient"> <div class="row" data-ng-show="targetClient">
<div class="col-md-3"> <div class="col-md-3">
<label class="control-label" for="client-available">{{:: 'available-roles' | translate}}</label> <label class="control-label" for="available-client">{{:: 'available-roles' | translate}}</label>
<kc-tooltip>{{:: 'assign.available-roles.tooltip' | translate}}</kc-tooltip> <kc-tooltip>{{:: 'assign.available-roles.tooltip' | translate}}</kc-tooltip>
<select id="client-available" class="form-control" multiple size="5" <select id="available-client" class="form-control" multiple size="5"
ng-multiple="true" ng-multiple="true"
ng-model="selectedClientRoles" ng-model="selectedClientRoles"
ng-options="r.name for r in clientRoles"> ng-options="r.name for r in clientRoles">
Expand All @@ -77,9 +77,9 @@ <h2><span>{{client.clientId}}</span> {{:: 'service-accounts' | translate}} </h2>
</button> </button>
</div> </div>
<div class="col-md-3"> <div class="col-md-3">
<label class="control-label" for="client-assigned">{{:: 'assigned-roles' | translate}}</label> <label class="control-label" for="assigned-client">{{:: 'assigned-roles' | translate}}</label>
<kc-tooltip>{{:: 'client.assigned-roles.tooltip' | translate}}</kc-tooltip> <kc-tooltip>{{:: 'client.assigned-roles.tooltip' | translate}}</kc-tooltip>
<select id="client-assigned" class="form-control" multiple size=5 <select id="assigned-client" class="form-control" multiple size=5
ng-multiple="true" ng-multiple="true"
ng-model="selectedClientMappings" ng-model="selectedClientMappings"
ng-options="r.name for r in clientMappings"> ng-options="r.name for r in clientMappings">
Expand Down

This file was deleted.

Expand Up @@ -9,8 +9,6 @@


/** /**
* @author Vaclav Muzikar <vmuzikar@redhat.com> * @author Vaclav Muzikar <vmuzikar@redhat.com>
*
* TODO: SAML
*/ */
public class CreateClientMappersForm extends Form { public class CreateClientMappersForm extends Form {


Expand Down
@@ -0,0 +1,31 @@
package org.keycloak.testsuite.console.page.clients.scope;

import org.jboss.arquillian.graphene.page.Page;
import org.keycloak.testsuite.console.page.clients.Client;
import org.keycloak.testsuite.console.page.roles.RoleCompositeRoles;

/**
*
* @author tkyjovsk
*/
public class ClientScope extends Client {

@Override
public String getUriFragment() {
return super.getUriFragment() + "/scope-mappings";
}

@Page
private ClientScopeForm clientScopeForm;

@Page
private RoleCompositeRoles scopeRoleForm;

public ClientScopeForm scopeForm() {
return clientScopeForm;
}

public RoleCompositeRoles roleForm() {
return scopeRoleForm;
}
}
@@ -0,0 +1,41 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.keycloak.testsuite.console.page.clients.scope;

import org.keycloak.testsuite.console.page.fragment.OnOffSwitch;
import org.keycloak.testsuite.page.Form;
import org.openqa.selenium.support.FindBy;

/**
*
* @author <a href="mailto:vramik@redhat.com">Vlastislav Ramik</a>
*/
public class ClientScopeForm extends Form {

@FindBy(className = "onoffswitch")
private OnOffSwitch fullScopeAllowedSwitch;


public void setFullScopeAllowed(boolean value) {
fullScopeAllowedSwitch.setOn(value);
}
}
@@ -1,7 +1,9 @@
package org.keycloak.testsuite.console.page.roles; package org.keycloak.testsuite.console.page.roles;


import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
Expand Down Expand Up @@ -88,6 +90,14 @@ private void removeRedundantRoles(Select select, WebElement button, Collection<S
button.click(); button.click();
} }


public void addRealmRole(String role) {
addMissingRoles(availableRealmRolesSelect, addSelectedRealmRolesButton, Arrays.asList(role));
}

public void addClientRole(String role) {
addMissingRoles(availableClientRolesSelect, addSelectedClientRolesButton, Arrays.asList(role));
}

protected void addMissingRoles(Select select, WebElement button, Collection<String> roles) { protected void addMissingRoles(Select select, WebElement button, Collection<String> roles) {
select.deselectAll(); select.deselectAll();
if (roles != null) { // if roles not provided, don't add any if (roles != null) { // if roles not provided, don't add any
Expand Down
Expand Up @@ -41,39 +41,39 @@ public class ClientCredentialsTest extends AbstractClientTest {
private ClientRepresentation newClient; private ClientRepresentation newClient;


@Page @Page
private ClientCredentials clientCredentials; private ClientCredentials clientCredentialsPage;
@Page @Page
private ClientCredentialsGeneratePrivateKeys generatePrivateKeysPage; private ClientCredentialsGeneratePrivateKeys generatePrivateKeysPage;


@Before @Before
public void beforeClientsTest() { public void before() {
newClient = createOidcClientRep(CONFIDENTIAL, TEST_CLIENT_ID, TEST_REDIRECT_URIS); newClient = createOidcClientRep(CONFIDENTIAL, TEST_CLIENT_ID, TEST_REDIRECT_URIS);
testRealmResource().clients().create(newClient).close(); testRealmResource().clients().create(newClient).close();


ClientRepresentation found = findClientByClientId(TEST_CLIENT_ID); ClientRepresentation found = findClientByClientId(TEST_CLIENT_ID);
assertNotNull("Client " + TEST_CLIENT_ID + " was not found.", found); assertNotNull("Client " + TEST_CLIENT_ID + " was not found.", found);
clientCredentials.setId(found.getId()); clientCredentialsPage.setId(found.getId());
clientCredentials.navigateTo(); clientCredentialsPage.navigateTo();
} }


@Test @Test
public void regenerateSecret() { public void regenerateSecret() {
clientCredentials.form().selectClientIdAndSecret(); clientCredentialsPage.form().selectClientIdAndSecret();
clientCredentials.form().regenerateSecret(); clientCredentialsPage.form().regenerateSecret();
assertFlashMessageSuccess(); assertFlashMessageSuccess();
} }


@Test @Test
public void regenerateRegistrationAccessToken() { public void regenerateRegistrationAccessToken() {
clientCredentials.form().regenerateRegistrationAccessToken(); clientCredentialsPage.form().regenerateRegistrationAccessToken();
assertFlashMessageSuccess(); assertFlashMessageSuccess();
} }


@Test @Test
public void generateNewKeysAndCert() { public void generateNewKeysAndCert() {
generatePrivateKeysPage.setId(clientCredentials.getId()); generatePrivateKeysPage.setId(clientCredentialsPage.getId());
clientCredentials.form().selectSignedJwt(); clientCredentialsPage.form().selectSignedJwt();
clientCredentials.form().generateNewKeysAndCert(); clientCredentialsPage.form().generateNewKeysAndCert();
assertCurrentUrlEquals(generatePrivateKeysPage); assertCurrentUrlEquals(generatePrivateKeysPage);


generatePrivateKeysPage.generateForm().setKeyPassword("pass"); generatePrivateKeysPage.generateForm().setKeyPassword("pass");
Expand Down
@@ -0,0 +1,102 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.keycloak.testsuite.console.clients;

import java.util.List;
import java.util.Map;
import org.jboss.arquillian.graphene.page.Page;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.keycloak.representations.idm.ClientMappingsRepresentation;
import org.keycloak.representations.idm.ClientRepresentation;
import org.keycloak.representations.idm.MappingsRepresentation;
import org.keycloak.representations.idm.RoleRepresentation;
import static org.keycloak.testsuite.console.clients.AbstractClientTest.createOidcClientRep;
import static org.keycloak.testsuite.console.page.clients.CreateClientForm.OidcAccessType.CONFIDENTIAL;
import org.keycloak.testsuite.console.page.clients.credentials.ClientCredentialsGeneratePrivateKeys;
import org.keycloak.testsuite.console.page.clients.scope.ClientScope;

/**
*
* @author <a href="mailto:vramik@redhat.com">Vlastislav Ramik</a>
*/
public class ClientScopeTest extends AbstractClientTest {

private ClientRepresentation newClient;
private ClientRepresentation found;

@Page
private ClientScope clientScopePage;
@Page
private ClientCredentialsGeneratePrivateKeys generatePrivateKeysPage;

@Before
public void before() {
newClient = createOidcClientRep(CONFIDENTIAL, TEST_CLIENT_ID, TEST_REDIRECT_URIS);
testRealmResource().clients().create(newClient).close();

found = findClientByClientId(TEST_CLIENT_ID);
assertNotNull("Client " + TEST_CLIENT_ID + " was not found.", found);
clientScopePage.setId(found.getId());
clientScopePage.navigateTo();
}

@Test
public void clientScopeTest() {
assertTrue(found.isFullScopeAllowed());
clientScopePage.scopeForm().setFullScopeAllowed(false);
assertFlashMessageSuccess();

found = findClientByClientId(TEST_CLIENT_ID);
assertFalse(found.isFullScopeAllowed());
assertNull(getAllMappingsRepresentation().getRealmMappings());
assertNull(getAllMappingsRepresentation().getClientMappings());

clientScopePage.roleForm().addRealmRole("offline_access");
assertFlashMessageSuccess();

clientScopePage.roleForm().selectClientRole("account");
clientScopePage.roleForm().addClientRole("view-profile");
assertFlashMessageSuccess();

found = findClientByClientId(TEST_CLIENT_ID);
List<RoleRepresentation> realmMappings = getAllMappingsRepresentation().getRealmMappings();
assertEquals(1, realmMappings.size());
assertEquals("offline_access", realmMappings.get(0).getName());
Map<String, ClientMappingsRepresentation> clientMappings = getAllMappingsRepresentation().getClientMappings();
assertEquals(1, clientMappings.size());
assertEquals("view-profile", clientMappings.get("account").getMappings().get(0).getName());

clientScopePage.roleForm().removeAssignedRole("offline_access");
assertFlashMessageSuccess();
clientScopePage.roleForm().removeAssignedClientRole("view-profile");
assertFlashMessageSuccess();

assertNull(getAllMappingsRepresentation().getRealmMappings());
assertNull(getAllMappingsRepresentation().getClientMappings());
}

private MappingsRepresentation getAllMappingsRepresentation() {
return testRealmResource().clients().get(found.getId()).getScopeMappings().getAll();
}
}

0 comments on commit 1b936a1

Please sign in to comment.