aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/scripts/keyring-controller.js9
-rw-r--r--app/scripts/lib/encryptor.js3
-rw-r--r--test/integration/lib/encryptor-test.js22
3 files changed, 30 insertions, 4 deletions
diff --git a/app/scripts/keyring-controller.js b/app/scripts/keyring-controller.js
index aa303c43c..81a05e133 100644
--- a/app/scripts/keyring-controller.js
+++ b/app/scripts/keyring-controller.js
@@ -131,9 +131,7 @@ module.exports = class KeyringController extends EventEmitter {
this.keyrings.push(keyring)
this.configManager.setSelectedAccount(keyring.getAccounts()[0])
}
- return this.persistAllKeyrings().then(() => {
- return key
- })
+ return key
})
}
@@ -144,6 +142,9 @@ module.exports = class KeyringController extends EventEmitter {
return this.migrateAndGetKey(password)
.then(() => {
+ return this.persistAllKeyrings()
+ })
+ .then(() => {
cb(null)
})
.catch((err) => {
@@ -173,7 +174,7 @@ module.exports = class KeyringController extends EventEmitter {
})
}
- placeSeedWords () {
+ placeSeedWords (cb) {
const firstKeyring = this.keyrings[0]
const seedWords = firstKeyring.serialize().mnemonic
this.configManager.setSeedWords(seedWords)
diff --git a/app/scripts/lib/encryptor.js b/app/scripts/lib/encryptor.js
index 832e6d528..fe83b86dd 100644
--- a/app/scripts/lib/encryptor.js
+++ b/app/scripts/lib/encryptor.js
@@ -69,6 +69,9 @@ function decryptWithKey (key, text) {
const decryptedObj = JSON.parse(decryptedStr)
return decryptedObj
})
+ .catch(function(reason) {
+ throw new Error('Incorrect password')
+ })
}
function convertStringToArrayBufferView (str) {
diff --git a/test/integration/lib/encryptor-test.js b/test/integration/lib/encryptor-test.js
index 1c8a7605a..d42608152 100644
--- a/test/integration/lib/encryptor-test.js
+++ b/test/integration/lib/encryptor-test.js
@@ -43,3 +43,25 @@ QUnit.test('encryptor:encrypt & decrypt', function(assert) {
})
})
+
+QUnit.test('encryptor:encrypt & decrypt with wrong password', function(assert) {
+ var done = assert.async();
+ var password, data, encrypted, wrongPassword
+
+ password = 'a sample passw0rd'
+ wrongPassword = 'a wrong password'
+ data = { foo: 'data to encrypt' }
+
+ encryptor.encrypt(password, data)
+ .then(function(encryptedStr) {
+ assert.equal(typeof encryptedStr, 'string', 'returns a string')
+ return encryptor.decrypt(wrongPassword, encryptedStr)
+ })
+ .then(function (decryptedObj) {
+ assert.equal(!decryptedObj, true, 'Wrong password should not decrypt')
+ done()
+ })
+ .catch(function(reason) {
+ done()
+ })
+})