2
2
3
3
## Local Testing
4
4
5
- To test locally, use the
6
- [ oidc_get_tokens.sh] ( https://github.com/mongodb-labs/drivers-evergreen-tools/blob/master/.evergreen/auth_oidc/oidc_get_tokens.sh )
7
- script from [ drivers-evergreen-tools] ( https://github.com/mongodb-labs/drivers-evergreen-tools/ ) to download a set of
8
- OIDC tokens, including ` test_user1 ` and ` test_user1_expires ` . You first have to install the AWS CLI and login using the
9
- SSO flow.
10
-
11
- For example, if the selected AWS profile ID is "drivers-test", run:
12
-
13
- ``` shell
14
- aws configure sso
15
- export OIDC_TOKEN_DIR=/tmp/tokens
16
- AWS_PROFILE=" drivers-test" oidc_get_tokens.sh
17
- OIDC_TOKEN_FILE=" $OIDC_TOKEN_DIR /test_user1" /my/test/command
18
- ```
5
+ See the detailed instructions in
6
+ [ drivers-evergreen-tools] ( https://github.com/mongodb-labs/drivers-evergreen-tools/blob/master/.evergreen/auth_oidc/README.md )
7
+ for how to set up your environment for OIDC testing.
19
8
20
9
______________________________________________________________________
21
10
@@ -36,25 +25,25 @@ Drivers MUST run the prose tests in all supported OIDC environments.
36
25
> For test cases that create fail points, drivers MUST either use a unique ` appName ` or explicitly remove the fail point
37
26
> callback to prevent interaction between test cases.
38
27
39
- Note that typically the preconfigured Atlas Dev clusters are used for testing, in Evergreen and locally. The URIs can be
40
- fetched from the ` drivers/oidc ` Secrets vault, see
41
- [ vault instructions ] ( https://wiki.corp.mongodb.com/display/DRIVERS/Using+AWS+Secrets+Manager+to+Store+Testing+Secrets ) .
42
- Use ` OIDC_ATLAS_URI_SINGLE ` for the ` MONGODB_URI ` . If using local servers is preferred, using the
43
- [ Local Testing ] ( https://github.com/mongodb-labs/drivers-evergreen-tools/blob/master/.evergreen/auth_oidc/README.md#local-testing )
44
- method, use ` mongodb://localhost/?authMechanism=MONGODB-OIDC ` for ` MONGODB_URI ` .
28
+ After setting up your OIDC
29
+ [ environment ] ( https://github.com/mongodb-labs/ drivers-evergreen-tools/blob/master/.evergreen/auth_oidc/README.md ) ,
30
+ source the ` secrets-export.sh ` file and use the associated env variables in your tests .
31
+
32
+ An OIDC configured client MUST set the appropriate ` ENVIRONMENT ` auth mechanism property and include a callback that
33
+ gets the appropriate token for the given environment .
45
34
46
35
### Callback Authentication
47
36
48
37
** 1.1 Callback is called during authentication**
49
38
50
- - Create a ` MongoClient ` configured with an OIDC callback that implements the ` ENVIRONMENT:test ` logic .
39
+ - Create an OIDC configured client .
51
40
- Perform a ` find ` operation that succeeds.
52
41
- Assert that the callback was called 1 time.
53
42
- Close the client.
54
43
55
44
** 1.2 Callback is called once for multiple connections**
56
45
57
- - Create a ` MongoClient ` configured with an OIDC callback that implements the ` ENVIRONMENT:test ` logic .
46
+ - Create an OIDC configured client .
58
47
- Start 10 threads and run 100 ` find ` operations in each thread that all succeed.
59
48
- Assert that the callback was called 1 time.
60
49
- Close the client.
@@ -63,49 +52,49 @@ method, use `mongodb://localhost/?authMechanism=MONGODB-OIDC` for `MONGODB_URI`.
63
52
64
53
** 2.1 Valid Callback Inputs**
65
54
66
- - Create a ` MongoClient ` configured with an OIDC callback that validates its inputs and returns a valid access token.
55
+ - Create an OIDC configured client with an OIDC callback that validates its inputs and returns a valid access token.
67
56
- Perform a ` find ` operation that succeeds.
68
57
- Assert that the OIDC callback was called with the appropriate inputs, including the timeout parameter if possible.
69
58
- Close the client.
70
59
71
60
** 2.2 OIDC Callback Returns Null**
72
61
73
- - Create a ` MongoClient ` configured with an OIDC callback that returns ` null ` .
62
+ - Create an OIDC configured client with an OIDC callback that returns ` null ` .
74
63
- Perform a ` find ` operation that fails.
75
64
- Close the client.
76
65
77
66
** 2.3 OIDC Callback Returns Missing Data**
78
67
79
- - Create a ` MongoClient ` configured with an OIDC callback that returns data not conforming to the ` OIDCCredential ` with
68
+ - Create an OIDC configured client with an OIDC callback that returns data not conforming to the ` OIDCCredential ` with
80
69
missing fields.
81
70
- Perform a ` find ` operation that fails.
82
71
- Close the client.
83
72
84
73
** 2.4 Invalid Client Configuration with Callback**
85
74
86
- - Create a ` MongoClient ` configured with an OIDC callback and auth mechanism property ` ENVIRONMENT:test ` .
75
+ - Create an OIDC configured client with an OIDC callback and auth mechanism property ` ENVIRONMENT:test ` .
87
76
- Assert it returns a client configuration error.
88
77
89
78
### (3) Authentication Failure
90
79
91
80
** 3.1 Authentication failure with cached tokens fetch a new token and retry auth**
92
81
93
- - Create a ` MongoClient ` configured with an OIDC callback that implements the ` ENVIRONMENT:test ` logic .
82
+ - Create an OIDC configured client .
94
83
- Poison the * Client Cache* with an invalid access token.
95
84
- Perform a ` find ` operation that succeeds.
96
85
- Assert that the callback was called 1 time.
97
86
- Close the client.
98
87
99
88
** 3.2 Authentication failures without cached tokens return an error**
100
89
101
- - Create a ` MongoClient ` configured with an OIDC callback that always returns invalid access tokens.
90
+ - Create an OIDC configured client with an OIDC callback that always returns invalid access tokens.
102
91
- Perform a ` find ` operation that fails.
103
92
- Assert that the callback was called 1 time.
104
93
- Close the client.
105
94
106
95
### (4) Reauthentication
107
96
108
- - Create a ` MongoClient ` configured with an OIDC callback that implements the ` ENVIRONMENT:test ` logic .
97
+ - Create an OIDC configured client .
109
98
- Set a fail point for ` find ` commands of the form:
110
99
111
100
``` javascript
@@ -130,18 +119,18 @@ method, use `mongodb://localhost/?authMechanism=MONGODB-OIDC` for `MONGODB_URI`.
130
119
## (5) Azure Tests
131
120
132
121
Drivers MUST only run the Azure tests when testing on an Azure VM. See instructions in
133
- [ Drivers Evergreen Tools] ( https://github.com/mongodb-labs/drivers-evergreen-tools/tree /master/.evergreen/auth_oidc/azure#azure-oidc-testing )
122
+ [ Drivers Evergreen Tools] ( https://github.com/mongodb-labs/drivers-evergreen-tools/blob /master/.evergreen/auth_oidc/azure/README.md )
134
123
for test setup.
135
124
136
125
# 5.1 Azure With No Username
137
126
138
- - Create a ` MongoClient ` configured with ` ENVIRONMENT:Azure ` and a valid ` TOKEN_RESOURCE ` and no username.
127
+ - Create an OIDC configured client with ` ENVIRONMENT:azure ` and a valid ` TOKEN_RESOURCE ` and no username.
139
128
- Perform a ` find ` operation that succeeds.
140
129
- Close the client.
141
130
142
131
# 5.2 Azure with Bad Usernam
143
132
144
- - Create a ` MongoClient ` configured with ` ENVIRONMENT:Azure ` and a valid ` TOKEN_RESOURCE ` and a username of ` "bad" ` .
133
+ - Create an OIDC configured client with ` ENVIRONMENT:azure ` and a valid ` TOKEN_RESOURCE ` and a username of ` "bad" ` .
145
134
- Perform a ` find ` operation that fails.
146
135
- Close the client.
147
136
@@ -152,71 +141,58 @@ ______________________________________________________________________
152
141
Drivers that support the [ Human Authentication Flow] ( ../auth.md#human-authentication-flow ) MUST implement all prose
153
142
tests in this section. Unless otherwise noted, all ` MongoClient ` instances MUST be configured with ` retryReads=false ` .
154
143
155
- The human workflow tests MUST only be run when testing in the default environment described beflow .
144
+ The human workflow tests MUST only be run when in ` ENVIRONMENT:test ` .
156
145
157
146
> [ !NOTE]
158
147
> For test cases that create fail points, drivers MUST either use a unique ` appName ` or explicitly remove the fail point
159
148
> after the test to prevent interaction between test cases.
160
149
161
150
Drivers MUST be able to authenticate against a server configured with either one or two configured identity providers.
162
151
163
- Note that typically the preconfigured Atlas Dev clusters are used for testing, in Evergreen and locally. The URIs can be
164
- fetched from the ` drivers/oidc ` Secrets vault, see
165
- [ vault instructions] ( https://wiki.corp.mongodb.com/display/DRIVERS/Using+AWS+Secrets+Manager+to+Store+Testing+Secrets ) .
166
- Use ` OIDC_ATLAS_URI_SINGLE ` for ` MONGODB_URI_SINGLE ` and ` OIDC_ATLAS_URI_MULTI ` for ` MONGODB_URI_MULTI ` . Currently the
167
- ` OIDC_ATLAS_URI_MULTI ` cluster does not work correctly with fail points, so all prose tests that use fail points SHOULD
168
- use ` OIDC_ATLAS_URI_SINGLE ` .
152
+ Unless otherwise specified, use ` MONGODB_URI_SINGLE ` and the ` test_user1 ` token in the ` OIDC_TOKEN_DIR ` as the
153
+ "access_token", and a dummy "refresh_token" for all tests.
169
154
170
- If using local servers is preferred, using the
171
- [ Local Testing] ( https://github.com/mongodb-labs/drivers-evergreen-tools/blob/master/.evergreen/auth_oidc/README.md#local-testing )
172
- method, use ` mongodb://localhost/?authMechanism=MONGODB-OIDC ` for ` MONGODB_URI_SINGLE ` and
173
- ` mongodb://localhost:27018/?authMechanism=MONGODB-OIDC&directConnection=true&readPreference=secondaryPreferred ` for
174
- ` MONGODB_URI_MULTI ` because the other server is a secondary on a replica set, on port ` 27018 ` .
175
-
176
- The default OIDC client used in the tests is configured with ` MONGODB_URI_SINGLE ` and a valid human callback handler
177
- that returns the ` test_user1 ` local token in ` OIDC_TOKEN_DIR ` as the "access_token", and a dummy "refresh_token".
155
+ When using an explicit username for the client, we use the token name and the domain name given by ` OIDC_DOMAIN ` , e.g.
156
+ ` test_user1@${OIDC_DOMAIN} ` .
178
157
179
158
### (1) OIDC Human Callback Authentication
180
159
181
160
Drivers MUST be able to authenticate using OIDC callback(s) when there is one principal configured.
182
161
183
162
** 1.1 Single Principal Implicit Username**
184
163
185
- - Create default OIDC client with ` authMechanism=MONGODB-OIDC ` .
164
+ - Create an OIDC configured client .
186
165
- Perform a ` find ` operation that succeeds.
187
166
- Close the client.
188
167
189
168
** 1.2 Single Principal Explicit Username**
190
169
191
- - Create a client with ` MONGODB_URI_SINGLE ` , a username of ` test_user1 ` , ` authMechanism=MONGODB-OIDC ` , and the OIDC
192
- human callback.
170
+ - Create an OIDC configured client with ` MONGODB_URI_SINGLE ` and a username of ` test_user1@${OIDC_DOMAIN} ` .
193
171
- Perform a ` find ` operation that succeeds.
194
172
- Close the client.
195
173
196
174
** 1.3 Multiple Principal User 1**
197
175
198
- - Create a client with ` MONGODB_URI_MULTI ` , a username of ` test_user1 ` , ` authMechanism=MONGODB-OIDC ` , and the OIDC human
199
- callback.
176
+ - Create an OIDC configured client with ` MONGODB_URI_MULTI ` and username of ` test_user1@${OIDC_DOMAIN} ` .
200
177
- Perform a ` find ` operation that succeeds.
201
178
- Close the client.
202
179
203
180
** 1.4 Multiple Principal User 2**
204
181
205
- - Create a human callback that reads in the generated ` test_user2 ` token file.
206
- - Create a client with ` MONGODB_URI_MULTI ` , a username of ` test_user2 ` , ` authMechanism=MONGODB-OIDC ` , and the OIDC human
207
- callback.
182
+ - Create an OIDC configured client with ` MONGODB_URI_MULTI ` and username of ` test_user2@${OIDC_DOMAIN} ` . that reads the
183
+ ` test_user2 ` token file.
208
184
- Perform a ` find ` operation that succeeds.
209
185
- Close the client.
210
186
211
187
** 1.5 Multiple Principal No User**
212
188
213
- - Create a client with ` MONGODB_URI_MULTI ` , no username, ` authMechanism=MONGODB-OIDC ` , and the OIDC human callback .
189
+ - Create an OIDC configured client with ` MONGODB_URI_MULTI ` and no username .
214
190
- Assert that a ` find ` operation fails.
215
191
- Close the client.
216
192
217
193
** 1.6 Allowed Hosts Blocked**
218
194
219
- - Create a default OIDC client, with an ` ALLOWED_HOSTS ` that is an empty list.
195
+ - Create an OIDC configured client with an ` ALLOWED_HOSTS ` that is an empty list.
220
196
- Assert that a ` find ` operation fails with a client-side error.
221
197
- Close the client.
222
198
- Create a client that uses the URL ` mongodb://localhost/?authMechanism=MONGODB-OIDC&ignored=example.com ` , a human
@@ -228,23 +204,23 @@ Drivers MUST be able to authenticate using OIDC callback(s) when there is one pr
228
204
229
205
** 2.1 Valid Callback Inputs**
230
206
231
- - Create a ` MongoClient ` with a human callback that validates its inputs and returns a valid access token.
207
+ - Create an OIDC configured client with a human callback that validates its inputs and returns a valid access token.
232
208
- Perform a ` find ` operation that succeeds. Verify that the human callback was called with the appropriate inputs,
233
209
including the timeout parameter if possible.
234
210
- Close the client.
235
211
236
212
** 2.3 Human Callback Returns Missing Data**
237
213
238
- - Create a ` MongoClient ` with a human callback that returns data not conforming to the ` OIDCCredential ` with missing
239
- fields.
214
+ - Create an OIDC configured client with a human callback that returns data not conforming to the ` OIDCCredential ` with
215
+ missing fields.
240
216
- Perform a ` find ` operation that fails.
241
217
- Close the client.
242
218
243
219
### (3) Speculative Authentication
244
220
245
221
** 3.1 Uses speculative authentication if there is a cached token**
246
222
247
- - Create a ` MongoClient ` with a human callback that returns a valid token.
223
+ - Create an OIDC configured client with a human callback that returns a valid token.
248
224
- Set a fail point for ` find ` commands of the form:
249
225
250
226
``` javascript
@@ -283,7 +259,7 @@ Drivers MUST be able to authenticate using OIDC callback(s) when there is one pr
283
259
284
260
** 3.2 Does not use speculative authentication if there is no cached token**
285
261
286
- - Create a ` MongoClient ` with a human callback that returns a valid token.
262
+ - Create an OIDC configured client with a human callback that returns a valid token.
287
263
- Set a fail point for ` saslStart ` commands of the form:
288
264
289
265
``` javascript
@@ -306,7 +282,7 @@ Drivers MUST be able to authenticate using OIDC callback(s) when there is one pr
306
282
307
283
** 4.1 Succeeds**
308
284
309
- - Create a default OIDC client and add an event listener. The following assumes that the driver does not emit
285
+ - Create an OIDC configured client and add an event listener. The following assumes that the driver does not emit
310
286
` saslStart ` or ` saslContinue ` events. If the driver does emit those events, ignore/filter them for the purposes of
311
287
this test.
312
288
- Perform a ` find ` operation that succeeds.
@@ -339,7 +315,7 @@ Drivers MUST be able to authenticate using OIDC callback(s) when there is one pr
339
315
340
316
** 4.2 Succeeds no refresh**
341
317
342
- - Create a default OIDC client with a human callback that does not return a refresh token.
318
+ - Create an OIDC configured client with a human callback that does not return a refresh token.
343
319
- Perform a ` find ` operation that succeeds.
344
320
- Assert that the human callback has been called once.
345
321
- Force a reauthenication using a fail point of the form:
@@ -365,7 +341,7 @@ Drivers MUST be able to authenticate using OIDC callback(s) when there is one pr
365
341
366
342
** 4.3 Succeeds after refresh fails**
367
343
368
- - Create a default OIDC client.
344
+ - Create an OIDC configured client.
369
345
- Perform a ` find ` operation that succeeds.
370
346
- Assert that the human callback has been called once.
371
347
- Force a reauthenication using a fail point of the form:
@@ -391,7 +367,7 @@ Drivers MUST be able to authenticate using OIDC callback(s) when there is one pr
391
367
392
368
** 4.4 Fails**
393
369
394
- - Create a default OIDC client.
370
+ - Create an OIDC configured client.
395
371
- Perform a find operation that succeeds (to force a speculative auth).
396
372
- Assert that the human callback has been called once.
397
373
- Force a reauthenication using a failCommand of the form:
0 commit comments