From 4239eeb89370774a6726806ab30ab28e2a00cc1a Mon Sep 17 00:00:00 2001 From: Lloyd Hilaiel <lloyd@hilaiel.com> Date: Tue, 10 Jan 2012 10:29:29 -0700 Subject: [PATCH] update wsapi_client to return errors in the standard node convention. update all clients. fix several areas in loadgen where we were not properly handling errors. improve informational output of loadgen failures. closes #838 - helps with issue #784 - closes #785 --- lib/load_gen/activities/add_email.js | 12 +++-- lib/load_gen/activities/change_pass.js | 3 +- lib/load_gen/activities/include_only.js | 6 ++- lib/load_gen/activities/reset_pass.js | 18 ++++--- lib/load_gen/activities/signup.js | 13 +++-- lib/load_gen/common.js | 18 ++++--- lib/wsapi_client.js | 25 +++++----- scripts/create_account.js | 15 ++++-- tests/add-email-with-assertion-test.js | 12 ++--- tests/auth-with-assertion-test.js | 2 +- tests/cert-emails-test.js | 22 ++++----- tests/cookie-session-security-test.js | 8 +-- tests/email-throttling-test.js | 12 ++--- tests/forgotten-email-test.js | 34 ++++++------- tests/lib/start-stop.js | 4 +- tests/list-emails-wsapi-test.js | 12 ++--- tests/page-requests-test.js | 2 +- tests/password-bcrypt-update-test.js | 14 +++--- tests/password-length-test.js | 10 ++-- tests/password-update-test.js | 18 +++---- tests/post-limiting-test.js | 12 ++--- tests/primary-then-secondary-test.js | 28 +++++------ tests/registration-status-wsapi-test.js | 48 +++++++++--------- tests/secrets-test.js | 0 tests/two-level-auth-test.js | 10 ++-- tests/verifier-test.js | 66 ++++++++++++------------- 26 files changed, 227 insertions(+), 197 deletions(-) mode change 100644 => 100755 tests/secrets-test.js diff --git a/lib/load_gen/activities/add_email.js b/lib/load_gen/activities/add_email.js index 3e5e34e50..b6fb987d4 100644 --- a/lib/load_gen/activities/add_email.js +++ b/lib/load_gen/activities/add_email.js @@ -87,7 +87,8 @@ exports.startFunc = function(cfg, cb) { wcli.post(cfg, '/wsapi/stage_email', context, { email: email, site: userdb.any(user.sites) - }, function (r) { + }, function (err, r) { + if (err) return cb(err); if (!r || r.code !== 200) { var msg = 'failed to add email: ' + email + ' to existing user ' + user.emails[0]; @@ -97,7 +98,8 @@ exports.startFunc = function(cfg, cb) { // now get the verification secret wcli.get(cfg, '/wsapi/fake_verification', context, { email: email - }, function (r) { + }, function (err, r) { + if (err) return cb(err); if (!r || r.code !== 200) { var err ='failed to fetch verification token for email: ' + email; winston.error(err); @@ -108,8 +110,9 @@ exports.startFunc = function(cfg, cb) { // and simulate clickthrough wcli.post(cfg, '/wsapi/complete_email_addition', context, { token: token - }, function (r) { + }, function (err, r) { try { + if (err) throw err; if (r.code !== 200) throw "bad response code"; if (JSON.parse(r.body).success !== true) throw "success? no."; } catch (e) { @@ -122,8 +125,9 @@ exports.startFunc = function(cfg, cb) { // process wcli.get(cfg, '/wsapi/email_addition_status', context, { email: email - }, function(r) { + }, function(err, r) { try { + if (err) throw err; if (r.code !== 200) throw "bad response code"; if (JSON.parse(r.body).status !== 'complete') throw "addition not complete? wrong: " + r.body; } catch(e) { diff --git a/lib/load_gen/activities/change_pass.js b/lib/load_gen/activities/change_pass.js index 5c4741eba..e8b4243fc 100644 --- a/lib/load_gen/activities/change_pass.js +++ b/lib/load_gen/activities/change_pass.js @@ -76,8 +76,9 @@ exports.startFunc = function(cfg, cb) { wcli.post(cfg, '/wsapi/update_password', context, { oldpass: user.password, newpass: user.password - }, function (r) { + }, function (err, r) { try { + if (err) throw err; if (r && r.code === 503) return cb("server is too busy"); cb(JSON.parse(r.body).success === true ? undefined : "password update failed"); } catch(e) { diff --git a/lib/load_gen/activities/include_only.js b/lib/load_gen/activities/include_only.js index 379e0dfed..433a57f3e 100644 --- a/lib/load_gen/activities/include_only.js +++ b/lib/load_gen/activities/include_only.js @@ -44,8 +44,10 @@ url = require('url'), client = require('../../wsapi_client.js'); exports.startFunc = function(cfg, cb) { - client.get(cfg, '/include.js', {}, undefined, function(r) { - if (!r || r.code !== 200) { + client.get(cfg, '/include.js', {}, undefined, function(err, r) { + if (err) { + cb(err); + } else if (!r || r.code !== 200) { cb("for include.js fetch response code is not 200: " + (r ? r.code : "no response")); } else { // XXX: check the checksum of body? diff --git a/lib/load_gen/activities/reset_pass.js b/lib/load_gen/activities/reset_pass.js index 29d4a4846..e1c46fcb8 100644 --- a/lib/load_gen/activities/reset_pass.js +++ b/lib/load_gen/activities/reset_pass.js @@ -95,19 +95,25 @@ exports.startFunc = function(cfg, cb) { wcli.post(cfg, '/wsapi/stage_user', context, { email: email, site: userdb.any(user.sites) - }, function (r) { - if (!r || r.code !== 200) return cb(false); + }, function (err, r) { + if (err) return cb(err); + if (!r || r.code !== 200) return cb("non 200 response"); + // now get the verification secret wcli.get(cfg, '/wsapi/fake_verification', context, { email: email - }, function (r) { - if (!r || r.code !== 200) return cb(false); + }, function (err, r) { + if (err) return cb(err); + if (!r || r.code !== 200) return cb("can't get verification secret: non 200 response"); + // and simulate clickthrough wcli.post(cfg, '/wsapi/complete_user_creation', context, { token: r.body, pass: user.password - }, function (r) { - if (r && r.code === 503) { + }, function (err, r) { + if (err) { + return cb(err); + } else if (r && r.code === 503) { return cb("server is too busy"); } else if (!r || r.code !== 200) { return cb("failed to complete user creation"); diff --git a/lib/load_gen/activities/signup.js b/lib/load_gen/activities/signup.js index c15db747d..c3230c378 100644 --- a/lib/load_gen/activities/signup.js +++ b/lib/load_gen/activities/signup.js @@ -94,19 +94,22 @@ exports.startFunc = function(cfg, cb) { wcli.post(cfg, '/wsapi/stage_user', context, { email: email, site: userdb.any(user.sites) - }, function (r) { - if (!r || r.code !== 200) return cb(false); + }, function (err, r) { + if (err) return cb(err); + if (r.code !== 200) return cb("can't stage user, non-200 response: " + r.code); // now get the verification secret wcli.get(cfg, '/wsapi/fake_verification', context, { email: email - }, function (r) { - if (!r || r.code !== 200) return cb(false); + }, function (err, r) { + if (err) return cb(err); + if (r.code !== 200) return cb("can't get verification secret: " + r.code); // and simulate clickthrough wcli.post(cfg, '/wsapi/complete_user_creation', context, { token: r.body, pass: user.password - }, function (r) { + }, function (err, r) { try { + if (err) throw err; r.body = JSON.parse(r.body); if (r.code !== 200 || r.body.success !== true) { throw "non-success" + (r.body && r.body.reason ? " (" + r.body.reason + ")" : ""); diff --git a/lib/load_gen/common.js b/lib/load_gen/common.js index cd94b5ade..5dd9edc73 100644 --- a/lib/load_gen/common.js +++ b/lib/load_gen/common.js @@ -12,13 +12,16 @@ exports.auth = function(cfg, user, ctx, email, cb) { wcli.post( cfg, '/wsapi/authenticate_user', ctx, { email: email, pass: user.password }, - function(r) { + function(err, r) { try { - if (JSON.parse(r.body).success !== true) throw "non-success response " + r.code + (r.body ? (" - " + r.body) : ""); + if (err) throw err; + if (JSON.parse(r.body).success !== true) { + throw "non-success response " + r.code + (r.body ? (" - " + r.body) : ""); + } ctx.session.authenticated = true; cb(); } catch (e) { - cb('failed to authenticate: ' + e); + cb("can't authenticate: " + e); } } ); @@ -35,8 +38,9 @@ exports.authAndKey = function(cfg, user, ctx, email, cb) { wcli.post(cfg, '/wsapi/cert_key', ctx, { email: email, pubkey: keypair.publicKey.serialize() - }, function(resp) { + }, function(err, resp) { try { + if (err) throw err; if (resp.code !== 200) throw "non-200 status: " + resp.code + + " - " + resp.body; if (typeof resp.body !== 'string') throw cb("no response body"); @@ -61,10 +65,11 @@ exports.genAssertionAndVerify = function(cfg, user, ctx, email, audience, cb) { // adds that to server time) var t = new Date(((new Date()).getTime() - ctx.sessionStartedAt) + ctx.session.server_time); - wcli.get(cfg, '/wsapi/list_emails', ctx, undefined, function (r) { + wcli.get(cfg, '/wsapi/list_emails', ctx, undefined, function (err, r) { // just verify that we got a JSON object, we don't care about // the contents so much try { + if (err) throw err; if (!typeof JSON.parse(r.body) === 'object') throw 'bogus response'; } catch(e) { return cb(e.toString() + (r ? (" - " + r.body) : "")); @@ -81,8 +86,9 @@ exports.genAssertionAndVerify = function(cfg, user, ctx, email, audience, cb) { wcli.post(cfg, '/verify', {}, { audience: assertion.audience, assertion: assertion.assertion - }, function (r) { + }, function (err, r) { try { + if (err) throw err; if (r.code !== 200) throw "non-200 status: " + resp.code; if (!JSON.parse(r.body).status === 'okay') throw "verification failed with: " + r.reason; cb(undefined); diff --git a/lib/wsapi_client.js b/lib/wsapi_client.js index 9f889fefa..1b8b50d7f 100644 --- a/lib/wsapi_client.js +++ b/lib/wsapi_client.js @@ -84,7 +84,7 @@ exports.get = function(cfg, path, context, getArgs, cb) { uObj = url.parse(cfg.browserid); meth = uObj.protocol === 'http:' ? http : https; } catch(e) { - cb(false); + cb("can't parse url: " + e); return; } @@ -105,32 +105,35 @@ exports.get = function(cfg, path, context, getArgs, cb) { var body = ''; res.on('data', function(chunk) { body += chunk; }) .on('end', function() { - cb({code: res.statusCode, headers: res.headers, body: body}); + cb(null, {code: res.statusCode, headers: res.headers, body: body}); }); }).on('error', function (e) { - cb(); + cb(e); }); }; function withCSRF(cfg, context, cb) { - if (context.session && context.session.csrf_token) cb(context.session.csrf_token); + if (context.session && context.session.csrf_token) cb(null, context.session.csrf_token); else { - exports.get(cfg, '/wsapi/session_context', context, undefined, function(r) { + exports.get(cfg, '/wsapi/session_context', context, undefined, function(err, r) { + if (err) return cb(err); try { if (r.code !== 200) throw 'http error'; context.session = JSON.parse(r.body); context.sessionStartedAt = new Date().getTime(); - cb(context.session.csrf_token); + cb(null, context.session.csrf_token); } catch(e) { console.log('error getting csrf token: ', e); - cb(); + cb(e); } }); } } exports.post = function(cfg, path, context, postArgs, cb) { - withCSRF(cfg, context, function(csrf) { + withCSRF(cfg, context, function(err, csrf) { + if (err) return cb(err); + // parse the server URL (cfg.browserid) var uObj; var meth; @@ -138,7 +141,7 @@ exports.post = function(cfg, path, context, postArgs, cb) { uObj = url.parse(cfg.browserid); meth = uObj.protocol === 'http:' ? http : https; } catch(e) { - cb(false); + cb("can't parse url: " + e); return; } var headers = { @@ -164,10 +167,10 @@ exports.post = function(cfg, path, context, postArgs, cb) { var body = ''; res.on('data', function(chunk) { body += chunk; }) .on('end', function() { - cb({code: res.statusCode, headers: res.headers, body: body}); + cb(null, {code: res.statusCode, headers: res.headers, body: body}); }); }).on('error', function (e) { - cb(); + cb(e); }); req.write(body); diff --git a/scripts/create_account.js b/scripts/create_account.js index ccc851fcf..2f5e709e7 100755 --- a/scripts/create_account.js +++ b/scripts/create_account.js @@ -68,14 +68,19 @@ wcli.post({ }, '/wsapi/stage_user', ctx, { email: args.e, site: args.d -}, function(response) { +}, function(err, response) { + function doError(e) { + process.stderr.write("error: " + e.toString() + "\n"); + process.stderr.write("response: " + response.body + "\n"); + process.exit(1); + } + if (err) return doError(err); try { var body = JSON.parse(response.body); - if (body.success !== true) + if (body.success !== true) { throw "request failed: " + response.body; + } } catch(e) { - process.stderr.write("error: " + e.toString() + "\n"); - process.stderr.write("response: " + response.body + "\n"); - process.exit(1); + return doError(e); } }); diff --git a/tests/add-email-with-assertion-test.js b/tests/add-email-with-assertion-test.js index 502241d75..f03ff094d 100755 --- a/tests/add-email-with-assertion-test.js +++ b/tests/add-email-with-assertion-test.js @@ -132,7 +132,7 @@ suite.addBatch({ assertion: g_assertion }).call(this); }, - "fails if not authenticated": function(r, err) { + "fails if not authenticated": function(err, r) { assert.strictEqual(r.code, 400); } } @@ -145,7 +145,7 @@ suite.addBatch({ email: TEST_FIRST_ACCT, site:'fakesite.com' }), - "works": function(r, err) { + "works": function(err, r) { assert.strictEqual(r.code, 200); }, "and a token": { @@ -159,7 +159,7 @@ suite.addBatch({ topic: function(token) { wsapi.post('/wsapi/complete_user_creation', { token: token, pass: 'fakepass' }).call(this); }, - "to verify email ownership": function(r, err) { + "to verify email ownership": function(err, r) { assert.equal(r.code, 200); assert.strictEqual(JSON.parse(r.body).success, true); token = undefined; @@ -176,7 +176,7 @@ suite.addBatch({ assertion: g_assertion }).call(this); }, - "works once we are authenticated": function(r, err) { + "works once we are authenticated": function(err, r) { var resp = JSON.parse(r.body); assert.isObject(resp); assert.isTrue(resp.success); @@ -187,10 +187,10 @@ suite.addBatch({ suite.addBatch({ "list emails": { topic: wsapi.get('/wsapi/list_emails', {}), - "succeeds with HTTP 200" : function(r, err) { + "succeeds with HTTP 200" : function(err, r) { assert.strictEqual(r.code, 200); }, - "returns an object with what we'd expect": function(r, err) { + "returns an object with what we'd expect": function(err, r) { var respObj = JSON.parse(r.body); var emails = Object.keys(respObj); assert.strictEqual(emails.length, 2) diff --git a/tests/auth-with-assertion-test.js b/tests/auth-with-assertion-test.js index 4ec2c50b8..103c1730a 100755 --- a/tests/auth-with-assertion-test.js +++ b/tests/auth-with-assertion-test.js @@ -83,7 +83,7 @@ suite.addBatch({ assertion: assertion }).call(this); }, - "works": function(r, err) { + "works": function(err, r) { var resp = JSON.parse(r.body); assert.isObject(resp); assert.isTrue(resp.success); diff --git a/tests/cert-emails-test.js b/tests/cert-emails-test.js index ee9b8ef9e..42dee2653 100755 --- a/tests/cert-emails-test.js +++ b/tests/cert-emails-test.js @@ -68,7 +68,7 @@ suite.addBatch({ pubkey: 'fakekey', site:'fakesite.com' }), - "succeeds": function(r, err) { + "succeeds": function(err, r) { assert.strictEqual(r.code, 200); } } @@ -92,7 +92,7 @@ suite.addBatch({ topic: function() { wsapi.post('/wsapi/complete_user_creation', { token: token, pass: 'fakepass' }).call(this); }, - "works": function(r, err) { + "works": function(err, r) { assert.equal(r.code, 200); assert.strictEqual(true, JSON.parse(r.body).success); } @@ -108,38 +108,38 @@ var kp = jwk.KeyPair.generate("RS",64); suite.addBatch({ "check the public key": { topic: wsapi.get("/pk"), - "returns a 200": function(r, err) { + "returns a 200": function(err, r) { assert.strictEqual(r.code, 200); }, - "returns the right public key": function(r, err) { + "returns the right public key": function(err, r) { var pk = jwk.PublicKey.deserialize(r.body); assert.ok(pk); } }, "cert key with no parameters": { topic: wsapi.post(cert_key_url, {}), - "fails with HTTP 400" : function(r, err) { + "fails with HTTP 400" : function(err, r) { assert.strictEqual(r.code, 400); } }, "cert key invoked with just an email": { topic: wsapi.post(cert_key_url, { email: 'syncer@somehost.com' }), - "returns a 400" : function(r, err) { + "returns a 400" : function(err, r) { assert.strictEqual(r.code, 400); } }, "cert key invoked with proper argument": { topic: wsapi.post(cert_key_url, { email: 'syncer@somehost.com', pubkey: kp.publicKey.serialize() }), - "returns a response with a proper content-type" : function(r, err) { + "returns a response with a proper content-type" : function(err, r) { assert.strictEqual(r.code, 200); }, - "returns a proper cert": function(r, err) { + "returns a proper cert": function(err, r) { ca.verifyChain([r.body], function(pk) { assert.isTrue(kp.publicKey.equals(pk)); }); }, "generate an assertion": { - topic: function(r) { + topic: function(err, r) { var serializedCert = r.body.toString(); var expiration = new Date(new Date().getTime() + (2 * 60 * 1000)); var assertion = new jwt.JWT(null, expiration, "rp.com"); @@ -173,9 +173,9 @@ suite.addBatch({ } } }, - "cert key invoked proper arguments but incorrect email address": { + "cert key invoked proper arguments but incorrect email address": { topic: wsapi.post(cert_key_url, { email: 'syncer2@somehost.com', pubkey: kp.publicKey.serialize() }), - "returns a response with a proper error content-type" : function(r, err) { + "returns a response with a proper error content-type" : function(err, r) { assert.strictEqual(r.code, 400); } } diff --git a/tests/cookie-session-security-test.js b/tests/cookie-session-security-test.js index 1cdee1822..6ef6945cd 100755 --- a/tests/cookie-session-security-test.js +++ b/tests/cookie-session-security-test.js @@ -67,7 +67,7 @@ function stripExpires(cookieString) { suite.addBatch({ "get context": { topic: wsapi.get('/wsapi/session_context'), - "has a cookie because of CSRF setting" : function(r, err) { + "has a cookie because of CSRF setting" : function(err, r) { // make sure there's NO cookie var cookie = r.headers["set-cookie"]; assert.isNotNull(cookie[0]); @@ -75,14 +75,14 @@ suite.addBatch({ }, "and then session context again": { topic: wsapi.get('/wsapi/logout'), - "should not set-cookie": function(r, err) { + "should not set-cookie": function(err, r) { var cookie = r.headers["set-cookie"]; assert.isUndefined(cookie); }, "then let's screw it up": { topic: function() { wsapi.clearCookies(); - + // mess up the cookie var the_match = first_cookie.match(/browserid_state=([^;]*);/); assert.isNotNull(the_match); @@ -92,7 +92,7 @@ suite.addBatch({ }, "and then get context": { topic: wsapi.get('/wsapi/session_context'), - "and result should have a new cookie for session reset": function(r, err) { + "and result should have a new cookie for session reset": function(err, r) { var cookie = r.headers["set-cookie"]; assert.isNotNull(cookie); assert.isNotNull(cookie[0]); diff --git a/tests/email-throttling-test.js b/tests/email-throttling-test.js index bc3a18059..d118c7be8 100755 --- a/tests/email-throttling-test.js +++ b/tests/email-throttling-test.js @@ -57,7 +57,7 @@ suite.addBatch({ email: 'first@fakeemail.com', site:'fakesite.com' }), - "returns 200": function(r, err) { + "returns 200": function(err, r) { assert.strictEqual(r.code, 200); } } @@ -82,7 +82,7 @@ suite.addBatch({ email: 'first@fakeemail.com', site:'fakesite.com' }), - "is throttled": function(r, err) { + "is throttled": function(err, r) { assert.strictEqual(r.code, 403); } } @@ -93,7 +93,7 @@ suite.addBatch({ topic: function() { wsapi.post('/wsapi/complete_user_creation', { token: token, pass: 'firstfakepass' }).call(this); }, - "works": function(r, err) { + "works": function(err, r) { assert.equal(r.code, 200); assert.strictEqual(true, JSON.parse(r.body).success); token = undefined; @@ -107,7 +107,7 @@ suite.addBatch({ email: 'second@fakeemail.com', site:'fakesite.com' }), - "works": function(r, err) { + "works": function(err, r) { assert.strictEqual(r.code, 200); } } @@ -132,7 +132,7 @@ suite.addBatch({ email: 'second@fakeemail.com', site:'fakesite.com' }), - "is throttled with a 403": function(r, err) { + "is throttled with a 403": function(err, r) { assert.strictEqual(r.code, 403); } } @@ -143,7 +143,7 @@ suite.addBatch({ topic: function() { wsapi.post('/wsapi/complete_email_addition', { token: token }).call(this); }, - "it works swimmingly": function(r, err) { + "it works swimmingly": function(err, r) { assert.equal(r.code, 200); assert.strictEqual(JSON.parse(r.body).success, true); token = undefined; diff --git a/tests/forgotten-email-test.js b/tests/forgotten-email-test.js index 14b2c2729..77a6b15a8 100755 --- a/tests/forgotten-email-test.js +++ b/tests/forgotten-email-test.js @@ -58,7 +58,7 @@ suite.addBatch({ email: 'first@fakeemail.com', site:'fakesite.com' }), - "works": function(r, err) { + "works": function(err, r) { assert.strictEqual(r.code, 200); } } @@ -82,7 +82,7 @@ suite.addBatch({ topic: function() { wsapi.post('/wsapi/complete_user_creation', { token: token, pass: 'firstfakepass' }).call(this); }, - "account created": function(r, err) { + "account created": function(err, r) { assert.equal(r.code, 200); assert.strictEqual(true, JSON.parse(r.body).success); token = undefined; @@ -93,7 +93,7 @@ suite.addBatch({ suite.addBatch({ "email created": { topic: wsapi.get('/wsapi/user_creation_status', { email: 'first@fakeemail.com' } ), - "should exist": function(r, err) { + "should exist": function(err, r) { assert.strictEqual(r.code, 200); assert.strictEqual(JSON.parse(r.body).status, "complete"); } @@ -107,7 +107,7 @@ suite.addBatch({ email: 'second@fakeemail.com', site:'fakesite.com' }), - "works": function(r, err) { + "works": function(err, r) { assert.strictEqual(r.code, 200); } } @@ -132,7 +132,7 @@ suite.addBatch({ topic: function() { wsapi.post('/wsapi/complete_email_addition', { token: token }).call(this); }, - "account created": function(r, err) { + "account created": function(err, r) { assert.equal(r.code, 200); assert.strictEqual(JSON.parse(r.body).success, true); token = undefined; @@ -144,19 +144,19 @@ suite.addBatch({ suite.addBatch({ "first email exists": { topic: wsapi.get('/wsapi/have_email', { email: 'first@fakeemail.com' }), - "should exist": function(r, err) { + "should exist": function(err, r) { assert.strictEqual(JSON.parse(r.body).email_known, true); } }, "second email exists": { topic: wsapi.get('/wsapi/have_email', { email: 'second@fakeemail.com' }), - "should exist": function(r, err) { + "should exist": function(err, r) { assert.strictEqual(JSON.parse(r.body).email_known, true); } }, "a random email doesn't exist": { topic: wsapi.get('/wsapi/have_email', { email: 'third@fakeemail.com' }), - "shouldn't exist": function(r, err) { + "shouldn't exist": function(err, r) { assert.strictEqual(JSON.parse(r.body).email_known, false); } } @@ -170,7 +170,7 @@ suite.addBatch({ email: 'first@fakeemail.com', site:'otherfakesite.com' }), - "works": function(r, err) { + "works": function(err, r) { assert.strictEqual(r.code, 200); } } @@ -194,13 +194,13 @@ suite.addBatch({ suite.addBatch({ "first email works": { topic: wsapi.post('/wsapi/authenticate_user', { email: 'first@fakeemail.com', pass: 'firstfakepass' }), - "should work": function(r, err) { + "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' }), - "should work": function(r, err) { + "should work": function(err, r) { assert.strictEqual(JSON.parse(r.body).success, true); } } @@ -212,7 +212,7 @@ suite.addBatch({ topic: function() { wsapi.post('/wsapi/complete_user_creation', { token: token, pass: 'secondfakepass' }).call(this); }, - "account created": function(r, err) { + "account created": function(err, r) { assert.equal(r.code, 200); assert.strictEqual(JSON.parse(r.body).success, true); } @@ -224,31 +224,31 @@ suite.addBatch({ suite.addBatch({ "first email, first pass bad": { topic: wsapi.post('/wsapi/authenticate_user', { email: 'first@fakeemail.com', pass: 'firstfakepass' }), - "shouldn't work": function(r, err) { + "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' }), - "should work": function(r, err) { + "should work": function(err, r) { assert.strictEqual(JSON.parse(r.body).success, true); } }, "logout": { topic: wsapi.post('/wsapi/logout', {}), - "should work": function(r, err) { + "should work": function(err, r) { assert.strictEqual(JSON.parse(r.body).success, true); } }, "second email, first pass good": { topic: wsapi.post('/wsapi/authenticate_user', { email: 'second@fakeemail.com', pass: 'firstfakepass' }), - "should work": function(r, err) { + "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' }), - "shouldn' work": function(r, err) { + "shouldn' work": function(err, r) { assert.strictEqual(JSON.parse(r.body).success, false); } }, diff --git a/tests/lib/start-stop.js b/tests/lib/start-stop.js index 5ea3b861d..a20c60647 100644 --- a/tests/lib/start-stop.js +++ b/tests/lib/start-stop.js @@ -152,7 +152,7 @@ exports.addStartupBatches = function(suite) { }, "server should be running": { topic: wsapi.get('/__heartbeat__'), - "server is running": function (r, err) { + "server is running": function (err, r) { assert.equal(r.code, 200); assert.equal(r.body, 'ok'); } @@ -186,7 +186,7 @@ exports.addRestartBatch = function(suite) { }, "server should be running": { topic: wsapi.get('/__heartbeat__'), - "server is running": function (r, err) { + "server is running": function (err, r) { assert.equal(r.code, 200); assert.equal(r.body, 'ok'); } diff --git a/tests/list-emails-wsapi-test.js b/tests/list-emails-wsapi-test.js index ca264db41..a4a6de3a3 100755 --- a/tests/list-emails-wsapi-test.js +++ b/tests/list-emails-wsapi-test.js @@ -60,7 +60,7 @@ suite.addBatch({ email: 'syncer@somehost.com', site:'fakesite.com' }), - "works": function(r, err) { + "works": function(err, r) { assert.strictEqual(r.code, 200); } } @@ -84,7 +84,7 @@ suite.addBatch({ topic: function() { wsapi.post('/wsapi/complete_user_creation', { token: token, pass: 'fakepass' }).call(this); }, - "works": function(r, err) { + "works": function(err, r) { assert.equal(r.code, 200); assert.strictEqual(JSON.parse(r.body).success, true); token = undefined; @@ -95,10 +95,10 @@ suite.addBatch({ suite.addBatch({ "calling user_creation_status after a creation is complete": { topic: wsapi.get("/wsapi/user_creation_status", { email: 'syncer@somehost.com' }), - "yields a HTTP 200": function (r, err) { + "yields a HTTP 200": function (err, r) { assert.strictEqual(r.code, 200); }, - "returns a json encoded string - `complete`": function (r, err) { + "returns a json encoded string - `complete`": function (err, r) { assert.strictEqual(JSON.parse(r.body).status, "complete"); } } @@ -107,10 +107,10 @@ suite.addBatch({ suite.addBatch({ "list emails API": { topic: wsapi.get('/wsapi/list_emails', {}), - "succeeds with HTTP 200" : function(r, err) { + "succeeds with HTTP 200" : function(err, r) { assert.strictEqual(r.code, 200); }, - "returns an object with proper email": function(r, err) { + "returns an object with proper email": function(err, r) { var respObj = JSON.parse(r.body); var emails = Object.keys(respObj); assert.equal(emails[0], "syncer@somehost.com"); diff --git a/tests/page-requests-test.js b/tests/page-requests-test.js index 294ebc077..6e5b457aa 100755 --- a/tests/page-requests-test.js +++ b/tests/page-requests-test.js @@ -55,7 +55,7 @@ start_stop.addStartupBatches(suite); // Taken from the vows page. function assertStatus(code) { - return function (res, err) { + return function (err, res) { assert.equal(res.code, code); }; } diff --git a/tests/password-bcrypt-update-test.js b/tests/password-bcrypt-update-test.js index 4dc07a589..894136e74 100755 --- a/tests/password-bcrypt-update-test.js +++ b/tests/password-bcrypt-update-test.js @@ -62,7 +62,7 @@ var token = undefined; suite.addBatch({ "get csrf token": { topic: wsapi.get('/wsapi/session_context'), - "works": function (r, err) { + "works": function (err, r) { assert.equal(typeof r.body, 'string'); var v = JSON.parse(r.body); assert.equal(typeof v, 'object'); @@ -79,7 +79,7 @@ suite.addBatch({ email: TEST_EMAIL, site:'fakesite.com' }), - "works": function(r, err) { + "works": function(err, r) { assert.equal(r.code, 200); } } @@ -107,7 +107,7 @@ suite.addBatch({ pass: TEST_PASSWORD }).call(this); }, - "works just fine": function(r, err) { + "works just fine": function(err, r) { assert.equal(r.code, 200); } } @@ -122,7 +122,7 @@ suite.addBatch({ db.checkAuth(uid, cb); }); }, - "is bcrypted with the expected number of rounds": function(r, err) { + "is bcrypted with the expected number of rounds": function(r) { assert.equal(typeof r, 'string'); assert.equal(config.get('bcrypt_work_factor'), bcrypt.get_rounds(r)); } @@ -149,7 +149,7 @@ suite.addBatch({ email: TEST_EMAIL, pass: TEST_PASSWORD }), - "should work": function(r, err) { + "should work": function(err, r) { assert.strictEqual(JSON.parse(r.body).success, true); } } @@ -169,7 +169,7 @@ suite.addBatch({ db.checkAuth(uid, cb); }); }, - "its bcrypted with 8 rounds": function(r, err) { + "its bcrypted with 8 rounds": function(r) { assert.equal(typeof r, 'string'); assert.equal(8, bcrypt.get_rounds(r)); } @@ -184,7 +184,7 @@ suite.addBatch({ email: TEST_EMAIL, pass: TEST_PASSWORD }), - "should still work": function(r, err) { + "should still work": function(err, r) { assert.strictEqual(JSON.parse(r.body).success, true); } } diff --git a/tests/password-length-test.js b/tests/password-length-test.js index e8d47283b..a9e1d33be 100755 --- a/tests/password-length-test.js +++ b/tests/password-length-test.js @@ -60,7 +60,7 @@ start_stop.browserid.on('token', function(secret) { suite.addBatch({ "get csrf token": { topic: wsapi.get('/wsapi/session_context'), - "works": function (r, err) { + "works": function (err, r) { assert.equal(typeof r.body, 'string'); var v = JSON.parse(r.body); assert.equal(typeof v, 'object'); @@ -77,7 +77,7 @@ suite.addBatch({ email: 'first@fakeemail.com', site:'fakesite.com' }), - "works": function(r, err) { + "works": function(err, r) { assert.equal(r.code, 200); } } @@ -90,7 +90,7 @@ suite.addBatch({ token: token, pass: '0123456' // less than 8 chars, invalid }), - "causes a HTTP error response": function(r, err) { + "causes a HTTP error response": function(err, r) { assert.equal(r.code, 400); assert.equal(r.body, "Bad Request: valid passwords are between 8 and 80 chars"); } @@ -100,7 +100,7 @@ suite.addBatch({ token: token, pass: '012345678901234567890123456789012345678901234567890123456789012345678901234567891', // more than 81 chars, invalid. }), - "causes a HTTP error response": function(r, err) { + "causes a HTTP error response": function(err, r) { assert.equal(r.code, 400); assert.equal(r.body, "Bad Request: valid passwords are between 8 and 80 chars"); } @@ -110,7 +110,7 @@ suite.addBatch({ token: token, pass: 'ahhh. this is just right.' }), - "works just fine": function(r, err) { + "works just fine": function(err, r) { assert.equal(r.code, 200); } } diff --git a/tests/password-update-test.js b/tests/password-update-test.js index f29d8f81e..8bd2ac6bd 100755 --- a/tests/password-update-test.js +++ b/tests/password-update-test.js @@ -67,7 +67,7 @@ suite.addBatch({ email: TEST_EMAIL, site: 'fakesite.com' }), - "works": function(r, err) { + "works": function(err, r) { assert.equal(r.code, 200); } } @@ -95,7 +95,7 @@ suite.addBatch({ pass: OLD_PASSWORD }).call(this); }, - "works just fine": function(r, err) { + "works just fine": function(err, r) { assert.equal(r.code, 200); } } @@ -107,7 +107,7 @@ suite.addBatch({ email: TEST_EMAIL, pass: OLD_PASSWORD }), - "works as expected": function(r, err) { + "works as expected": function(err, r) { assert.strictEqual(JSON.parse(r.body).success, true); } }, @@ -116,7 +116,7 @@ suite.addBatch({ email: TEST_EMAIL, pass: NEW_PASSWORD }), - "fails as expected": function(r, err) { + "fails as expected": function(err, r) { assert.strictEqual(JSON.parse(r.body).success, false); } } @@ -128,7 +128,7 @@ suite.addBatch({ oldpass: "bogus ass password", newpass: NEW_PASSWORD }), - "fails as expected": function(r, err) { + "fails as expected": function(err, r) { assert.strictEqual(JSON.parse(r.body).success, false); } } @@ -140,7 +140,7 @@ suite.addBatch({ oldpass: OLD_PASSWORD, newpass: 'bogus' // too short }), - "fails as expected": function(r, err) { + "fails as expected": function(err, r) { assert.strictEqual(JSON.parse(r.body).success, false); } } @@ -152,7 +152,7 @@ suite.addBatch({ oldpass: OLD_PASSWORD, newpass: NEW_PASSWORD }), - "works as expected": function(r, err) { + "works as expected": function(err, r) { assert.strictEqual(JSON.parse(r.body).success, true); } } @@ -164,7 +164,7 @@ suite.addBatch({ email: TEST_EMAIL, pass: NEW_PASSWORD }), - "works as expected": function(r, err) { + "works as expected": function(err, r) { assert.strictEqual(JSON.parse(r.body).success, true); } }, @@ -173,7 +173,7 @@ suite.addBatch({ email: TEST_EMAIL, pass: OLD_PASSWORD }), - "fails as expected": function(r, err) { + "fails as expected": function(err, r) { assert.strictEqual(JSON.parse(r.body).success, false); } } diff --git a/tests/post-limiting-test.js b/tests/post-limiting-test.js index 70b86b71c..51b032101 100755 --- a/tests/post-limiting-test.js +++ b/tests/post-limiting-test.js @@ -67,14 +67,14 @@ suite.addBatch({ }, method: "POST" }, function (res) { - cb(res); + cb(null, res); }).on('error', function (e) { - cb(undefined, e); + cb(e); }); req.write(secrets.weakGenerate(1024 * 10 + 1)); req.end(); }, - "fails": function (r, err) { + "fails": function (err, r) { assert.ok(/socket hang up/.test(err.toString())); } } @@ -95,14 +95,14 @@ suite.addBatch({ }, method: "POST" }, function (res) { - cb(res); + cb(null, res); }).on('error', function (e) { - cb(undefined, e); + cb(e); }); req.write(secrets.weakGenerate(1024 * 10 + 1)); req.end(); }, - "fails": function (r, err) { + "fails": function (err, r) { assert.strictEqual(413, r.statusCode); } } diff --git a/tests/primary-then-secondary-test.js b/tests/primary-then-secondary-test.js index d4d244d57..ac52a515b 100755 --- a/tests/primary-then-secondary-test.js +++ b/tests/primary-then-secondary-test.js @@ -75,7 +75,7 @@ suite.addBatch({ topic: function() { return primaryUser.getAssertion(TEST_ORIGIN); }, - "succeeds": function(r, err) { + "succeeds": function(r) { assert.isString(r); }, "and logging in with the assertion succeeds": { @@ -85,7 +85,7 @@ suite.addBatch({ assertion: assertion }).call(this); }, - "works": function(r, err) { + "works": function(err, r) { var resp = JSON.parse(r.body); assert.isObject(resp); assert.isTrue(resp.success); @@ -99,7 +99,7 @@ suite.addBatch({ suite.addBatch({ "auth_level": { topic: wsapi.get('/wsapi/session_context'), - "is 'assertion' after authenticating with assertion" : function(r, err) { + "is 'assertion' after authenticating with assertion" : function(err, r) { assert.strictEqual(JSON.parse(r.body).auth_level, 'assertion'); } } @@ -114,7 +114,7 @@ suite.addBatch({ email: SECONDARY_EMAIL, site:'fakesite.com' }), - "works": function(r, err) { + "works": function(err, r) { assert.strictEqual(r.code, 200); }, "and get a token": { @@ -131,7 +131,7 @@ suite.addBatch({ token: t }).call(this); }, - "we need to set our password": function (r) { + "we need to set our password": function (err, r) { r = JSON.parse(r.body); assert.ok(r.needs_password); }, @@ -139,7 +139,7 @@ suite.addBatch({ topic: function() { wsapi.post('/wsapi/complete_email_addition', { token: this._token }).call(this); }, - "no password fails": function(r, err) { + "no password fails": function(err, r) { assert.equal(r.code, 200); assert.strictEqual(JSON.parse(r.body).success, false); }, @@ -150,7 +150,7 @@ suite.addBatch({ pass: TEST_PASS }).call(this); }, - "succeeds": function(r, err) { + "succeeds": function(err, r) { assert.equal(r.code, 200); assert.strictEqual(JSON.parse(r.body).success, true); } @@ -165,7 +165,7 @@ suite.addBatch({ suite.addBatch({ "auth_level": { topic: wsapi.get('/wsapi/session_context'), - "is 'password' after authenticating with password" : function(r, err) { + "is 'password' after authenticating with password" : function(err, r) { assert.strictEqual(JSON.parse(r.body).auth_level, 'password'); } } @@ -179,7 +179,7 @@ suite.addBatch({ email: SECOND_SECONDARY_EMAIL, site:'fakesite.com' }), - "works": function(r, err) { + "works": function(err, r) { assert.strictEqual(r.code, 200); }, "and get a token": { @@ -196,7 +196,7 @@ suite.addBatch({ token: t }).call(this); }, - "we do not need to set our password": function (r) { + "we do not need to set our password": function (err, r) { r = JSON.parse(r.body); assert.isFalse(r.needs_password); }, @@ -204,7 +204,7 @@ suite.addBatch({ topic: function() { wsapi.post('/wsapi/complete_email_addition', { token: this._token, pass: TEST_PASS }).call(this); }, - "a password fails": function(r, err) { + "a password fails": function(err, r) { assert.equal(r.code, 200); assert.strictEqual(JSON.parse(r.body).success, false); }, @@ -214,7 +214,7 @@ suite.addBatch({ token: this._token }).call(this); }, - "succeeds": function(r, err) { + "succeeds": function(err, r) { assert.equal(r.code, 200); assert.strictEqual(JSON.parse(r.body).success, true); } @@ -231,7 +231,7 @@ suite.addBatch({ email: TEST_EMAIL, pass: TEST_PASS }), - "works": function(r, err) { + "works": function(err, r) { assert.strictEqual(r.code, 200); }, }, @@ -240,7 +240,7 @@ suite.addBatch({ email: SECONDARY_EMAIL, pass: TEST_PASS }), - "works": function(r, err) { + "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 73012662d..e52f63178 100755 --- a/tests/registration-status-wsapi-test.js +++ b/tests/registration-status-wsapi-test.js @@ -58,7 +58,7 @@ start_stop.addStartupBatches(suite); suite.addBatch({ "calling registration_status without a pending reg is an error": { topic: wsapi.get("/wsapi/user_creation_status"), - "HTTP 400": function (r, err) { + "HTTP 400": function (err, r) { assert.equal(400, r.code); } } @@ -67,7 +67,7 @@ suite.addBatch({ suite.addBatch({ "authentication as an unknown user": { topic: wsapi.post('/wsapi/authenticate_user', { email: 'first@fakeemail.com', pass: 'secondfakepass' }), - "fails": function (r, err) { + "fails": function (err, r) { assert.isFalse(JSON.parse(r.body).success); } } @@ -80,7 +80,7 @@ suite.addBatch({ email: 'first@fakeemail.com', site:'fakesite.com' }), - "returns 200": function(r, err) { + "returns 200": function(err, r) { assert.strictEqual(r.code, 200); } } @@ -104,7 +104,7 @@ suite.addBatch({ topic: function() { return wsapi.get('/wsapi/email_for_token', {token: token}).call(this); }, - "and it matches": function(r, err) { + "and it matches": function(err, r) { assert.strictEqual(JSON.parse(r.body).email, 'first@fakeemail.com'); } } @@ -113,10 +113,10 @@ suite.addBatch({ suite.addBatch({ "calling user_creation_status without an email argument": { topic: wsapi.get("/wsapi/user_creation_status"), - "yields a HTTP 400": function (r, err) { + "yields a HTTP 400": function (err, r) { assert.strictEqual(r.code, 400); }, - "returns an error string": function (r, err) { + "returns an error string": function (err, r) { assert.strictEqual(r.body, "Bad Request: missing 'email' argument"); } } @@ -125,10 +125,10 @@ suite.addBatch({ suite.addBatch({ "calling user_creation_status when a reg is really pending": { topic: wsapi.get("/wsapi/user_creation_status", { email: 'first@fakeemail.com' }), - "yields a HTTP 200": function (r, err) { + "yields a HTTP 200": function (err, r) { assert.strictEqual(r.code, 200); }, - "returns a json encoded string - `pending`": function (r, err) { + "returns a json encoded string - `pending`": function (err, r) { assert.strictEqual(JSON.parse(r.body).status, "pending"); } } @@ -139,7 +139,7 @@ suite.addBatch({ topic: function() { wsapi.post('/wsapi/complete_user_creation', { token: token, pass: 'firstfakepass' }).call(this); }, - "works": function(r, err) { + "works": function(err, r) { assert.equal(r.code, 200); token = undefined; } @@ -149,10 +149,10 @@ suite.addBatch({ suite.addBatch({ "calling user_creation_status after a registration is complete": { topic: wsapi.get("/wsapi/user_creation_status", { email: 'first@fakeemail.com' }), - "yields a HTTP 200": function (r, err) { + "yields a HTTP 200": function (err, r) { assert.strictEqual(r.code, 200); }, - "returns a json encoded string - `complete`": function (r, err) { + "returns a json encoded string - `complete`": function (err, r) { assert.strictEqual(JSON.parse(r.body).status, "complete"); } } @@ -161,10 +161,10 @@ suite.addBatch({ suite.addBatch({ "calling registration_status a second time after a registration is complete": { topic: wsapi.get("/wsapi/user_creation_status", { email: 'first@fakeemail.com' }), - "still yields a HTTP 200": function (r, err) { + "still yields a HTTP 200": function (err, r) { assert.strictEqual(r.code, 200); }, - "and still returns a json encoded string - `complete`": function (r, err) { + "and still returns a json encoded string - `complete`": function (err, r) { assert.strictEqual(JSON.parse(r.body).status, "complete"); } } @@ -173,11 +173,11 @@ suite.addBatch({ suite.addBatch({ "after successful registration": { topic: wsapi.get("/wsapi/session_context"), - "we're authenticated": function (r, err) { + "we're authenticated": function (err, r) { assert.strictEqual(r.code, 200); assert.strictEqual(JSON.parse(r.body).auth_level, 'password'); }, - "but we can easily clear cookies on the client to change that!": function(r, err) { + "but we can easily clear cookies on the client to change that!": function(err, r) { wsapi.clearCookies(); } } @@ -186,7 +186,7 @@ suite.addBatch({ suite.addBatch({ "after clearing cookies": { topic: wsapi.get("/wsapi/session_context"), - "we're NOT authenticated": function (r, err) { + "we're NOT authenticated": function (err, r) { assert.strictEqual(r.code, 200); assert.strictEqual(JSON.parse(r.body).authenticated, false); } @@ -199,7 +199,7 @@ suite.addBatch({ email: 'first@fakeemail.com', site:'secondfakesite.com' }), - "yields a HTTP 200": function (r, err) { + "yields a HTTP 200": function (err, r) { assert.strictEqual(r.code, 200); } } @@ -221,10 +221,10 @@ suite.addBatch({ suite.addBatch({ "calling registration_status when a reg is pending for an email that is already verified": { topic: wsapi.get("/wsapi/user_creation_status", { email: 'first@fakeemail.com' }), - "should yield a HTTP 200": function (r, err) { + "should yield a HTTP 200": function (err, r) { assert.strictEqual(r.code, 200); }, - "returns a json encoded string - `pending`": function (r, err) { + "returns a json encoded string - `pending`": function (err, r) { assert.strictEqual(JSON.parse(r.body).status, "pending"); } } @@ -235,7 +235,7 @@ suite.addBatch({ topic: function() { wsapi.post('/wsapi/complete_user_creation', { token: token, pass: 'secondfakepass' }).call(this); }, - "and returns a 200 code": function(r, err) { + "and returns a 200 code": function(err, r) { assert.equal(r.code, 200); token = undefined; } @@ -245,10 +245,10 @@ suite.addBatch({ suite.addBatch({ "calling registration_status after proving a re-registration": { topic: wsapi.get("/wsapi/user_creation_status", { email: 'first@fakeemail.com' }), - "yields a HTTP 200": function (r, err) { + "yields a HTTP 200": function (err, r) { assert.strictEqual(r.code, 200); }, - "returns a json encoded string - `complete`": function (r, err) { + "returns a json encoded string - `complete`": function (err, r) { assert.strictEqual(JSON.parse(r.body).status, "complete"); } } @@ -257,7 +257,7 @@ suite.addBatch({ suite.addBatch({ "again, calling registration_status a second time after a registration is complete": { topic: wsapi.get("/wsapi/user_creation_status", { email: 'first@fakeemail.com' }), - "yields a HTTP 200": function (r, err) { + "yields a HTTP 200": function (err, r) { assert.strictEqual(r.code, 200); } } @@ -266,7 +266,7 @@ suite.addBatch({ suite.addBatch({ "after re-registration, authenticating with new credetials": { topic: wsapi.post('/wsapi/authenticate_user', { email: 'first@fakeemail.com', pass: 'secondfakepass' }), - "works as you might expect": function (r, err) { + "works as you might expect": function (err, r) { assert.strictEqual(JSON.parse(r.body).success, true); } } diff --git a/tests/secrets-test.js b/tests/secrets-test.js old mode 100644 new mode 100755 diff --git a/tests/two-level-auth-test.js b/tests/two-level-auth-test.js index b486a42c4..48cc8ca8a 100755 --- a/tests/two-level-auth-test.js +++ b/tests/two-level-auth-test.js @@ -66,7 +66,7 @@ suite.addBatch({ topic: function() { return primaryUser.getAssertion(TEST_ORIGIN); }, - "succeeds": function(r, err) { + "succeeds": function(r) { assert.isString(r); }, "and logging in with the assertion": { @@ -76,7 +76,7 @@ suite.addBatch({ assertion: assertion }).call(this); }, - "succeeds": function(r, err) { + "succeeds": function(err, r) { var resp = JSON.parse(r.body); assert.isObject(resp); assert.isTrue(resp.success); @@ -88,19 +88,19 @@ suite.addBatch({ suite.addBatch({ "updating our password": { topic: wsapi.post('/wsapi/update_password', { oldpass: '', newpass: 'frobaztastic' }), - "won't work": function(r) { + "won't work": function(err, r) { assert.strictEqual(r.code, 400); } }, "certifying a key": { topic: wsapi.post('/wsapi/cert_key', { email: TEST_EMAIL, pubkey: 'fake_key' }), - "won't work": function(r) { + "won't work": function(err, r) { assert.strictEqual(r.code, 400); } }, "listing emails": { topic: wsapi.get('/wsapi/list_emails'), - "works fine": function(r) { + "works fine": function(err, r) { assert.strictEqual(r.code, 200); assert.equal(Object.keys(JSON.parse(r.body)).length, 1); } diff --git a/tests/verifier-test.js b/tests/verifier-test.js index c960717b2..9ccd7066d 100755 --- a/tests/verifier-test.js +++ b/tests/verifier-test.js @@ -74,7 +74,7 @@ suite.addBatch({ email: TEST_EMAIL, site: TEST_DOMAIN }), - "works": function(r, err) { + "works": function(err, r) { assert.equal(r.code, 200); } } @@ -100,7 +100,7 @@ suite.addBatch({ pass: TEST_PASSWORD }).call(this); }, - "works just fine": function(r, err) { + "works just fine": function(err, r) { assert.equal(r.code, 200); } } @@ -114,7 +114,7 @@ suite.addBatch({ topic: function() { return jwk.KeyPair.generate("DS", 256) }, - "succeeds": function(r, err) { + "succeeds": function(r) { assert.isObject(r); assert.isObject(r.publicKey); assert.isObject(r.secretKey); @@ -131,7 +131,7 @@ suite.addBatch({ pubkey: g_keypair.publicKey.serialize() }).call(this); }, - "works swimmingly": function(r, err) { + "works swimmingly": function(err, r) { assert.isString(r.body); g_cert = r.body; assert.lengthOf(g_cert.split('.'), 3); @@ -151,7 +151,7 @@ function make_basic_tests(new_style) { tok.sign(g_keypair.secretKey), new_style); }, - "succeeds": function(r, err) { + "succeeds": function(r) { assert.isString(r); }, "and verifying that assertion by specifying domain as audience": { @@ -161,7 +161,7 @@ function make_basic_tests(new_style) { assertion: assertion }).call(this); }, - "works": function(r, err) { + "works": function(err, r) { var resp = JSON.parse(r.body); assert.isObject(resp); assert.strictEqual(resp.status, 'okay'); @@ -180,7 +180,7 @@ function make_basic_tests(new_style) { assertion: assertion }).call(this); }, - "works": function(r, err) { + "works": function(err, r) { var resp = JSON.parse(r.body); assert.isObject(resp); assert.strictEqual(resp.status, 'okay'); @@ -199,7 +199,7 @@ function make_basic_tests(new_style) { assertion: assertion }).call(this); }, - "fails with a nice error": function(r, err) { + "fails with a nice error": function(err, r) { var resp = JSON.parse(r.body); assert.strictEqual(resp.status, 'failure'); assert.strictEqual(resp.reason, 'audience mismatch: domain mismatch'); @@ -212,7 +212,7 @@ function make_basic_tests(new_style) { assertion: assertion }).call(this); }, - "fails with a nice error": function(r, err) { + "fails with a nice error": function(err, r) { var resp = JSON.parse(r.body); assert.strictEqual(resp.status, 'failure'); assert.strictEqual(resp.reason, 'audience mismatch: port mismatch'); @@ -225,7 +225,7 @@ function make_basic_tests(new_style) { assertion: assertion }).call(this); }, - "fails with a nice error": function(r, err) { + "fails with a nice error": function(err, r) { var resp = JSON.parse(r.body); assert.strictEqual(resp.status, 'failure'); assert.strictEqual(resp.reason, 'audience mismatch: scheme mismatch'); @@ -238,7 +238,7 @@ function make_basic_tests(new_style) { assertion: assertion }).call(this); }, - "is cool": function(r, err) { + "is cool": function(err, r) { var resp = JSON.parse(r.body); assert.isObject(resp); assert.strictEqual(resp.status, 'okay'); @@ -257,7 +257,7 @@ function make_basic_tests(new_style) { assertion: assertion }).call(this); }, - "fails as you would expect": function(r, err) { + "fails as you would expect": function(err, r) { var resp = JSON.parse(r.body); assert.strictEqual(resp.status, 'failure'); assert.strictEqual(resp.reason, 'audience mismatch: port mismatch'); @@ -269,7 +269,7 @@ function make_basic_tests(new_style) { assertion: assertion }).call(this); }, - "fails as you would expect": function(r, err) { + "fails as you would expect": function(err, r) { var resp = JSON.parse(r.body); assert.strictEqual(resp.status, 'failure'); assert.strictEqual(resp.reason, 'need assertion and audience'); @@ -281,7 +281,7 @@ function make_basic_tests(new_style) { audience: TEST_ORIGIN }).call(this); }, - "fails as you would expect": function(r, err) { + "fails as you would expect": function(err, r) { var resp = JSON.parse(r.body); assert.strictEqual(resp.status, 'failure'); assert.strictEqual(resp.reason, 'need assertion and audience'); @@ -310,7 +310,7 @@ function make_post_format_tests(new_style) { tok.sign(g_keypair.secretKey), new_style); }, - "succeeds": function(r, err) { + "succeeds": function(r) { assert.isString(r); }, "posting assertion and audience as get parameters in a post request": { @@ -335,7 +335,7 @@ function make_post_format_tests(new_style) { cb("error: ", e); }).end(); }, - "works, oddly enough": function (r, err) { + "works, oddly enough": function (r) { var resp = JSON.parse(r); assert.isObject(resp); assert.strictEqual(resp.status, 'okay'); @@ -372,7 +372,7 @@ function make_post_format_tests(new_style) { req.write(postArgs); req.end(); }, - "works, oddly enough": function (r, err) { + "works, oddly enough": function (r) { var resp = JSON.parse(r); assert.isObject(resp); assert.strictEqual(resp.status, 'okay'); @@ -409,7 +409,7 @@ function make_post_format_tests(new_style) { req.write(postArgs); req.end(); }, - "works, oddly enough": function (r, err) { + "works, oddly enough": function (r) { var resp = JSON.parse(r); assert.isObject(resp); assert.strictEqual(resp.status, 'okay'); @@ -546,7 +546,7 @@ function make_incorrect_assertion_tests(new_style) { assertion: assertion }).call(this); }, - "to return a clear error message": function (r, err) { + "to return a clear error message": function (err, r) { var resp = JSON.parse(r.body); assert.strictEqual(resp.status, 'failure'); // XXX: the verifier response should simply be "invalid signature" @@ -572,7 +572,7 @@ suite.addBatch({ assertion: "test@example.com" }).call(this); }, - "fails with a nice error": function(r, err) { + "fails with a nice error": function(err, r) { var resp = JSON.parse(r.body); assert.strictEqual(resp.status, 'failure'); assert.strictEqual(resp.reason, 'malformed assertion'); @@ -585,7 +585,7 @@ suite.addBatch({ assertion: 777 }).call(this); }, - "fails with a nice error": function(r, err) { + "fails with a nice error": function(err, r) { var resp = JSON.parse(r.body); assert.strictEqual(resp.status, 'failure'); assert.strictEqual(resp.reason, 'malformed assertion'); @@ -615,7 +615,7 @@ function make_crazy_assertion_tests(new_style) { assertion: assertion }).call(this); }, - "fails with a nice error": function(r, err) { + "fails with a nice error": function(err, r) { var resp = JSON.parse(r.body); assert.strictEqual(resp.status, 'failure'); // with new assertion format, the error is different @@ -634,7 +634,7 @@ function make_crazy_assertion_tests(new_style) { assertion: assertion }).call(this); }, - "fails with a nice error": function(r, err) { + "fails with a nice error": function(err, r) { // XXX this test is failing because there's an exception thrown // that's revealing too much info about the malformed assertion var resp = JSON.parse(r.body); @@ -654,7 +654,7 @@ function make_crazy_assertion_tests(new_style) { assertion: assertion }).call(this); }, - "fails with a nice error": function(r, err) { + "fails with a nice error": function(err, r) { var resp = JSON.parse(r.body); assert.strictEqual(resp.status, 'failure'); if (new_style) { @@ -691,7 +691,7 @@ suite.addBatch({ assertion: assertion }).call(this); }, - "fails with a nice error": function(r, err) { + "fails with a nice error": function(err, r) { var resp = JSON.parse(r.body); assert.strictEqual(resp.status, 'failure'); // XXX: the verifier should return a clearer error message @@ -711,7 +711,7 @@ suite.addBatch({ assertion: assertion }).call(this); }, - "fails with a nice error": function(r, err) { + "fails with a nice error": function(err, r) { var resp = JSON.parse(r.body); assert.strictEqual(resp.status, 'failure'); // XXX: this error should be clearer @@ -734,7 +734,7 @@ suite.addBatch({ assertion: assertion }).call(this); }, - "fails with a nice error": function(r, err) { + "fails with a nice error": function(err, r) { var resp = JSON.parse(r.body); assert.strictEqual(resp.status, 'failure'); // XXX: this error should be clearer @@ -761,7 +761,7 @@ function make_other_issuer_tests(new_style) { tok.sign(newClientKeypair.secretKey), new_style); }, - "yields a good looking assertion": function (r, err) { + "yields a good looking assertion": function (r) { assert.isString(r); assert.equal(r.length > 0, true); }, @@ -772,7 +772,7 @@ function make_other_issuer_tests(new_style) { assertion: assertion }).call(this); }, - "to return a clear error message": function (r, err) { + "to return a clear error message": function (err, r) { var resp = JSON.parse(r.body); assert.strictEqual(resp.status, 'failure'); assert.strictEqual(resp.reason, "can't get public key for lloyd.io"); @@ -806,7 +806,7 @@ suite.addBatch({ var tok = new jwt.JWT(null, expirationDate, TEST_ORIGIN); return vep.bundleCertsAndAssertion([cert], tok.sign(newClientKeypair.secretKey)); }, - "yields a good looking assertion": function (r, err) { + "yields a good looking assertion": function (r) { assert.isString(r); assert.equal(r.length > 0, true); }, @@ -817,7 +817,7 @@ suite.addBatch({ assertion: assertion }).call(this); }, - "to return a clear error message": function (r, err) { + "to return a clear error message": function (err, r) { var resp = JSON.parse(r.body); assert.strictEqual(resp.status, 'failure'); assert.strictEqual(resp.reason, "issuer issue 'example.domain' may not speak for emails from 'somedomain.com'"); @@ -844,7 +844,7 @@ suite.addBatch({ var tok = new jwt.JWT(null, expirationDate, TEST_ORIGIN); return vep.bundleCertsAndAssertion([cert], tok.sign(newClientKeypair.secretKey)); }, - "yields a good looking assertion": function (r, err) { + "yields a good looking assertion": function (r) { assert.isString(r); assert.equal(r.length > 0, true); }, @@ -855,7 +855,7 @@ suite.addBatch({ assertion: assertion }).call(this); }, - "to return a clear error message": function (r, err) { + "to return a clear error message": function (err, r) { var resp = JSON.parse(r.body); assert.strictEqual(resp.status, 'okay'); assert.strictEqual(resp.issuer, "example.domain"); -- GitLab