|
1 | | -package authorization_grant |
| 1 | +package authorization_grant_test |
| 2 | + |
| 3 | +import data.authorization_grant |
| 4 | +import rego.v1 |
2 | 5 |
|
3 | 6 | user := {"username": "john"} |
4 | 7 |
|
5 | 8 | client := {"client_id": "client"} |
6 | 9 |
|
7 | | -test_standard_scopes { |
8 | | - allow with input.user as user |
| 10 | +test_standard_scopes if { |
| 11 | + authorization_grant.allow with input.user as user |
9 | 12 | with input.client as client |
10 | 13 | with input.scope as "" |
11 | 14 |
|
12 | | - allow with input.user as user |
| 15 | + authorization_grant.allow with input.user as user |
13 | 16 | with input.client as client |
14 | 17 | with input.scope as "openid" |
15 | 18 |
|
16 | | - allow with input.user as user |
| 19 | + authorization_grant.allow with input.user as user |
17 | 20 | with input.client as client |
18 | 21 | with input.scope as "email" |
19 | 22 |
|
20 | | - allow with input.user as user |
| 23 | + authorization_grant.allow with input.user as user |
21 | 24 | with input.client as client |
22 | 25 | with input.scope as "openid email" |
23 | 26 |
|
24 | 27 | # Not supported yet |
25 | | - not allow with input.user as user |
| 28 | + not authorization_grant.allow with input.user as user |
26 | 29 | with input.client as client |
27 | 30 | with input.scope as "phone" |
28 | 31 |
|
29 | 32 | # Not supported yet |
30 | | - not allow with input.user as user |
| 33 | + not authorization_grant.allow with input.user as user |
31 | 34 | with input.client as client |
32 | 35 | with input.scope as "profile" |
33 | 36 | } |
34 | 37 |
|
35 | | -test_matrix_scopes { |
36 | | - allow with input.user as user |
| 38 | +test_matrix_scopes if { |
| 39 | + authorization_grant.allow with input.user as user |
37 | 40 | with input.client as client |
38 | 41 | with input.grant_type as "authorization_code" |
39 | 42 | with input.scope as "urn:matrix:org.matrix.msc2967.client:api:*" |
40 | 43 |
|
41 | | - allow with input.user as user |
| 44 | + authorization_grant.allow with input.user as user |
42 | 45 | with input.client as client |
43 | 46 | with input.grant_type as "urn:ietf:params:oauth:grant-type:device_code" |
44 | 47 | with input.scope as "urn:matrix:org.matrix.msc2967.client:api:*" |
45 | 48 |
|
46 | | - not allow with input.user as user |
| 49 | + not authorization_grant.allow with input.user as user |
47 | 50 | with input.client as client |
48 | 51 | with input.grant_type as "client_credentials" |
49 | 52 | with input.scope as "urn:matrix:org.matrix.msc2967.client:api:*" |
50 | 53 | } |
51 | 54 |
|
52 | | -test_device_scopes { |
53 | | - allow with input.user as user |
| 55 | +test_device_scopes if { |
| 56 | + authorization_grant.allow with input.user as user |
54 | 57 | with input.client as client |
55 | 58 | with input.grant_type as "authorization_code" |
56 | 59 | with input.scope as "urn:matrix:org.matrix.msc2967.client:device:AAbbCCdd01" |
57 | 60 |
|
58 | | - allow with input.user as user |
| 61 | + authorization_grant.allow with input.user as user |
59 | 62 | with input.client as client |
60 | 63 | with input.grant_type as "authorization_code" |
61 | 64 | with input.scope as "urn:matrix:org.matrix.msc2967.client:device:AAbbCCdd01-asdasdsa1-2313" |
62 | 65 |
|
63 | 66 | # Too short |
64 | | - not allow with input.user as user |
| 67 | + not authorization_grant.allow with input.user as user |
65 | 68 | with input.client as client |
66 | 69 | with input.grant_type as "authorization_code" |
67 | 70 | with input.scope as "urn:matrix:org.matrix.msc2967.client:device:abcd" |
68 | 71 |
|
69 | 72 | # Multiple device scope |
70 | | - not allow with input.user as user |
| 73 | + not authorization_grant.allow with input.user as user |
71 | 74 | with input.client as client |
72 | 75 | with input.grant_type as "authorization_code" |
73 | 76 | with input.scope as "urn:matrix:org.matrix.msc2967.client:device:AAbbCCdd01 urn:matrix:org.matrix.msc2967.client:device:AAbbCCdd02" |
74 | 77 |
|
75 | 78 | # Allowed with the device code grant |
76 | | - allow with input.user as user |
| 79 | + authorization_grant.allow with input.user as user |
77 | 80 | with input.client as client |
78 | 81 | with input.grant_type as "urn:ietf:params:oauth:grant-type:device_code" |
79 | 82 | with input.scope as "urn:matrix:org.matrix.msc2967.client:device:AAbbCCdd01" |
80 | 83 |
|
81 | | - # Not allowed for the client credentials grant |
82 | | - not allow with input.client as client |
| 84 | + # Not authorization_grant.allowed for the client credentials grant |
| 85 | + not authorization_grant.allow with input.client as client |
83 | 86 | with input.grant_type as "client_credentials" |
84 | 87 | with input.scope as "urn:matrix:org.matrix.msc2967.client:device:AAbbCCdd01" |
85 | 88 | } |
86 | 89 |
|
87 | | -test_synapse_admin_scopes { |
88 | | - allow with input.user as user |
89 | | - with input.client as client |
90 | | - with data.admin_users as ["john"] |
91 | | - with input.grant_type as "authorization_code" |
92 | | - with input.scope as "urn:synapse:admin:*" |
| 90 | +test_synapse_admin_scopes if { |
| 91 | + some grant_type in ["authorization_code", "urn:ietf:params:oauth:grant-type:device_code"] |
93 | 92 |
|
94 | | - allow with input.user as user |
| 93 | + authorization_grant.allow with input.user as user |
95 | 94 | with input.client as client |
96 | 95 | with data.admin_users as ["john"] |
97 | | - with input.grant_type as "urn:ietf:params:oauth:grant-type:device_code" |
98 | | - with input.scope as "urn:synapse:admin:*" |
99 | | - |
100 | | - not allow with input.user as user |
101 | | - with input.client as client |
102 | | - with data.admin_users as [] |
103 | | - with input.grant_type as "authorization_code" |
104 | | - with input.scope as "urn:synapse:admin:*" |
105 | | - |
106 | | - not allow with input.user as user |
107 | | - with input.client as client |
108 | | - with data.admin_users as [] |
109 | | - with input.grant_type as "urn:ietf:params:oauth:grant-type:device_code" |
| 96 | + with input.grant_type as grant_type |
110 | 97 | with input.scope as "urn:synapse:admin:*" |
111 | 98 |
|
112 | | - allow with input.user as user |
113 | | - with input.user.can_request_admin as true |
| 99 | + not authorization_grant.allow with input.user as user |
114 | 100 | with input.client as client |
115 | 101 | with data.admin_users as [] |
116 | | - with input.grant_type as "authorization_code" |
| 102 | + with input.grant_type as grant_type |
117 | 103 | with input.scope as "urn:synapse:admin:*" |
118 | 104 |
|
119 | | - allow with input.user as user |
| 105 | + authorization_grant.allow with input.user as user |
120 | 106 | with input.user.can_request_admin as true |
121 | 107 | with input.client as client |
122 | 108 | with data.admin_users as [] |
123 | | - with input.grant_type as "urn:ietf:params:oauth:grant-type:device_code" |
| 109 | + with input.grant_type as grant_type |
124 | 110 | with input.scope as "urn:synapse:admin:*" |
125 | 111 |
|
126 | | - not allow with input.user as user |
| 112 | + not authorization_grant.allow with input.user as user |
127 | 113 | with input.user.can_request_admin as false |
128 | 114 | with input.client as client |
129 | 115 | with data.admin_users as [] |
130 | | - with input.grant_type as "authorization_code" |
131 | | - with input.scope as "urn:synapse:admin:*" |
132 | | - |
133 | | - not allow with input.user as user |
134 | | - with input.user.can_request_admin as false |
135 | | - with input.client as client |
136 | | - with data.admin_users as [] |
137 | | - with input.grant_type as "urn:ietf:params:oauth:grant-type:device_code" |
| 116 | + with input.grant_type as grant_type |
138 | 117 | with input.scope as "urn:synapse:admin:*" |
139 | 118 | } |
140 | 119 |
|
141 | | -test_mas_scopes { |
142 | | - allow with input.user as user |
| 120 | +test_mas_scopes if { |
| 121 | + authorization_grant.allow with input.user as user |
143 | 122 | with input.client as client |
144 | 123 | with input.scope as "urn:mas:graphql:*" |
145 | 124 |
|
146 | | - allow with input.user as user |
| 125 | + authorization_grant.allow with input.user as user |
147 | 126 | with input.client as client |
148 | 127 | with data.admin_users as ["john"] |
149 | 128 | with input.grant_type as "authorization_code" |
150 | 129 | with input.scope as "urn:mas:admin" |
151 | 130 |
|
152 | | - not allow with input.user as user |
| 131 | + not authorization_grant.allow with input.user as user |
153 | 132 | with input.client as client |
154 | 133 | with data.admin_users as [] |
155 | 134 | with input.grant_type as "authorization_code" |
|
0 commit comments