You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/development/contributing.md
+6Lines changed: 6 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -72,6 +72,7 @@ Make sure your code adheres to our Rust and TypeScript code style by running:
72
72
73
73
-`cargo +nightly fmt` (with the nightly toolchain installed)
74
74
-`npm run format` in the `frontend` directory
75
+
-`make fmt` in the `policies` directory (if changed)
75
76
76
77
When updating SQL queries in the `crates/storage-pg/` crate, you may need to update the `sqlx` introspection data. To do this, make sure to install `cargo-sqlx` (`cargo install sqlx-cli`) and:
77
78
@@ -86,13 +87,18 @@ While you're developing and before submitting a patch, you'll want to test your
86
87
87
88
- Run `cargo clippy --workspace` to lint the Rust code.
88
89
- Run `npm run lint` in the `frontend` directory to lint the frontend code.
90
+
- Run `make fmt` and `make lint` in the `policies` directory to format and lint the included policy.
89
91
90
92
### Run the tests
91
93
92
94
If you haven't already, install [Cargo-Nextest](https://nexte.st/docs/installation/pre-built-binaries/).
93
95
94
96
- Run the tests to the backend by running `cargo nextest run --workspace`. This requires a connection to a PostgreSQL database, set via the `DATABASE_URL` environment variable.
95
97
- Run the tests to the frontend by running `npm run test` in the `frontend` directory.
98
+
- To run the tests for the included policy, change to the `policies` directory and run one of:
99
+
-`make test` (needs Open Policy Agent installed)
100
+
-`make PODMAN=1 test` (runs inside a container; needs Podman installed)
101
+
-`make DOCKER=1 test` (runs inside a container; needs Docker installed)
Copy file name to clipboardExpand all lines: policies/authorization_grant/authorization_grant_test.rego
+26-12Lines changed: 26 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -78,70 +78,84 @@ test_unstable_device_scopes if {
78
78
authorization_grant.allow with input.user as user
79
79
with input.client as client
80
80
with input.grant_type as "authorization_code"
81
-
with input.scope as "urn:matrix:org.matrix.msc2967.client:device:AAbbCCdd01"
81
+
with input.scope as "urn:matrix:org.matrix.msc2967.client:api:* urn:matrix:org.matrix.msc2967.client:device:AAbbCCdd01"
82
82
83
83
authorization_grant.allow with input.user as user
84
84
with input.client as client
85
85
with input.grant_type as "authorization_code"
86
-
with input.scope as "urn:matrix:org.matrix.msc2967.client:device:AAbbCCdd01-asdasdsa1-2313"
86
+
with input.scope as "urn:matrix:org.matrix.msc2967.client:api:* urn:matrix:org.matrix.msc2967.client:device:AAbbCCdd01-asdasdsa1-2313"
87
87
88
88
# Too short
89
89
not authorization_grant.allow with input.user as user
90
90
with input.client as client
91
91
with input.grant_type as "authorization_code"
92
-
with input.scope as "urn:matrix:org.matrix.msc2967.client:device:abcd"
92
+
with input.scope as "urn:matrix:org.matrix.msc2967.client:api:* urn:matrix:org.matrix.msc2967.client:device:abcd"
93
93
94
94
# Multiple device scope
95
95
not authorization_grant.allow with input.user as user
96
96
with input.client as client
97
97
with input.grant_type as "authorization_code"
98
-
with input.scope as "urn:matrix:org.matrix.msc2967.client:device:AAbbCCdd01 urn:matrix:org.matrix.msc2967.client:device:AAbbCCdd02"
98
+
with input.scope as "urn:matrix:org.matrix.msc2967.client:api:* urn:matrix:org.matrix.msc2967.client:device:AAbbCCdd01 urn:matrix:org.matrix.msc2967.client:device:AAbbCCdd02"
99
99
100
100
# Allowed with the device code grant
101
101
authorization_grant.allow with input.user as user
102
102
with input.client as client
103
103
with input.grant_type as "urn:ietf:params:oauth:grant-type:device_code"
104
-
with input.scope as "urn:matrix:org.matrix.msc2967.client:device:AAbbCCdd01"
104
+
with input.scope as "urn:matrix:org.matrix.msc2967.client:api:* urn:matrix:org.matrix.msc2967.client:device:AAbbCCdd01"
105
105
106
106
# Not authorization_grant.allowed for the client credentials grant
107
107
not authorization_grant.allow with input.client as client
108
108
with input.grant_type as "client_credentials"
109
-
with input.scope as "urn:matrix:org.matrix.msc2967.client:device:AAbbCCdd01"
109
+
with input.scope as "urn:matrix:org.matrix.msc2967.client:api:* urn:matrix:org.matrix.msc2967.client:device:AAbbCCdd01"
110
110
}
111
111
112
112
test_stable_device_scopes if {
113
113
authorization_grant.allow with input.user as user
114
114
with input.client as client
115
115
with input.grant_type as "authorization_code"
116
-
with input.scope as "urn:matrix:client:device:AAbbCCdd01"
116
+
with input.scope as "urn:matrix:client:api:* urn:matrix:client:device:AAbbCCdd01"
117
117
118
118
authorization_grant.allow with input.user as user
119
119
with input.client as client
120
120
with input.grant_type as "authorization_code"
121
-
with input.scope as "urn:matrix:client:device:AAbbCCdd01-asdasdsa1-2313"
121
+
with input.scope as "urn:matrix:client:api:* urn:matrix:client:device:AAbbCCdd01-asdasdsa1-2313"
122
122
123
123
# Too short
124
124
not authorization_grant.allow with input.user as user
125
125
with input.client as client
126
126
with input.grant_type as "authorization_code"
127
-
with input.scope as "urn:matrix:client:device:abcd"
127
+
with input.scope as "urn:matrix:client:api:* urn:matrix:client:device:abcd"
128
128
129
129
# Multiple device scope
130
130
not authorization_grant.allow with input.user as user
131
131
with input.client as client
132
132
with input.grant_type as "authorization_code"
133
-
with input.scope as "urn:matrix:client:device:AAbbCCdd01 urn:matrix:client:device:AAbbCCdd02"
133
+
with input.scope as "urn:matrix:client:api:* urn:matrix:client:device:AAbbCCdd01 urn:matrix:client:device:AAbbCCdd02"
134
134
135
135
# Allowed with the device code grant
136
136
authorization_grant.allow with input.user as user
137
137
with input.client as client
138
138
with input.grant_type as "urn:ietf:params:oauth:grant-type:device_code"
139
-
with input.scope as "urn:matrix:client:device:AAbbCCdd01"
139
+
with input.scope as "urn:matrix:client:api:* urn:matrix:client:device:AAbbCCdd01"
140
140
141
141
# Not authorization_grant.allowed for the client credentials grant
142
142
not authorization_grant.allow with input.client as client
143
143
with input.grant_type as "client_credentials"
144
-
with input.scope as "urn:matrix:client:device:AAbbCCdd01"
144
+
with input.scope as "urn:matrix:client:api:* urn:matrix:client:device:AAbbCCdd01"
145
+
}
146
+
147
+
test_device_scope_only_with_cs_api_scope if {
148
+
not authorization_grant.allow with input.user as user
149
+
with input.client as client
150
+
with input.grant_type as "authorization_code"
151
+
# Requested a device scope but no C-S API scope:
152
+
with input.scope as "urn:matrix:client:device:AAbbCCdd01"
153
+
154
+
not authorization_grant.allow with input.user as user
155
+
with input.client as client
156
+
with input.grant_type as "authorization_code"
157
+
# Requested a device scope but no C-S API scope:
158
+
with input.scope as "urn:matrix:org.matrix.msc2967.client:device:AAbbCCdd01"
0 commit comments