Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/e2e-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"dependencies": {
"@mongosh/cli-repl": "0.0.0-dev.0",
"@mongosh/service-provider-core": "0.0.0-dev.0",
"@mongodb-js/oidc-plugin": "^1.1.5",
"strip-ansi": "^6.0.0"
},
"devDependencies": {
Expand Down
40 changes: 40 additions & 0 deletions packages/e2e-tests/test/e2e-oidc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
commonOidcServerArgs,
skipOIDCTestsDueToPlatformOrServerVersion,
} from './oidc-helpers';
import { createMongoDBOIDCPlugin } from '@mongodb-js/oidc-plugin';

/**
* @securityTest OIDC Authentication End-to-End Tests
Expand Down Expand Up @@ -528,4 +529,43 @@ describe('OIDC auth e2e', function () {
shell.assertContainsOutput('"lastServerIdPInfo":');
shell.assertContainsOutput(/"refreshToken": "(?!debugid:)/);
});

it('can successfully authenticate using workload OIDC', async function () {
// Get a token from the OIDC server, store it to disk, then pass that to mongosh
const tokenFile = path.join(tmpdir.path, 'token');
let accessToken!: string;
const plugin = createMongoDBOIDCPlugin({
notifyDeviceFlow: () => {},
allowedFlows: ['device-auth'],
});
try {
({ accessToken } =
await plugin.mongoClientOptions.authMechanismProperties.OIDC_HUMAN_CALLBACK(
{
version: 1,
idpInfo: { issuer: oidcMockProvider.issuer, clientId: 'workload' },
}
));
} finally {
await plugin.destroy();
}
await fs.writeFile(tokenFile, accessToken);

shell = this.startTestShell({
args: [
await testServer.connectionString({
authMechanism: 'MONGODB-OIDC',
authMechanismProperties: 'ENVIRONMENT:k8s',
}),
],
env: {
...process.env,
AWS_WEB_IDENTITY_TOKEN_FILE: tokenFile,
},
});
await shell.waitForPrompt();

await verifyUser(shell, 'testuser', 'workload-group');
shell.assertNoErrors();
});
});
Loading