diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2023-08-07 13:45:31 +0200 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2023-08-07 15:16:41 +0200 |
commit | a59af71a77d928536412ea71b20689dfc99dd033 (patch) | |
tree | cca2e21ee76fa47364cae883a2ab1d05d310b4cb /test/test_password.py | |
parent | Add mail relation tree. (diff) | |
download | mu4web-a59af71a77d928536412ea71b20689dfc99dd033.tar.gz mu4web-a59af71a77d928536412ea71b20689dfc99dd033.tar.xz |
Add tests.
Diffstat (limited to '')
-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') |