mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-19 13:41:10 +02:00
* Add util for determining whether secret data is advanced * Add test coverage for bug * use non-dumb logic for detecting advanced object * Add changelog * Add header * Move util to core * Add escaped newline to test coverage * headers again *eyeroll*
41 lines
1.3 KiB
JavaScript
41 lines
1.3 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import { isAdvancedSecret } from 'core/utils/advanced-secret';
|
|
import { module, test } from 'qunit';
|
|
|
|
module('Unit | Utility | advanced-secret', function () {
|
|
test('it returns false for non-valid JSON', function (assert) {
|
|
assert.expect(5);
|
|
let result;
|
|
['some-string', 'character{string', '{value}', '[blah]', 'multi\nline\nstring'].forEach((value) => {
|
|
result = isAdvancedSecret('some-string');
|
|
assert.false(result, `returns false for ${value}`);
|
|
});
|
|
});
|
|
|
|
test('it returns false for single-level objects', function (assert) {
|
|
assert.expect(3);
|
|
let result;
|
|
[{ single: 'one' }, { first: '1', two: 'three' }, ['my', 'array']].forEach((value) => {
|
|
result = isAdvancedSecret(JSON.stringify(value));
|
|
assert.false(result, `returns false for object ${JSON.stringify(value)}`);
|
|
});
|
|
});
|
|
|
|
test('it returns true for any nested object', function (assert) {
|
|
assert.expect(3);
|
|
let result;
|
|
[
|
|
{ single: { one: 'uno' } },
|
|
{ first: ['this', 'counts\ntoo'] },
|
|
{ deeply: { nested: { item: 1 } } },
|
|
].forEach((value) => {
|
|
result = isAdvancedSecret(JSON.stringify(value));
|
|
assert.true(result, `returns true for object ${JSON.stringify(value)}`);
|
|
});
|
|
});
|
|
});
|