Skip to content

Commit 25b5c0d

Browse files
committed
fix: allows non-secret array value, if all items are secret
1 parent aa9288e commit 25b5c0d

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

app-config/src/schema.test.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { JsonObject } from './common';
22
import { ParsedValue } from './parsed-value';
33
import { generateSymmetricKey, encryptValue } from './encryption';
4-
import { encryptedDirective, extendsDirective } from './extensions';
4+
import { encryptedDirective, extendsDirective, envDirective } from './extensions';
55
import { loadSchema } from './schema';
66
import { withTempFiles } from './test-util';
77

@@ -556,5 +556,34 @@ describe('Validation', () => {
556556
},
557557
);
558558
});
559+
560+
it('allows a "secret" array with all secret values, but not secret itself', async () => {
561+
await withTempFiles(
562+
{
563+
'.app-config.schema.yml': `
564+
type: object
565+
properties:
566+
foo:
567+
type: array
568+
secret: true
569+
items:
570+
type: string
571+
`,
572+
},
573+
async (inDir) => {
574+
const { validate } = await loadSchema({ directory: inDir('.') });
575+
const symmetricKey = await generateSymmetricKey(1);
576+
577+
const parsed = await ParsedValue.parseLiteral(
578+
{
579+
foo: [await encryptValue('secret-1', symmetricKey)],
580+
},
581+
[encryptedDirective(symmetricKey), envDirective()],
582+
);
583+
584+
validate(parsed.toJSON() as JsonObject, parsed);
585+
},
586+
);
587+
});
559588
});
560589
});

app-config/src/schema.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,11 @@ export async function loadSchema({
123123
const arr = found.asArray();
124124

125125
if (arr) {
126-
if (!arr.every((v) => v.meta.fromSecrets)) {
127-
return false;
128-
}
126+
return arr.every((v) => v.meta.fromSecrets);
129127
}
130128

131129
if (!found.meta.fromSecrets) {
130+
// arrays that are "secret" don't need to be secret themselves, just the items in that array do
132131
return false;
133132
}
134133
}

0 commit comments

Comments
 (0)