forked from Github-Mirrors/canaille
avoids api call from tests
This commit is contained in:
parent
2787252d81
commit
ec43d9157f
2 changed files with 9 additions and 3 deletions
|
@ -1,7 +1,7 @@
|
||||||
import datetime
|
import datetime
|
||||||
|
import hashlib
|
||||||
import math
|
import math
|
||||||
import re
|
import re
|
||||||
from hashlib import sha1
|
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
import wtforms.validators
|
import wtforms.validators
|
||||||
|
@ -89,7 +89,7 @@ def password_strength_calculator(password):
|
||||||
|
|
||||||
def compromised_password_validator(form, field):
|
def compromised_password_validator(form, field):
|
||||||
if current_app.config["CANAILLE"]["ENABLE_PASSWORD_COMPROMISSION_CHECK"]:
|
if current_app.config["CANAILLE"]["ENABLE_PASSWORD_COMPROMISSION_CHECK"]:
|
||||||
hashed_password = sha1(field.data.encode("utf-8")).hexdigest()
|
hashed_password = hashlib.sha1(field.data.encode("utf-8")).hexdigest()
|
||||||
hashed_password_prefix, hashed_password_suffix = (
|
hashed_password_prefix, hashed_password_suffix = (
|
||||||
hashed_password[:5].upper(),
|
hashed_password[:5].upper(),
|
||||||
hashed_password[5:].upper(),
|
hashed_password[5:].upper(),
|
||||||
|
|
|
@ -337,7 +337,13 @@ def test_maximum_password_length_config(testclient):
|
||||||
password_too_long_validator(None, Field("a" * 4097))
|
password_too_long_validator(None, Field("a" * 4097))
|
||||||
|
|
||||||
|
|
||||||
def test_compromised_password_validator(testclient):
|
@mock.patch("requests.api.get")
|
||||||
|
def test_compromised_password_validator(api_get, testclient):
|
||||||
|
class Response:
|
||||||
|
content = b"1E4C9B93F3F0682250B6CF8331B7EE68FD8:3\r\nCAA6D483CC3887DCE9D1B8EB91408F1EA7A:3\r\nAD6438836DBE526AA231ABDE2D0EEF74D42:3\r\n8289894DDB6317178960AB5AE98B81BBF97:1\r\n5FF0B6F9EAC40D5CA7B4DAA7B64F0E6F4AA:2\r\n"
|
||||||
|
|
||||||
|
api_get.return_value = Response
|
||||||
|
|
||||||
class Field:
|
class Field:
|
||||||
def __init__(self, data):
|
def __init__(self, data):
|
||||||
self.data = data
|
self.data = data
|
||||||
|
|
Loading…
Reference in a new issue