Passed
Push — main ( cb2e8b...5593c7 )
by Jochen
04:09
created

test_is_password_hash_current()   A

Complexity

Conditions 1

Size

Total Lines 32
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 20
nop 2
dl 0
loc 32
rs 9.4
c 0
b 0
f 0
1
"""
2
:Copyright: 2006-2021 Jochen Kupperschmidt
3
:License: Revised BSD (see `LICENSE` file for details)
4
"""
5
6
import pytest
7
8
from byceps.services.authentication.password import service as password_service
9
10
11
@pytest.mark.parametrize(
12
    'password_hash, expected',
13
    [
14
        (
15
            # matches neither configured algorithm nor iteration count
16
            'pbkdf2:sha1:1000$JDbgv2Sk0yDVFCFM$ecfd05f5922d820d6ead9af3b3e70a501c1b4ae7',
17
            False,
18
        ),
19
        (
20
            # matches configured iteration count but not algorithm
21
            'pbkdf2:sha1:100000$h2Kec422sB2TqJ1Q$5abca818362323e085057f430ae36870e296fdaa',
22
            False,
23
        ),
24
        (
25
            # matches configured algorithm but not iteration count
26
            'pbkdf2:sha256:100000$9gf08FbwILpoROvt$99805a27d6e6447db4af26832ba94c54032b5a94ce83d1d290165210176a8454',
27
            False,
28
        ),
29
        (
30
            # matches configured algorithm and iteration count
31
            'pbkdf2:sha256:250000$rNGHJHbqxDsNHHJr$e0fd1fe49f3d3aeda97f36af78283d2de557efa270ab6cb281ad6ca9879d7c2c',
32
            True,
33
        ),
34
        (
35
            # higher number of iterations, but not the one configured
36
            'pbkdf2:sha256:260000$hGZgOpv58UJaX91I$6f2afba4a2a1637cc25d2143de9ec91ce0897a79d79ce59ce85792e275be5418',
37
            False,
38
        ),
39
    ],
40
)
41
def test_is_password_hash_current(password_hash, expected):
42
    assert password_service.is_password_hash_current(password_hash) == expected
43