Merge pull request #2910 from mposolda/master
KEYCLOAK-3074 AdminEventStoreProviderTest fixes
This commit is contained in:
commit
193233899f
3 changed files with 41 additions and 29 deletions
|
@ -61,9 +61,7 @@ import org.keycloak.events.EventType;
|
||||||
import org.keycloak.events.admin.AdminEventQuery;
|
import org.keycloak.events.admin.AdminEventQuery;
|
||||||
import org.keycloak.events.admin.AuthDetails;
|
import org.keycloak.events.admin.AuthDetails;
|
||||||
import org.keycloak.events.admin.OperationType;
|
import org.keycloak.events.admin.OperationType;
|
||||||
import org.keycloak.models.utils.RepresentationToModel;
|
|
||||||
import org.keycloak.representations.idm.AuthDetailsRepresentation;
|
import org.keycloak.representations.idm.AuthDetailsRepresentation;
|
||||||
import org.keycloak.services.resources.admin.RealmAuth;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
||||||
|
@ -386,8 +384,8 @@ public class TestingResourceProvider implements RealmResourceProvider {
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public List<AdminEventRepresentation> getAdminEvents(@QueryParam("realmId") String realmId, @QueryParam("operationTypes") List<String> operationTypes, @QueryParam("authRealm") String authRealm, @QueryParam("authClient") String authClient,
|
public List<AdminEventRepresentation> getAdminEvents(@QueryParam("realmId") String realmId, @QueryParam("operationTypes") List<String> operationTypes, @QueryParam("authRealm") String authRealm, @QueryParam("authClient") String authClient,
|
||||||
@QueryParam("authUser") String authUser, @QueryParam("authIpAddress") String authIpAddress,
|
@QueryParam("authUser") String authUser, @QueryParam("authIpAddress") String authIpAddress,
|
||||||
@QueryParam("resourcePath") String resourcePath, @QueryParam("dateFrom") Date dateFrom,
|
@QueryParam("resourcePath") String resourcePath, @QueryParam("dateFrom") String dateFrom,
|
||||||
@QueryParam("dateTo") Date dateTo, @QueryParam("first") Integer firstResult,
|
@QueryParam("dateTo") String dateTo, @QueryParam("first") Integer firstResult,
|
||||||
@QueryParam("max") Integer maxResults) {
|
@QueryParam("max") Integer maxResults) {
|
||||||
|
|
||||||
EventStoreProvider eventStore = session.getProvider(EventStoreProvider.class);
|
EventStoreProvider eventStore = session.getProvider(EventStoreProvider.class);
|
||||||
|
@ -426,17 +424,37 @@ public class TestingResourceProvider implements RealmResourceProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(dateFrom != null) {
|
if(dateFrom != null) {
|
||||||
query.fromTime(dateFrom);
|
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
|
Date from;
|
||||||
|
try {
|
||||||
|
from = df.parse(dateFrom);
|
||||||
|
} catch (ParseException e) {
|
||||||
|
throw new BadRequestException("Invalid value for 'Date(From)', expected format is yyyy-MM-dd");
|
||||||
|
}
|
||||||
|
|
||||||
|
query.fromTime(from);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(dateTo != null) {
|
if(dateTo != null) {
|
||||||
query.toTime(dateTo);
|
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
|
Date to;
|
||||||
|
try {
|
||||||
|
to = df.parse(dateTo);
|
||||||
|
} catch (ParseException e) {
|
||||||
|
throw new BadRequestException("Invalid value for 'Date(To)', expected format is yyyy-MM-dd");
|
||||||
|
}
|
||||||
|
|
||||||
|
query.toTime(to);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (firstResult != null) {
|
if (firstResult != null || maxResults != null) {
|
||||||
|
if (firstResult == null) {
|
||||||
|
firstResult = 0;
|
||||||
|
}
|
||||||
|
if (maxResults == null) {
|
||||||
|
maxResults = 100;
|
||||||
|
}
|
||||||
query.firstResult(firstResult);
|
query.firstResult(firstResult);
|
||||||
}
|
|
||||||
if (maxResults != null) {
|
|
||||||
query.maxResults(maxResults);
|
query.maxResults(maxResults);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -159,8 +159,8 @@ public interface TestingResource {
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public List<AdminEventRepresentation> getAdminEvents(@QueryParam("realmId") String realmId, @QueryParam("operationTypes") List<String> operationTypes, @QueryParam("authRealm") String authRealm, @QueryParam("authClient") String authClient,
|
public List<AdminEventRepresentation> getAdminEvents(@QueryParam("realmId") String realmId, @QueryParam("operationTypes") List<String> operationTypes, @QueryParam("authRealm") String authRealm, @QueryParam("authClient") String authClient,
|
||||||
@QueryParam("authUser") String authUser, @QueryParam("authIpAddress") String authIpAddress,
|
@QueryParam("authUser") String authUser, @QueryParam("authIpAddress") String authIpAddress,
|
||||||
@QueryParam("resourcePath") String resourcePath, @QueryParam("dateFrom") Date dateFrom,
|
@QueryParam("resourcePath") String resourcePath, @QueryParam("dateFrom") String dateFrom,
|
||||||
@QueryParam("dateTo") Date dateTo, @QueryParam("first") Integer firstResult,
|
@QueryParam("dateTo") String dateTo, @QueryParam("first") Integer firstResult,
|
||||||
@QueryParam("max") Integer maxResults);
|
@QueryParam("max") Integer maxResults);
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
|
|
|
@ -87,18 +87,12 @@ public class AdminEventStoreProviderTest extends AbstractEventsTest {
|
||||||
|
|
||||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
Date date1 = null, date2 = null, date3 = null, date4 = null;
|
Date date1 = null, date2 = null, date3 = null, date4 = null;
|
||||||
Date date5 = null, date6 = null, date7 = null, date8 = null;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
date1 = formatter.parse(d1);
|
date1 = formatter.parse(d1);
|
||||||
date2 = formatter.parse(d2);
|
date2 = formatter.parse(d2);
|
||||||
date3 = formatter.parse(d3);
|
date3 = formatter.parse(d3);
|
||||||
date4 = formatter.parse(d4);
|
date4 = formatter.parse(d4);
|
||||||
|
|
||||||
date5 = formatter.parse(d5);
|
|
||||||
date6 = formatter.parse(d6);
|
|
||||||
date7 = formatter.parse(d7);
|
|
||||||
date8 = formatter.parse(d8);
|
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -127,22 +121,22 @@ public class AdminEventStoreProviderTest extends AbstractEventsTest {
|
||||||
Assert.assertEquals(1, testing().getAdminEvents(null, toList(OperationType.DELETE), null, null, null, null, null, null, null, null, null).size());
|
Assert.assertEquals(1, testing().getAdminEvents(null, toList(OperationType.DELETE), null, null, null, null, null, null, null, null, null).size());
|
||||||
Assert.assertEquals(4, testing().getAdminEvents(null, toList(OperationType.CREATE), null, null, null, null, null, null, null, null, null).size());
|
Assert.assertEquals(4, testing().getAdminEvents(null, toList(OperationType.CREATE), null, null, null, null, null, null, null, null, null).size());
|
||||||
|
|
||||||
Assert.assertEquals(8, testing().getAdminEvents(null, null, null, null, null, null, null, date1, null, null, null).size());
|
Assert.assertEquals(8, testing().getAdminEvents(null, null, null, null, null, null, null, d1, null, null, null).size());
|
||||||
Assert.assertEquals(8, testing().getAdminEvents(null, null, null, null, null, null, null, null, date4, null, null).size());
|
Assert.assertEquals(8, testing().getAdminEvents(null, null, null, null, null, null, null, null, d4, null, null).size());
|
||||||
|
|
||||||
Assert.assertEquals(4, testing().getAdminEvents(null, null, null, null, null, null, null, date3, null, null, null).size());
|
Assert.assertEquals(4, testing().getAdminEvents(null, null, null, null, null, null, null, d3, null, null, null).size());
|
||||||
Assert.assertEquals(4, testing().getAdminEvents(null, null, null, null, null, null, null, null, date2, null, null).size());
|
Assert.assertEquals(4, testing().getAdminEvents(null, null, null, null, null, null, null, null, d2, null, null).size());
|
||||||
|
|
||||||
Assert.assertEquals(0, testing().getAdminEvents(null, null, null, null, null, null, null, date7, null, null, null).size());
|
Assert.assertEquals(0, testing().getAdminEvents(null, null, null, null, null, null, null, d7, null, null, null).size());
|
||||||
Assert.assertEquals(0, testing().getAdminEvents(null, null, null, null, null, null, null, null, date6, null, null).size());
|
Assert.assertEquals(0, testing().getAdminEvents(null, null, null, null, null, null, null, null, d6, null, null).size());
|
||||||
|
|
||||||
Assert.assertEquals(8, testing().getAdminEvents(null, null, null, null, null, null, null, date1, date4, null, null).size());
|
Assert.assertEquals(8, testing().getAdminEvents(null, null, null, null, null, null, null, d1, d4, null, null).size());
|
||||||
Assert.assertEquals(6, testing().getAdminEvents(null, null, null, null, null, null, null, date2, date4, null, null).size());
|
Assert.assertEquals(6, testing().getAdminEvents(null, null, null, null, null, null, null, d2, d4, null, null).size());
|
||||||
Assert.assertEquals(4, testing().getAdminEvents(null, null, null, null, null, null, null, date1, date2, null, null).size());
|
Assert.assertEquals(4, testing().getAdminEvents(null, null, null, null, null, null, null, d1, d2, null, null).size());
|
||||||
Assert.assertEquals(4, testing().getAdminEvents(null, null, null, null, null, null, null, date3, date4, null, null).size());
|
Assert.assertEquals(4, testing().getAdminEvents(null, null, null, null, null, null, null, d3, d4, null, null).size());
|
||||||
|
|
||||||
Assert.assertEquals(0, testing().getAdminEvents(null, null, null, null, null, null, null, date5, date6, null, null).size());
|
Assert.assertEquals(0, testing().getAdminEvents(null, null, null, null, null, null, null, d5, d6, null, null).size());
|
||||||
Assert.assertEquals(0, testing().getAdminEvents(null, null, null, null, null, null, null, date7, date8, null, null).size());
|
Assert.assertEquals(0, testing().getAdminEvents(null, null, null, null, null, null, null, d7, d8, null, null).size());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue