Skip to content

Commit c4f1d00

Browse files
author
Fabien Coelho
committed
use random passwords
1 parent 7dbdbb0 commit c4f1d00

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ please report any [issues](https://github.com/zx80/flask-tester/issues).
193193
Improved documentation and tests.
194194
Raise an error when setting unusable passwords or tokens.
195195
Add support for `pkg:name` application syntax.
196+
Use random passwords when testing.
196197

197198
### 1.1 on 2024-03-13
198199

tests/app.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
import FlaskSimpleAuth as fsa
44

5-
TEST_PASSES: dict[str, str] = {"calvin": "clv-pass", "hobbes": "hbs-pass", "susie": "ss-pass", "moe": "m-pass"}
6-
75
app = fsa.Flask("app", FSA_MODE="dev", FSA_AUTH=["token", "param", "basic"])
86

9-
# authentication
10-
PASSDB = {login: app.hash_password(pwd) for login, pwd in TEST_PASSES.items()}
7+
# authentication with randomly-generated passwordss
8+
import secret
9+
PASSDB = {login: app.hash_password(pwd) for login, pwd in secret.PASSES.items()}
1110

1211
@app.get_user_pass
1312
def get_user_pass(login: str) -> str|None:

tests/secret.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import random
2+
import string
3+
4+
LENGTH = 16
5+
PASSES: dict[str, str] = {}
6+
CHARS = "".join(string.printable.split(","))
7+
8+
for login in ("calvin", "hobbes", "susie", "moe"):
9+
PASSES[login] = "".join(random.choice(CHARS) for _ in range(LENGTH))

tests/test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import FlaskSimpleAuth as fsa
44
import FlaskTester as ft
55
from FlaskTester import ft_client, ft_authenticator
6-
import app
6+
import secret
77
import http.server as htsv
88
import threading
99
import io
@@ -14,7 +14,7 @@
1414
# set authn for ft_authenticator
1515
os.environ.update(
1616
FLASK_TESTER_ALLOW="bearer basic param",
17-
FLASK_TESTER_AUTH=",".join(f"{l}:{p}" for l, p in app.TEST_PASSES.items()),
17+
FLASK_TESTER_AUTH=",".join(f"{l}:{p}" for l, p in secret.PASSES.items()),
1818
)
1919

2020
def test_sanity():
@@ -25,8 +25,8 @@ def test_sanity():
2525
@pytest.fixture
2626
def app(ft_client):
2727
# add test passwords for Calvin and Hobbes (must be consistent with app!)
28-
ft_client.setPass("calvin", "clv-pass")
29-
ft_client.setPass("hobbes", "hbs-pass")
28+
ft_client.setPass("calvin", secret.PASSES["calvin"])
29+
ft_client.setPass("hobbes", secret.PASSES["hobbes"])
3030
# get Calvin's token, assume json result {"token": "<token-value>"}
3131
res = ft_client.get("/token", login="calvin", auth="basic", status=200)
3232
assert res.is_json

0 commit comments

Comments
 (0)