Search in sources :

Example 26 with Form

use of jakarta.ws.rs.core.Form in project minijax by minijax.

the class ResetPasswordTest method testResetPasswordTooShort.

@Test
void testResetPasswordTooShort() throws IOException {
    final User user = new User();
    user.setName("Example 3");
    user.setEmail("reset-3@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", "foo");
    form.param("confirmNewPassword", "foo");
    final Response r = target("/resetpassword/" + code).request().post(Entity.form(form));
    assertNotNull(r);
    assertEquals(400, r.getStatus());
    assertTrue(r.getCookies().isEmpty());
}
Also used : Response(jakarta.ws.rs.core.Response) MinijaxRequestContext(org.minijax.rs.MinijaxRequestContext) Form(jakarta.ws.rs.core.Form) MinijaxTest(org.minijax.rs.test.MinijaxTest) Test(org.junit.jupiter.api.Test)

Example 27 with Form

use of jakarta.ws.rs.core.Form in project minijax by minijax.

the class ResetPasswordTest method testResetPasswordMismatch.

@Test
void testResetPasswordMismatch() throws IOException {
    final User user = new User();
    user.setName("Example 2");
    user.setEmail("reset-2@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", "different-password");
    final Response r = target("/resetpassword/" + code).request().post(Entity.form(form));
    assertNotNull(r);
    assertEquals(400, r.getStatus());
    assertTrue(r.getCookies().isEmpty());
}
Also used : Response(jakarta.ws.rs.core.Response) MinijaxRequestContext(org.minijax.rs.MinijaxRequestContext) Form(jakarta.ws.rs.core.Form) MinijaxTest(org.minijax.rs.test.MinijaxTest) Test(org.junit.jupiter.api.Test)

Example 28 with Form

use of jakarta.ws.rs.core.Form in project minijax by minijax.

the class ResetPasswordTest method testResetPasswordNotFound.

@Test
void testResetPasswordNotFound() throws IOException {
    final String code = "does-not-exist";
    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(404, r.getStatus());
    assertTrue(r.getCookies().isEmpty());
}
Also used : Response(jakarta.ws.rs.core.Response) Form(jakarta.ws.rs.core.Form) MinijaxTest(org.minijax.rs.test.MinijaxTest) Test(org.junit.jupiter.api.Test)

Example 29 with Form

use of jakarta.ws.rs.core.Form in project minijax by minijax.

the class CsrfFilterTest method testPrivateFormWithoutUser.

@Test
void testPrivateFormWithoutUser() {
    final Form form = new Form();
    final Response r = target("/private_form").request().post(Entity.form(form));
    assertNotNull(r);
    assertEquals(401, r.getStatus());
}
Also used : Response(jakarta.ws.rs.core.Response) Form(jakarta.ws.rs.core.Form) MinijaxTest(org.minijax.rs.test.MinijaxTest) Test(org.junit.jupiter.api.Test)

Example 30 with Form

use of jakarta.ws.rs.core.Form in project minijax by minijax.

the class CsrfFilterTest method testPrivateFormWithoutCsrf.

@Test
void testPrivateFormWithoutCsrf() {
    final Form form = new Form();
    final Response r = target("/private_form").request().cookie(cookie).post(Entity.form(form));
    assertNotNull(r);
    assertEquals(400, r.getStatus());
}
Also used : Response(jakarta.ws.rs.core.Response) Form(jakarta.ws.rs.core.Form) MinijaxTest(org.minijax.rs.test.MinijaxTest) Test(org.junit.jupiter.api.Test)

Aggregations

Form (jakarta.ws.rs.core.Form)80 Response (jakarta.ws.rs.core.Response)60 Test (org.junit.Test)33 Test (org.junit.jupiter.api.Test)24 MinijaxTest (org.minijax.rs.test.MinijaxTest)14 Builder (jakarta.ws.rs.client.Invocation.Builder)11 WebTarget (jakarta.ws.rs.client.WebTarget)10 MinijaxRequestContext (org.minijax.rs.MinijaxRequestContext)8 Cookie (jakarta.ws.rs.core.Cookie)7 MultivaluedHashMap (jakarta.ws.rs.core.MultivaluedHashMap)7 Client (jakarta.ws.rs.client.Client)6 ClientBuilder (jakarta.ws.rs.client.ClientBuilder)6 List (java.util.List)5 JsonBindingTest (org.jboss.resteasy.test.providers.jsonb.basic.JsonBindingTest)5 IOException (java.io.IOException)4 ResteasyWebTarget (org.jboss.resteasy.client.jaxrs.ResteasyWebTarget)4 PetClinicTest (com.example.PetClinicTest)3 Invocation (jakarta.ws.rs.client.Invocation)3 Owner (com.example.model.Owner)2 Holder (io.jans.as.model.common.Holder)2