use of org.minijax.rs.MinijaxRequestContext in project minijax by minijax.
the class AdapterTest method testOnError.
@Test
void testOnError() throws IOException {
try (final MinijaxRequestContext ctx = createRequestContext()) {
final MinijaxUndertowWebSocketAdapter adapter = new MinijaxUndertowWebSocketAdapter(ctx, TestSocket4.class);
adapter.onOpen(emptyMap());
adapter.onMessage(emptyMap());
adapter.onClose(emptyMap());
adapter.onError(emptyMap());
}
}
use of org.minijax.rs.MinijaxRequestContext in project minijax by minijax.
the class RolesAllowedTest method testLoginUserNotFound.
@Test
void testLoginUserNotFound() throws Exception {
try (final MinijaxRequestContext ctx = createRequestContext()) {
final LoginResult result = ctx.getResource(Security.class).login("notfound@example.com", "alicepwd");
assertEquals(LoginResult.Status.NOT_FOUND, result.getStatus());
}
}
use of org.minijax.rs.MinijaxRequestContext in project minijax by minijax.
the class RolesAllowedTest method setUpSecurityTest.
@BeforeAll
public static void setUpSecurityTest() throws IOException {
resetServer();
getServer().register(PersistenceFeature.class).register(new SecurityFeature(User.class, Dao.class)).register(RolesAllowedTest.class);
try (final MinijaxRequestContext ctx = createRequestContext()) {
final Dao dao = ctx.getResource(Dao.class);
alice = new User();
alice.setName("Alice");
alice.setEmail("alice@example.com");
alice.setHandle("alice");
alice.setPassword("alicepwd");
alice.setRoles("user", "admin");
dao.create(alice);
bob = new User();
bob.setName("Bob");
bob.setEmail("bob@example.com");
bob.setHandle("bob");
bob.setPassword("bobpwd");
bob.setRoles("user");
dao.create(bob);
aliceCookie = ctx.getResource(Security.class).loginAs(alice);
bobCookie = ctx.getResource(Security.class).loginAs(bob);
}
}
use of org.minijax.rs.MinijaxRequestContext in project minijax by minijax.
the class ResetPasswordTest method testResetPasswordSuccess.
@Test
void testResetPasswordSuccess() throws IOException {
final User user = new User();
user.setName("Example 1");
user.setEmail("reset-1@example.com");
user.setRoles("user");
String code = null;
try (MinijaxRequestContext ctx = createRequestContext()) {
ctx.getResource(Dao.class).create(user);
code = ctx.getResource(Security.class).forgotPassword(user);
}
final Form form = new Form();
form.param("newPassword", "my-new-password");
form.param("confirmNewPassword", "my-new-password");
final Response r = target("/resetpassword/" + code).request().post(Entity.form(form));
assertNotNull(r);
assertEquals(200, r.getStatus());
assertFalse(r.getCookies().isEmpty());
try (MinijaxRequestContext ctx = createRequestContext()) {
final User check = ctx.getResource(Dao.class).read(User.class, user.getId());
assertFalse(BCrypt.checkpw("my-old-password", check.getPasswordHash()));
assertTrue(BCrypt.checkpw("my-new-password", check.getPasswordHash()));
}
}
use of org.minijax.rs.MinijaxRequestContext in project minijax by minijax.
the class ChangePasswordTest method testIncorrectOldPassword.
@Test
void testIncorrectOldPassword() throws IOException {
final User user = new User();
user.setName("Example 3");
user.setEmail("pwd-3@example.com");
user.setRoles("user");
user.setPassword("my-old-password");
Cookie cookie = null;
try (MinijaxRequestContext ctx = createRequestContext()) {
ctx.getResource(Dao.class).create(user);
cookie = ctx.getResource(Security.class).loginAs(user);
}
final Form form = new Form();
form.param("csrf", cookie.getValue());
form.param("oldPassword", "wrong-old-password");
form.param("newPassword", "my-new-password");
form.param("confirmNewPassword", "my-new-password");
final Response r = target("/changepassword").request().cookie(cookie).post(Entity.form(form));
assertNotNull(r);
assertEquals(400, r.getStatus());
}
Aggregations