Skip to content

Commit 5f0265c

Browse files
committed
chore: changed vaultName:. to vaultName in tests
1 parent 0d604b8 commit 5f0265c

File tree

2 files changed

+57
-17
lines changed

2 files changed

+57
-17
lines changed

src/utils/options.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* but not the default value
66
* @module
77
*/
8-
import commander, { InvalidArgumentError } from 'commander';
8+
import commander from 'commander';
99
import config from 'polykey/dist/config';
1010
import * as binParsers from '../utils/parsers';
1111

@@ -216,7 +216,7 @@ const envVariables = new commander.Option('-e --env <envs...>', 'specify envs')
216216
const acc = previous ?? [];
217217
const [vault, secret, val] = binParsers.parseSecretPathEnv(value);
218218
if (secret == null) {
219-
throw new InvalidArgumentError(
219+
throw new commander.InvalidArgumentError(
220220
'You must provide at least one secret path',
221221
);
222222
}

tests/secrets/env.test.ts

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ describe('commandEnv', () => {
325325
dataDir,
326326
'--env-format',
327327
'unix',
328-
`${vaultName}:.`,
328+
`${vaultName}`,
329329
];
330330

331331
const result = await testUtils.pkExec([...command], {
@@ -364,8 +364,8 @@ describe('commandEnv', () => {
364364
dataDir,
365365
'--env-format',
366366
'unix',
367-
`${vaultName}1:.`,
368-
`${vaultName}2:.`,
367+
`${vaultName}1`,
368+
`${vaultName}2`,
369369
];
370370

371371
const result = await testUtils.pkExec([...command], {
@@ -404,8 +404,8 @@ describe('commandEnv', () => {
404404
dataDir,
405405
'--env-format',
406406
'cmd',
407-
`${vaultName}1:.`,
408-
`${vaultName}2:.`,
407+
`${vaultName}1`,
408+
`${vaultName}2`,
409409
];
410410

411411
const result = await testUtils.pkExec([...command], {
@@ -444,8 +444,8 @@ describe('commandEnv', () => {
444444
dataDir,
445445
'--env-format',
446446
'powershell',
447-
`${vaultName}1:.`,
448-
`${vaultName}2:.`,
447+
`${vaultName}1`,
448+
`${vaultName}2`,
449449
];
450450

451451
const result = await testUtils.pkExec([...command], {
@@ -475,7 +475,7 @@ describe('commandEnv', () => {
475475
dataDir,
476476
'--env-format',
477477
'json',
478-
`${vaultName}:.`,
478+
`${vaultName}`,
479479
];
480480

481481
const result = await testUtils.pkExec([...command], {
@@ -560,7 +560,7 @@ describe('commandEnv', () => {
560560
'unix',
561561
'-ei',
562562
'error',
563-
`${vaultName}:.`,
563+
`${vaultName}`,
564564
],
565565
{ env: { PK_PASSWORD: password } },
566566
);
@@ -584,7 +584,7 @@ describe('commandEnv', () => {
584584
'unix',
585585
'-ei',
586586
'warn',
587-
`${vaultName}:.`,
587+
`${vaultName}`,
588588
],
589589
{ env: { PK_PASSWORD: password } },
590590
);
@@ -612,7 +612,7 @@ describe('commandEnv', () => {
612612
'unix',
613613
'-ei',
614614
'ignore',
615-
`${vaultName}:.`,
615+
`${vaultName}`,
616616
],
617617
{ env: { PK_PASSWORD: password } },
618618
);
@@ -642,7 +642,7 @@ describe('commandEnv', () => {
642642
'unix',
643643
'-ed',
644644
'error',
645-
`${vaultName}:.`,
645+
`${vaultName}`,
646646
],
647647
{ env: { PK_PASSWORD: password } },
648648
);
@@ -669,7 +669,7 @@ describe('commandEnv', () => {
669669
'unix',
670670
'-ed',
671671
'warn',
672-
`${vaultName}:.`,
672+
`${vaultName}`,
673673
],
674674
{ env: { PK_PASSWORD: password } },
675675
);
@@ -698,7 +698,7 @@ describe('commandEnv', () => {
698698
'unix',
699699
'-ed',
700700
'keep',
701-
`${vaultName}:.`,
701+
`${vaultName}`,
702702
],
703703
{ env: { PK_PASSWORD: password } },
704704
);
@@ -725,7 +725,7 @@ describe('commandEnv', () => {
725725
'unix',
726726
'-ed',
727727
'overwrite',
728-
`${vaultName}:.`,
728+
`${vaultName}`,
729729
],
730730
{ env: { PK_PASSWORD: password } },
731731
);
@@ -816,4 +816,44 @@ describe('commandEnv', () => {
816816
});
817817
expect(result1.exitCode).toBe(64);
818818
});
819+
test('should output all secrets without explicit secret path', async () => {
820+
const vaultId1 = await polykeyAgent.vaultManager.createVault(
821+
`${vaultName}1`,
822+
);
823+
const vaultId2 = await polykeyAgent.vaultManager.createVault(
824+
`${vaultName}2`,
825+
);
826+
827+
await polykeyAgent.vaultManager.withVaults(
828+
[vaultId1, vaultId2],
829+
async (vault1, vault2) => {
830+
await vaultOps.addSecret(vault1, 'SECRET1', 'this is the secret1');
831+
await vaultOps.addSecret(vault2, 'SECRET2', 'this is the secret2');
832+
await vaultOps.mkdir(vault1, 'dir1');
833+
await vaultOps.mkdir(vault2, 'dir1');
834+
await vaultOps.addSecret(vault1, 'dir1/SECRET3', 'this is the secret3');
835+
await vaultOps.addSecret(vault2, 'dir1/SECRET4', 'this is the secret4');
836+
},
837+
);
838+
839+
command = [
840+
'secrets',
841+
'env',
842+
'-np',
843+
dataDir,
844+
'--env-format',
845+
'unix',
846+
`${vaultName}1`,
847+
`${vaultName}2`,
848+
];
849+
850+
const result = await testUtils.pkExec([...command], {
851+
env: { PK_PASSWORD: password },
852+
});
853+
expect(result.exitCode).toBe(0);
854+
expect(result.stdout).toContain("SECRET1='this is the secret1'");
855+
expect(result.stdout).toContain("SECRET2='this is the secret2'");
856+
expect(result.stdout).toContain("SECRET3='this is the secret3'");
857+
expect(result.stdout).toContain("SECRET4='this is the secret4'");
858+
});
819859
});

0 commit comments

Comments
 (0)