|
|
|
@ -216,3 +216,77 @@ def test_check_vendor_name(input, name, found):
@@ -216,3 +216,77 @@ def test_check_vendor_name(input, name, found):
|
|
|
|
|
|
|
|
|
|
assert result.name == name |
|
|
|
|
assert result.found == found |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_have_i_been_pwned_ok(): |
|
|
|
|
from ordr3.services import have_i_been_pwned |
|
|
|
|
|
|
|
|
|
assert not have_i_been_pwned("21BD2x") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_have_i_been_pwned_not_ok(): |
|
|
|
|
from ordr3.services import have_i_been_pwned |
|
|
|
|
|
|
|
|
|
assert have_i_been_pwned("21BD2008F2FF3F9F3AE0A2072D19CD17E971B33A") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_have_i_been_pwned_request_exception(): |
|
|
|
|
from ordr3.services import have_i_been_pwned |
|
|
|
|
|
|
|
|
|
assert not have_i_been_pwned("xxxxx") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_set_new_password_ok(monkeypatch): |
|
|
|
|
from ordr3 import services |
|
|
|
|
from ordr3.models import User |
|
|
|
|
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") |
|
|
|
|
|
|
|
|
|
assert get_passlib_context().verify("1234567890123456", user.password) |
|
|
|
|
assert result == [] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_set_new_password_to_short(monkeypatch): |
|
|
|
|
from ordr3 import services |
|
|
|
|
from ordr3.models import User |
|
|
|
|
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") |
|
|
|
|
|
|
|
|
|
assert get_passlib_context().verify("1", user.password) |
|
|
|
|
assert len(result) == 1 |
|
|
|
|
assert result[0].message.startswith("Your password is quite short") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_set_new_password_breached(monkeypatch): |
|
|
|
|
from ordr3 import services |
|
|
|
|
from ordr3.models import User |
|
|
|
|
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") |
|
|
|
|
|
|
|
|
|
assert get_passlib_context().verify("1234567890123456", user.password) |
|
|
|
|
assert len(result) == 1 |
|
|
|
|
assert result[0].message.startswith("This password appears in a breach") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_set_new_password_to_short_and_breached(monkeypatch): |
|
|
|
|
from ordr3 import services |
|
|
|
|
from ordr3.models import User |
|
|
|
|
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") |
|
|
|
|
|
|
|
|
|
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") |
|
|
|
|