use of org.keycloak.testsuite.runonserver.RunOnServerException in project keycloak by keycloak.
the class MultiVersionClusterTest method verifyFailureOnCurrent.
@Test
public void verifyFailureOnCurrent() throws Exception {
deploy(deployment(), legacyNode);
try {
backendTestingClients.get(legacyNode).server().run(session -> {
try {
Class<?> itShouldFail = Module.getContextModuleLoader().loadModule("deployment.negative.jar").getClassLoader().loadClassLocal(SerializableTestClass.class.getName());
session.getProvider(InfinispanConnectionProvider.class).getCache(InfinispanConnectionProvider.USER_SESSION_CACHE_NAME).put("itShouldFail", Reflections.newInstance(itShouldFail));
} catch (Exception ex) {
throw new RunOnServerException(ex);
}
});
} catch (Exception e) {
assertThat(e, instanceOf(RunOnServerException.class));
assertThat(e.getCause().getCause(), instanceOf(TimeoutException.class));
} finally {
undeploy(deployment(), legacyNode);
}
}
use of org.keycloak.testsuite.runonserver.RunOnServerException in project keycloak by keycloak.
the class MultiVersionClusterTest method verifyFailureOnLegacy.
@Test
public void verifyFailureOnLegacy() throws Exception {
deploy(deployment(), currentNode);
try {
backendTestingClients.get(currentNode).server().run(session -> {
try {
Class<?> itShouldFail = Module.getContextModuleLoader().loadModule("deployment.negative.jar").getClassLoader().loadClassLocal(SerializableTestClass.class.getName());
session.getProvider(InfinispanConnectionProvider.class).getCache(InfinispanConnectionProvider.USER_SESSION_CACHE_NAME).put("itShouldFail", Reflections.newInstance(itShouldFail));
} catch (Exception ex) {
throw new RunOnServerException(ex);
}
});
} catch (Exception e) {
assertThat(e, instanceOf(RunOnServerException.class));
assertThat(e.getCause().getCause(), instanceOf(TimeoutException.class));
} finally {
undeploy(deployment(), currentNode);
}
}
use of org.keycloak.testsuite.runonserver.RunOnServerException in project keycloak by keycloak.
the class ImportTest method importWithoutRequestContext.
// KEYCLOAK-12921 NPE importing realm with no request context
@Test
public void importWithoutRequestContext() throws IOException {
final String realmString = IOUtils.toString(getClass().getResourceAsStream("/model/realm-validation.json"), StandardCharsets.UTF_8);
testingClient.server().run(session -> {
RealmRepresentation testRealm = JsonSerialization.readValue(realmString, RealmRepresentation.class);
AtomicReference<Throwable> err = new AtomicReference<>();
// Need a new thread to not get context from thread processing request to run-on-server endpoint
Thread t = new Thread(() -> {
try {
KeycloakSession ses = session.getKeycloakSessionFactory().create();
ses.getContext().setRealm(session.getContext().getRealm());
ses.getTransactionManager().begin();
RealmModel realmModel = new RealmManager(ses).importRealm(testRealm);
ses.getTransactionManager().commit();
ses.close();
ses = session.getKeycloakSessionFactory().create();
ses.getTransactionManager().begin();
session.realms().removeRealm(realmModel.getId());
ses.getTransactionManager().commit();
ses.close();
} catch (Throwable th) {
err.set(th);
}
});
synchronized (t) {
t.start();
try {
t.wait(10000);
} catch (InterruptedException e) {
throw new RunOnServerException(e);
}
}
if (err.get() != null) {
throw new RunOnServerException(err.get());
}
});
}
use of org.keycloak.testsuite.runonserver.RunOnServerException in project keycloak by keycloak.
the class LDAPUserLoginTest method afterImportTestRealm.
@Override
protected void afterImportTestRealm() {
try {
getTestingClient().server().run(session -> {
LDAPTestContext ctx = LDAPTestContext.init(session);
RealmModel appRealm = ctx.getRealm();
// Delete all LDAP users
LDAPTestUtils.removeAllLDAPUsers(ctx.getLdapProvider(), appRealm);
// Add some new LDAP users for testing
LDAPObject john = LDAPTestUtils.addLDAPUser(ctx.getLdapProvider(), appRealm, DEFAULT_TEST_USERS.get("VALID_USER_NAME"), DEFAULT_TEST_USERS.get("VALID_USER_FIRST_NAME"), DEFAULT_TEST_USERS.get("VALID_USER_LAST_NAME"), DEFAULT_TEST_USERS.get("VALID_USER_EMAIL"), DEFAULT_TEST_USERS.get("VALID_USER_STREET"), DEFAULT_TEST_USERS.get("VALID_USER_POSTAL_CODE"));
LDAPTestUtils.updateLDAPPassword(ctx.getLdapProvider(), john, DEFAULT_TEST_USERS.get("VALID_USER_PASSWORD"));
});
} catch (RunOnServerException ex) {
Assume.assumeFalse("Work around JDK-8214440", ex.getCause() instanceof ModelException && ex.getCause().getCause() instanceof ModelException && ex.getCause().getCause().getCause() instanceof javax.naming.AuthenticationException && Objects.equals(ex.getCause().getCause().getCause().getMessage(), "Could not negotiate TLS"));
}
}
use of org.keycloak.testsuite.runonserver.RunOnServerException in project keycloak by keycloak.
the class LdapUsernameAttributeTest method testUsernameChangeAlreadyExists.
@Test
public void testUsernameChangeAlreadyExists() {
// create a user johndow and johndow2
testingClient.server().run(session -> {
LDAPTestContext ctx = LDAPTestContext.init(session);
RealmModel appRealm = ctx.getRealm();
UserModel john = session.users().addUser(appRealm, "johndow");
john.setEmail("johndow@email.cz");
john.setFirstName("johndow");
john.setLastName("johndow");
UserModel john2 = session.users().addUser(appRealm, "johndow2");
john.setEmail("johndow2@email.cz");
john.setFirstName("johndow2");
john.setLastName("johndow2");
});
// check they are there
testingClient.server().run(session -> {
LDAPTestContext ctx = LDAPTestContext.init(session);
RealmModel appRealm = ctx.getRealm();
UserModel john = session.users().getUserByUsername(appRealm, "johndow");
Assert.assertNotNull(john);
Assert.assertNotNull(john.getFederationLink());
UserModel john2 = session.users().getUserByUsername(appRealm, "johndow2");
Assert.assertNotNull(john2);
Assert.assertNotNull(john2.getFederationLink());
});
// rename johndow to johndow2 => it should fail
try {
testingClient.server().run(session -> {
LDAPTestContext ctx = LDAPTestContext.init(session);
RealmModel appRealm = ctx.getRealm();
UserModel john = session.users().getUserByUsername(appRealm, "johndow");
john.setUsername("johndow2");
});
Assert.assertFalse("Model exception is expected here, so it should not reach this point", true);
} catch (RunOnServerException e) {
Assert.assertTrue("Model exception is expected here but another error found", e.getCause() instanceof ModelDuplicateException);
Assert.assertEquals(UserModel.USERNAME, ((ModelDuplicateException) e.getCause()).getDuplicateFieldName());
}
// remove both users
testingClient.server().run(session -> {
LDAPTestContext ctx = LDAPTestContext.init(session);
RealmModel appRealm = ctx.getRealm();
UserModel john = session.users().getUserByUsername(appRealm, "johndow");
Assert.assertNotNull(john);
UserModel john2 = session.users().getUserByUsername(appRealm, "johndow2");
Assert.assertNotNull(john2);
session.users().removeUser(appRealm, john);
session.users().removeUser(appRealm, john2);
Assert.assertNull(session.users().getUserByUsername(appRealm, "johndow"));
Assert.assertNull(session.users().getUserByUsername(appRealm, "johndow2"));
});
}
Aggregations