diff --git a/browserid/lib/db.js b/browserid/lib/db.js index 66eb41ebfa402db6affad75e5c0958a3df92a10d..4dfef67b704f99e6e94269ecb9dd3a74a47d3e58 100644 --- a/browserid/lib/db.js +++ b/browserid/lib/db.js @@ -101,7 +101,6 @@ exports.onReady = function(f) { 'gotVerificationSecret', 'checkAuth', 'listEmails', - 'getSyncResponse', 'removeEmail', 'cancelAccount' ].forEach(function(fn) { diff --git a/browserid/lib/db_mysql.js b/browserid/lib/db_mysql.js index eb590526c864f49f7a1901477b1410cc41a65c4d..8ca817a5c3bb08e0f499e752836fe8448ef454be 100644 --- a/browserid/lib/db_mysql.js +++ b/browserid/lib/db_mysql.js @@ -312,10 +312,9 @@ function emailHasPubkey(email, pubkey, cb) { } /* - * a simpler action than syncResponse, just list the user's emails. - * this is more appropriate for the certs approach. + * list the user's emails. * - * returns an object keyed by email address with properties for each email + * returns an object keyed by email address with properties for each email. */ exports.listEmails = function(email, cb) { client.query( @@ -335,66 +334,6 @@ exports.listEmails = function(email, cb) { }); }; -/* a high level operation that attempts to sync a client's view with that of the - * server. email is the identity of the authenticated channel with the user, - * identities is a map of email -> pubkey. - * We'll return an object that expresses three different types of information: - * there are several things we need to express: - * 1. emails that the client knows about but we do not - * 2. emails that we know about and the client does not - * 3. emails that we both know about but who need to be re-keyed - * NOTE: it's not neccesary to differentiate between #2 and #3, as the client action - * is the same (regen keypair and tell us about it). - */ -exports.getSyncResponse = function(email, identities, cb) { - var respBody = { - unknown_emails: [ ], - key_refresh: [ ] - }; - - client.query( - 'SELECT address FROM email WHERE user = ( SELECT user FROM email WHERE address = ? ) ', - [ email ], - function (err, rows) { - if (err) cb(err); - else { - var emails = [ ]; - var keysToCheck = [ ]; - for (var i = 0; i < rows.length; i++) emails.push(rows[i].address); - - // #1 - for (var e in identities) { - if (emails.indexOf(e) == -1) respBody.unknown_emails.push(e); - else keysToCheck.push(e); - } - - // #2 - for (var e in emails) { - e = emails[e]; - if (!identities.hasOwnProperty(e)) respBody.key_refresh.push(e); - } - - // #3 -- yes, this is sub-optimal in terms of performance. when we - // move away from public keys this will be unnec. - if (keysToCheck.length) { - var checked = 0; - keysToCheck.forEach(function(e) { - emailHasPubkey(e, identities[e], function(v) { - checked++; - if (!v) respBody.key_refresh.push(e); - if (checked === keysToCheck.length) { - cb(undefined, respBody); - } - }); - }); - } else { - cb(undefined, respBody); - } - } - }); -}; - - exports.removeEmail = function(authenticated_email, email, cb) { exports.emailsBelongToSameAccount(authenticated_email, email, function(ok) { if (!ok) { diff --git a/browserid/lib/wsapi.js b/browserid/lib/wsapi.js index eefbed81d61abfdb7695d4ef9d118c30309acda0..c52ca320957397e05d0e2a4c6ac2c20a2afe1c3e 100644 --- a/browserid/lib/wsapi.js +++ b/browserid/lib/wsapi.js @@ -349,31 +349,6 @@ function setup(app) { }); }); - app.post('/wsapi/sync_emails', checkAuthed, function(req,resp) { - // validate that the post body contains an object with an .emails - // property that is an array of strings. - var valid = true; - try { - req.body.emails = JSON.parse(req.body.emails); - Object.keys(req.body.emails).forEach(function(k) { - if (typeof req.body.emails[k] !== 'string') { - // for certs, this is changing - // throw "bogus value for key " + k; - } - }); - } catch (e) { - logger.warn("invalid request to sync_emails: " + e); - return httputils.badRequest(resp, "sync_emails requires a JSON formatted 'emails' " + - "post argument"); - } - - logger.debug('sync emails called. client provides: ' + JSON.stringify(req.body.emails)); - db.getSyncResponse(req.session.authenticatedUser, req.body.emails, function(err, syncResponse) { - if (err) httputils.serverError(resp, err); - else resp.json(syncResponse); - }); - }); - app.get('/wsapi/prove_email_ownership', checkParams(["token"]), function(req, resp) { db.gotVerificationSecret(req.query.token, function(e) { if (e) { diff --git a/browserid/static/dialog/resources/browserid-identities.js b/browserid/static/dialog/resources/browserid-identities.js index 50dc0b96ddceb53c37a2ccc027f5a48628096b7a..75ea84e5b70e780b3abeb6121954410722ccc471 100644 --- a/browserid/static/dialog/resources/browserid-identities.js +++ b/browserid/static/dialog/resources/browserid-identities.js @@ -132,28 +132,6 @@ var BrowserIDIdentities = (function() { addNextEmail(); }); - - /* - network.syncEmails(issued_identities, function(resp) { - removeUnknownIdentities(resp.unknown_emails); - - // now let's begin iteratively re-keying the emails mentioned in the server provided list - var emailsToAdd = resp.key_refresh; - - function addNextEmail() { - if (!emailsToAdd || !emailsToAdd.length) { - onSuccess(); - return; - } - - var email = emailsToAdd.shift(); - - self.syncIdentity(email, "browserid.org:443", addNextEmail, onFailure); - } - - addNextEmail(); - }, onFailure); - */ }, /** diff --git a/browserid/static/dialog/resources/browserid-network.js b/browserid/static/dialog/resources/browserid-network.js index d8dfbe1a29253ae92e535455ed1fa1eb99a9f6c6..f363220e1e2d33d03898f5a90d118bfed6b2910e 100644 --- a/browserid/static/dialog/resources/browserid-network.js +++ b/browserid/static/dialog/resources/browserid-network.js @@ -317,30 +317,8 @@ var BrowserIDNetwork = (function() { success: onSuccess, error: onFailure }); - }, - - /** - * Sync emails - * @method syncEmails - * @param {object} issued_identities - Identities to check against. - * @param {function} [onSuccess] - Called with response when complete. - * @param {function} [onFailure] - Called on XHR failure. - */ - syncEmails: function(issued_identities, onSuccess, onFailure) { - withCSRF(function() { - $.ajax({ - type: "POST", - url: '/wsapi/sync_emails', - data: { - emails: JSON.stringify(issued_identities), - csrf: csrf_token - }, - success: onSuccess, - error: onFailure - }); - }); } - + }; return Network; diff --git a/browserid/tests/cert-emails-test.js b/browserid/tests/cert-emails-test.js index 7f0d0582f3d11675e4ddee4e149c2fe84261aeb6..ad6feeef65d7caae5f786af39501fdf4ea25aca9 100755 --- a/browserid/tests/cert-emails-test.js +++ b/browserid/tests/cert-emails-test.js @@ -181,9 +181,6 @@ suite.addBatch({ assert.strictEqual(r.code, 400); } } - - - // NOTE: db-test has more thorough tests of the algorithm behind the sync_emails API }); start_stop.addShutdownBatches(suite); diff --git a/browserid/tests/sync-emails-wsapi-test.js b/browserid/tests/list-emails-wsapi-test.js similarity index 61% rename from browserid/tests/sync-emails-wsapi-test.js rename to browserid/tests/list-emails-wsapi-test.js index 1375a5cb990604d5ae335a11099ec10e96122109..e243445b070d6a0cfcb7106c58f0154362c3e564 100755 --- a/browserid/tests/sync-emails-wsapi-test.js +++ b/browserid/tests/list-emails-wsapi-test.js @@ -107,62 +107,6 @@ suite.addBatch({ } }); -/* -suite.addBatch({ - "the sync emails API invoked without a proper argument": { - topic: wsapi.post('/wsapi/sync_emails', {}), - "fails with HTTP 400" : function(r, err) { - assert.strictEqual(r.code, 400); - } - }, - "the sync emails API invoked with a proper argument": { - topic: wsapi.post('/wsapi/sync_emails', { emails: '{}' }), - "returns a response with a proper content-type" : function(r, err) { - assert.strictEqual(r.code, 200); - //assert.strictEqual(r.headers['content-type'], 'application/json; charset=utf-8'); - } - }, - "the sync emails API invoked without a empty emails argument": { - topic: wsapi.post('/wsapi/sync_emails', { emails: undefined }), - "returns a 400" : function(r, err) { - assert.strictEqual(r.code, 400); - } - }, - "the sync emails API invoked without malformed JSON in emails argument": { - topic: wsapi.post('/wsapi/sync_emails', { emails: '{ "foo@bar.com": "fakekey" '}), - "returns a 400" : function(r, err) { - assert.strictEqual(r.code, 400); - } - }, - "syncing emails without providing anything": { - topic: wsapi.post('/wsapi/sync_emails', {emails: '{}'}), - "should tell us to refresh keys for exisitng accounts" : function(r, err) { - assert.strictEqual(r.code, 200); - r = JSON.parse(r.body); - assert.strictEqual(typeof r, 'object'); - assert.isTrue(Array.isArray(r.unknown_emails)); - assert.isTrue(Array.isArray(r.key_refresh)); - assert.strictEqual(r.unknown_emails.length, 0); - assert.strictEqual(r.key_refresh.length, 1); - } - }, - "syncing emails with an unknown email address": { - topic: wsapi.post('/wsapi/sync_emails', {emails: '{ "foo@bar.com": "fake" }'}), - "should tell us to refresh keys for exisitng accounts" : function(r, err) { - assert.strictEqual(r.code, 200); - r = JSON.parse(r.body); - assert.strictEqual(typeof r, 'object'); - assert.isTrue(Array.isArray(r.unknown_emails)); - assert.isTrue(Array.isArray(r.key_refresh)); - assert.strictEqual(r.unknown_emails.length, 1); - assert.strictEqual(r.unknown_emails[0], 'foo@bar.com'); - assert.strictEqual(r.key_refresh.length, 1); - assert.strictEqual(r.key_refresh[0], 'syncer@somehost.com'); - } - } - // NOTE: db-test has more thorough tests of the algorithm behind the sync_emails API -}); -*/ start_stop.addShutdownBatches(suite);