Skip to content

Commit

Permalink
coverage masterpassword
Browse files Browse the repository at this point in the history
  • Loading branch information
xeroc committed Aug 7, 2018
1 parent 84a3d21 commit dddee40
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
10 changes: 7 additions & 3 deletions graphenestorage/masterpassword.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,15 @@ def decryptEncryptedMaster(self):
try:
decrypted_master = aes.decrypt(encrypted_master)
except:
raise WrongMasterPasswordException
self.raiseWrongMasterPasswordException()
if checksum != self.deriveChecksum(decrypted_master):
raise WrongMasterPasswordException
self.raiseWrongMasterPasswordException()
self.decrypted_master = decrypted_master

def raiseWrongMasterPasswordException(self):
self.password = None
raise WrongMasterPasswordException

def saveEncrytpedMaster(self):
self.config[self.config_key] = self.getEncryptedMaster()

Expand Down Expand Up @@ -140,7 +144,7 @@ def tryUnlockFromEnv(self):
log.debug("Trying to use environmental variable to unlock wallet")
self.unlock(os.environ.get("UNLOCK"))
else:
raise WrongMasterPasswordException
self.raiseWrongMasterPasswordException()

def decrypt(self, wif):
return format(
Expand Down
26 changes: 25 additions & 1 deletion tests/test_storage.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os
import unittest

from graphenebase.account import PrivateKey
from graphenestorage.exceptions import WrongMasterPasswordException

import graphenestorage as storage

Expand Down Expand Up @@ -130,10 +132,32 @@ def test_masterpassword(self):
)

def test_wrongmastermass(self):
from graphenestorage.exceptions import WrongMasterPasswordException
config = storage.InRamConfigurationStore()
keys = storage.InRamEncryptedKeyStore(config=config)
keys.newMaster("foobar")
keys.lock()
with self.assertRaises(WrongMasterPasswordException):
keys.unlock("foobar2")

def test_masterpwd(self):
with self.assertRaises(Exception):
storage.InRamEncryptedKeyStore()
config = storage.InRamConfigurationStore()
keys = storage.InRamEncryptedKeyStore(config=config)
self.assertTrue(keys.locked())
keys.unlock("foobar")
keys.password = "FOoo"
with self.assertRaises(Exception):
keys.decryptEncryptedMaster()
keys.lock()

with self.assertRaises(WrongMasterPasswordException):
keys.unlock("foobar2")

with self.assertRaises(Exception):
keys.getEncryptedMaster()

os.environ["UNLOCK"] = "foobar"
keys.unlocked()

self.assertFalse(keys.locked())

0 comments on commit dddee40

Please sign in to comment.