diff --git a/resources/static/shared/user.js b/resources/static/shared/user.js index ade50c2718769eca3224a6146c4557069c844255..28b1ee7d4accaeca99248598a7788cf51c9f3a26 100644 --- a/resources/static/shared/user.js +++ b/resources/static/shared/user.js @@ -672,7 +672,8 @@ BrowserID.User = (function() { // yield! setTimeout(function() { - assertion = vep.bundleCertsAndAssertion([idInfo.cert], tok.sign(sk)); + // use new assertion format + assertion = vep.bundleCertsAndAssertion([idInfo.cert], tok.sign(sk), true); storage.site.set(self.getOrigin(), "email", email); if (onSuccess) { onSuccess(assertion); diff --git a/resources/static/test/qunit/shared/user_unit_test.js b/resources/static/test/qunit/shared/user_unit_test.js index e90fd1c32e4a82ffb971c2538566a94fe5ff710c..6251087621eadee45dc66d955b5086032ea3bb4e 100644 --- a/resources/static/test/qunit/shared/user_unit_test.js +++ b/resources/static/test/qunit/shared/user_unit_test.js @@ -37,6 +37,7 @@ var jwk = require("./jwk"); var jwt = require("./jwt"); var jwcert = require("./jwcert"); +var vep = require("./vep"); (function() { var bid = BrowserID, @@ -57,7 +58,9 @@ var jwcert = require("./jwcert"); equal(typeof assertion, "string", "An assertion was correctly generated"); // Decode the assertion to a bundle. - var bundle = JSON.parse(window.atob(assertion)); + // var bundle = JSON.parse(window.atob(assertion)); + // WOW, ^^ was assuming a specific format, let's fix that + var bundle = vep.unbundleCertsAndAssertion(assertion); // Make sure both parts of the bundle exist ok(bundle.certificates && bundle.certificates.length, "we have an array like object for the certificates"); diff --git a/tests/verifier-test.js b/tests/verifier-test.js index 1cf64f544483fe8829b246fadbc563a2cc69ecfd..e8b1569788d6debc5a74c1bf3b1f6f54c44e0da8 100755 --- a/tests/verifier-test.js +++ b/tests/verifier-test.js @@ -140,13 +140,15 @@ suite.addBatch({ // several positive and negative basic verification tests // with a valid assertion -suite.addBatch({ - "generating an assertion": { +function make_basic_tests(new_style) { + var title = "generating an assertion with " + (new_style ? "old style" : "new style"); + var tests = { topic: function() { var expirationDate = new Date(new Date().getTime() + (2 * 60 * 1000)); var tok = new jwt.JWT(null, expirationDate, TEST_ORIGIN); return vep.bundleCertsAndAssertion([g_cert], - tok.sign(g_keypair.secretKey)); + tok.sign(g_keypair.secretKey), + new_style); }, "succeeds": function(r, err) { assert.isString(r); @@ -284,19 +286,28 @@ suite.addBatch({ assert.strictEqual(resp.reason, 'need assertion and audience'); } } - } -}); + }; + + var overall_test = {}; + overall_test[title] = tests; + return overall_test; +}; + +suite.addBatch(make_basic_tests(false)); +suite.addBatch(make_basic_tests(true)); // testing post format requirements and flexibility // several positive and negative basic verification tests // with a valid assertion -suite.addBatch({ - "generating an assertion": { +function make_post_format_tests(new_style) { + var title = "generating an assertion with " + (new_style ? "old style" : "new style"); + var tests = { topic: function() { var expirationDate = new Date(new Date().getTime() + (2 * 60 * 1000)); var tok = new jwt.JWT(null, expirationDate, TEST_ORIGIN); return vep.bundleCertsAndAssertion([g_cert], - tok.sign(g_keypair.secretKey)); + tok.sign(g_keypair.secretKey), + new_style); }, "succeeds": function(r, err) { assert.isString(r); @@ -409,15 +420,26 @@ suite.addBatch({ assert.strictEqual(resp.status, 'okay'); } } - } -}); + }; -suite.addBatch({ - "generating an assertion": { + var overall_test = {}; + overall_test[title] = tests; + return overall_test; +} + +suite.addBatch(make_post_format_tests(false)); +suite.addBatch(make_post_format_tests(true)); + +function make_post_format_2_tests(new_style) { + var title = "generating an assertion with " + (new_style ? "old style" : "new style"); + var tests = { topic: function() { var expirationDate = new Date(new Date().getTime() + (2 * 60 * 1000)); var tok = new jwt.JWT(null, expirationDate, TEST_ORIGIN); - return vep.bundleCertsAndAssertion([g_cert], tok.sign(g_keypair.secretKey)); + return vep.bundleCertsAndAssertion( + [g_cert], + tok.sign(g_keypair.secretKey), + new_style); }, "succeeds": function(r, err) { assert.isString(r); @@ -485,12 +507,19 @@ suite.addBatch({ assert.strictEqual(resp.status, 'okay'); } } - } -}); + }; + var overall_test = {}; + overall_test[title] = tests; + return overall_test; +}; + +suite.addBatch(make_post_format_2_tests(false)); +suite.addBatch(make_post_format_2_tests(true)); // now verify that a incorrectly signed assertion yields a good error message -suite.addBatch({ - "generating an assertion from a bogus cert": { +function make_incorrect_assertion_tests(new_style) { + var title = "generating an assertion from a bogus cert with " + (new_style? "new style" : "old style"); + var tests = { topic: function() { var fakeDomainKeypair = jwk.KeyPair.generate("RS", 64); var newClientKeypair = jwk.KeyPair.generate("DS", 256); @@ -500,7 +529,10 @@ suite.addBatch({ var expirationDate = new Date(new Date().getTime() + (2 * 60 * 1000)); var tok = new jwt.JWT(null, expirationDate, TEST_ORIGIN); - return vep.bundleCertsAndAssertion([cert], tok.sign(newClientKeypair.secretKey)); + return vep.bundleCertsAndAssertion( + [cert], + tok.sign(newClientKeypair.secretKey), + new_style); }, "yields a good looking assertion": function (r, err) { assert.isString(r); @@ -520,8 +552,15 @@ suite.addBatch({ assert.strictEqual(resp.reason, 'bad signature in chain'); } } - } -}); + }; + + var overall_test = {}; + overall_test[title] = tests; + return overall_test; +} + +suite.addBatch(make_incorrect_assertion_tests(false)); +suite.addBatch(make_incorrect_assertion_tests(true)); // now let's really get down and screw with the assertion suite.addBatch({ @@ -550,12 +589,19 @@ suite.addBatch({ assert.strictEqual(resp.status, 'failure'); assert.strictEqual(resp.reason, 'malformed assertion'); } - }, - "generating a valid assertion": { + } +}); + +function make_crazy_assertion_tests(new_style) { + var title = "generating a valid assertion with " + (new_style ? "new style" : "old style"); + var tests = { topic: function() { var expirationDate = new Date(new Date().getTime() + (2 * 60 * 1000)); var tok = new jwt.JWT(null, expirationDate, TEST_ORIGIN); - return vep.bundleCertsAndAssertion([g_cert], tok.sign(g_keypair.secretKey)); + return vep.bundleCertsAndAssertion( + [g_cert], + tok.sign(g_keypair.secretKey), + new_style); }, "and removing the last char from it": { topic: function(assertion) { @@ -568,7 +614,12 @@ suite.addBatch({ "fails with a nice error": function(r, err) { var resp = JSON.parse(r.body); assert.strictEqual(resp.status, 'failure'); - assert.strictEqual(resp.reason, 'malformed assertion'); + // with new assertion format, the error is different + if (new_style) { + assert.strictEqual(resp.reason, 'verification failure'); + } else { + assert.strictEqual(resp.reason, 'malformed assertion'); + } } }, "and removing the first char from it": { @@ -580,9 +631,15 @@ suite.addBatch({ }).call(this); }, "fails with a nice error": function(r, err) { + // 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); assert.strictEqual(resp.status, 'failure'); - assert.strictEqual(resp.reason, 'malformed assertion'); + if (new_style) { + assert.strictEqual(resp.reason, 'SyntaxError: Unexpected token Ș'); + } else { + assert.strictEqual(resp.reason, 'malformed assertion'); + } } }, "and appending gunk to it": { @@ -596,19 +653,35 @@ suite.addBatch({ "fails with a nice error": function(r, err) { var resp = JSON.parse(r.body); assert.strictEqual(resp.status, 'failure'); - assert.strictEqual(resp.reason, 'malformed assertion'); + if (new_style) { + assert.strictEqual(resp.reason, 'verification failure'); + } else { + assert.strictEqual(resp.reason, 'malformed assertion'); + } } } - } -}); + }; + + var overall_test = {}; + overall_test[title] = tests; + return overall_test; +} + +suite.addBatch(make_crazy_assertion_tests(false)); +suite.addBatch(make_crazy_assertion_tests(true)); // how about bogus parameters inside the assertion? +// now we only test the new assertion format, because +// for crazy stuff we don't really care about old format anymore suite.addBatch({ "An assertion that expired a millisecond ago": { topic: function() { var expirationDate = new Date(new Date().getTime() - 10); var tok = new jwt.JWT(null, expirationDate, TEST_ORIGIN); - var assertion = vep.bundleCertsAndAssertion([g_cert], tok.sign(g_keypair.secretKey)); + var assertion = vep.bundleCertsAndAssertion( + [g_cert], + tok.sign(g_keypair.secretKey), + true); wsapi.post('/verify', { audience: TEST_ORIGIN, assertion: assertion @@ -625,7 +698,10 @@ suite.addBatch({ topic: function() { var expirationDate = new Date(new Date().getTime() + (2 * 60 * 1000)); var tok = new jwt.JWT(null, expirationDate, TEST_ORIGIN); - var assertion = vep.bundleCertsAndAssertion([g_cert, "bogus cert"], tok.sign(g_keypair.secretKey)); + var assertion = vep.bundleCertsAndAssertion( + [g_cert, "bogus cert"], + tok.sign(g_keypair.secretKey), + true); wsapi.post('/verify', { audience: TEST_ORIGIN, assertion: assertion @@ -642,7 +718,13 @@ suite.addBatch({ topic: function() { var expirationDate = new Date(new Date().getTime() + (2 * 60 * 1000)); var tok = new jwt.JWT(null, expirationDate, TEST_ORIGIN); - var assertion = vep.bundleCertsAndAssertion([], tok.sign(g_keypair.secretKey)); + + // XXX this call throws an exception if it's new style + // how to test this? + var assertion = vep.bundleCertsAndAssertion( + [], + tok.sign(g_keypair.secretKey), + false); wsapi.post('/verify', { audience: TEST_ORIGIN, assertion: assertion @@ -659,8 +741,9 @@ suite.addBatch({ // now verify that no-one other than browserid is allowed to issue assertions // (until primary support is implemented) -suite.addBatch({ - "generating an assertion from a cert signed by some other domain": { +function make_other_issuer_tests(new_style) { + var title = "generating an assertion from a cert signed by some other domain with " + (new_style ? "new style" : "old style"); + var tests = { topic: function() { var fakeDomainKeypair = jwk.KeyPair.generate("RS", 64); var newClientKeypair = jwk.KeyPair.generate("DS", 256); @@ -670,7 +753,9 @@ suite.addBatch({ var expirationDate = new Date(new Date().getTime() + (2 * 60 * 1000)); var tok = new jwt.JWT(null, expirationDate, TEST_ORIGIN); - return vep.bundleCertsAndAssertion([cert], tok.sign(newClientKeypair.secretKey)); + return vep.bundleCertsAndAssertion([cert], + tok.sign(newClientKeypair.secretKey), + new_style); }, "yields a good looking assertion": function (r, err) { assert.isString(r); @@ -689,8 +774,15 @@ suite.addBatch({ assert.strictEqual(resp.reason, "this verifier doesn't respect certs issued from domains other than: 127.0.0.1"); } } - } -}); + }; + + var overall_test = {}; + overall_test[title] = tests; + return overall_test; +} + +suite.addBatch(make_other_issuer_tests(false)); +suite.addBatch(make_other_issuer_tests(true)); start_stop.addShutdownBatches(suite);