@@ -39,11 +39,14 @@ def test_call(mock_auth_tween):
39
39
path = "/something" ,
40
40
method = "post" ,
41
41
headers = {"Authorization" : "Bearer aaa.bbb.ccc" },
42
+ swagger_data = {"service" : "foobar" },
42
43
)
43
44
with patch .object (mock_auth_tween , "is_request_authorized" ) as mock_is_authorized :
44
45
mock_is_authorized .return_value = auth .AuthorizationOutcome (True , "Ok" )
45
46
mock_auth_tween (mock_request )
46
- mock_is_authorized .assert_called_once_with ("/something" , "aaa.bbb.ccc" , "post" )
47
+ mock_is_authorized .assert_called_once_with (
48
+ "/something" , "aaa.bbb.ccc" , "post" , "foobar"
49
+ )
47
50
mock_auth_tween .handler .assert_called_once_with (mock_request )
48
51
49
52
@@ -52,6 +55,7 @@ def test_call_deny(mock_auth_tween):
52
55
path = "/something" ,
53
56
method = "post" ,
54
57
headers = {"Authorization" : "Bearer aaa.bbb.ccc" },
58
+ swagger_data = {},
55
59
)
56
60
with patch .object (mock_auth_tween , "is_request_authorized" ) as mock_is_authorized :
57
61
mock_is_authorized .return_value = auth .AuthorizationOutcome (False , "Denied" )
@@ -65,7 +69,7 @@ def test_is_request_authorized(mock_auth_tween):
65
69
"result" : {"allowed" : True , "reason" : "User allowed" }
66
70
}
67
71
assert mock_auth_tween .is_request_authorized (
68
- "/allowed" , "aaa.bbb.ccc" , "get"
72
+ "/allowed" , "aaa.bbb.ccc" , "get" , "foobar"
69
73
) == auth .AuthorizationOutcome (True , "User allowed" )
70
74
mock_auth_tween .session .post .assert_called_once_with (
71
75
url = "http://localhost:31337" ,
@@ -75,6 +79,7 @@ def test_is_request_authorized(mock_auth_tween):
75
79
"backend" : "paasta" ,
76
80
"token" : "aaa.bbb.ccc" ,
77
81
"method" : "get" ,
82
+ "service" : "foobar" ,
78
83
}
79
84
},
80
85
timeout = 2 ,
@@ -84,12 +89,18 @@ def test_is_request_authorized(mock_auth_tween):
84
89
def test_is_request_authorized_fail (mock_auth_tween ):
85
90
mock_auth_tween .session .post .side_effect = Exception
86
91
assert mock_auth_tween .is_request_authorized (
87
- "/allowed" , "eee.ddd.fff" , "get"
92
+ "/allowed" ,
93
+ "eee.ddd.fff" ,
94
+ "get" ,
95
+ "foobar" ,
88
96
) == auth .AuthorizationOutcome (False , "Auth backend error" )
89
97
90
98
91
99
def test_is_request_authorized_malformed (mock_auth_tween ):
92
100
mock_auth_tween .session .post .return_value .json .return_value = {"foo" : "bar" }
93
101
assert mock_auth_tween .is_request_authorized (
94
- "/allowed" , "eee.ddd.fff" , "post"
102
+ "/allowed" ,
103
+ "eee.ddd.fff" ,
104
+ "post" ,
105
+ "foobar" ,
95
106
) == auth .AuthorizationOutcome (False , "Malformed auth response" )
0 commit comments