--- /dev/null
+package org.cacert.gigi.pages.account;
+
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLEncoder;
+
+import org.cacert.gigi.dbObjects.User;
+import org.cacert.gigi.pages.wot.TestAssurance;
+import org.cacert.gigi.testUtils.ClientTest;
+import org.cacert.gigi.testUtils.IOUtils;
+import org.cacert.gigi.testUtils.TestEmailReceiver.TestMail;
+import org.cacert.gigi.util.RandomToken;
+import org.junit.Test;
+
+public class TestPasswordResetExternal extends ClientTest {
+
+ @Test
+ public void testByAssurance() throws IOException {
+ User u = User.getById(createAssuranceUser("fn", "ln", createUniqueName() + "@example.com", TEST_PASSWORD));
+ String cookie2 = login(u.getEmail(), TEST_PASSWORD);
+ URLConnection uc = TestAssurance.buildupAssureFormConnection(cookie2, email, true);
+ String avalue = RandomToken.generateToken(32);
+ uc.getOutputStream().write(("date=1910-01-01&location=testcase&certify=1&rules=1&CCAAgreed=1&assertion=1&points=10&passwordReset=1&passwordResetValue=" + URLEncoder.encode(avalue, "UTF-8")).getBytes("UTF-8"));
+ uc.getOutputStream().flush();
+ String error = fetchStartErrorMessage(IOUtils.readURL(uc));
+ assertNull(error);
+
+ TestMail mail = getMailReciever().receive();
+ System.out.println(mail.getMessage());
+ String link = mail.extractLink();
+ String npw = TEST_PASSWORD + "'";
+ assertNotNull(toPasswordReset(avalue, link, npw, npw + "'"));
+ assertNotNull(toPasswordReset(avalue + "'", link, npw, npw));
+ assertNotNull(toPasswordReset(avalue, link, "a", "a"));
+ assertNull(toPasswordReset(avalue, link, npw, npw));
+ assertNotNull(login(email, npw));
+ }
+
+ private String toPasswordReset(String avalue, String link, String npw, String npw2) throws IOException, MalformedURLException, UnsupportedEncodingException {
+ URLConnection uc2 = new URL(link).openConnection();
+ String csrf = getCSRF(uc2);
+ String headerField = uc2.getHeaderField("Set-Cookie");
+ assertNotNull(headerField);
+ String cookie3 = stripCookie(headerField);
+ uc2 = new URL(link).openConnection();
+ cookie(uc2, cookie3);
+ uc2.setDoOutput(true);
+ OutputStream o = uc2.getOutputStream();
+ o.write(("csrf=" + csrf + "&pword1=" + URLEncoder.encode(npw, "UTF-8") + "&pword2=" + URLEncoder.encode(npw2, "UTF-8") + "&private_token=" + URLEncoder.encode(avalue, "UTF-8")).getBytes("UTF-8"));
+ return fetchStartErrorMessage(IOUtils.readURL(uc2));
+ }
+}
}
private URLConnection buildupAssureFormConnection(boolean doCSRF) throws MalformedURLException, IOException {
+ return buildupAssureFormConnection(cookie, assureeM, doCSRF);
+ }
+
+ public static URLConnection buildupAssureFormConnection(String cookie, String email, boolean doCSRF) throws MalformedURLException, IOException {
URL u = new URL("https://" + getServerName() + AssurePage.PATH);
URLConnection uc = u.openConnection();
uc.addRequestProperty("Cookie", cookie);
uc.setDoOutput(true);
- uc.getOutputStream().write(("email=" + URLEncoder.encode(assureeM, "UTF-8") + "&day=1&month=1&year=1910&search").getBytes("UTF-8"));
+ uc.getOutputStream().write(("email=" + URLEncoder.encode(email, "UTF-8") + "&day=1&month=1&year=1910&search").getBytes("UTF-8"));
String csrf = getCSRF(uc);
uc = u.openConnection();