aboutsummaryrefslogtreecommitdiff
path: root/test/test_password.py
blob: ed62f109e89452248693b7f28043d677313a75fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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')