FlaskTester 2.0__tar.gz → 3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: FlaskTester
3
- Version: 2.0
3
+ Version: 3.0
4
4
  Summary: Pytest fixtures for Flask internal and external authenticated tests
5
5
  Author-email: Fabien Coelho <flask.tester@coelho.net>
6
6
  License: CC0
@@ -32,7 +32,7 @@ Requires-Dist: twine; extra == "dev"
32
32
  Requires-Dist: wheel; extra == "dev"
33
33
  Requires-Dist: types-flask; extra == "dev"
34
34
  Requires-Dist: types-requests; extra == "dev"
35
- Requires-Dist: FlaskSimpleAuth>=29.4; extra == "dev"
35
+ Requires-Dist: FlaskSimpleAuth>=29.5; extra == "dev"
36
36
  Requires-Dist: passlib; extra == "dev"
37
37
  Provides-Extra: doc
38
38
  Requires-Dist: sphinx; extra == "doc"
@@ -52,7 +52,7 @@ Only one set of tests is needed, switching from internal to external is
52
52
  achieved through environment variables.
53
53
 
54
54
  ![Status](https://github.com/zx80/flask-tester/actions/workflows/package.yml/badge.svg?branch=main&style=flat)
55
- ![Tests](https://img.shields.io/badge/tests-10%20✓-success)
55
+ ![Tests](https://img.shields.io/badge/tests-11%20✓-success)
56
56
  ![Coverage](https://img.shields.io/badge/coverage-100%25-success)
57
57
  ![Issues](https://img.shields.io/github/issues/zx80/flask-tester?style=flat)
58
58
  ![Python](https://img.shields.io/badge/python-3-informational)
@@ -136,7 +136,7 @@ The package provides two fixtures:
136
136
  - `ft_authenticator` for app authentication, which depends on environment variables:
137
137
 
138
138
  - `FLASK_TESTER_ALLOW` space-separated list of allowed authentication schemes,
139
- default is `["bearer", "basic", "param"]`.
139
+ default is `["bearer", "basic", "param", "none"]`.
140
140
  - `FLASK_TESTER_AUTH` comma-separated list of _login:password_ credentials.
141
141
  - `FLASK_TESTER_USER` user login parameter for `param` password authentication,
142
142
  default is `USER`.
@@ -159,7 +159,7 @@ The package provides two fixtures:
159
159
  - `setPass` to associate a password to a user, set to _None_ to remove credential.
160
160
  - `setToken` to associate a token to a user, set to _None_ to remove credential.
161
161
  - `setCookie` to add a cookie to a user, set value to _None_ to remove cookie.
162
- - `setAuth` to add authentication data to a request `kwargs`.
162
+ - `setAuth` to add authentication data to a request `kwargs` and `cookies`.
163
163
 
164
164
  - `ft_client` for app testing, which depends on the previous fixture, plus
165
165
  environment variables which allow to find the application, at least one must
@@ -242,6 +242,10 @@ Packages are distributed from [PyPI](https://pypi.org/project/FlaskTester/),
242
242
  see also the [documentation](https://zx80.github.io/flask-tester/),
243
243
  please report any [issues](https://github.com/zx80/flask-tester/issues).
244
244
 
245
+ ### 3.0 on 2024-03-23
246
+
247
+ Add support for `none` authentication, with only cookies.
248
+
245
249
  ### 2.0 on 2024-03-23
246
250
 
247
251
  Add support for cookies.
@@ -13,7 +13,7 @@ twine
13
13
  wheel
14
14
  types-flask
15
15
  types-requests
16
- FlaskSimpleAuth>=29.4
16
+ FlaskSimpleAuth>=29.5
17
17
  passlib
18
18
 
19
19
  [doc]
@@ -36,11 +36,12 @@ class Authenticator:
36
36
  - ``cookie``: token in a cookie
37
37
  - ``tparam``: token in a parameter
38
38
  - ``fake``: fake scheme, login directly passed as a parameter
39
+ - ``none``: no authentication, only cookies
39
40
 
40
41
  Constructor parameters:
41
42
 
42
43
  - ``allow``: list of allowed schemes.
43
- default is ``["bearer", "basic", "param"]``
44
+ default is ``["bearer", "basic", "param", "none"]``
44
45
  - ``user``: parameter for user on ``param`` password authentication,
45
46
  default is ``USER``
46
47
  - ``pwd``: parameter for password on ``param`` password authentication,
@@ -61,12 +62,12 @@ class Authenticator:
61
62
  _PASS_SCHEMES = {"basic", "param"}
62
63
 
63
64
  # all supported authentication schemes
64
- _AUTH_SCHEMES = {"fake"}
65
+ _AUTH_SCHEMES = {"fake", "none"}
65
66
  _AUTH_SCHEMES.update(_TOKEN_SCHEMES)
66
67
  _AUTH_SCHEMES.update(_PASS_SCHEMES)
67
68
 
68
69
  def __init__(self,
69
- allow: list[str] = ["bearer", "basic", "param"],
70
+ allow: list[str] = ["bearer", "basic", "param", "none"],
70
71
  # parameter names for "basic" and "param"
71
72
  user: str = "USER",
72
73
  pwd: str = "PASS",
@@ -214,6 +215,10 @@ class Authenticator:
214
215
 
215
216
  self._param(kwargs, self._login, login)
216
217
 
218
+ elif self._try_auth(auth, "none"):
219
+
220
+ pass
221
+
217
222
  else:
218
223
 
219
224
  raise AuthError(f"no authentication for login={login} auth={auth} allow={self._allow}")
@@ -461,7 +466,7 @@ def ft_authenticator():
461
466
  ``DEBUG INFO WARNING ERROR CRITICAL NOSET``.
462
467
  Default is ``NOTSET``.
463
468
  - ``FLASK_TESTER_ALLOW``: allowed space-separated authentication schemes, in
464
- ``basic param bearer header cookie tparam fake``.
469
+ ``basic param bearer header cookie tparam fake none``.
465
470
  Default is ``bearer basic param``.
466
471
  - ``FLASK_TESTER_USER``: user login parameter for ``param`` authentication.
467
472
  Default is ``USER``.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: FlaskTester
3
- Version: 2.0
3
+ Version: 3.0
4
4
  Summary: Pytest fixtures for Flask internal and external authenticated tests
5
5
  Author-email: Fabien Coelho <flask.tester@coelho.net>
6
6
  License: CC0
@@ -32,7 +32,7 @@ Requires-Dist: twine; extra == "dev"
32
32
  Requires-Dist: wheel; extra == "dev"
33
33
  Requires-Dist: types-flask; extra == "dev"
34
34
  Requires-Dist: types-requests; extra == "dev"
35
- Requires-Dist: FlaskSimpleAuth>=29.4; extra == "dev"
35
+ Requires-Dist: FlaskSimpleAuth>=29.5; extra == "dev"
36
36
  Requires-Dist: passlib; extra == "dev"
37
37
  Provides-Extra: doc
38
38
  Requires-Dist: sphinx; extra == "doc"
@@ -52,7 +52,7 @@ Only one set of tests is needed, switching from internal to external is
52
52
  achieved through environment variables.
53
53
 
54
54
  ![Status](https://github.com/zx80/flask-tester/actions/workflows/package.yml/badge.svg?branch=main&style=flat)
55
- ![Tests](https://img.shields.io/badge/tests-10%20✓-success)
55
+ ![Tests](https://img.shields.io/badge/tests-11%20✓-success)
56
56
  ![Coverage](https://img.shields.io/badge/coverage-100%25-success)
57
57
  ![Issues](https://img.shields.io/github/issues/zx80/flask-tester?style=flat)
58
58
  ![Python](https://img.shields.io/badge/python-3-informational)
@@ -136,7 +136,7 @@ The package provides two fixtures:
136
136
  - `ft_authenticator` for app authentication, which depends on environment variables:
137
137
 
138
138
  - `FLASK_TESTER_ALLOW` space-separated list of allowed authentication schemes,
139
- default is `["bearer", "basic", "param"]`.
139
+ default is `["bearer", "basic", "param", "none"]`.
140
140
  - `FLASK_TESTER_AUTH` comma-separated list of _login:password_ credentials.
141
141
  - `FLASK_TESTER_USER` user login parameter for `param` password authentication,
142
142
  default is `USER`.
@@ -159,7 +159,7 @@ The package provides two fixtures:
159
159
  - `setPass` to associate a password to a user, set to _None_ to remove credential.
160
160
  - `setToken` to associate a token to a user, set to _None_ to remove credential.
161
161
  - `setCookie` to add a cookie to a user, set value to _None_ to remove cookie.
162
- - `setAuth` to add authentication data to a request `kwargs`.
162
+ - `setAuth` to add authentication data to a request `kwargs` and `cookies`.
163
163
 
164
164
  - `ft_client` for app testing, which depends on the previous fixture, plus
165
165
  environment variables which allow to find the application, at least one must
@@ -242,6 +242,10 @@ Packages are distributed from [PyPI](https://pypi.org/project/FlaskTester/),
242
242
  see also the [documentation](https://zx80.github.io/flask-tester/),
243
243
  please report any [issues](https://github.com/zx80/flask-tester/issues).
244
244
 
245
+ ### 3.0 on 2024-03-23
246
+
247
+ Add support for `none` authentication, with only cookies.
248
+
245
249
  ### 2.0 on 2024-03-23
246
250
 
247
251
  Add support for cookies.
@@ -9,7 +9,7 @@ Only one set of tests is needed, switching from internal to external is
9
9
  achieved through environment variables.
10
10
 
11
11
  ![Status](https://github.com/zx80/flask-tester/actions/workflows/package.yml/badge.svg?branch=main&style=flat)
12
- ![Tests](https://img.shields.io/badge/tests-10%20✓-success)
12
+ ![Tests](https://img.shields.io/badge/tests-11%20✓-success)
13
13
  ![Coverage](https://img.shields.io/badge/coverage-100%25-success)
14
14
  ![Issues](https://img.shields.io/github/issues/zx80/flask-tester?style=flat)
15
15
  ![Python](https://img.shields.io/badge/python-3-informational)
@@ -93,7 +93,7 @@ The package provides two fixtures:
93
93
  - `ft_authenticator` for app authentication, which depends on environment variables:
94
94
 
95
95
  - `FLASK_TESTER_ALLOW` space-separated list of allowed authentication schemes,
96
- default is `["bearer", "basic", "param"]`.
96
+ default is `["bearer", "basic", "param", "none"]`.
97
97
  - `FLASK_TESTER_AUTH` comma-separated list of _login:password_ credentials.
98
98
  - `FLASK_TESTER_USER` user login parameter for `param` password authentication,
99
99
  default is `USER`.
@@ -116,7 +116,7 @@ The package provides two fixtures:
116
116
  - `setPass` to associate a password to a user, set to _None_ to remove credential.
117
117
  - `setToken` to associate a token to a user, set to _None_ to remove credential.
118
118
  - `setCookie` to add a cookie to a user, set value to _None_ to remove cookie.
119
- - `setAuth` to add authentication data to a request `kwargs`.
119
+ - `setAuth` to add authentication data to a request `kwargs` and `cookies`.
120
120
 
121
121
  - `ft_client` for app testing, which depends on the previous fixture, plus
122
122
  environment variables which allow to find the application, at least one must
@@ -199,6 +199,10 @@ Packages are distributed from [PyPI](https://pypi.org/project/FlaskTester/),
199
199
  see also the [documentation](https://zx80.github.io/flask-tester/),
200
200
  please report any [issues](https://github.com/zx80/flask-tester/issues).
201
201
 
202
+ ### 3.0 on 2024-03-23
203
+
204
+ Add support for `none` authentication, with only cookies.
205
+
202
206
  ### 2.0 on 2024-03-23
203
207
 
204
208
  Add support for cookies.
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "FlaskTester"
7
- version = "2.0"
7
+ version = "3.0"
8
8
  authors = [ { name = "Fabien Coelho", email = "flask.tester@coelho.net" } ]
9
9
  description = "Pytest fixtures for Flask internal and external authenticated tests"
10
10
  readme = "README.md"
@@ -33,7 +33,7 @@ package = "https://pypi.org/project/FlaskTester/"
33
33
 
34
34
  [project.optional-dependencies]
35
35
  # various dev tools
36
- dev = ["mypy", "pyright", "ruff", "coverage", "pymarkdownlnt!=0.9.5", "build", "twine", "wheel", "types-flask", "types-requests", "FlaskSimpleAuth>=29.4", "passlib"]
36
+ dev = ["mypy", "pyright", "ruff", "coverage", "pymarkdownlnt!=0.9.5", "build", "twine", "wheel", "types-flask", "types-requests", "FlaskSimpleAuth>=29.5", "passlib"]
37
37
  # documentation generation
38
38
  doc = ["sphinx", "sphinx_rtd_theme", "sphinx-autoapi", "sphinx-lint", "myst_parser"]
39
39
 
@@ -15,7 +15,7 @@ logging.basicConfig(level=logging.INFO)
15
15
 
16
16
  # set authn for ft_authenticator
17
17
  os.environ.update(
18
- FLASK_TESTER_ALLOW="bearer basic param",
18
+ FLASK_TESTER_ALLOW="bearer basic param none",
19
19
  FLASK_TESTER_AUTH=",".join(f"{l}:{p}" for l, p in secret.PASSES.items()),
20
20
  )
21
21
 
@@ -66,8 +66,8 @@ def api(ft_client):
66
66
  ft_client.setPass("moe", "bad password")
67
67
  ft_client.setToken("moe", "bad token")
68
68
  # cookies
69
- ft_client.setCookie("calvin", "lang", "en_EN")
70
- ft_client.setCookie("hobbes", "lang", "fr_FR")
69
+ ft_client.setCookie("calvin", "lang", "en")
70
+ ft_client.setCookie("hobbes", "lang", "fr")
71
71
  # get valid tokens using password authn
72
72
  res = ft_client.get("/login", login="calvin", auth="basic", status=200)
73
73
  assert res.json["user"] == "calvin"
@@ -78,11 +78,12 @@ def api(ft_client):
78
78
  res = ft_client.post("/login", login="susie", auth="param", status=201, json={})
79
79
  assert res.json["user"] == "susie"
80
80
  ft_client._auth.setToken("susie", res.json["token"])
81
+ ft_client.get("/login", login="calvin", auth="none", status=401)
81
82
  # check that token auth and cookie is ok
82
83
  res = ft_client.get("/who-am-i", login="calvin", status=200, auth="bearer")
83
- assert res.json["user"] == "calvin" and res.json["lang"] == "en_EN"
84
+ assert res.json["user"] == "calvin" and res.json["lang"] == "en"
84
85
  res = ft_client.get("/who-am-i", login="hobbes", status=200, auth="bearer")
85
- assert res.json["user"] == "hobbes" and res.json["lang"] == "fr_FR"
86
+ assert res.json["user"] == "hobbes" and res.json["lang"] == "fr"
86
87
  res = ft_client.get("/who-am-i", login="susie", status=200, auth="bearer")
87
88
  assert res.json["user"] == "susie" and res.json["lang"] is None
88
89
  # with defaults
@@ -117,6 +118,7 @@ def test_admin(api):
117
118
  assert "NOT THERE" in str(e)
118
119
 
119
120
  def test_errors(api):
121
+ # these schemes are not allowed
120
122
  for scheme in ("header", "cookie", "fake", "tparam", "unexpected"):
121
123
  try:
122
124
  api.get("/login", login="calvin", auth=scheme)
@@ -125,13 +127,27 @@ def test_errors(api):
125
127
  assert True, "expected error"
126
128
 
127
129
  def test_methods(api):
128
- res = api.get("/who-am-i", login="susie", status=200, cookies={"lang": "python"})
129
- assert res.json["lang"] == "python"
130
+ res = api.get("/who-am-i", login="susie", status=200, cookies={"lang": "it"})
131
+ assert res.json["lang"] == "it"
130
132
  api.post("/who-am-i", login="hobbes", status=405)
131
133
  api.put("/who-am-i", login="hobbes", status=405)
132
134
  api.patch("/who-am-i", login="hobbes", status=405)
133
135
  api.delete("/who-am-i", login="hobbes", status=405)
134
136
 
137
+ def test_hello(api):
138
+ res = api.get("/hello", login="calvin", auth="none", status=200)
139
+ assert res.json["hello"] == "Hi"
140
+ assert res.headers["FSA-User"] == "None (None)"
141
+ res = api.get("/hello", login="hobbes", auth="none", status=200)
142
+ assert res.json["hello"] == "Salut"
143
+ assert res.headers["FSA-User"] == "None (None)"
144
+ res = api.get("/hello", login="susie", auth="none", status=200, cookies={"lang": "it"})
145
+ assert res.json["hello"] == "Ciao"
146
+ assert res.headers["FSA-User"] == "None (None)"
147
+ res = api.get("/hello", login="moe", auth="none", status=200)
148
+ assert res.json["hello"] == "Hi"
149
+ assert res.headers["FSA-User"] == "None (None)"
150
+
135
151
  def test_authenticator_token():
136
152
  # all token carriers
137
153
  auth = ft.Authenticator(allow=["bearer", "header", "tparam", "cookie"])
File without changes
File without changes
File without changes