diff --git a/plugins/emailstore.js b/plugins/emailstore.js index bf81ab7..0973081 100644 --- a/plugins/emailstore.js +++ b/plugins/emailstore.js @@ -52,10 +52,6 @@ code: 406, message: 'User quota exceeded', }, - REGISTRATION_EXPIRED: { - code: 400, - message: 'Registration expired', - }, }; var EMAIL_TO_PASSPHRASE = 'email-to-passphrase-'; @@ -74,8 +70,6 @@ var POST_LIMIT = 1024 * 300 /* Max POST 300 kb */ ; - var DAYS_TO_EXPIRATION = 7; // An email can be awaiting validation for this long before expiring - var valueKey = function(email, key) { return STORED_VALUE + bitcore.util.twoSha256(email + SEPARATOR + key).toString('hex'); }; @@ -371,18 +365,11 @@ */ emailPlugin.createVerificationSecret = function(email, callback) { emailPlugin.db.get(pendingKey(email), function(err, value) { - var available = false; - - var notFound = err && err.notFound; - var expired = !err && _.isObject(value) && moment().unix() > value.expires; - - var available = notFound || expired; - - if (available) { + if (err && err.notFound) { var secret = emailPlugin.crypto.randomBytes(16).toString('hex'); var value = { secret: secret, - expires: moment().add(DAYS_TO_EXPIRATION, 'days').unix(), + created: moment().unix(), }; emailPlugin.db.put(pendingKey(email), JSON.stringify(value), function(err) { if (err) { @@ -770,11 +757,7 @@ } catch (e) {} if (parsed && _.isObject(parsed)) { - if (moment().unix() > parsed.expires) { - return emailPlugin.returnError(emailPlugin.errors.REGISTRATION_EXPIRED, response); - } else { - value = parsed.secret; - } + value = parsed.secret; } if (value !== secret) { diff --git a/test/test.EmailStore.js b/test/test.EmailStore.js index 13da8c6..759b9f7 100644 --- a/test/test.EmailStore.js +++ b/test/test.EmailStore.js @@ -230,7 +230,7 @@ describe('emailstore test', function() { plugin.createVerificationSecretAndSendEmail(fakeEmail, function(err) { var arg = JSON.parse(leveldb_stub.put.firstCall.args[1]); arg.secret.should.equal(fakeRandom); - arg.expires.should.equal(moment().add(7, 'days').unix()); + arg.created.should.equal(moment().unix()); clock.restore(); done(); }); @@ -367,7 +367,7 @@ describe('emailstore test', function() { response.json.returnsThis(); }); - it('should validate correctly an email if the secret matches (without expiration date)', function() { + it('should validate correctly an email if the secret matches (secret only)', function() { leveldb_stub.get.onFirstCall().callsArgWith(1, null, secret); leveldb_stub.del = sinon.stub().yields(null); response.redirect = sinon.stub(); @@ -377,10 +377,10 @@ describe('emailstore test', function() { assert(response.redirect.firstCall.calledWith(plugin.redirectUrl)); }); - it('should validate correctly an email if the secret matches (using expiration date)', function() { + it('should validate correctly an email if the secret matches (secret + creation date)', function() { leveldb_stub.get.onFirstCall().callsArgWith(1, null, JSON.stringify({ secret: secret, - expires: moment().add(7, 'days').unix(), + created: moment().unix(), })); leveldb_stub.del = sinon.stub().yields(null); response.redirect = sinon.stub(); @@ -404,23 +404,6 @@ describe('emailstore test', function() { })); assert(response.end.calledOnce); }); - - it('should fail to validate an email if the secret has expired', function() { - leveldb_stub.get.onFirstCall().callsArgWith(1, null, JSON.stringify({ - secret: secret, - expires: moment().subtract(2, 'days').unix(), - })); - response.status.returnsThis(); - response.json.returnsThis(); - - plugin.validate(request, response); - - assert(response.status.firstCall.calledWith(plugin.errors.REGISTRATION_EXPIRED.code)); - assert(response.json.firstCall.calledWith({ - error: 'Registration expired' - })); - assert(response.end.calledOnce); - }); }); describe('removing items', function() {