mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-13 02:58:57 +00:00
tests: fix trezor.config test
This commit is contained in:
parent
5bd39c70b0
commit
40a9ac2e29
@ -4,6 +4,18 @@ from trezor.crypto import random
|
||||
|
||||
from trezor import config
|
||||
|
||||
PINAPP = 0x00
|
||||
PINKEY = 0x00
|
||||
|
||||
|
||||
def random_entry():
|
||||
while True:
|
||||
appid, key = random.uniform(256), random.uniform(256)
|
||||
if appid != PINAPP or key != PINKEY:
|
||||
break
|
||||
return appid, key
|
||||
|
||||
|
||||
class TestConfig(unittest.TestCase):
|
||||
|
||||
def test_init(self):
|
||||
@ -14,23 +26,59 @@ class TestConfig(unittest.TestCase):
|
||||
def test_wipe(self):
|
||||
config.init()
|
||||
config.wipe()
|
||||
config.set(0, 0, b'hello')
|
||||
self.assertEqual(config.unlock(''), True)
|
||||
config.set(0, 1, b'hello')
|
||||
config.set(1, 1, b'world')
|
||||
v0 = config.get(0, 0)
|
||||
v0 = config.get(0, 1)
|
||||
v1 = config.get(1, 1)
|
||||
self.assertEqual(v0, b'hello')
|
||||
self.assertEqual(v1, b'world')
|
||||
config.wipe()
|
||||
v0 = config.get(0, 0)
|
||||
v0 = config.get(0, 1)
|
||||
v1 = config.get(1, 1)
|
||||
self.assertEqual(v0, bytes())
|
||||
self.assertEqual(v1, bytes())
|
||||
|
||||
def test_lock(self):
|
||||
for _ in range(128):
|
||||
config.init()
|
||||
config.wipe()
|
||||
self.assertEqual(config.unlock(''), True)
|
||||
appid, key = random_entry()
|
||||
value = random.bytes(16)
|
||||
config.set(appid, key, value)
|
||||
config.init()
|
||||
self.assertEqual(config.get(appid, key), bytes())
|
||||
with self.assertRaises(RuntimeError):
|
||||
config.set(appid, key, bytes())
|
||||
config.init()
|
||||
config.wipe()
|
||||
self.assertEqual(config.change_pin('', 'xxx'), False)
|
||||
|
||||
def test_change_pin(self):
|
||||
config.init()
|
||||
config.wipe()
|
||||
self.assertEqual(config.unlock(''), True)
|
||||
with self.assertRaises(RuntimeError):
|
||||
config.set(PINAPP, PINKEY, 'xxx')
|
||||
self.assertEqual(config.change_pin('xxx', 'yyy'), False)
|
||||
self.assertEqual(config.change_pin('', 'xxx'), True)
|
||||
self.assertEqual(config.get(PINAPP, PINKEY), bytes())
|
||||
config.set(1, 1, b'value')
|
||||
config.init()
|
||||
self.assertEqual(config.unlock('xxx'), True)
|
||||
config.change_pin('xxx', '')
|
||||
config.init()
|
||||
self.assertEqual(config.unlock('xxx'), False)
|
||||
self.assertEqual(config.unlock(''), True)
|
||||
self.assertEqual(config.get(1, 1), b'value')
|
||||
|
||||
def test_set_get(self):
|
||||
config.init()
|
||||
config.wipe()
|
||||
for _ in range(64):
|
||||
appid, key = random.uniform(256), random.uniform(256)
|
||||
self.assertEqual(config.unlock(''), True)
|
||||
for _ in range(32):
|
||||
appid, key = random_entry()
|
||||
value = random.bytes(128)
|
||||
config.set(appid, key, value)
|
||||
value2 = config.get(appid, key)
|
||||
@ -39,8 +87,9 @@ class TestConfig(unittest.TestCase):
|
||||
def test_get_default(self):
|
||||
config.init()
|
||||
config.wipe()
|
||||
for _ in range(64):
|
||||
appid, key = random.uniform(256), random.uniform(256)
|
||||
self.assertEqual(config.unlock(''), True)
|
||||
for _ in range(128):
|
||||
appid, key = random_entry()
|
||||
value = config.get(appid, key)
|
||||
self.assertEqual(value, bytes())
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user