mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Fix password validation and persistence issue
Was wiping the vault on each successful password attempt... :P
This commit is contained in:
parent
2afc06287d
commit
ba7d6b437f
@ -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
|
||||
})
|
||||
}
|
||||
|
||||
@ -143,6 +141,9 @@ module.exports = class KeyringController extends EventEmitter {
|
||||
configManager.setSalt(salt)
|
||||
|
||||
return this.migrateAndGetKey(password)
|
||||
.then(() => {
|
||||
return this.persistAllKeyrings()
|
||||
})
|
||||
.then(() => {
|
||||
cb(null)
|
||||
})
|
||||
@ -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)
|
||||
|
@ -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) {
|
||||
|
@ -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()
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user