Skip to content

Commit 671f442

Browse files
author
Fabien Coelho
committed
changes for FSA 35.0
1 parent e43ad31 commit 671f442

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

tests/app.py

+21-15
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,44 @@
44
import secret
55

66
# create application with token, param and basic authentication
7-
app = fsa.Flask("app", FSA_MODE="dev", FSA_AUTH=["token", "param", "basic", "none"])
7+
app = fsa.Flask(
8+
"app",
9+
FSA_MODE="dev",
10+
FSA_AUTH=["token", "param", "basic", "none"],
11+
)
812

913
# authentication with randomly-generated passwords
10-
PASSDB: dict[str, str] = {login: app.hash_password(pwd) for login, pwd in secret.PASSES.items()}
14+
PASSDB: dict[str, str] = {
15+
login: app.hash_password(pwd) for login, pwd in secret.PASSES.items()
16+
}
1117
app.get_user_pass(PASSDB.get)
1218

1319
# admin group authorization
1420
ADMINS: set[str] = {"calvin", "susie"}
1521
app.group_check("ADMIN", ADMINS.__contains__)
1622

1723
# login routes
18-
@app.get("/login", authorize="AUTH", auth="basic")
24+
@app.get("/login", authz="AUTH", authn="basic")
1925
def get_login(user: fsa.CurrentUser):
2026
return {"user": user, "token": app.create_token(user)}, 200
2127

22-
@app.post("/login", authorize="AUTH", auth="param")
28+
@app.post("/login", authz="AUTH", authn="param")
2329
def post_login(user: fsa.CurrentUser):
2430
return {"user": user, "token": app.create_token(user)}, 201
2531

2632
# identity routes
27-
@app.get("/who-am-i", authorize="AUTH")
33+
@app.get("/who-am-i", authz="AUTH")
2834
def get_who_am_i(user: fsa.CurrentUser, lang: fsa.Cookie = None):
2935
return {"user": user, "isadmin": user in ADMINS, "lang": lang}, 200
3036

31-
@app.get("/admin", authorize="ADMIN")
37+
@app.get("/admin", authz="ADMIN")
3238
def get_admin(user: fsa.CurrentUser):
3339
return {"user": user, "isadmin": True}, 200
3440

3541
# incredible open service for top-notch translations
3642
HELLO = {"it": "Ciao", "fr": "Salut", "en": "Hi", "ko": "안녕"}
3743

38-
@app.get("/hello", authorize="OPEN")
44+
@app.get("/hello", authz="OPEN")
3945
def get_hello(lang: fsa.Cookie = "en"):
4046
return {"lang": lang, "hello": HELLO.get(lang, "Hi")}, 200
4147

@@ -45,34 +51,34 @@ def get_hello(lang: fsa.Cookie = "en"):
4551
import model
4652

4753
# FIXME could we drop fsa.jsonify?
48-
@app.get("/t0", authorize="OPEN")
54+
@app.get("/t0", authz="OPEN")
4955
def get_t0(t: fsa.JsonData):
5056
return fsa.jsonify(t)
5157

52-
@app.post("/t0", authorize="OPEN")
58+
@app.post("/t0", authz="OPEN")
5359
def post_t0(t: fsa.JsonData):
5460
return fsa.jsonify(t)
5561

56-
@app.get("/t1", authorize="OPEN")
62+
@app.get("/t1", authz="OPEN")
5763
def get_t1(t: model.Thing1):
5864
return fsa.jsonify(t)
5965

60-
@app.post("/t1", authorize="OPEN")
66+
@app.post("/t1", authz="OPEN")
6167
def post_t1(t: model.Thing1):
6268
return fsa.jsonify(t)
6369

64-
@app.get("/t2", authorize="OPEN")
70+
@app.get("/t2", authz="OPEN")
6571
def get_t2(t: model.Thing2):
6672
return fsa.jsonify(t)
6773

68-
@app.post("/t2", authorize="OPEN")
74+
@app.post("/t2", authz="OPEN")
6975
def post_t2(t: model.Thing2):
7076
return fsa.jsonify(t)
7177

72-
@app.get("/t3", authorize="OPEN")
78+
@app.get("/t3", authz="OPEN")
7379
def get_t3(t: model.Thing3):
7480
return fsa.jsonify(t)
7581

76-
@app.post("/t3", authorize="OPEN")
82+
@app.post("/t3", authz="OPEN")
7783
def post_t3(t: model.Thing3):
7884
return fsa.jsonify(t)

tests/app2.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ def create_app():
1717
app.group_check("admin", ADMIN.__contains__)
1818

1919
# 4 routes
20-
@app.get("/open", authorize="OPEN")
20+
@app.get("/open", authz="OPEN")
2121
def get_no_auth(lang: fsa.Cookie = "de"):
2222
return fsa.jsonify(HELLO.get(lang, "Hey"))
2323

24-
@app.get("/authenticated", authorize="AUTH")
24+
@app.get("/authenticated", authz="AUTH")
2525
def get_authenticated(user: fsa.CurrentUser, lang: fsa.Cookie = "de"):
2626
return fsa.jsonify(HELLO.get(lang, "Hey") + " " + user)
2727

28-
@app.get("/only-admin", authorize="admin")
28+
@app.get("/only-admin", authz="admin")
2929
def get_only_admin():
3030
return fsa.jsonify("Salut administrateur !")
3131

32-
@app.get("/add", authorize="OPEN")
32+
@app.get("/add", authz="OPEN")
3333
def get_add(i: int, j: int):
3434
return {"sum": i + j}
3535

0 commit comments

Comments
 (0)