File: test_audit.py

package info (click to toggle)
pass-audit 1.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 396 kB
  • sloc: python: 798; makefile: 41; sh: 17
file content (78 lines) | stat: -rw-r--r-- 2,985 bytes parent folder | download | duplicates (2)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# -*- encoding: utf-8 -*-
# pass-audit - test suite
# Copyright (C) 2018-2022 Alexandre PUJOL <alexandre@pujol.io>.
#

from unittest import mock

import pass_audit.audit
import pass_audit.msg
import tests


class TestPassAudit(tests.Test):
    """Test the PassAudit class."""
    passwords_nb = 7

    @mock.patch('requests.get', tests.mock_request)
    def test_password_notpwned(self):
        """Testing: pass audit for password not breached with K-anonymity."""
        data = tests.getdata('Password/notpwned')
        audit = pass_audit.audit.PassAudit(data, True)
        breached = audit.password()
        self.assertTrue(len(breached) == 0)

    @mock.patch('requests.get', tests.mock_request)
    def test_password_pwned(self):
        """Testing: pass audit for password breached with K-anonymity."""
        ref_counts = [52579, 3, 120, 1386, 3730471, 123422, 411]
        data = tests.getdata('Password/pwned')
        audit = pass_audit.audit.PassAudit(data, True)
        breached = audit.password()
        self.assertTrue(len(breached) == self.passwords_nb)
        for path, password, count in breached:
            self.assertIn(path, data)
            self.assertTrue(data[path]['password'] == password)
            ref_index = int(path[-1:]) - 1
            self.assertTrue(ref_counts[ref_index] == count)

    def test_zxcvbn_weak(self):
        """Testing: pass audit for weak password with zxcvbn."""
        data = tests.getdata('Password/pwned/1')
        audit = pass_audit.audit.PassAudit(data, True)
        weak = audit.zxcvbn()
        self.assertTrue(len(weak) == 1)
        self.assertTrue(weak[0][2]['score'] == 0)

    def test_zxcvbn_strong(self):
        """Testing: pass audit for strong password with zxcvbn."""
        data = tests.getdata('Password/good')
        audit = pass_audit.audit.PassAudit(data, True)
        weak = audit.zxcvbn()
        self.assertTrue(len(weak) == 0)

    def test_duplicates_yes(self):
        """Testing: pass audit for duplicates password."""
        data = tests.getdata('Password/notpwned/1')
        data['Password/notpwned/copy'] = data['Password/notpwned/1']
        audit = pass_audit.audit.PassAudit(data, True)
        duplicated = audit.duplicates()
        self.assertTrue(len(duplicated) == 1)

    def test_duplicates_no(self):
        """Testing: pass audit for not duplicated password."""
        data = tests.getdata('Password/notpwned/')
        audit = pass_audit.audit.PassAudit(data, True)
        duplicated = audit.duplicates()
        self.assertTrue(len(duplicated) == 0)

    def test_empty(self):
        """Testing: pass audit for empty password."""
        data = {'empty': {'password': ''}}
        audit = pass_audit.audit.PassAudit(data, True)
        weak = audit.zxcvbn()
        breached = audit.password()
        duplicated = audit.duplicates()
        self.assertTrue(len(weak) == 0)
        self.assertTrue(len(breached) == 0)
        self.assertTrue(len(duplicated) == 0)