Fix audit mongo tests
This commit is contained in:
parent
7f0cf3eda8
commit
354cf02aaa
3 changed files with 41 additions and 8 deletions
|
@ -13,7 +13,8 @@ public class Config {
|
|||
|
||||
public static final String MODEL_PROVIDER_KEY = "keycloak.model";
|
||||
|
||||
public static final String AUDIT_KEY = "keycloak.audit";
|
||||
public static final String AUDIT_PROVIDER_KEY = "keycloak.audit";
|
||||
public static final String AUDIT_PROVIDER_DEFAULT = "jpa";
|
||||
public static final String AUDIT_EXPIRATION_SCHEDULE_KEY = "keycloak.audit.expirationSchedule";
|
||||
public static final String AUDIT_EXPIRATION_SCHEDULE_DEFAULT = String.valueOf(TimeUnit.MINUTES.toMillis(15));
|
||||
|
||||
|
@ -36,7 +37,7 @@ public class Config {
|
|||
}
|
||||
|
||||
public static String getAuditProvider() {
|
||||
return System.getProperty(AUDIT_KEY);
|
||||
return System.getProperty(AUDIT_PROVIDER_KEY, AUDIT_PROVIDER_DEFAULT);
|
||||
}
|
||||
|
||||
public static void setAuditProvider(String provider) {
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package org.keycloak.testsuite;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
||||
*/
|
||||
public class Retry {
|
||||
|
||||
public static void execute(Runnable runnable, int retry, long interval) throws InterruptedException {
|
||||
while (true) {
|
||||
try {
|
||||
runnable.run();
|
||||
return;
|
||||
} catch (RuntimeException e) {
|
||||
retry--;
|
||||
if (retry > 0) {
|
||||
Thread.sleep(interval);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -22,8 +22,10 @@
|
|||
package org.keycloak.testsuite.account;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
@ -31,6 +33,7 @@ import org.keycloak.audit.Details;
|
|||
import org.keycloak.audit.Event;
|
||||
import org.keycloak.audit.jpa.JpaAuditProviderFactory;
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.Config;
|
||||
import org.keycloak.models.PasswordPolicy;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.UserCredentialModel;
|
||||
|
@ -40,6 +43,7 @@ import org.keycloak.representations.idm.CredentialRepresentation;
|
|||
import org.keycloak.services.managers.RealmManager;
|
||||
import org.keycloak.testsuite.AssertEvents;
|
||||
import org.keycloak.testsuite.OAuthClient;
|
||||
import org.keycloak.testsuite.Retry;
|
||||
import org.keycloak.testsuite.pages.AccountLogPage;
|
||||
import org.keycloak.testsuite.pages.AccountPasswordPage;
|
||||
import org.keycloak.testsuite.pages.AccountTotpPage;
|
||||
|
@ -145,8 +149,6 @@ public class AccountTest {
|
|||
appRealm.updateCredential(user, cred);
|
||||
}
|
||||
});
|
||||
|
||||
System.out.println(JpaAuditProviderFactory.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -365,17 +367,23 @@ public class AccountTest {
|
|||
|
||||
Assert.assertTrue(logPage.isCurrent());
|
||||
|
||||
List<List<String>> actual = logPage.getEvents();
|
||||
final int expectedEvents = e.size();
|
||||
Retry.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Assert.assertEquals(expectedEvents, logPage.getEvents().size());
|
||||
}
|
||||
}, 10, 500);
|
||||
|
||||
Assert.assertEquals(e.size(), actual.size());
|
||||
|
||||
Iterator<List<String>> itr = actual.iterator();
|
||||
Iterator<List<String>> itr = logPage.getEvents().iterator();
|
||||
for (Event event : e) {
|
||||
List<String> a = itr.next();
|
||||
Assert.assertEquals(event.getEvent().replace('_', ' '), a.get(1));
|
||||
Assert.assertEquals(event.getIpAddress(), a.get(2));
|
||||
Assert.assertEquals(event.getClientId(), a.get(3));
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
keycloakRule.configure(new KeycloakSetup() {
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue