From d02879d82d8aa1316e577701ac99045b9140ef63 Mon Sep 17 00:00:00 2001
From: Lloyd Hilaiel <lloyd@hilaiel.com>
Date: Thu, 15 Mar 2012 00:58:03 -0600
Subject: [PATCH] fix unit tests - autenticate_user and cert_key now require a
 boolean 'ephemeral' value which will affect duration of authentication and
 certificate validity respectively.

---
 tests/cert-emails-test.js               | 12 +++++++--
 tests/forgotten-email-test.js           | 36 ++++++++++++++++++++-----
 tests/password-bcrypt-update-test.js    |  6 +++--
 tests/password-update-test.js           | 12 ++++++---
 tests/primary-then-secondary-test.js    |  6 +++--
 tests/registration-status-wsapi-test.js | 12 +++++++--
 tests/stalled-mysql-test.js             |  6 +++--
 tests/verifier-test.js                  |  3 ++-
 8 files changed, 72 insertions(+), 21 deletions(-)

diff --git a/tests/cert-emails-test.js b/tests/cert-emails-test.js
index d58dea80a..19ded2b42 100755
--- a/tests/cert-emails-test.js
+++ b/tests/cert-emails-test.js
@@ -98,7 +98,11 @@ suite.addBatch({
     }
   },
   "cert key invoked with proper argument": {
-    topic: wsapi.post(cert_key_url, { email: 'syncer@somehost.com', pubkey: kp.publicKey.serialize() }),
+    topic: wsapi.post(cert_key_url, {
+      email: 'syncer@somehost.com',
+      pubkey: kp.publicKey.serialize(),
+      ephemeral: false
+    }),
     "returns a response with a proper content-type" : function(err, r) {
       assert.strictEqual(r.code, 200);
     },
@@ -143,7 +147,11 @@ suite.addBatch({
     }
   },
   "cert key invoked proper arguments but incorrect email address": {
-    topic: wsapi.post(cert_key_url, { email: 'syncer2@somehost.com', pubkey: kp.publicKey.serialize() }),
+    topic: wsapi.post(cert_key_url, {
+      email: 'syncer2@somehost.com',
+      pubkey: kp.publicKey.serialize(),
+      ephemeral: false
+    }),
     "returns a response with a proper error content-type" : function(err, r) {
       assert.strictEqual(r.code, 400);
     }
diff --git a/tests/forgotten-email-test.js b/tests/forgotten-email-test.js
index ed0fbc8ce..9fc0bc430 100755
--- a/tests/forgotten-email-test.js
+++ b/tests/forgotten-email-test.js
@@ -162,13 +162,21 @@ suite.addBatch({
 // valid (this is so *until* someone clicks through)
 suite.addBatch({
   "first email works": {
-    topic: wsapi.post('/wsapi/authenticate_user', { email: 'first@fakeemail.com', pass: 'firstfakepass' }),
+    topic: wsapi.post('/wsapi/authenticate_user', {
+      email: 'first@fakeemail.com',
+      pass: 'firstfakepass',
+      ephemeral: false
+    }),
     "should work": function(err, r) {
       assert.strictEqual(JSON.parse(r.body).success, true);
     }
   },
   "second email works": {
-    topic: wsapi.post('/wsapi/authenticate_user', { email: 'second@fakeemail.com', pass: 'firstfakepass' }),
+    topic: wsapi.post('/wsapi/authenticate_user', {
+      email: 'second@fakeemail.com',
+      pass: 'firstfakepass',
+      ephemeral: false
+    }),
     "should work": function(err, r) {
       assert.strictEqual(JSON.parse(r.body).success, true);
     }
@@ -192,13 +200,21 @@ suite.addBatch({
 // password, and all other combinations should fail
 suite.addBatch({
   "first email, first pass bad": {
-    topic: wsapi.post('/wsapi/authenticate_user', { email: 'first@fakeemail.com', pass: 'firstfakepass' }),
+    topic: wsapi.post('/wsapi/authenticate_user', {
+      email: 'first@fakeemail.com',
+      pass: 'firstfakepass',
+      ephemeral: false
+    }),
     "shouldn't work": function(err, r) {
       assert.strictEqual(JSON.parse(r.body).success, false);
     }
   },
   "first email, second pass good": {
-    topic: wsapi.post('/wsapi/authenticate_user', { email: 'first@fakeemail.com', pass: 'secondfakepass' }),
+    topic: wsapi.post('/wsapi/authenticate_user', {
+      email: 'first@fakeemail.com',
+      pass: 'secondfakepass',
+      ephemeral: false
+    }),
     "should work": function(err, r) {
       assert.strictEqual(JSON.parse(r.body).success, true);
     }
@@ -210,13 +226,21 @@ suite.addBatch({
     }
   },
   "second email, first pass good": {
-    topic: wsapi.post('/wsapi/authenticate_user', { email: 'second@fakeemail.com', pass: 'firstfakepass' }),
+    topic: wsapi.post('/wsapi/authenticate_user', {
+      email: 'second@fakeemail.com',
+      pass: 'firstfakepass',
+      ephemeral: false
+    }),
     "should work": function(err, r) {
       assert.strictEqual(JSON.parse(r.body).success, true);
     }
   },
   "second email, second pass bad": {
-    topic: wsapi.post('/wsapi/authenticate_user', { email: 'second@fakeemail.com', pass: 'secondfakepass' }),
+    topic: wsapi.post('/wsapi/authenticate_user', {
+      email: 'second@fakeemail.com',
+      pass: 'secondfakepass',
+      ephemeral: false
+    }),
     "shouldn' work": function(err, r) {
       assert.strictEqual(JSON.parse(r.body).success, false);
     }
diff --git a/tests/password-bcrypt-update-test.js b/tests/password-bcrypt-update-test.js
index c403d6ef7..51d966081 100755
--- a/tests/password-bcrypt-update-test.js
+++ b/tests/password-bcrypt-update-test.js
@@ -117,7 +117,8 @@ suite.addBatch({
   "re-authentication": {
     topic: wsapi.post('/wsapi/authenticate_user', {
       email: TEST_EMAIL,
-      pass: TEST_PASSWORD
+      pass: TEST_PASSWORD,
+      ephemeral: false
     }),
     "should work": function(err, r) {
       assert.strictEqual(JSON.parse(r.body).success, true);
@@ -153,7 +154,8 @@ suite.addBatch({
   "and re-authentication": {
     topic: wsapi.post('/wsapi/authenticate_user', {
       email: TEST_EMAIL,
-      pass: TEST_PASSWORD
+      pass: TEST_PASSWORD,
+      ephemeral: false
     }),
     "should still work": function(err, r) {
       assert.strictEqual(JSON.parse(r.body).success, true);
diff --git a/tests/password-update-test.js b/tests/password-update-test.js
index 9d484f56f..a8cbf9fc9 100755
--- a/tests/password-update-test.js
+++ b/tests/password-update-test.js
@@ -74,7 +74,8 @@ suite.addBatch({
   "authenticating with the password": {
     topic: wsapi.post('/wsapi/authenticate_user', {
       email: TEST_EMAIL,
-      pass: OLD_PASSWORD
+      pass: OLD_PASSWORD,
+      ephemeral: false
     }),
     "works as expected": function(err, r) {
       assert.strictEqual(JSON.parse(r.body).success, true);
@@ -83,7 +84,8 @@ suite.addBatch({
   "authenticating with the wrong password": {
     topic: wsapi.post('/wsapi/authenticate_user', {
       email: TEST_EMAIL,
-      pass: NEW_PASSWORD
+      pass: NEW_PASSWORD,
+      ephemeral: false
     }),
     "fails as expected": function(err, r) {
       assert.strictEqual(JSON.parse(r.body).success, false);
@@ -131,7 +133,8 @@ suite.addBatch({
   "authenticating with the password": {
     topic: wsapi.post('/wsapi/authenticate_user', {
       email: TEST_EMAIL,
-      pass: NEW_PASSWORD
+      pass: NEW_PASSWORD,
+      ephemeral: false
     }),
     "works as expected": function(err, r) {
       assert.strictEqual(JSON.parse(r.body).success, true);
@@ -140,7 +143,8 @@ suite.addBatch({
   "authenticating with the wrong password": {
     topic: wsapi.post('/wsapi/authenticate_user', {
       email: TEST_EMAIL,
-      pass: OLD_PASSWORD
+      pass: OLD_PASSWORD,
+      ephemeral: false
     }),
     "fails as expected": function(err, r) {
       assert.strictEqual(JSON.parse(r.body).success, false);
diff --git a/tests/primary-then-secondary-test.js b/tests/primary-then-secondary-test.js
index 6b47385a9..06a8230f9 100755
--- a/tests/primary-then-secondary-test.js
+++ b/tests/primary-then-secondary-test.js
@@ -198,7 +198,8 @@ suite.addBatch({
   "authentication with first email": {
     topic: wsapi.post('/wsapi/authenticate_user', {
       email: TEST_EMAIL,
-      pass: TEST_PASS
+      pass: TEST_PASS,
+      ephemeral: false
     }),
     "works": function(err, r) {
       assert.strictEqual(r.code, 200);
@@ -207,7 +208,8 @@ suite.addBatch({
   "authentication with second email": {
     topic: wsapi.post('/wsapi/authenticate_user', {
       email: SECONDARY_EMAIL,
-      pass: TEST_PASS
+      pass: TEST_PASS,
+      ephemeral: false
     }),
     "works": function(err, r) {
       assert.strictEqual(r.code, 200);
diff --git a/tests/registration-status-wsapi-test.js b/tests/registration-status-wsapi-test.js
index 394383c20..f4515775c 100755
--- a/tests/registration-status-wsapi-test.js
+++ b/tests/registration-status-wsapi-test.js
@@ -35,7 +35,11 @@ suite.addBatch({
 
 suite.addBatch({
   "authentication as an unknown user": {
-    topic: wsapi.post('/wsapi/authenticate_user', { email: 'first@fakeemail.com', pass: 'secondfakepass' }),
+    topic: wsapi.post('/wsapi/authenticate_user', {
+      email: 'first@fakeemail.com',
+      pass: 'secondfakepass',
+      ephemeral: false
+    }),
     "fails": function (err, r) {
       assert.isFalse(JSON.parse(r.body).success);
     }
@@ -234,7 +238,11 @@ suite.addBatch({
 
 suite.addBatch({
   "after re-registration, authenticating with new credetials": {
-    topic: wsapi.post('/wsapi/authenticate_user', { email: 'first@fakeemail.com', pass: 'secondfakepass' }),
+    topic: wsapi.post('/wsapi/authenticate_user', {
+      email: 'first@fakeemail.com',
+      pass: 'secondfakepass',
+      ephemeral: false
+    }),
     "works as you might expect": function (err, r) {
       assert.strictEqual(JSON.parse(r.body).success, true);
     }
diff --git a/tests/stalled-mysql-test.js b/tests/stalled-mysql-test.js
index a07535527..c4b1e1839 100755
--- a/tests/stalled-mysql-test.js
+++ b/tests/stalled-mysql-test.js
@@ -105,7 +105,8 @@ suite.addBatch({
   "authenticate_user": {
     topic: wsapi.post('/wsapi/authenticate_user', {
       email: 'test@example.com',
-      pass: 'oogabooga'
+      pass: 'oogabooga',
+      ephemeral: false
     }),
     "fails with 503": function(err, r) {
       assert.strictEqual(r.code, 503);
@@ -203,7 +204,8 @@ suite.addBatch({
   "cert_key": {
     topic: wsapi.post('/wsapi/cert_key', {
       email: "test@whatev.er",
-      pubkey: "bogus"
+      pubkey: "bogus",
+      ephemeral: false
     }),
     "fails with 503": function(err, r) {
       assert.strictEqual(r.code, 503);
diff --git a/tests/verifier-test.js b/tests/verifier-test.js
index b2a455dc0..499855873 100755
--- a/tests/verifier-test.js
+++ b/tests/verifier-test.js
@@ -97,7 +97,8 @@ suite.addBatch({
     topic: function() {
       wsapi.post('/wsapi/cert_key', {
         email: TEST_EMAIL,
-        pubkey: g_keypair.publicKey.serialize()
+        pubkey: g_keypair.publicKey.serialize(),
+        ephemeral: false
       }).call(this);
     },
     "works swimmingly": function(err, r) {
-- 
GitLab