diff options
Diffstat (limited to 'test/test_password.py')
-rw-r--r-- | test/test_password.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/test/test_password.py b/test/test_password.py new file mode 100644 index 0000000..ed62f10 --- /dev/null +++ b/test/test_password.py @@ -0,0 +1,31 @@ +from tempfile import TemporaryDirectory +import os.path +from mu4web.password import ( + Passwords, +) + + +dir = TemporaryDirectory() +path = os.path.join(dir.name, 'passwords.json') + + +def test_password() -> None: + # Start with a blank store + store1 = Passwords(path) + # Try to validate a non-existant user (this should fail) + assert not store1.validate('hugo', 'password') + + # Add a user + store1.add('hugo', 'password') + # Try to validate it (this should succeed) + assert store1.validate('hugo', 'password') + # Try to validate it with the wrong password (this should not succeed) + assert not store1.validate('hugo', 'Hunter2') + + # Save store to disk + store1.save() + + # Load same store into different instance + store2 = Passwords(path) + # Check that password was correctly saved. + assert store2.validate('hugo', 'password') |