Skip to content

Commit 4cfb729

Browse files
committed
test: prose tests up to aws
1 parent 0f73b04 commit 4cfb729

File tree

1 file changed

+118
-5
lines changed

1 file changed

+118
-5
lines changed

test/manual/mongodb_oidc.prose.test.ts

Lines changed: 118 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,12 @@ import path from 'node:path';
44
import { expect } from 'chai';
55

66
import {
7+
Collection,
78
MongoClient,
8-
MongoInvalidArgumentError,
99
OIDC_WORKFLOWS,
1010
OIDCClientInfo,
1111
OIDCMechanismServerStep1,
12-
OIDCRefreshFunction,
13-
OIDCRequestFunction,
14-
OIDCRequestTokenResult,
15-
Collection
12+
OIDCRequestTokenResult
1613
} from '../mongodb';
1714

1815
describe('MONGODB-OIDC', function () {
@@ -101,34 +98,99 @@ describe('MONGODB-OIDC', function () {
10198
});
10299

103100
describe('1.2 Single Principal Explicit Username', function () {
101+
before(function () {
102+
client = new MongoClient('mongodb://test_user@localhost/?authMechanism=MONGODB-OIDC', {
103+
authMechanismProperties: {
104+
REQUEST_TOKEN_CALLBACK: createRequestCallback()
105+
}
106+
});
107+
collection = client.db('test').collection('test');
108+
});
109+
104110
// Clear the cache.
105111
// Create a request callback that returns a valid token.
106112
// Create a client with a url of the form mongodb://test_user1@localhost/?authMechanism=MONGODB-OIDC and the OIDC request callback.
107113
// Perform a find operation that succeeds.
108114
// Close the client.
115+
it('successfully authenticates', function () {
116+
expect(async () => {
117+
await collection.findOne();
118+
}).to.not.throw;
119+
});
109120
});
110121

111122
describe('1.3 Multiple Principal User 1', function () {
123+
before(function () {
124+
client = new MongoClient(
125+
'mongodb://test_user1@localhost:27018/?authMechanism=MONGODB-OIDC&directConnection=true&readPreference=secondaryPreferred',
126+
{
127+
authMechanismProperties: {
128+
REQUEST_TOKEN_CALLBACK: createRequestCallback()
129+
}
130+
}
131+
);
132+
collection = client.db('test').collection('test');
133+
});
134+
112135
// Clear the cache.
113136
// Create a request callback that returns a valid token.
114137
// Create a client with a url of the form mongodb://test_user1@localhost:27018/?authMechanism=MONGODB-OIDC&directConnection=true&readPreference=secondaryPreferred and a valid OIDC request callback.
115138
// Perform a find operation that succeeds.
116139
// Close the client.
140+
it('successfully authenticates', function () {
141+
expect(async () => {
142+
await collection.findOne();
143+
}).to.not.throw;
144+
});
117145
});
118146

119147
describe('1.4 Multiple Principal User 2', function () {
148+
before(function () {
149+
client = new MongoClient(
150+
'mongodb://test_user2@localhost:27018/?authMechanism=MONGODB-OIDC&directConnection=true&readPreference=secondaryPreferred',
151+
{
152+
authMechanismProperties: {
153+
REQUEST_TOKEN_CALLBACK: createRequestCallback()
154+
}
155+
}
156+
);
157+
collection = client.db('test').collection('test');
158+
});
159+
120160
// Clear the cache.
121161
// Create a request callback that reads in the generated test_user2 token file.
122162
// Create a client with a url of the form mongodb://test_user2@localhost:27018/?authMechanism=MONGODB-OIDC&directConnection=true&readPreference=secondaryPreferred and a valid OIDC request callback.
123163
// Perform a find operation that succeeds.
124164
// Close the client.
165+
it('successfully authenticates', function () {
166+
expect(async () => {
167+
await collection.findOne();
168+
}).to.not.throw;
169+
});
125170
});
126171

127172
describe('1.5 Multiple Principal No User', function () {
173+
before(function () {
174+
client = new MongoClient(
175+
'mongodb://localhost:27018/?authMechanism=MONGODB-OIDC&directConnection=true&readPreference=secondaryPreferred',
176+
{
177+
authMechanismProperties: {
178+
REQUEST_TOKEN_CALLBACK: createRequestCallback()
179+
}
180+
}
181+
);
182+
collection = client.db('test').collection('test');
183+
});
184+
128185
// Clear the cache.
129186
// Create a client with a url of the form mongodb://localhost:27018/?authMechanism=MONGODB-OIDC&directConnection=true&readPreference=secondaryPreferred and a valid OIDC request callback.
130187
// Assert that a find operation fails.
131188
// Close the client.
189+
it('fails authentication', function () {
190+
expect(async () => {
191+
await collection.findOne();
192+
}).to.throw;
193+
});
132194
});
133195

134196
describe('1.6 Allowed Hosts Blocked', function () {
@@ -144,24 +206,75 @@ describe('MONGODB-OIDC', function () {
144206
});
145207

146208
describe('2. AWS Automatic Auth', function () {
209+
let client: MongoClient;
210+
let collection: Collection;
211+
212+
afterEach(async function () {
213+
await client?.close();
214+
});
215+
147216
describe('2.1 Single Principal', function () {
217+
before(function () {
218+
client = new MongoClient(
219+
'mongodb://localhost/?authMechanism=MONGODB-OIDC&authMechanismProperties=PROVIDER_NAME:aws'
220+
);
221+
collection = client.db('test').collection('test');
222+
});
223+
148224
// Create a client with a url of the form mongodb://localhost/?authMechanism=MONGODB-OIDC&authMechanismProperties=PROVIDER_NAME:aws.
149225
// Perform a find operation that succeeds.
150226
// Close the client.
227+
it('successfully authenticates', function () {
228+
expect(async () => {
229+
await collection.findOne();
230+
}).to.not.throw;
231+
});
151232
});
152233

153234
describe('2.2 Multiple Principal User 1', function () {
235+
before(function () {
236+
client = new MongoClient(
237+
'mongodb://localhost:27018/?authMechanism=MONGODB-OIDC&authMechanismProperties=PROVIDER_NAME:aws&directConnection=true&readPreference=secondaryPreferred'
238+
);
239+
collection = client.db('test').collection('test');
240+
});
241+
154242
// Create a client with a url of the form mongodb://localhost:27018/?authMechanism=MONGODB-OIDC&authMechanismProperties=PROVIDER_NAME:aws&directConnection=true&readPreference=secondaryPreferred.
155243
// Perform a find operation that succeeds.
156244
// Close the client.
245+
it('successfully authenticates', function () {
246+
expect(async () => {
247+
await collection.findOne();
248+
}).to.not.throw;
249+
});
157250
});
158251

159252
describe('2.3 Multiple Principal User 2', function () {
253+
let tokenFile;
254+
255+
before(function () {
256+
tokenFile = process.env.AWS_WEB_IDENTITY_TOKEN_FILE;
257+
process.env.AWS_WEB_IDENTITY_TOKEN_FILE = path.join(process.env.OIDC_TOKEN_DIR, 'test2');
258+
client = new MongoClient(
259+
'mongodb://localhost:27018/?authMechanism=MONGODB-OIDC&authMechanismProperties=PROVIDER_NAME:aws&directConnection=true&readPreference=secondaryPreferred'
260+
);
261+
collection = client.db('test').collection('test');
262+
});
263+
264+
after(function () {
265+
process.env.AWS_WEB_IDENTITY_TOKEN_FILE = tokenFile;
266+
});
267+
160268
// Set the AWS_WEB_IDENTITY_TOKEN_FILE environment variable to the location of valid test_user2 credentials.
161269
// Create a client with a url of the form mongodb://localhost:27018/?authMechanism=MONGODB-OIDC&authMechanismProperties=PROVIDER_NAME:aws&directConnection=true&readPreference=secondaryPreferred.
162270
// Perform a find operation that succeeds.
163271
// Close the client.
164272
// Restore the AWS_WEB_IDENTITY_TOKEN_FILE environment variable to the location of valid test_user2 credentials.
273+
it('successfully authenticates', function () {
274+
expect(async () => {
275+
await collection.findOne();
276+
}).to.not.throw;
277+
});
165278
});
166279

167280
describe('2.4 Allowed Hosts Ignored', function () {

0 commit comments

Comments
 (0)