Exemplo n.º 1
0
  @Test
  public void authorizationRequest() throws IOException {
    oauth.state("mystate");

    AuthorizationCodeResponse response = oauth.doLogin("test-user@localhost", "password");

    Assert.assertTrue(response.isRedirected());
    Assert.assertNotNull(response.getCode());
    Assert.assertEquals("mystate", response.getState());
    Assert.assertNull(response.getError());

    oauth.verifyCode(response.getCode());
  }
Exemplo n.º 2
0
  @Test
  public void sessions() {
    loginPage.open();
    loginPage.clickRegister();

    registerPage.register(
        "view", "sessions", "view-sessions@localhost", "view-sessions", "password", "password");

    Event registerEvent =
        events.expectRegister("view-sessions", "view-sessions@localhost").assertEvent();
    String userId = registerEvent.getUserId();

    events.expectLogin().user(userId).detail(Details.USERNAME, "view-sessions").assertEvent();

    sessionsPage.open();

    Assert.assertTrue(sessionsPage.isCurrent());

    List<List<String>> sessions = sessionsPage.getSessions();
    Assert.assertEquals(1, sessions.size());
    Assert.assertEquals("127.0.0.1", sessions.get(0).get(0));

    // Create second session
    WebDriver driver2 = WebRule.createWebDriver();
    try {
      OAuthClient oauth2 = new OAuthClient(driver2);
      oauth2.state("mystate");
      oauth2.doLogin("view-sessions", "password");

      Event login2Event =
          events.expectLogin().user(userId).detail(Details.USERNAME, "view-sessions").assertEvent();

      sessionsPage.open();
      sessions = sessionsPage.getSessions();
      Assert.assertEquals(2, sessions.size());

      sessionsPage.logoutAll();

      events.expectLogout(registerEvent.getSessionId());
      events.expectLogout(login2Event.getSessionId());
    } finally {
      driver2.close();
    }
  }
Exemplo n.º 3
0
  @Test
  public void authorizationValidRedirectUri() throws IOException {
    keycloakRule.configure(
        new KeycloakRule.KeycloakSetup() {
          @Override
          public void config(
              RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) {
            appRealm.getApplicationByName("test-app").addRedirectUri(oauth.getRedirectUri());
          }
        });

    oauth.state("mystate");

    AuthorizationCodeResponse response = oauth.doLogin("test-user@localhost", "password");

    Assert.assertTrue(response.isRedirected());
    Assert.assertNotNull(response.getCode());

    oauth.verifyCode(response.getCode());
  }
Exemplo n.º 4
0
 @Before
 public void before() {
   oauth.state("mystate"); // keycloak enforces that a state param has been sent by client
   userId = keycloakRule.getUser("test", "test-user@localhost").getId();
 }