X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=tests%2Forg%2Fcacert%2Fgigi%2Fpages%2Faccount%2FTestChangePassword.java;h=89d318e6e54e06c89fd0b8105fb366d75e395759;hb=6dcec2ace981aadba1f0a04e20e2bafe19b47976;hp=4b9e48d7711ab50b82aedbe369dd8986b23e8e8d;hpb=be62d3da06430c2615c80a6313ade448072482a5;p=gigi.git diff --git a/tests/org/cacert/gigi/pages/account/TestChangePassword.java b/tests/org/cacert/gigi/pages/account/TestChangePassword.java index 4b9e48d7..89d318e6 100644 --- a/tests/org/cacert/gigi/pages/account/TestChangePassword.java +++ b/tests/org/cacert/gigi/pages/account/TestChangePassword.java @@ -6,103 +6,96 @@ import java.io.IOException; import java.net.URLEncoder; import org.cacert.gigi.GigiApiException; -import org.cacert.gigi.User; -import org.cacert.gigi.testUtils.ManagedTest; +import org.cacert.gigi.testUtils.ClientTest; import org.junit.Test; -public class TestChangePassword extends ManagedTest { - User u = User.getById(createVerifiedUser("fn", "ln", createUniqueName() + "uni@example.org", TEST_PASSWORD)); - String cookie; - String path = ChangePasswordPage.PATH; - - public TestChangePassword() throws IOException { - cookie = login(u.getEmail(), TEST_PASSWORD); - assertTrue(isLoggedin(cookie)); - } - - @Test - public void testChangePasswordInternal() throws IOException, GigiApiException { - try { - u.changePassword(TEST_PASSWORD + "wrong", TEST_PASSWORD + "v2"); - fail("Password change must not succeed if old password is wrong."); - } catch (GigiApiException e) { - // expected - } - ; - assertTrue(isLoggedin(login(u.getEmail(), TEST_PASSWORD))); - u.changePassword(TEST_PASSWORD, TEST_PASSWORD + "v2"); - assertTrue(isLoggedin(login(u.getEmail(), TEST_PASSWORD + "v2"))); - } - - @Test - public void testChangePasswordWeb() throws IOException { - String error = executeBasicWebInteraction(cookie, path, - "oldpassword=" + URLEncoder.encode(TEST_PASSWORD, "UTF-8") // - + "&pword1=" + URLEncoder.encode(TEST_PASSWORD + "v2", "UTF-8")// - + "&pword2=" + URLEncoder.encode(TEST_PASSWORD + "v2", "UTF-8")); - assertNull(error); - assertTrue(isLoggedin(login(u.getEmail(), TEST_PASSWORD + "v2"))); - assertFalse(isLoggedin(login(u.getEmail(), TEST_PASSWORD))); - - } - - @Test - public void testChangePasswordWebOldWrong() throws IOException { - String error = executeBasicWebInteraction(cookie, path, - "oldpassword=a" + URLEncoder.encode(TEST_PASSWORD, "UTF-8") // - + "&pword1=" + URLEncoder.encode(TEST_PASSWORD + "v2", "UTF-8")// - + "&pword2=" + URLEncoder.encode(TEST_PASSWORD + "v2", "UTF-8")); - assertNotNull(error); - assertFalse(isLoggedin(login(u.getEmail(), TEST_PASSWORD + "v2"))); - assertTrue(isLoggedin(login(u.getEmail(), TEST_PASSWORD))); - - } - - @Test - public void testChangePasswordWebNewWrong() throws IOException { - String error = executeBasicWebInteraction(cookie, path, - "oldpassword=" + URLEncoder.encode(TEST_PASSWORD, "UTF-8") // - + "&pword1=" + URLEncoder.encode(TEST_PASSWORD + "v2", "UTF-8")// - + "&pword2=a" + URLEncoder.encode(TEST_PASSWORD + "v2", "UTF-8")); - assertNotNull(error); - assertFalse(isLoggedin(login(u.getEmail(), TEST_PASSWORD + "v2"))); - assertTrue(isLoggedin(login(u.getEmail(), TEST_PASSWORD))); - - } - - @Test - public void testChangePasswordWebNewEasy() throws IOException { - String error = executeBasicWebInteraction(cookie, path, - "oldpassword=" + URLEncoder.encode(TEST_PASSWORD, "UTF-8") // - + "&pword1=a&pword2=a"); - assertNotNull(error); - assertFalse(isLoggedin(login(u.getEmail(), TEST_PASSWORD + "v2"))); - assertTrue(isLoggedin(login(u.getEmail(), TEST_PASSWORD))); - - } - - @Test - public void testChangePasswordWebMissingFields() throws IOException { - String np = URLEncoder.encode(TEST_PASSWORD + "v2", "UTF-8"); - assertTrue(isLoggedin(login(u.getEmail(), TEST_PASSWORD))); - String error = executeBasicWebInteraction(cookie, path, - "oldpassword=" + URLEncoder.encode(TEST_PASSWORD, "UTF-8") // - + "&pword1=" + np); - assertNotNull(error); - assertFalse(isLoggedin(login(u.getEmail(), TEST_PASSWORD + "v2"))); - assertTrue(isLoggedin(login(u.getEmail(), TEST_PASSWORD))); - - error = executeBasicWebInteraction(cookie, path, "oldpassword=" + URLEncoder.encode(TEST_PASSWORD, "UTF-8") // - + "&pword2=" + np); - assertNotNull(error); - assertFalse(isLoggedin(login(u.getEmail(), TEST_PASSWORD + "v2"))); - assertTrue(isLoggedin(login(u.getEmail(), TEST_PASSWORD))); - - error = executeBasicWebInteraction(cookie, path, "pword1=" + np + "&pword2=" + np); - assertNotNull(error); - assertFalse(isLoggedin(login(u.getEmail(), TEST_PASSWORD + "v2"))); - assertTrue(isLoggedin(login(u.getEmail(), TEST_PASSWORD))); - - } +public class TestChangePassword extends ClientTest { + + String path = ChangePasswordPage.PATH; + + public TestChangePassword() throws IOException { + cookie = login(u.getEmail(), TEST_PASSWORD); + assertTrue(isLoggedin(cookie)); + } + + @Test + public void testChangePasswordInternal() throws IOException, GigiApiException { + try { + u.changePassword(TEST_PASSWORD + "wrong", TEST_PASSWORD + "v2"); + fail("Password change must not succeed if old password is wrong."); + } catch (GigiApiException e) { + // expected + } + ; + assertTrue(isLoggedin(login(u.getEmail(), TEST_PASSWORD))); + u.changePassword(TEST_PASSWORD, TEST_PASSWORD + "v2"); + assertTrue(isLoggedin(login(u.getEmail(), TEST_PASSWORD + "v2"))); + } + + @Test + public void testChangePasswordWeb() throws IOException { + String error = executeBasicWebInteraction(cookie, path, "oldpassword=" + URLEncoder.encode(TEST_PASSWORD, "UTF-8") // + + "&pword1=" + URLEncoder.encode(TEST_PASSWORD + "v2", "UTF-8")// + + "&pword2=" + URLEncoder.encode(TEST_PASSWORD + "v2", "UTF-8")); + assertNull(error); + assertTrue(isLoggedin(login(u.getEmail(), TEST_PASSWORD + "v2"))); + assertFalse(isLoggedin(login(u.getEmail(), TEST_PASSWORD))); + + } + + @Test + public void testChangePasswordWebOldWrong() throws IOException { + String error = executeBasicWebInteraction(cookie, path, "oldpassword=a" + URLEncoder.encode(TEST_PASSWORD, "UTF-8") // + + "&pword1=" + URLEncoder.encode(TEST_PASSWORD + "v2", "UTF-8")// + + "&pword2=" + URLEncoder.encode(TEST_PASSWORD + "v2", "UTF-8")); + assertNotNull(error); + assertFalse(isLoggedin(login(u.getEmail(), TEST_PASSWORD + "v2"))); + assertTrue(isLoggedin(login(u.getEmail(), TEST_PASSWORD))); + + } + + @Test + public void testChangePasswordWebNewWrong() throws IOException { + String error = executeBasicWebInteraction(cookie, path, "oldpassword=" + URLEncoder.encode(TEST_PASSWORD, "UTF-8") // + + "&pword1=" + URLEncoder.encode(TEST_PASSWORD + "v2", "UTF-8")// + + "&pword2=a" + URLEncoder.encode(TEST_PASSWORD + "v2", "UTF-8")); + assertNotNull(error); + assertFalse(isLoggedin(login(u.getEmail(), TEST_PASSWORD + "v2"))); + assertTrue(isLoggedin(login(u.getEmail(), TEST_PASSWORD))); + + } + + @Test + public void testChangePasswordWebNewEasy() throws IOException { + String error = executeBasicWebInteraction(cookie, path, "oldpassword=" + URLEncoder.encode(TEST_PASSWORD, "UTF-8") // + + "&pword1=a&pword2=a"); + assertNotNull(error); + assertFalse(isLoggedin(login(u.getEmail(), TEST_PASSWORD + "v2"))); + assertTrue(isLoggedin(login(u.getEmail(), TEST_PASSWORD))); + + } + + @Test + public void testChangePasswordWebMissingFields() throws IOException { + String np = URLEncoder.encode(TEST_PASSWORD + "v2", "UTF-8"); + assertTrue(isLoggedin(login(u.getEmail(), TEST_PASSWORD))); + String error = executeBasicWebInteraction(cookie, path, "oldpassword=" + URLEncoder.encode(TEST_PASSWORD, "UTF-8") // + + "&pword1=" + np); + assertNotNull(error); + assertFalse(isLoggedin(login(u.getEmail(), TEST_PASSWORD + "v2"))); + assertTrue(isLoggedin(login(u.getEmail(), TEST_PASSWORD))); + + error = executeBasicWebInteraction(cookie, path, "oldpassword=" + URLEncoder.encode(TEST_PASSWORD, "UTF-8") // + + "&pword2=" + np); + assertNotNull(error); + assertFalse(isLoggedin(login(u.getEmail(), TEST_PASSWORD + "v2"))); + assertTrue(isLoggedin(login(u.getEmail(), TEST_PASSWORD))); + + error = executeBasicWebInteraction(cookie, path, "pword1=" + np + "&pword2=" + np); + assertNotNull(error); + assertFalse(isLoggedin(login(u.getEmail(), TEST_PASSWORD + "v2"))); + assertTrue(isLoggedin(login(u.getEmail(), TEST_PASSWORD))); + + } }