Skip to content
This repository has been archived by the owner on May 10, 2019. It is now read-only.

Commit

Permalink
Merge pull request #3168 from mozilla/issue_3153_invalid_certs
Browse files Browse the repository at this point in the history
Issue 3153 invalid certs
  • Loading branch information
jaredhirsch committed Apr 3, 2013
2 parents 37fa473 + 60d1752 commit 5402de1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
15 changes: 6 additions & 9 deletions resources/static/common/js/user.js
Expand Up @@ -33,7 +33,7 @@ BrowserID.User = (function() {
}

// remove identities that are no longer valid
function cleanupIdentities(cb) {
function cleanupIdentities(onSuccess, onFailure) {
network.serverTime(function(serverTime) {
network.domainKeyCreationTime(function(creationTime) {
// Determine if a certificate is expired. That will be
Expand Down Expand Up @@ -64,7 +64,7 @@ BrowserID.User = (function() {
var emails = storage.getEmails();
var issued_identities = {};
prepareDeps();
_(emails).each(function(email_obj, email_address) {
_.each(emails, function(email_obj, email_address) {
try {
email_obj.pub = jwcrypto.loadPublicKeyFromObject(email_obj.pub);
} catch (x) {
Expand Down Expand Up @@ -93,12 +93,9 @@ BrowserID.User = (function() {
}
}
});
cb();
}, function(e) {
// we couldn't get domain key creation time! uh oh.
cb();
});
});
onSuccess();
}, onFailure);
}, onFailure);
}

function stageAddressVerification(email, password, stagingStrategy, onComplete, onFailure) {
Expand Down Expand Up @@ -941,7 +938,7 @@ BrowserID.User = (function() {

complete(onComplete);
}, onFailure);
});
}, onFailure);
},

/**
Expand Down
25 changes: 25 additions & 0 deletions resources/static/test/cases/common/js/user.js
Expand Up @@ -954,6 +954,25 @@
}, testHelpers.unexpectedXHRFailure);
});

asyncTest("syncEmails with one invalid cert preloaded and none to add - remove expired cert but not identity", function() {
storage.addEmail(TEST_EMAIL, {
cert: "bad cert that should be removed when certs are checked"
});

lib.syncEmails(function onSuccess() {
var records = lib.getStoredEmailKeypairs();

ok(TEST_EMAIL in records, "Our new email is added");
equal(_.size(records), 1, "there is one identity");

// cert was invalid and should be wiped.
var identity = records[TEST_EMAIL];
equal("cert" in identity, false);

start();
}, testHelpers.unexpectedXHRFailure);
});


asyncTest("syncEmails with identities preloaded and one to add", function() {
storage.addEmail(TEST_EMAIL, {pubkey: pubkey, cert: random_cert});
Expand Down Expand Up @@ -988,6 +1007,12 @@
failureCheck(lib.syncEmails);
});

asyncTest("syncEmails, could not get context - call error", function() {
xhr.useResult("contextAjaxError");
failureCheck(lib.syncEmails);
});


asyncTest("getAssertion with known email that has key", function() {
lib.syncEmailKeypair(TEST_EMAIL, function() {
lib.getAssertion(TEST_EMAIL, lib.getOrigin(), function onSuccess(assertion) {
Expand Down

0 comments on commit 5402de1

Please sign in to comment.