import org.cacert.gigi.dbObjects.CertificateProfile;
import org.cacert.gigi.dbObjects.Digest;
import org.cacert.gigi.dbObjects.User;
+import org.cacert.gigi.pages.account.certs.Certificates;
+import org.cacert.gigi.testUtils.IOUtils;
import org.cacert.gigi.testUtils.ManagedTest;
import org.junit.Test;
testFails(CertificateStatus.DRAFT, c);
c.issue(null, "2y", u).waitFor(60000);
+ String cookie = login(u.getEmail(), TEST_PASSWORD);
testFails(CertificateStatus.ISSUED, c);
X509Certificate cert = c.cert();
assertNotNull(login(pk, cert));
+ assertEquals(1, countRegex(IOUtils.readURL(get(cookie, Certificates.PATH)), "<td>(?:revoked|issued)</td>"));
+ assertEquals(1, countRegex(IOUtils.readURL(get(cookie, Certificates.PATH + "?withRevoked")), "<td>(?:revoked|issued)</td>"));
c.revoke().waitFor(60000);
testFails(CertificateStatus.REVOKED, c);
assertNull(login(pk, cert));
+ assertEquals(0, countRegex(IOUtils.readURL(get(cookie, Certificates.PATH)), "<td>(?:revoked|issued)</td>"));
+ assertEquals(1, countRegex(IOUtils.readURL(get(cookie, Certificates.PATH + "?withRevoked")), "<td>(?:revoked|issued)</td>"));
}
private void testFails(CertificateStatus status, Certificate c) throws IOException, GeneralSecurityException, SQLException, GigiApiException {
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))));
+ assertEquals("Först", getFname(IOUtils.readURL(get(userCookie, MyDetails.PATH))));
// 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))));
+ assertEquals("Kurti", getFname(IOUtils.readURL(get(userCookie, MyDetails.PATH))));
// 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))));
+ assertNull(getFname(IOUtils.readURL(get(userCookie, MyDetails.PATH))));
+ assertEquals("Kurti", getFnamePlain(IOUtils.readURL(get(userCookie, MyDetails.PATH))));
// 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))));
+ assertEquals("Kurti3", getFnamePlain(IOUtils.readURL(get(userCookie, MyDetails.PATH))));
}
}
private int logCountAdmin(int id) throws IOException {
- return getLogEntryCount(IOUtils.readURL(get(UserHistory.SUPPORT_PATH.replace("*", Integer.toString(id)), 0)));
+ return getLogEntryCount(IOUtils.readURL(get(UserHistory.SUPPORT_PATH.replace("*", Integer.toString(id)))));
}
private int logCountUser(String cookie) throws IOException {
- return getLogEntryCount(IOUtils.readURL(get(cookie, UserHistory.PATH, 0)));
+ return getLogEntryCount(IOUtils.readURL(get(cookie, UserHistory.PATH)));
}
private int getLogEntryCount(String readURL) {
}
public HttpURLConnection get(String path) throws IOException {
- return get(path, 0);
- }
-
- public HttpURLConnection get(String path, int formIndex) throws IOException {
- return get(cookie, path, formIndex);
+ return get(cookie, path);
}
}
import java.security.Signature;
import java.util.Properties;
import java.util.TimeZone;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import org.cacert.gigi.database.DatabaseConnection;
import org.cacert.gigi.util.PEM;
return "test" + System.currentTimeMillis() + "a" + (count++) + "u";
}
+ public static int countRegex(String text, String pattern) {
+ Pattern p = Pattern.compile(pattern);
+ Matcher m = p.matcher(text);
+ int i = 0;
+ while (m.find()) {
+ i++;
+ }
+ return i;
+ }
}
return (HttpURLConnection) uc;
}
- public HttpURLConnection get(String cookie, String path, int formIndex) throws IOException {
+ public HttpURLConnection get(String cookie, String path) throws IOException {
URLConnection uc = new URL("https://" + getServerName() + path).openConnection();
uc.addRequestProperty("Cookie", cookie);
return (HttpURLConnection) uc;