use of org.minijax.MinijaxRequestContext in project minijax by minijax.
the class ChangePasswordTest method testIncorrectOldPassword.
@Test
public 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.get(Dao.class).create(user);
cookie = ctx.get(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());
}
use of org.minijax.MinijaxRequestContext in project minijax by minijax.
the class ExceptionMapperTest method testNotFound.
@Test
public void testNotFound() throws IOException {
try (final MinijaxRequestContext ctx = createRequestContext()) {
final MinijaxJsonExceptionMapper mapper = new MinijaxJsonExceptionMapper();
final Response response = mapper.toResponse(new NotFoundException());
assertNotNull(response);
assertEquals(404, response.getStatus());
assertEquals(404, ((MinijaxJsonExceptionWrapper) response.getEntity()).getCode());
assertEquals("HTTP 404 Not Found", ((MinijaxJsonExceptionWrapper) response.getEntity()).getMessage());
}
}
use of org.minijax.MinijaxRequestContext in project minijax by minijax.
the class ResetPasswordTest method testResetPasswordSuccess.
@Test
public 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.get(Dao.class).create(user);
code = ctx.get(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.get(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.MinijaxRequestContext in project minijax by minijax.
the class EntityProvider method get.
@Override
public T get() {
final MinijaxRequestContext context = MinijaxRequestContext.getThreadLocal();
final InputStream entityStream = context.getEntityStream();
try {
return getImpl(context, entityStream);
} catch (final IOException ex) {
throw new InjectionException(ex.getMessage(), ex);
}
}
use of org.minijax.MinijaxRequestContext in project minijax by minijax.
the class RequestScopedProvider method get.
@Override
public T get() {
final MinijaxRequestContext context = MinijaxRequestContext.getThreadLocal();
final ResourceCache resourceCache = context.getResourceCache();
T instance = resourceCache.get(key);
if (instance == null) {
instance = sourceProvider.get();
resourceCache.put(key, instance);
}
return instance;
}
Aggregations