import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
+import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
String d = IOUtils.readURL(uc);
return d;
}
- public String fetchStartErrorMessage(String query) throws IOException {
- String d = runRegister(query);
+ public String fetchStartErrorMessage(String d) throws IOException {
String formFail = "<div class='formError'>";
int idx = d.indexOf(formFail);
assertNotEquals(-1, idx);
+ "&pword1=" + URLEncoder.encode(password, "UTF-8")
+ "&pword2=" + URLEncoder.encode(password, "UTF-8")
+ "&day=1&month=1&year=1910&cca_agree=1";
- String data = fetchStartErrorMessage(query);
+ String data = fetchStartErrorMessage(runRegister(query));
assertTrue(data, data.startsWith("</div>"));
} catch (UnsupportedEncodingException e) {
throw new Error(e);
public int createAssuranceUser(String firstName, String lastName,
String email, String password) {
int uid = createVerifiedUser(firstName, lastName, email, password);
- // TODO make him pass CATS and be assured for 100 points
+ try {
+ PreparedStatement ps = DatabaseConnection
+ .getInstance()
+ .prepare(
+ "INSERT INTO `cats_passed` SET `user_id`=?, `variant_id`=?");
+ ps.setInt(1, uid);
+ ps.setInt(2, 0);
+ ps.execute();
+ ps = DatabaseConnection.getInstance().prepare(
+ "INSERT INTO `notary` SET `from`=?, `to`=?, points='100'");
+ ps.setInt(1, uid);
+ ps.setInt(2, uid);
+ ps.execute();
+
+ } catch (SQLException e) {
+ throw new Error(e);
+ }
return uid;
}
static int count = 0;
public String createUniqueName() {
return "test" + System.currentTimeMillis() + "a" + (count++);
}
+ public String login(String email, String pw) throws IOException {
+ URL u = new URL("https://" + getServerName() + "/login");
+ HttpURLConnection huc = (HttpURLConnection) u.openConnection();
+ huc.setDoOutput(true);
+ OutputStream os = huc.getOutputStream();
+ String data = "username=" + URLEncoder.encode(email, "UTF-8")
+ + "&password=" + URLEncoder.encode(pw, "UTF-8");
+ os.write(data.getBytes());
+ os.flush();
+ String headerField = huc.getHeaderField("Set-Cookie");
+ headerField = headerField.substring(0, headerField.indexOf(';'));
+ return headerField;
+ }
}