]> WPIA git - gigi.git/commitdiff
Test login with email verification.
authorFelix Dörre <felix@dogcraft.de>
Wed, 25 Jun 2014 13:31:37 +0000 (15:31 +0200)
committerFelix Dörre <felix@dogcraft.de>
Wed, 25 Jun 2014 13:33:32 +0000 (15:33 +0200)
doc/tableStructure.sql
tests/org/cacert/gigi/LoginTest.java [new file with mode: 0644]
tests/org/cacert/gigi/testUtils/ManagedTest.java

index e132aec0612bf843fe551f75325c76b6f0da4556..24007a877d4cdb4534dd9a76586b3a23c5618150 100644 (file)
@@ -83,4 +83,39 @@ CREATE TABLE `user_agreements` (
   `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
diff --git a/tests/org/cacert/gigi/LoginTest.java b/tests/org/cacert/gigi/LoginTest.java
new file mode 100644 (file)
index 0000000..9aa24c7
--- /dev/null
@@ -0,0 +1,52 @@
+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;
+       }
+
+}
index f591e77259e0f6a1a6d9fd3cf576f0f92469fa45..c9a44b8a158046c778ac6291f53faee948e078d9 100644 (file)
@@ -19,6 +19,7 @@ import java.util.Properties;
 
 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;
@@ -35,6 +36,11 @@ public class ManagedTest {
                return url;
        }
        static Properties testProps = new Properties();
+       static {
+               InitTruststore.run();
+               HttpURLConnection.setFollowRedirects(false);
+       }
+
        @BeforeClass
        public static void connectToServer() {
                try {
@@ -171,7 +177,8 @@ public class ManagedTest {
                        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);