Example #1
0
    describe('saving encrypted data', function() {
      var fakeEmail = '*****@*****.**';
      var fakeKey = 'nameForData';
      var fakeRecord = 'fakeRecord';
      var expectedKey = 'emailstore-' + bitcore.util.twoSha256(fakeEmail + '#' + fakeKey).toString('hex');

      beforeEach(function() {
        leveldb_stub.get.reset();
        leveldb_stub.put.reset();
      });

      it('saves data under the expected key', function(done) {
        leveldb_stub.put.onFirstCall().callsArgWith(2);

        plugin.saveEncryptedData(fakeEmail, fakeKey, fakeRecord, function(err) {
          leveldb_stub.put.firstCall.args[0].should.equal(expectedKey);
          done();
        });
      });

      it('fails with INTERNAL_ERROR on database error', function(done) {
        leveldb_stub.put.onFirstCall().callsArgWith(2, 'error');

        plugin.saveEncryptedData(fakeEmail, fakeKey, fakeRecord, function(err) {
          err.should.equal(plugin.errors.INTERNAL_ERROR);
          done();
        });
      });
    });
Example #2
0
    describe('exists', function() {
      var fakeEmail = '*****@*****.**';
      var fakeEmailKey = 'email-to-passphrase-' + bitcore.util.twoSha256(fakeEmail).toString('hex');

      beforeEach(function() {
        leveldb_stub.get.reset();
      });

      it('validates that an email is already registered', function(done) {
        leveldb_stub.get.onFirstCall().callsArg(1);

        plugin.exists(fakeEmail, function(err, exists) {
          leveldb_stub.get.firstCall.args[0].should.equal(fakeEmailKey);
          exists.should.equal(true);
          done();
        });
      });

      it('returns false when an email doesn\'t exist', function(done) {
        leveldb_stub.get.onFirstCall().callsArgWith(1, {
          notFound: true
        });

        plugin.exists(fakeEmail, function(err, exists) {
          leveldb_stub.get.firstCall.args[0].should.equal(fakeEmailKey);
          exists.should.equal(false);
          done();
        });
      });

      it('returns an internal error if database query couldn\'t be made', function(done) {
        leveldb_stub.get.onFirstCall().callsArgWith(1, 'error');
        plugin.exists(fakeEmail, function(err, exists) {
          err.should.equal(plugin.errors.INTERNAL_ERROR);
          done();
        });
      });
    });
Example #3
0
 var emailToPassphrase = function(email) {
   return EMAIL_TO_PASSPHRASE + bitcore.util.twoSha256(email).toString('hex');
 };
Example #4
0
 var validatedKey = function(email) {
   return VALIDATED + bitcore.util.twoSha256(email).toString('hex');
 };
Example #5
0
 var countKey = function(email) {
   return ITEMS_COUNT + bitcore.util.twoSha256(email).toString('hex');
 };
Example #6
0
 var valueKey = function(email, key) {
   return STORED_VALUE + bitcore.util.twoSha256(email + SEPARATOR + key).toString('hex');
 };