|
|
|
@ -63,6 +63,11 @@ class FakePasslibContext:
@@ -63,6 +63,11 @@ class FakePasslibContext:
|
|
|
|
|
return True, None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FakeEventQueue(list): |
|
|
|
|
def emit(self, event): |
|
|
|
|
self.append(event) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture |
|
|
|
|
def prefilled_repo(): |
|
|
|
|
from itertools import count |
|
|
|
@ -218,22 +223,34 @@ def test_check_vendor_name(input, name, found):
@@ -218,22 +223,34 @@ def test_check_vendor_name(input, name, found):
|
|
|
|
|
assert result.found == found |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_have_i_been_pwned_ok(): |
|
|
|
|
from ordr3.services import have_i_been_pwned |
|
|
|
|
def test__check_have_i_been_pwned_ok(): |
|
|
|
|
from ordr3.services import _check_have_i_been_pwned |
|
|
|
|
|
|
|
|
|
queue = FakeEventQueue() |
|
|
|
|
|
|
|
|
|
assert not _check_have_i_been_pwned("21BD2x", queue) |
|
|
|
|
assert len(queue) == 0 |
|
|
|
|
|
|
|
|
|
assert not have_i_been_pwned("21BD2x") |
|
|
|
|
|
|
|
|
|
def test__check_have_i_been_pwned_not_ok(): |
|
|
|
|
from ordr3.services import _check_have_i_been_pwned |
|
|
|
|
|
|
|
|
|
def test_have_i_been_pwned_not_ok(): |
|
|
|
|
from ordr3.services import have_i_been_pwned |
|
|
|
|
queue = FakeEventQueue() |
|
|
|
|
|
|
|
|
|
assert have_i_been_pwned("21BD2008F2FF3F9F3AE0A2072D19CD17E971B33A") |
|
|
|
|
assert _check_have_i_been_pwned( |
|
|
|
|
"21BD2008F2FF3F9F3AE0A2072D19CD17E971B33A", queue |
|
|
|
|
) |
|
|
|
|
assert len(queue) == 1 |
|
|
|
|
assert queue[0].text.startswith("This password appears in a breach") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_have_i_been_pwned_request_exception(): |
|
|
|
|
from ordr3.services import have_i_been_pwned |
|
|
|
|
def test__check_have_i_been_pwned_request_exception(): |
|
|
|
|
from ordr3.services import _check_have_i_been_pwned |
|
|
|
|
|
|
|
|
|
assert not have_i_been_pwned("xxxxx") |
|
|
|
|
queue = FakeEventQueue() |
|
|
|
|
|
|
|
|
|
assert not _check_have_i_been_pwned("xxxxx", queue) |
|
|
|
|
assert len(queue) == 0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_set_new_password_ok(monkeypatch): |
|
|
|
@ -242,11 +259,16 @@ def test_set_new_password_ok(monkeypatch):
@@ -242,11 +259,16 @@ def test_set_new_password_ok(monkeypatch):
|
|
|
|
|
from ordr3.security import get_passlib_context |
|
|
|
|
|
|
|
|
|
user = User(*list("ABCDEFG")) |
|
|
|
|
monkeypatch.setattr(services, "have_i_been_pwned", lambda x: False) |
|
|
|
|
result = services.set_new_password(user, "1234567890123456") |
|
|
|
|
queue = FakeEventQueue() |
|
|
|
|
monkeypatch.setattr( |
|
|
|
|
services, "_check_have_i_been_pwned", lambda x, y: False |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
result = services.set_new_password(user, "1234567890123456", queue) |
|
|
|
|
|
|
|
|
|
assert result |
|
|
|
|
assert get_passlib_context().verify("1234567890123456", user.password) |
|
|
|
|
assert result == [] |
|
|
|
|
assert len(queue) == 0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_set_new_password_to_short(monkeypatch): |
|
|
|
@ -255,12 +277,17 @@ def test_set_new_password_to_short(monkeypatch):
@@ -255,12 +277,17 @@ def test_set_new_password_to_short(monkeypatch):
|
|
|
|
|
from ordr3.security import get_passlib_context |
|
|
|
|
|
|
|
|
|
user = User(*list("ABCDEFG")) |
|
|
|
|
monkeypatch.setattr(services, "have_i_been_pwned", lambda x: False) |
|
|
|
|
result = services.set_new_password(user, "1") |
|
|
|
|
queue = FakeEventQueue() |
|
|
|
|
monkeypatch.setattr( |
|
|
|
|
services, "_check_have_i_been_pwned", lambda x, y: False |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
result = services.set_new_password(user, "1", queue) |
|
|
|
|
|
|
|
|
|
assert not result |
|
|
|
|
assert get_passlib_context().verify("1", user.password) |
|
|
|
|
assert len(result) == 1 |
|
|
|
|
assert result[0].message.startswith("Your password is quite short") |
|
|
|
|
assert len(queue) == 1 |
|
|
|
|
assert queue[0].text.startswith("Your password is quite short") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_set_new_password_breached(monkeypatch): |
|
|
|
@ -269,12 +296,15 @@ def test_set_new_password_breached(monkeypatch):
@@ -269,12 +296,15 @@ def test_set_new_password_breached(monkeypatch):
|
|
|
|
|
from ordr3.security import get_passlib_context |
|
|
|
|
|
|
|
|
|
user = User(*list("ABCDEFG")) |
|
|
|
|
monkeypatch.setattr(services, "have_i_been_pwned", lambda x: True) |
|
|
|
|
result = services.set_new_password(user, "1234567890123456") |
|
|
|
|
queue = FakeEventQueue() |
|
|
|
|
monkeypatch.setattr( |
|
|
|
|
services, "_check_have_i_been_pwned", lambda x, y: True |
|
|
|
|
) |
|
|
|
|
result = services.set_new_password(user, "1234567890123456", queue) |
|
|
|
|
|
|
|
|
|
assert not result |
|
|
|
|
assert get_passlib_context().verify("1234567890123456", user.password) |
|
|
|
|
assert len(result) == 1 |
|
|
|
|
assert result[0].message.startswith("This password appears in a breach") |
|
|
|
|
assert len(queue) == 0 # no item in que due to monkeypatch |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_set_new_password_to_short_and_breached(monkeypatch): |
|
|
|
@ -283,10 +313,13 @@ def test_set_new_password_to_short_and_breached(monkeypatch):
@@ -283,10 +313,13 @@ def test_set_new_password_to_short_and_breached(monkeypatch):
|
|
|
|
|
from ordr3.security import get_passlib_context |
|
|
|
|
|
|
|
|
|
user = User(*list("ABCDEFG")) |
|
|
|
|
monkeypatch.setattr(services, "have_i_been_pwned", lambda x: True) |
|
|
|
|
result = services.set_new_password(user, "1") |
|
|
|
|
queue = FakeEventQueue() |
|
|
|
|
monkeypatch.setattr( |
|
|
|
|
services, "_check_have_i_been_pwned", lambda x, y: True |
|
|
|
|
) |
|
|
|
|
result = services.set_new_password(user, "1", queue) |
|
|
|
|
|
|
|
|
|
assert not result |
|
|
|
|
assert get_passlib_context().verify("1", user.password) |
|
|
|
|
assert len(result) == 2 |
|
|
|
|
assert result[0].message.startswith("Your password is quite short") |
|
|
|
|
assert result[1].message.startswith("This password appears in a breach") |
|
|
|
|
assert len(queue) == 1 # only one item in que due to monkeypatch |
|
|
|
|
assert queue[0].text.startswith("Your password is quite short") |
|
|
|
|