Search in sources :

Example 21 with TokenUtil

use of org.keycloak.testsuite.util.TokenUtil in project keycloak by keycloak.

the class AccountRestServiceTest method listApplicationsWithoutPermission.

@Test
public void listApplicationsWithoutPermission() throws IOException {
    TokenUtil token = new TokenUtil("no-account-access", "password");
    SimpleHttp.Response response = SimpleHttp.doGet(getAccountUrl("applications"), httpClient).header("Accept", "application/json").auth(token.getToken()).asResponse();
    assertEquals(403, response.getStatus());
}
Also used : SimpleHttp(org.keycloak.broker.provider.util.SimpleHttp) TokenUtil(org.keycloak.testsuite.util.TokenUtil) Test(org.junit.Test) AbstractAuthenticationTest(org.keycloak.testsuite.admin.authentication.AbstractAuthenticationTest)

Example 22 with TokenUtil

use of org.keycloak.testsuite.util.TokenUtil in project keycloak by keycloak.

the class AccountRestServiceTest method testUpdateProfilePermissions.

@Test
public void testUpdateProfilePermissions() throws IOException {
    TokenUtil noaccessToken = new TokenUtil("no-account-access", "password");
    int status = SimpleHttp.doGet(getAccountUrl(null), httpClient).header("Accept", "application/json").auth(noaccessToken.getToken()).asStatus();
    assertEquals(403, status);
    TokenUtil viewToken = new TokenUtil("view-account-access", "password");
    status = SimpleHttp.doGet(getAccountUrl(null), httpClient).header("Accept", "application/json").auth(viewToken.getToken()).asStatus();
    assertEquals(200, status);
}
Also used : TokenUtil(org.keycloak.testsuite.util.TokenUtil) Test(org.junit.Test) AbstractAuthenticationTest(org.keycloak.testsuite.admin.authentication.AbstractAuthenticationTest)

Example 23 with TokenUtil

use of org.keycloak.testsuite.util.TokenUtil in project keycloak by keycloak.

the class AccountRestServiceTest method createConsentForNotExistingClient.

@Test
public void createConsentForNotExistingClient() throws IOException {
    TokenUtil token = new TokenUtil("manage-consent-access", "password");
    String appId = "not-existing";
    ClientScopeRepresentation clientScopeRepresentation = testRealm().clientScopes().findAll().get(0);
    ConsentScopeRepresentation consentScopeRepresentation = new ConsentScopeRepresentation();
    consentScopeRepresentation.setId(clientScopeRepresentation.getId());
    ConsentRepresentation requestedConsent = new ConsentRepresentation();
    requestedConsent.setGrantedScopes(Collections.singletonList(consentScopeRepresentation));
    SimpleHttp.Response response = SimpleHttp.doPost(getAccountUrl("applications/" + appId + "/consent"), httpClient).header("Accept", "application/json").json(requestedConsent).auth(token.getToken()).asResponse();
    assertEquals(404, response.getStatus());
}
Also used : ConsentRepresentation(org.keycloak.representations.account.ConsentRepresentation) SimpleHttp(org.keycloak.broker.provider.util.SimpleHttp) ClientScopeRepresentation(org.keycloak.representations.idm.ClientScopeRepresentation) ConsentScopeRepresentation(org.keycloak.representations.account.ConsentScopeRepresentation) TokenUtil(org.keycloak.testsuite.util.TokenUtil) Test(org.junit.Test) AbstractAuthenticationTest(org.keycloak.testsuite.admin.authentication.AbstractAuthenticationTest)

Example 24 with TokenUtil

use of org.keycloak.testsuite.util.TokenUtil in project keycloak by keycloak.

the class AccountRestServiceTest method createConsentForNotExistingClientWithPut.

