`method` varchar(100) NOT NULL,
`comment` varchar(100) DEFAULT NULL,
PRIMARY KEY (`id`)
-) ENGINE=InnoDB AUTO_INCREMENT=61411 DEFAULT CHARSET=latin1;
+) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=latin1;
+
+DROP TABLE IF EXISTS `emailcerts`;
+CREATE TABLE `emailcerts` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `memid` int(11) NOT NULL DEFAULT '0',
+ `serial` varchar(50) NOT NULL DEFAULT '',
+ `CN` varchar(255) NOT NULL DEFAULT '',
+ `subject` text NOT NULL,
+ `keytype` char(2) NOT NULL DEFAULT 'NS',
+ `codesign` tinyint(1) NOT NULL DEFAULT '0',
+ `csr_name` varchar(255) NOT NULL DEFAULT '',
+ `crt_name` varchar(255) NOT NULL DEFAULT '',
+ `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
+ `modified` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
+ `revoked` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
+ `expire` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
+ `warning` tinyint(1) NOT NULL DEFAULT '0',
+ `renewed` tinyint(1) NOT NULL DEFAULT '0',
+ `rootcert` int(2) NOT NULL DEFAULT '1',
+ `md` enum('md5','sha1','sha256','sha512') NOT NULL DEFAULT 'sha512',
+ `type` tinyint(4) DEFAULT NULL,
+ `disablelogin` int(1) NOT NULL DEFAULT '0',
+ `pkhash` char(40) DEFAULT NULL,
+ `certhash` char(40) DEFAULT NULL,
+ `coll_found` tinyint(1) NOT NULL,
+ `description` varchar(100) NOT NULL DEFAULT '',
+ PRIMARY KEY (`id`),
+ KEY `emailcerts_pkhash` (`pkhash`),
+ KEY `revoked` (`revoked`),
+ KEY `created` (`created`),
+ KEY `memid` (`memid`),
+ KEY `serial` (`serial`),
+ KEY `stats_emailcerts_expire` (`expire`),
+ KEY `emailcrt` (`crt_name`)
+) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=latin1;
\ No newline at end of file
--- /dev/null
+package org.cacert.gigi;
+
+import java.io.IOException;
+import static org.junit.Assert.*;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLEncoder;
+
+import org.cacert.gigi.testUtils.ManagedTest;
+import org.junit.Test;
+
+public class LoginTest extends ManagedTest {
+ public static final String secureReference = "/account/certs/email";
+ @Test
+ public void testLoginUnverified() throws IOException {
+ long uniq = System.currentTimeMillis();
+ String email = "system" + uniq + "@testmail.org";
+ String pw = "1'aAaA";
+ registerUser("an", "bn", email, pw);
+ waitForMail();
+ assertFalse(isLoggedin(login(email, pw)));
+ }
+ @Test
+ public void testLoginVerified() throws IOException {
+ long uniq = System.currentTimeMillis();
+ String email = "system2" + uniq + "@testmail.org";
+ String pw = "1'aAaA";
+ createVerifiedUser("an", "bn", email, pw);
+ assertTrue(isLoggedin(login(email, pw)));
+ }
+ public boolean isLoggedin(String cookie) throws IOException {
+ URL u = new URL("https://" + getServerName() + secureReference);
+ HttpURLConnection huc = (HttpURLConnection) u.openConnection();
+ huc.addRequestProperty("Cookie", cookie);
+ return huc.getResponseCode() == 200;
+ }
+ 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;
+ }
+
+}
import org.cacert.gigi.DevelLauncher;
import org.cacert.gigi.IOUtils;
+import org.cacert.gigi.InitTruststore;
import org.cacert.gigi.testUtils.TestEmailReciever.TestMail;
import org.junit.After;
import org.junit.AfterClass;
return url;
}
static Properties testProps = new Properties();
+ static {
+ InitTruststore.run();
+ HttpURLConnection.setFollowRedirects(false);
+ }
+
@BeforeClass
public static void connectToServer() {
try {
TestMail tm = ter.recieve();
String verifyLink = tm.extractLink();
String[] parts = verifyLink.split("\\?");
- URL u = new URL("https://" + getServerName() + "/verify" + parts[1]);
+ URL u = new URL("https://" + getServerName() + "/verify?"
+ + parts[1]);
u.openStream().close();;
} catch (InterruptedException e) {
throw new Error(e);