Skip to content

Commit e422e02

Browse files
authored
chore(e2e-tests): add workload OIDC test MONGOSH-1832 (#2283)
Now that the driver has support for the Kubernetes OIDC workload integration, it's quite easy to add a test for OIDC workload usage with mongosh.
1 parent 0130549 commit e422e02

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/e2e-tests/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"dependencies": {
3030
"@mongosh/cli-repl": "0.0.0-dev.0",
3131
"@mongosh/service-provider-core": "0.0.0-dev.0",
32+
"@mongodb-js/oidc-plugin": "^1.1.5",
3233
"strip-ansi": "^6.0.0"
3334
},
3435
"devDependencies": {

packages/e2e-tests/test/e2e-oidc.spec.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
commonOidcServerArgs,
1717
skipOIDCTestsDueToPlatformOrServerVersion,
1818
} from './oidc-helpers';
19+
import { createMongoDBOIDCPlugin } from '@mongodb-js/oidc-plugin';
1920

2021
/**
2122
* @securityTest OIDC Authentication End-to-End Tests
@@ -528,4 +529,43 @@ describe('OIDC auth e2e', function () {
528529
shell.assertContainsOutput('"lastServerIdPInfo":');
529530
shell.assertContainsOutput(/"refreshToken": "(?!debugid:)/);
530531
});
532+
533+
it('can successfully authenticate using workload OIDC', async function () {
534+
// Get a token from the OIDC server, store it to disk, then pass that to mongosh
535+
const tokenFile = path.join(tmpdir.path, 'token');
536+
let accessToken!: string;
537+
const plugin = createMongoDBOIDCPlugin({
538+
notifyDeviceFlow: () => {},
539+
allowedFlows: ['device-auth'],
540+
});
541+
try {
542+
({ accessToken } =
543+
await plugin.mongoClientOptions.authMechanismProperties.OIDC_HUMAN_CALLBACK(
544+
{
545+
version: 1,
546+
idpInfo: { issuer: oidcMockProvider.issuer, clientId: 'workload' },
547+
}
548+
));
549+
} finally {
550+
await plugin.destroy();
551+
}
552+
await fs.writeFile(tokenFile, accessToken);
553+
554+
shell = this.startTestShell({
555+
args: [
556+
await testServer.connectionString({
557+
authMechanism: 'MONGODB-OIDC',
558+
authMechanismProperties: 'ENVIRONMENT:k8s',
559+
}),
560+
],
561+
env: {
562+
...process.env,
563+
AWS_WEB_IDENTITY_TOKEN_FILE: tokenFile,
564+
},
565+
});
566+
await shell.waitForPrompt();
567+
568+
await verifyUser(shell, 'testuser', 'workload-group');
569+
shell.assertNoErrors();
570+
});
531571
});

0 commit comments

Comments
 (0)