@Test
public void createConsentForNotExistingClientWithPut() throws IOException {
    TokenUtil token = new TokenUtil("manage-consent-access", "password");
    String appId = "not-existing";
    ClientScopeRepresentation clientScopeRepresentation = testRealm().clientScopes().findAll().get(0);
    ConsentScopeRepresentation consentScopeRepresentation = new ConsentScopeRepresentation();
    consentScopeRepresentation.setId(clientScopeRepresentation.getId());
    ConsentRepresentation requestedConsent = new ConsentRepresentation();
    requestedConsent.setGrantedScopes(Collections.singletonList(consentScopeRepresentation));
    SimpleHttp.Response response = SimpleHttp.doPut(getAccountUrl("applications/" + appId + "/consent"), httpClient).header("Accept", "application/json").json(requestedConsent).auth(token.getToken()).asResponse();
    assertEquals(404, response.getStatus());
}
Also used : ConsentRepresentation(org.keycloak.representations.account.ConsentRepresentation) SimpleHttp(org.keycloak.broker.provider.util.SimpleHttp) ClientScopeRepresentation(org.keycloak.representations.idm.ClientScopeRepresentation) ConsentScopeRepresentation(org.keycloak.representations.account.ConsentScopeRepresentation) TokenUtil(org.keycloak.testsuite.util.TokenUtil) Test(org.junit.Test) AbstractAuthenticationTest(org.keycloak.testsuite.admin.authentication.AbstractAuthenticationTest)

Example 25 with TokenUtil

use of org.keycloak.testsuite.util.TokenUtil in project keycloak by keycloak.

the class AccountRestServiceTest method getConsentForClient.

@Test
public void getConsentForClient() throws IOException {
    TokenUtil token = new TokenUtil("manage-consent-access", "password");
    String appId = "security-admin-console";
    ClientScopeRepresentation clientScopeRepresentation = testRealm().clientScopes().findAll().get(0);
    ConsentScopeRepresentation consentScopeRepresentation = new ConsentScopeRepresentation();
    consentScopeRepresentation.setId(clientScopeRepresentation.getId());
    ConsentRepresentation requestedConsent = new ConsentRepresentation();
    requestedConsent.setGrantedScopes(Collections.singletonList(consentScopeRepresentation));
    ConsentRepresentation consentRepresentation1 = SimpleHttp.doPost(getAccountUrl("applications/" + appId + "/consent"), httpClient).header("Accept", "application/json").json(requestedConsent).auth(token.getToken()).asJson(ConsentRepresentation.class);
    assertTrue(consentRepresentation1.getCreatedDate() > 0);
    assertTrue(consentRepresentation1.getLastUpdatedDate() > 0);
    assertEquals(1, consentRepresentation1.getGrantedScopes().size());
    assertEquals(consentScopeRepresentation.getId(), consentRepresentation1.getGrantedScopes().get(0).getId());
    ConsentRepresentation consentRepresentation2 = SimpleHttp.doGet(getAccountUrl("applications/" + appId + "/consent"), httpClient).header("Accept", "application/json").auth(token.getToken()).asJson(ConsentRepresentation.class);
    assertEquals(consentRepresentation1.getLastUpdatedDate(), consentRepresentation2.getLastUpdatedDate());
    assertEquals(consentRepresentation1.getCreatedDate(), consentRepresentation2.getCreatedDate());
    assertEquals(consentRepresentation1.getGrantedScopes().get(0).getId(), consentRepresentation2.getGrantedScopes().get(0).getId());
}
Also used : ConsentRepresentation(org.keycloak.representations.account.ConsentRepresentation) ClientScopeRepresentation(org.keycloak.representations.idm.ClientScopeRepresentation) ConsentScopeRepresentation(org.keycloak.representations.account.ConsentScopeRepresentation) TokenUtil(org.keycloak.testsuite.util.TokenUtil) Test(org.junit.Test) AbstractAuthenticationTest(org.keycloak.testsuite.admin.authentication.AbstractAuthenticationTest)

Aggregations

TokenUtil (org.keycloak.testsuite.util.TokenUtil)29 Test (org.junit.Test)28 AbstractAuthenticationTest (org.keycloak.testsuite.admin.authentication.AbstractAuthenticationTest)25 SimpleHttp (org.keycloak.broker.provider.util.SimpleHttp)18 ConsentRepresentation (org.keycloak.representations.account.ConsentRepresentation)16 ConsentScopeRepresentation (org.keycloak.representations.account.ConsentScopeRepresentation)16 ClientScopeRepresentation (org.keycloak.representations.idm.ClientScopeRepresentation)16 SessionRepresentation (org.keycloak.representations.account.SessionRepresentation)8 TypeReference (com.fasterxml.jackson.core.type.TypeReference)7 List (java.util.List)7 Response (javax.ws.rs.core.Response)7 IOException (java.io.IOException)6 Collections (java.util.Collections)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 Collectors (java.util.stream.Collectors)6 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)6 Assert (org.junit.Assert)6 Assert.assertEquals (org.junit.Assert.assertEquals)6 Assert.assertFalse (org.junit.Assert.assertFalse)6