diff --git a/integration/admin-client/src/main/java/org/keycloak/admin/client/resource/ClientResource.java b/integration/admin-client/src/main/java/org/keycloak/admin/client/resource/ClientResource.java index 3597ab71bc..ee1c69ad26 100755 --- a/integration/admin-client/src/main/java/org/keycloak/admin/client/resource/ClientResource.java +++ b/integration/admin-client/src/main/java/org/keycloak/admin/client/resource/ClientResource.java @@ -17,6 +17,7 @@ package org.keycloak.admin.client.resource; +import org.jboss.resteasy.annotations.cache.NoCache; import org.keycloak.representations.idm.ClientRepresentation; import org.keycloak.representations.idm.CredentialRepresentation; import org.keycloak.representations.idm.UserSessionRepresentation; @@ -80,14 +81,9 @@ public interface ClientResource { public CredentialRepresentation getSecret(); @GET - @Path("installation/jboss") - @Produces(MediaType.APPLICATION_XML) - public String getInstallationJbossXml(); - - @GET - @Path("installation/json") - @Produces(MediaType.APPLICATION_JSON) - public String getInstallationJson(); + @NoCache + @Path("installation/providers/{providerId}") + public String getInstallationProvider(@PathParam("providerId") String providerId); @POST @Path("logout-all") diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/client/AbstractClientTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/client/AbstractClientTest.java new file mode 100644 index 0000000000..7059318479 --- /dev/null +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/client/AbstractClientTest.java @@ -0,0 +1,72 @@ +/* + * Copyright 2016 Red Hat Inc. and/or its affiliates and other contributors + * as indicated by the @author tags. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package org.keycloak.testsuite.admin.client; + +import javax.ws.rs.core.Response; +import org.keycloak.admin.client.resource.ClientResource; +import org.keycloak.representations.idm.ClientRepresentation; +import org.keycloak.representations.idm.RealmRepresentation; +import org.keycloak.testsuite.AbstractAuthTest; +import org.keycloak.testsuite.admin.ApiUtil; + +/** + * + * @author Stan Silvert ssilvert@redhat.com (C) 2016 Red Hat Inc. + */ +public abstract class AbstractClientTest extends AbstractAuthTest { + + protected RealmRepresentation realmRep() { + return testRealmResource().toRepresentation(); + } + + protected void createOidcClient(String name) { + ClientRepresentation clientRep = new ClientRepresentation(); + clientRep.setClientId(name); + clientRep.setName(name); + clientRep.setRootUrl("foo"); + clientRep.setProtocol("openid-connect"); + createClient(clientRep); + } + + protected void createSamlClient(String name) { + ClientRepresentation clientRep = new ClientRepresentation(); + clientRep.setClientId(name); + clientRep.setName(name); + clientRep.setProtocol("saml"); + clientRep.setAdminUrl("samlEndpoint"); + createClient(clientRep); + } + + protected void createClient(ClientRepresentation clientRep) { + Response resp = testRealmResource().clients().create(clientRep); + // for some reason, findAll() will later fail unless readEntity is called here + resp.readEntity(String.class); + //testRealmResource().clients().findAll(); + } + + protected ClientRepresentation findClientRepresentation(String name) { + ClientResource clientRsc = findClientResource(name); + if (clientRsc == null) return null; + return findClientResource(name).toRepresentation(); + } + + protected ClientResource findClientResource(String name) { + return ApiUtil.findClientResourceByName(testRealmResource(), name); + } + +} diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/client/ClientRolesTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/client/ClientRolesTest.java new file mode 100644 index 0000000000..9180f15242 --- /dev/null +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/client/ClientRolesTest.java @@ -0,0 +1,76 @@ +/* + * Copyright 2016 Red Hat Inc. and/or its affiliates and other contributors + * as indicated by the @author tags. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package org.keycloak.testsuite.admin.client; + +import org.junit.Before; +import org.junit.Test; +import org.keycloak.admin.client.resource.ClientResource; +import org.keycloak.admin.client.resource.RolesResource; +import org.keycloak.representations.idm.RoleRepresentation; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + * + * @author Stan Silvert ssilvert@redhat.com (C) 2016 Red Hat Inc. + */ +public class ClientRolesTest extends AbstractClientTest { + + private ClientResource clientRsc; + private RolesResource rolesRsc; + + @Before + public void init() { + createOidcClient("roleClient"); + clientRsc = findClientResource("roleClient"); + rolesRsc = clientRsc.roles(); + } + + private RoleRepresentation makeRole(String name) { + RoleRepresentation role = new RoleRepresentation(); + role.setName(name); + return role; + } + + /* private boolean hasRole(RolesResource rolesRsc, String name) { + return rolesRsc.get(name) != null; + }*/ + + private boolean hasRole(RolesResource rolesRsc, String name) { + for (RoleRepresentation role : rolesRsc.list()) { + if (role.getName().equals(name)) return true; + } + + return false; + } + + @Test + public void testAddRole() { + rolesRsc.create(makeRole("role1")); + assertTrue(hasRole(rolesRsc, "role1")); + } + + @Test + public void testRemoveRole() { + rolesRsc.create(makeRole("role2")); + rolesRsc.deleteRole("role2"); + assertFalse(hasRole(rolesRsc, "role2")); + } + +} diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/client/ClientTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/client/ClientTest.java new file mode 100644 index 0000000000..1670a6b80b --- /dev/null +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/client/ClientTest.java @@ -0,0 +1,118 @@ +/* + * Copyright 2016 Red Hat Inc. and/or its affiliates and other contributors + * as indicated by the @author tags. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package org.keycloak.testsuite.admin.client; + +import java.util.List; +import org.junit.Test; +import org.keycloak.admin.client.resource.ClientResource; +import org.keycloak.representations.idm.ClientRepresentation; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +/** + * + * @author Stan Silvert ssilvert@redhat.com (C) 2016 Red Hat Inc. + */ +public class ClientTest extends AbstractClientTest { + + + public static void assertEqualClients(ClientRepresentation expected, ClientRepresentation actual) { + assertEquals(expected.getClientId(), actual.getClientId()); + assertEquals(expected.getName(), actual.getName()); + assertEquals(expected.getDescription(), actual.getDescription()); + assertEquals(expected.getBaseUrl(), actual.getBaseUrl()); + + assertTrue(expected.getRedirectUris().containsAll(actual.getRedirectUris())); + assertTrue(expected.getWebOrigins().containsAll(actual.getWebOrigins())); + assertEquals(expected.getRegisteredNodes(), actual.getRegisteredNodes()); + } + + @Test + public void testCreateClient() { + createOidcClient("foo"); + assertEquals("foo", findClientRepresentation("foo").getName()); + } + + @Test + public void testDeleteClient() { + createOidcClient("deleteMe"); + ClientResource clientRsc = findClientResource("deleteMe"); + assertNotNull(clientRsc); + clientRsc.remove(); + assertNull(findClientResource("deleteMe")); + } + + @Test + public void testUpdateClient() { + createOidcClient("updateMe"); + ClientRepresentation clientRep = findClientRepresentation("updateMe"); + assertEquals("updateMe", clientRep.getName()); + + clientRep.setName("iWasUpdated"); + findClientResource("updateMe").update(clientRep); + + ClientRepresentation updatedClient = findClientRepresentation("iWasUpdated"); + assertNotNull(updatedClient); + assertEquals("updateMe", updatedClient.getClientId()); + assertEquals("iWasUpdated", updatedClient.getName()); + } + + @Test + public void testGetAllClients() { + List allClients = testRealmResource().clients().findAll(); + assertNotNull(allClients); + assertFalse(allClients.isEmpty()); + } + + @Test + public void getClientByIdTest() { + createOidcClient("byidclient"); + ClientRepresentation rep = findClientRepresentation("byidclient"); + ClientRepresentation gotById = testRealmResource().clients().get(rep.getId()).toRepresentation(); + assertEqualClients(rep, gotById); + } + + /* DEPRECATED? + @Test + public void testAllowedOrigins() { + createOidcClient("originsClient"); + ClientResource client = findClientResource("originsClient"); + java.util.Set origins = client.getAllowedOrigins(); + assertEquals(1, origins.size()); + assertTrue(origins.contains("foo/*")); + + origins.add("bar/*"); + client.updateAllowedOrigins(origins); //<-- STACK OVERFLOW + origins = client.getAllowedOrigins(); + assertEquals(2, origins.size()); + assertTrue(origins.contains("foo/*")); + assertTrue(origins.contains("bar/*")); + + java.util.Set toRemove = new java.util.HashSet<>(); + toRemove.add("bar/*"); + client.removeAllowedOrigins(origins); + origins = client.getAllowedOrigins(); + assertEquals(1, origins.size()); + assertTrue(origins.contains("foo/*")); + } */ + +} diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/client/InstallationTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/client/InstallationTest.java new file mode 100644 index 0000000000..86927e468a --- /dev/null +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/client/InstallationTest.java @@ -0,0 +1,115 @@ +/* + * Copyright 2016 Red Hat Inc. and/or its affiliates and other contributors + * as indicated by the @author tags. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package org.keycloak.testsuite.admin.client; + +import org.junit.Before; +import org.junit.Test; +import org.keycloak.admin.client.resource.ClientResource; +import org.keycloak.representations.idm.RealmRepresentation; +import org.keycloak.testsuite.arquillian.AuthServerTestEnricher; + +import static org.junit.Assert.assertTrue; + +/** + * Test getting the installation/configuration files for OIDC and SAML. + * + * @author Stan Silvert ssilvert@redhat.com (C) 2016 Red Hat Inc. + */ +public class InstallationTest extends AbstractClientTest { + + private static final String OIDC_NAME = "oidcInstallationClient"; + private static final String SAML_NAME = "samlInstallationClient"; + + private ClientResource oidcClient; + private ClientResource samlClient; + + @Before + public void createClients() { + createOidcClient(OIDC_NAME); + oidcClient = findClientResource(OIDC_NAME); + + createSamlClient(SAML_NAME); + samlClient = findClientResource(SAML_NAME); + } + + private String authServerUrl() { + return AuthServerTestEnricher.getAuthServerContextRoot() + "/auth"; + } + + private String samlUrl(RealmRepresentation realmRep) { + return authServerUrl() + "/realms/" + realmRep.getId() + "/protocol/saml"; + } + + @Test + public void testOidcJBossXml() { + String xml = oidcClient.getInstallationProvider("keycloak-oidc-jboss-subsystem"); + assertOidcInstallationConfig(xml); + assertTrue(xml.contains("")); + assertTrue(xml.contains(SAML_NAME)); + assertTrue(xml.contains(realmRep.getCertificate())); + assertTrue(xml.contains(samlUrl(realmRep))); + } + + @Test + public void testSamlMetadataSpDescriptor() { + String xml = samlClient.getInstallationProvider("saml-sp-descriptor"); + assertTrue(xml.contains("