|
1 | | -import { describe, it, expect, vi, beforeEach } from "vitest"; |
| 1 | +import { describe, it, expect, vi, beforeEach, afterEach } from "vitest"; |
2 | 2 | import type { UserConfig } from "../../../src/common/config.js"; |
3 | | -import { setupUserConfig, defaultUserConfig, warnAboutDeprecatedCliArgs } from "../../../src/common/config.js"; |
| 3 | +import { |
| 4 | + setupUserConfig, |
| 5 | + defaultUserConfig, |
| 6 | + warnAboutDeprecatedCliArgs, |
| 7 | + registerKnownSecretsInRootKeychain, |
| 8 | +} from "../../../src/common/config.js"; |
4 | 9 | import type { CliOptions } from "@mongosh/arg-parser"; |
| 10 | +import { Keychain } from "../../../src/common/keychain.js"; |
| 11 | +import type { Secret } from "../../../src/common/keychain.js"; |
5 | 12 |
|
6 | 13 | describe("config", () => { |
7 | 14 | describe("env var parsing", () => { |
@@ -641,4 +648,40 @@ describe("Deprecated CLI arguments", () => { |
641 | 648 | }); |
642 | 649 | }); |
643 | 650 | } |
| 651 | + |
| 652 | + describe("keychain management", () => { |
| 653 | + type TestCase = { readonly cliArg: keyof UserConfig; secretKind: Secret["kind"] }; |
| 654 | + const testCases = [ |
| 655 | + { cliArg: "apiClientId", secretKind: "user" }, |
| 656 | + { cliArg: "apiClientSecret", secretKind: "password" }, |
| 657 | + { cliArg: "awsAccessKeyId", secretKind: "password" }, |
| 658 | + { cliArg: "awsIamSessionToken", secretKind: "password" }, |
| 659 | + { cliArg: "awsSecretAccessKey", secretKind: "password" }, |
| 660 | + { cliArg: "awsSessionToken", secretKind: "password" }, |
| 661 | + { cliArg: "password", secretKind: "password" }, |
| 662 | + { cliArg: "tlsCAFile", secretKind: "url" }, |
| 663 | + { cliArg: "tlsCRLFile", secretKind: "url" }, |
| 664 | + { cliArg: "tlsCertificateKeyFile", secretKind: "url" }, |
| 665 | + { cliArg: "tlsCertificateKeyFilePassword", secretKind: "password" }, |
| 666 | + { cliArg: "username", secretKind: "user" }, |
| 667 | + ] as TestCase[]; |
| 668 | + let keychain: Keychain; |
| 669 | + |
| 670 | + beforeEach(() => { |
| 671 | + keychain = Keychain.root; |
| 672 | + keychain.clearAllSecrets(); |
| 673 | + }); |
| 674 | + |
| 675 | + afterEach(() => { |
| 676 | + keychain.clearAllSecrets(); |
| 677 | + }); |
| 678 | + |
| 679 | + for (const { cliArg, secretKind } of testCases) { |
| 680 | + it(`should register ${cliArg} as a secret of kind ${secretKind} in the root keychain`, () => { |
| 681 | + registerKnownSecretsInRootKeychain({ [cliArg]: cliArg }); |
| 682 | + |
| 683 | + expect(keychain.allSecrets).to.deep.equal([{ value: cliArg, kind: secretKind }]); |
| 684 | + }); |
| 685 | + } |
| 686 | + }); |
644 | 687 | }); |
0 commit comments