forked from mongodb/node-mongodb-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmongodb_oidc_gcp.prose.06.test.ts
More file actions
55 lines (46 loc) · 1.89 KB
/
mongodb_oidc_gcp.prose.06.test.ts
File metadata and controls
55 lines (46 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { expect } from 'chai';
import * as process from 'process';
import { type Collection, MongoClient, type MongoClientOptions } from '../../../src';
const DEFAULT_URI = 'mongodb://127.0.0.1:27017';
describe('OIDC Auth Spec GCP Tests', function () {
// Note there is no spec or tests for GCP yet, these are 2 scenarios based on the
// drivers tools scripts available.
describe('6. GCP Tests', function () {
let client: MongoClient;
let collection: Collection;
beforeEach(function () {
if (!this.configuration.isOIDC(process.env.MONGODB_URI_SINGLE, 'gcp')) {
this.skipReason = 'GCP OIDC prose tests require a GCP OIDC environment.';
this.skip();
}
});
afterEach(async function () {
await client?.close();
});
describe('6.1 GCP With Valid Token Resource', function () {
beforeEach(function () {
const options: MongoClientOptions = {};
if (process.env.GCPOIDC_AUDIENCE) {
options.authMechanismProperties = { TOKEN_RESOURCE: process.env.GCPOIDC_AUDIENCE };
}
client = new MongoClient(process.env.MONGODB_URI_SINGLE ?? DEFAULT_URI, options);
collection = client.db('test').collection('test');
});
it('successfully authenticates', async function () {
const result = await collection.findOne();
expect(result).to.not.be.null;
});
});
describe('6.2 GCP With Invalid Token Resource', function () {
beforeEach(function () {
const options: MongoClientOptions = { authMechanismProperties: { TOKEN_RESOURCE: 'bad' } };
client = new MongoClient(process.env.MONGODB_URI_SINGLE ?? DEFAULT_URI, options);
collection = client.db('test').collection('test');
});
it('successfully authenticates', async function () {
const result = await collection.findOne();
expect(result).to.not.be.null;
});
});
});
});