KEYCLOAK-2533: Test values of events in LoginEventsTest. Also do the same
for AdminEventTest.
This commit is contained in:
parent
3383b044b2
commit
64b2aed370
3 changed files with 52 additions and 4 deletions
|
@ -54,4 +54,8 @@ public abstract class AbstractEventTest extends AbstractAuthTest {
|
|||
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
protected String realmName() {
|
||||
return testRealmResource().toRepresentation().getId();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<AdminEventRepresentation> 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
|
||||
|
|
|
@ -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<EventRepresentation> 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<String, String> 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());
|
||||
|
|
Loading…
Reference in a new issue