Skip to content

Commit fa71260

Browse files
committed
test: update per suggestions
1 parent ac2b5cc commit fa71260

File tree

10 files changed

+44
-46
lines changed

10 files changed

+44
-46
lines changed

.evergreen/ci_matrix_constants.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const DEFAULT_OS = 'rhel80-large';
1717
const WINDOWS_OS = 'windows-vsCurrent-large';
1818
const MACOS_OS = 'macos-1100';
1919
const UBUNTU_OS = 'ubuntu1804-large';
20+
const UBUNTU_20_OS = 'ubuntu1004-small'
2021
const DEBIAN_OS = 'debian11-small';
2122

2223
module.exports = {
@@ -32,5 +33,6 @@ module.exports = {
3233
WINDOWS_OS,
3334
MACOS_OS,
3435
UBUNTU_OS,
36+
UBUNTU_20_OS,
3537
DEBIAN_OS
3638
};

.evergreen/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4030,7 +4030,7 @@ buildvariants:
40304030
- test-azurekms-fail-task
40314031
- name: ubuntu20-test-azure-oidc
40324032
display_name: Azure OIDC
4033-
run_on: ubuntu2004-small
4033+
run_on: ubuntu1004-small
40344034
batchtime: 20160
40354035
tasks:
40364036
- testazureoidc_task_group

.evergreen/generate_evergreen_tasks.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const {
1616
WINDOWS_OS,
1717
MACOS_OS,
1818
UBUNTU_OS,
19+
UBUNTU_20_OS,
1920
DEBIAN_OS
2021
} = require('./ci_matrix_constants');
2122

@@ -757,7 +758,7 @@ BUILD_VARIANTS.push({
757758
BUILD_VARIANTS.push({
758759
name: 'ubuntu20-test-azure-oidc',
759760
display_name: 'Azure OIDC',
760-
run_on: 'ubuntu2004-small',
761+
run_on: UBUNTU_20_OS,
761762
batchtime: 20160,
762763
tasks: ['testazureoidc_task_group']
763764
});

src/cmap/auth/mongodb_oidc/azure_service_workflow.ts

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,7 @@ export interface AzureAccessToken {
3434
* @internal
3535
*/
3636
export class AzureServiceWorkflow extends ServiceWorkflow {
37-
cache: AzureTokenCache;
38-
39-
/**
40-
* Instantiate the Azure service workflow.
41-
*/
42-
constructor() {
43-
super();
44-
this.cache = new AzureTokenCache();
45-
}
37+
cache = new AzureTokenCache();
4638

4739
/**
4840
* Get the token from the environment.
@@ -59,7 +51,7 @@ export class AzureServiceWorkflow extends ServiceWorkflow {
5951
} else {
6052
this.cache.deleteEntry(tokenAudience);
6153
const response = await getAzureTokenData(tokenAudience);
62-
if (isEndpointResultInvalid(response)) {
54+
if (!isEndpointResultValid(response)) {
6355
throw new MongoAzureError(ENDPOINT_RESULT_ERROR);
6456
}
6557
this.cache.addEntry(tokenAudience, response);
@@ -82,11 +74,13 @@ async function getAzureTokenData(tokenAudience: string): Promise<AzureAccessToke
8274
}
8375

8476
/**
85-
* Determines if a result returned from the endpoint is invalid.
86-
* This means the result is nullish, doesn't contain the access_token required field,
87-
* the expires_in required field.
77+
* Determines if a result returned from the endpoint is valid.
78+
* This means the result is not nullish, contains the access_token required field
79+
* and the expires_in required field.
8880
*/
89-
function isEndpointResultInvalid(token: unknown): boolean {
90-
if (token == null || typeof token !== 'object') return true;
91-
return !('access_token' in token) && !('expires_in' in token);
81+
function isEndpointResultValid(
82+
token: unknown
83+
): token is { access_token: unknown; expires_in: unknown } {
84+
if (token == null || typeof token !== 'object') return false;
85+
return 'access_token' in token && 'expires_in' in token;
9286
}

src/cmap/auth/mongodb_oidc/azure_token_cache.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { AzureAccessToken } from './azure_service_workflow';
2-
import { AbstractCache, ExpiringCacheEntry } from './cache';
2+
import { Cache, ExpiringCacheEntry } from './cache';
33

44
/** @internal */
55
export class AzureTokenEntry extends ExpiringCacheEntry {
@@ -18,7 +18,7 @@ export class AzureTokenEntry extends ExpiringCacheEntry {
1818
* A cache of access tokens from Azure.
1919
* @internal
2020
*/
21-
export class AzureTokenCache extends AbstractCache<AzureTokenEntry> {
21+
export class AzureTokenCache extends Cache<AzureTokenEntry> {
2222
/**
2323
* Add an entry to the cache.
2424
*/

src/cmap/auth/mongodb_oidc/cache.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,10 @@ export abstract class ExpiringCacheEntry {
2929
}
3030
}
3131

32-
/**
33-
* An OIDC token cache.
34-
*/
35-
export interface Cache {
36-
/**
37-
* Implement the cache key for the token.
38-
*/
39-
cacheKey(address: string, username: string, callbackHash: string): string;
40-
}
41-
4232
/**
4333
* Base class for OIDC caches.
4434
*/
45-
export abstract class AbstractCache<T> implements Cache {
35+
export abstract class Cache<T> {
4636
entries: Map<string, T>;
4737

4838
/**

src/cmap/auth/mongodb_oidc/callback_lock_cache.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type {
88
OIDCRefreshFunction,
99
OIDCRequestFunction
1010
} from '../mongodb_oidc';
11-
import { AbstractCache } from './cache';
11+
import { Cache } from './cache';
1212

1313
/** Error message for when request callback is missing. */
1414
const REQUEST_CALLBACK_REQUIRED_ERROR =
@@ -34,7 +34,7 @@ interface CallbacksEntry {
3434
/**
3535
* A cache of request and refresh callbacks per server/user.
3636
*/
37-
export class CallbackLockCache extends AbstractCache<CallbacksEntry> {
37+
export class CallbackLockCache extends Cache<CallbacksEntry> {
3838
/**
3939
* Get the callbacks for the connection and credentials. If an entry does not
4040
* exist a new one will get set.

src/cmap/auth/mongodb_oidc/token_entry_cache.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { IdPServerInfo, IdPServerResponse } from '../mongodb_oidc';
2-
import { AbstractCache, ExpiringCacheEntry } from './cache';
2+
import { Cache, ExpiringCacheEntry } from './cache';
33

44
/* Default expiration is now for when no expiration provided */
55
const DEFAULT_EXPIRATION_SECS = 0;
@@ -23,7 +23,7 @@ export class TokenEntry extends ExpiringCacheEntry {
2323
* Cache of OIDC token entries.
2424
* @internal
2525
*/
26-
export class TokenEntryCache extends AbstractCache<TokenEntry> {
26+
export class TokenEntryCache extends Cache<TokenEntry> {
2727
/**
2828
* Set an entry in the token cache.
2929
*/

test/manual/mongodb_oidc_azure.prose.test.ts renamed to test/integration/auth/mongodb_oidc_azure.prose.test.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
CommandSucceededEvent,
88
MongoClient,
99
OIDC_WORKFLOWS
10-
} from '../mongodb';
10+
} from '../../mongodb';
1111

1212
describe('OIDC Auth Spec Prose Tests', function () {
1313
const callbackCache = OIDC_WORKFLOWS.get('callback').cache;
@@ -17,13 +17,20 @@ describe('OIDC Auth Spec Prose Tests', function () {
1717
let client: MongoClient;
1818
let collection: Collection;
1919

20+
beforeEach(function () {
21+
if (!this.configuration.isAzureOIDC(process.env.MONGODB_URI)) {
22+
this.currentTest?.skipReason = 'Azure OIDC prose tests require an Azure OIDC environment.';
23+
this.skip();
24+
}
25+
});
26+
2027
afterEach(async function () {
2128
await client?.close();
2229
});
2330

2431
describe('3.1 Connect', function () {
25-
before(function () {
26-
client = new MongoClient(process.env.MONGODB_URI);
32+
beforeEach(function () {
33+
client = this.configuration.newClient(process.env.MONGODB_URI);
2734
collection = client.db('test').collection('test');
2835
});
2936

@@ -37,8 +44,8 @@ describe('OIDC Auth Spec Prose Tests', function () {
3744
});
3845

3946
describe('3.2 Allowed Hosts Ignored', function () {
40-
before(function () {
41-
client = new MongoClient(process.env.MONGODB_URI, {
47+
beforeEach(function () {
48+
client = this.configuration.newClient(process.env.MONGODB_URI, {
4249
authMechanismProperties: {
4350
ALLOWED_HOSTS: []
4451
}
@@ -57,9 +64,9 @@ describe('OIDC Auth Spec Prose Tests', function () {
5764
});
5865

5966
describe('3.3 Main Cache Not Used', function () {
60-
before(function () {
67+
beforeEach(function () {
6168
callbackCache?.clear();
62-
client = new MongoClient(process.env.MONGODB_URI);
69+
client = this.configuration.newClient(process.env.MONGODB_URI);
6370
collection = client.db('test').collection('test');
6471
});
6572

@@ -76,10 +83,10 @@ describe('OIDC Auth Spec Prose Tests', function () {
7683
});
7784

7885
describe('3.4 Azure Cache is Used', function () {
79-
before(function () {
86+
beforeEach(function () {
8087
callbackCache?.clear();
8188
azureCache?.clear();
82-
client = new MongoClient(process.env.MONGODB_URI);
89+
client = this.configuration.newClient(process.env.MONGODB_URI);
8390
collection = client.db('test').collection('test');
8491
});
8592

@@ -148,9 +155,9 @@ describe('OIDC Auth Spec Prose Tests', function () {
148155
});
149156
};
150157

151-
before(async function () {
158+
beforeEach(async function () {
152159
azureCache?.clear();
153-
client = new MongoClient(process.env.MONGODB_URI, { monitorCommands: true });
160+
client = this.configuration.newClient(process.env.MONGODB_URI, { monitorCommands: true });
154161
await client.db('test').collection('test').findOne();
155162
addListeners();
156163
await setupFailPoint();

test/tools/runner/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ export class TestConfiguration {
153153
return this.options.replicaSet;
154154
}
155155

156+
isAzureOIDC(uri: string): boolean {
157+
return uri.indexOf('MONGODB-OIDC') > -1 && uri.indexOf('PROVIDER_NAME:azure') > -1;
158+
}
159+
156160
newClient(dbOptions?: string | Record<string, any>, serverOptions?: Record<string, any>) {
157161
serverOptions = Object.assign({}, getEnvironmentalOptions(), serverOptions);
158162

0 commit comments

Comments
 (0)