Skip to content

Commit 8c42ea0

Browse files
committed
add CASBIN_USER_NAME_HEADERS configuration unit tests
1 parent 12e3697 commit 8c42ea0

1 file changed

Lines changed: 20 additions & 15 deletions

File tree

tests/test_casbin_enforcer.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,29 @@ def update_callback(self):
4444

4545

4646
@pytest.mark.parametrize(
47-
"header, user, method, status",
47+
"header, user, method, status, user_name",
4848
[
49-
("X-User", "alice", "GET", 200),
50-
("X-User", "alice", "POST", 201),
51-
("X-User", "alice", "DELETE", 202),
52-
("X-User", "bob", "GET", 200),
53-
("X-User", "bob", "POST", 401),
54-
("X-User", "bob", "DELETE", 401),
55-
("X-Idp-Groups", "admin", "GET", 401),
56-
("X-Idp-Groups", "users", "GET", 200),
57-
("X-Idp-Groups", "noexist,testnoexist,users", "GET", 200),
58-
("X-Idp-Groups", "noexist testnoexist users", "GET", 200),
59-
("X-Idp-Groups", "noexist, testnoexist, users", "GET", 200),
60-
("Authorization", "Basic Ym9iOnBhc3N3b3Jk", "GET", 200),
61-
("Authorization", "Unsupported Ym9iOnBhc3N3b3Jk", "GET", 401),
49+
("X-User", "alice", "GET", 200, "X-User"),
50+
("X-User", "alice", "GET", 200, "X-Not-A-Header"),
51+
("X-User", "alice", "POST", 201, None),
52+
("X-User", "alice", "DELETE", 202, None),
53+
("X-User", "bob", "GET", 200, None),
54+
("X-User", "bob", "POST", 401, None),
55+
("X-User", "bob", "DELETE", 401, None),
56+
("X-Idp-Groups", "admin", "GET", 401, "X-User"),
57+
("X-Idp-Groups", "users", "GET", 200, None),
58+
("X-Idp-Groups", "noexist,testnoexist,users", "GET", 200, None),
59+
("X-Idp-Groups", "noexist testnoexist users", "GET", 200, None),
60+
("X-Idp-Groups", "noexist, testnoexist, users", "GET", 200, None),
61+
("Authorization", "Basic Ym9iOnBhc3N3b3Jk", "GET", 200, "Authorization"),
62+
("Authorization", "Unsupported Ym9iOnBhc3N3b3Jk", "GET", 401, None),
6263
],
6364
)
64-
def test_enforcer(app_fixture, enforcer, header, user, method, status):
65+
def test_enforcer(app_fixture, enforcer, header, user, method, status, user_name):
66+
# enable auditing with user name
67+
if user_name:
68+
enforcer.user_name_headers = {user_name}
69+
6570
@app_fixture.route("/")
6671
@enforcer.enforcer
6772
def index():

0 commit comments

Comments
 (0)