1 package org.cacert.gigi.pages.admin;
3 import static org.hamcrest.CoreMatchers.*;
4 import static org.junit.Assert.*;
6 import java.io.IOException;
7 import java.net.MalformedURLException;
9 import java.net.URLConnection;
10 import java.util.regex.Matcher;
11 import java.util.regex.Pattern;
13 import org.cacert.gigi.dbObjects.Group;
14 import org.cacert.gigi.pages.account.MyDetails;
15 import org.cacert.gigi.pages.admin.support.SupportEnterTicketPage;
16 import org.cacert.gigi.pages.admin.support.SupportUserDetailsPage;
17 import org.cacert.gigi.testUtils.ClientTest;
18 import org.cacert.gigi.testUtils.IOUtils;
19 import org.junit.Test;
21 public class TestSEAdminPageDetails extends ClientTest {
23 public TestSEAdminPageDetails() throws IOException {
24 grant(email, Group.SUPPORTER);
25 assertEquals(302, post(cookie, SupportEnterTicketPage.PATH, "ticketno=a20140808.8&setTicket=action", 0).getResponseCode());
29 public void testUserDetailsDisplay() throws MalformedURLException, IOException {
30 String email = createUniqueName() + "@example.com";
31 String fname = "Först";
32 String lname = "Secönd";
33 int id = createVerifiedUser(fname, lname, email, TEST_PASSWORD);
34 URLConnection uc = new URL("https://" + getServerName() + SupportUserDetailsPage.PATH + id).openConnection();
35 uc.addRequestProperty("Cookie", cookie);
37 String res = IOUtils.readURL(uc);
38 assertThat(res, containsString("<input type=\"text\" value=\"" + fname + "\" name=\"fname\">"));
39 assertThat(res, containsString("<input type=\"text\" value=\"" + lname + "\" name=\"lname\">"));
40 assertThat(res, containsString(email));
44 public void testUserDetailsEdit() throws MalformedURLException, IOException {
45 String email = createUniqueName() + "@example.com";
46 String fname = "Först";
47 String lname = "Secönd";
48 int id = createVerifiedUser(fname, lname, email, TEST_PASSWORD);
50 String userCookie = login(email, TEST_PASSWORD);
51 assertEquals("Först", getFname(IOUtils.readURL(get(userCookie, MyDetails.PATH, 0))));
52 // User can change his name
53 assertNull(executeBasicWebInteraction(userCookie, MyDetails.PATH, "fname=Kurti&lname=Hansel&mname=&suffix=&day=1&month=1&year=2000&processDetails", 0));
54 assertEquals("Kurti", getFname(IOUtils.readURL(get(userCookie, MyDetails.PATH, 0))));
57 // User cannot change his name, and the form changed
58 assertNotNull(executeBasicWebInteraction(userCookie, MyDetails.PATH, "fname=Kurti2&lname=Hansel&mname=&suffix=&day=1&month=1&year=2000&processDetails", 0));
59 assertNull(getFname(IOUtils.readURL(get(userCookie, MyDetails.PATH, 0))));
60 assertEquals("Kurti", getFnamePlain(IOUtils.readURL(get(userCookie, MyDetails.PATH, 0))));
62 // but support still can
63 assertNull(executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + id, "fname=Kurti3&lname=Hansel&mname=&suffix=&dobd=1&dobm=2&doby=2000&detailupdate", 0));
64 assertEquals("Kurti3", getFnamePlain(IOUtils.readURL(get(userCookie, MyDetails.PATH, 0))));
68 private String getFname(String res) {
69 Pattern p = Pattern.compile("<input type=\"text\" name=\"fname\" value=\"([^\"]*)\">");
70 Matcher m = p.matcher(res);
77 private String getFnamePlain(String res) {
78 Pattern p = Pattern.compile("\\s*<td width=\"125\">First Name: </td>\\s*<td width=\"125\">([^<]*)</td>");
79 Matcher m = p.matcher(res);