]> WPIA git - gigi.git/commitdiff
add: another support test case
authorFelix Dörre <felix@dogcraft.de>
Fri, 6 Nov 2015 11:49:56 +0000 (12:49 +0100)
committerFelix Dörre <felix@dogcraft.de>
Fri, 6 Nov 2015 11:49:56 +0000 (12:49 +0100)
tests/org/cacert/gigi/pages/admin/TestSEAdminPageDetails.java
tests/org/cacert/gigi/testUtils/ClientTest.java
tests/org/cacert/gigi/testUtils/ManagedTest.java

index ef71210b8948e694bcb063045744491e435a65aa..39e7c5de3c30ac4df605bfbc1be23aa119e96b72 100644 (file)
@@ -1,6 +1,5 @@
 package org.cacert.gigi.pages.admin;
 
-import static org.cacert.gigi.testUtils.ManagedTest.*;
 import static org.hamcrest.CoreMatchers.*;
 import static org.junit.Assert.*;
 
@@ -8,8 +7,11 @@ import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLConnection;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import org.cacert.gigi.dbObjects.Group;
+import org.cacert.gigi.pages.account.MyDetails;
 import org.cacert.gigi.pages.admin.support.SupportEnterTicketPage;
 import org.cacert.gigi.pages.admin.support.SupportUserDetailsPage;
 import org.cacert.gigi.testUtils.ClientTest;
@@ -37,4 +39,47 @@ public class TestSEAdminPageDetails extends ClientTest {
         assertThat(res, containsString("<input type=\"text\" value=\"" + lname + "\" name=\"lname\">"));
         assertThat(res, containsString(email));
     }
+
+    @Test
+    public void testUserDetailsEdit() throws MalformedURLException, IOException {
+        String email = createUniqueName() + "@example.com";
+        String fname = "Först";
+        String lname = "Secönd";
+        int id = createVerifiedUser(fname, lname, email, TEST_PASSWORD);
+
+        String userCookie = login(email, TEST_PASSWORD);
+        assertEquals("Först", getFname(IOUtils.readURL(get(userCookie, MyDetails.PATH, 0))));
+        // User can change his name
+        assertNull(executeBasicWebInteraction(userCookie, MyDetails.PATH, "fname=Kurti&lname=Hansel&mname=&suffix=&day=1&month=1&year=2000&processDetails", 0));
+        assertEquals("Kurti", getFname(IOUtils.readURL(get(userCookie, MyDetails.PATH, 0))));
+        // But when assurer
+        makeAssurer(id);
+        // User cannot change his name, and the form changed
+        assertNotNull(executeBasicWebInteraction(userCookie, MyDetails.PATH, "fname=Kurti2&lname=Hansel&mname=&suffix=&day=1&month=1&year=2000&processDetails", 0));
+        assertNull(getFname(IOUtils.readURL(get(userCookie, MyDetails.PATH, 0))));
+        assertEquals("Kurti", getFnamePlain(IOUtils.readURL(get(userCookie, MyDetails.PATH, 0))));
+
+        // but support still can
+        assertNull(executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + id, "fname=Kurti3&lname=Hansel&mname=&suffix=&dobd=1&dobm=2&doby=2000&detailupdate", 0));
+        assertEquals("Kurti3", getFnamePlain(IOUtils.readURL(get(userCookie, MyDetails.PATH, 0))));
+
+    }
+
+    private String getFname(String res) {
+        Pattern p = Pattern.compile("<input type=\"text\" name=\"fname\" value=\"([^\"]*)\">");
+        Matcher m = p.matcher(res);
+        if (m.find()) {
+            return m.group(1);
+        }
+        return null;
+    }
+
+    private String getFnamePlain(String res) {
+        Pattern p = Pattern.compile("\\s*<td width=\"125\">First Name: </td>\\s*<td width=\"125\">([^<]*)</td>");
+        Matcher m = p.matcher(res);
+        if (m.find()) {
+            return m.group(1);
+        }
+        return null;
+    }
 }
index 846a5abeac6a9e851d96a7c069cd7f20a0c6a42b..5b565093752dc2da9adae939ddf0eaf8c59d3227 100644 (file)
@@ -2,8 +2,6 @@ package org.cacert.gigi.testUtils;
 
 import java.io.IOException;
 import java.net.HttpURLConnection;
-import java.net.URL;
-import java.net.URLConnection;
 
 import org.cacert.gigi.dbObjects.User;
 
@@ -54,9 +52,7 @@ public abstract class ClientTest extends ManagedTest {
     }
 
     public HttpURLConnection get(String path, int formIndex) throws IOException {
-        URLConnection uc = new URL("https://" + getServerName() + path).openConnection();
-        uc.addRequestProperty("Cookie", cookie);
-        return (HttpURLConnection) uc;
+        return get(cookie, path, formIndex);
     }
 
 }
index 3bc32ca728e26bbdd69b6b171a3d641cc8cb69fc..3d5c124684132aa021fd8208a085582d88d6df76 100644 (file)
@@ -473,6 +473,12 @@ public class ManagedTest extends ConfiguredTest {
         return (HttpURLConnection) uc;
     }
 
+    public HttpURLConnection get(String cookie, String path, int formIndex) throws IOException {
+        URLConnection uc = new URL("https://" + getServerName() + path).openConnection();
+        uc.addRequestProperty("Cookie", cookie);
+        return (HttpURLConnection) uc;
+    }
+
     public static EmailAddress createVerifiedEmail(User u) throws InterruptedException, GigiApiException {
         EmailAddress adrr = new EmailAddress(u, createUniqueName() + "test@test.tld", Locale.ENGLISH);
         TestMail testMail = getMailReciever().receive();