From 64b2aed370ef833e580be0f3762fbc289f98e8e8 Mon Sep 17 00:00:00 2001 From: Stan Silvert Date: Tue, 23 Feb 2016 14:20:35 -0500 Subject: [PATCH] KEYCLOAK-2533: Test values of events in LoginEventsTest. Also do the same for AdminEventTest. --- .../admin/event/AbstractEventTest.java | 4 +++ .../testsuite/admin/event/AdminEventTest.java | 26 ++++++++++++++++--- .../admin/event/LoginEventsTest.java | 26 +++++++++++++++++++ 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/event/AbstractEventTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/event/AbstractEventTest.java index 338bbaa6d4..ba50fe7227 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/event/AbstractEventTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/event/AbstractEventTest.java @@ -54,4 +54,8 @@ public abstract class AbstractEventTest extends AbstractAuthTest { saveConfig(); } + + protected String realmName() { + return testRealmResource().toRepresentation().getId(); + } } diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/event/AdminEventTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/event/AdminEventTest.java index bc755f0aee..d7c0845626 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/event/AdminEventTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/event/AdminEventTest.java @@ -23,6 +23,7 @@ import java.util.List; import org.junit.Before; import org.junit.Test; import org.keycloak.representations.idm.AdminEventRepresentation; +import org.keycloak.representations.idm.AuthDetailsRepresentation; import org.keycloak.representations.idm.RealmRepresentation; import org.keycloak.representations.idm.UserRepresentation; import org.keycloak.testsuite.admin.ApiUtil; @@ -60,10 +61,6 @@ public class AdminEventTest extends AbstractEventTest { testRealmResource().update(realm); } - private String realmName() { - return testRealmResource().toRepresentation().getId(); - } - @Test public void clearAdminEventsTest() { createUser("user0"); @@ -72,6 +69,26 @@ public class AdminEventTest extends AbstractEventTest { assertEquals(Collections.EMPTY_LIST, events()); } + @Test + public void adminEventAttributeTest() { + createUser("user5"); + List events = events(); + assertEquals(1, events.size()); + + AdminEventRepresentation event = events.get(0); + assertTrue(event.getTime() > 0); + assertEquals(realmName(), event.getRealmId()); + assertEquals("CREATE", event.getOperationType()); + assertNotNull(event.getResourcePath()); + assertNull(event.getError()); + + AuthDetailsRepresentation details = event.getAuthDetails(); + assertEquals(realmName(), details.getRealmId()); + assertNotNull(details.getClientId()); + assertNotNull(details.getUserId()); + assertNotNull(details.getIpAddress()); + } + @Test public void retrieveAdminEventTest() { createUser("user1"); @@ -95,6 +112,7 @@ public class AdminEventTest extends AbstractEventTest { AdminEventRepresentation event = events().get(0); assertNotNull(event.getRepresentation()); assertTrue(event.getRepresentation().contains("foo")); + assertTrue(event.getRepresentation().contains("bar")); } @Test diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/event/LoginEventsTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/event/LoginEventsTest.java index ef75b3fb98..fa44674e3c 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/event/LoginEventsTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/event/LoginEventsTest.java @@ -19,6 +19,7 @@ package org.keycloak.testsuite.admin.event; import java.util.Arrays; import java.util.List; +import java.util.Map; import org.jboss.arquillian.graphene.page.Page; import org.junit.Before; import org.junit.Test; @@ -26,6 +27,9 @@ import org.keycloak.representations.idm.EventRepresentation; import org.keycloak.testsuite.console.page.events.LoginEvents; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; /** @@ -62,6 +66,28 @@ public class LoginEventsTest extends AbstractEventTest { } } + @Test + public void eventAttributesTest() { + badLogin(); + List events = events(); + assertEquals(1, events.size()); + EventRepresentation event = events.get(0); + assertTrue(event.getTime() > 0); + assertNotNull(event.getIpAddress()); + assertEquals("LOGIN_ERROR", event.getType()); + assertEquals(realmName(), event.getRealmId()); + assertNull(event.getUserId()); // no user for bad login + assertNull(event.getSessionId()); // no session for bad login + assertEquals("user_not_found", event.getError()); + + Map details = event.getDetails(); + assertEquals("openid-connect", details.get("auth_method")); + assertEquals("code", details.get("auth_type")); + assertNotNull(details.get("redirect_uri")); + assertNotNull(details.get("code_id")); + assertEquals("bad", details.get("username")); + } + @Test public void clearEventsTest() { assertEquals(0, events().size());