@platform-sec/sensitive-string-testing 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assertions.d.ts +81 -0
- package/dist/assertions.d.ts.map +1 -0
- package/dist/assertions.js +132 -0
- package/dist/assertions.js.map +1 -0
- package/dist/canary.d.ts +49 -0
- package/dist/canary.d.ts.map +1 -0
- package/dist/canary.js +116 -0
- package/dist/canary.js.map +1 -0
- package/dist/create-test-secret.d.ts +78 -0
- package/dist/create-test-secret.d.ts.map +1 -0
- package/dist/create-test-secret.js +91 -0
- package/dist/create-test-secret.js.map +1 -0
- package/dist/describe-type.d.ts +16 -0
- package/dist/describe-type.d.ts.map +1 -0
- package/dist/describe-type.js +35 -0
- package/dist/describe-type.js.map +1 -0
- package/dist/index.d.ts +51 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +77 -0
- package/dist/index.js.map +1 -0
- package/dist/leak-scan.d.ts +94 -0
- package/dist/leak-scan.d.ts.map +1 -0
- package/dist/leak-scan.js +309 -0
- package/dist/leak-scan.js.map +1 -0
- package/dist/matchers.d.ts +93 -0
- package/dist/matchers.d.ts.map +1 -0
- package/dist/matchers.js +170 -0
- package/dist/matchers.js.map +1 -0
- package/dist/mocks.d.ts +140 -0
- package/dist/mocks.d.ts.map +1 -0
- package/dist/mocks.js +146 -0
- package/dist/mocks.js.map +1 -0
- package/dist/serializer.d.ts +136 -0
- package/dist/serializer.d.ts.map +1 -0
- package/dist/serializer.js +210 -0
- package/dist/serializer.js.map +1 -0
- package/dist/vitest.d.ts +59 -0
- package/dist/vitest.d.ts.map +1 -0
- package/dist/vitest.js +3 -0
- package/dist/vitest.js.map +1 -0
- package/package.json +10 -10
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sensitiveSerializer = void 0;
|
|
4
|
+
exports.createSensitiveSerializer = createSensitiveSerializer;
|
|
5
|
+
const sensitive_string_core_1 = require("@platform-sec/sensitive-string-core");
|
|
6
|
+
const describe_type_js_1 = require("./describe-type.js");
|
|
7
|
+
/** The placeholders a format may contain. */
|
|
8
|
+
const PLACEHOLDERS = ['class', 'label', 'length', 'expired'];
|
|
9
|
+
/** Matches one `{placeholder}`, and nothing that merely looks like one. */
|
|
10
|
+
const PLACEHOLDER_PATTERN = /\{([a-z]+)\}/g;
|
|
11
|
+
/**
|
|
12
|
+
* Control characters, which a label must not carry into the rendering.
|
|
13
|
+
*
|
|
14
|
+
* Matching them is the point, so `no-control-regex` has nothing to warn about
|
|
15
|
+
* here: the rule guards against a control character reaching a pattern by
|
|
16
|
+
* accident, and this one is looking for them.
|
|
17
|
+
*/
|
|
18
|
+
// eslint-disable-next-line no-control-regex
|
|
19
|
+
const CONTROL_CHARACTERS = /[\u0000-\u001f\u007f]/g;
|
|
20
|
+
/** The escapes worth reading, for the control characters a label might hold. */
|
|
21
|
+
const CONTROL_ESCAPES = {
|
|
22
|
+
'\b': '\\b',
|
|
23
|
+
'\t': '\\t',
|
|
24
|
+
'\n': '\\n',
|
|
25
|
+
'\f': '\\f',
|
|
26
|
+
'\r': '\\r',
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Build a snapshot serializer with a custom rendering.
|
|
30
|
+
*
|
|
31
|
+
* @param options - The format, and the fields to include.
|
|
32
|
+
* @returns A plugin for `expect.addSnapshotSerializer` or for a runner's config.
|
|
33
|
+
* @throws TypeError If an option has the wrong type, or the format names a placeholder that does not exist.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* const verbose = createSensitiveSerializer({ showLength: true, showExpiration: true });
|
|
38
|
+
*
|
|
39
|
+
* expect.addSnapshotSerializer(verbose);
|
|
40
|
+
* // SensitiveString<credential:api_key:len=32>
|
|
41
|
+
* // SensitiveString<credential:otp:len=6:EXPIRED>
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
function createSensitiveSerializer(options = {}) {
|
|
45
|
+
// Resolved once, at registration, so a bad format is a loud failure in a
|
|
46
|
+
// setup file rather than a failure inside the first snapshot that happens to
|
|
47
|
+
// hold a sensitive value.
|
|
48
|
+
const format = resolveFormat(options);
|
|
49
|
+
return {
|
|
50
|
+
test(value) {
|
|
51
|
+
return isSensitiveString(value);
|
|
52
|
+
},
|
|
53
|
+
serialize(value) {
|
|
54
|
+
if (!isSensitiveString(value)) {
|
|
55
|
+
// Reachable only by calling the plugin directly, since `pretty-format`
|
|
56
|
+
// calls `serialize` only for what `test` accepted. Naming the type is
|
|
57
|
+
// safe; rendering the value would not be, because whatever arrived here
|
|
58
|
+
// may be a raw copy of a secret.
|
|
59
|
+
throw new TypeError(`The sensitive-string snapshot serializer received ${(0, describe_type_js_1.describeType)(value)}, not a SensitiveString.`);
|
|
60
|
+
}
|
|
61
|
+
return render(format, value);
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* A snapshot serializer for `SensitiveString`, with the default format.
|
|
67
|
+
*
|
|
68
|
+
* Register it once, in a setup file:
|
|
69
|
+
*
|
|
70
|
+
* ```ts
|
|
71
|
+
* import { expect } from 'vitest';
|
|
72
|
+
* import { sensitiveSerializer } from '@platform-sec/sensitive-string-testing';
|
|
73
|
+
*
|
|
74
|
+
* expect.addSnapshotSerializer(sensitiveSerializer);
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* A snapshot of a structure holding sensitive values then keeps the shape of
|
|
78
|
+
* the structure and says what each sensitive field is, without recording what
|
|
79
|
+
* it holds:
|
|
80
|
+
*
|
|
81
|
+
* ```
|
|
82
|
+
* {
|
|
83
|
+
* "id": 1,
|
|
84
|
+
* "email": SensitiveString<sensitive:email>,
|
|
85
|
+
* "apiKey": SensitiveString<credential:api_key>,
|
|
86
|
+
* }
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
* The rendering is built from the class and the label, which are public
|
|
90
|
+
* metadata, and never from the value: nothing here calls `reveal()`, and no
|
|
91
|
+
* format placeholder prints a value. It also does not use the class policy's
|
|
92
|
+
* `redact()`, so a project that registered a custom redaction format gets the
|
|
93
|
+
* same snapshots as one that did not, and a policy registered with
|
|
94
|
+
* `skipRedactValidation` cannot route a value into a snapshot through it.
|
|
95
|
+
*/
|
|
96
|
+
exports.sensitiveSerializer = createSensitiveSerializer();
|
|
97
|
+
/**
|
|
98
|
+
* The plugin again, as a default export, for a runner that loads it by path
|
|
99
|
+
* rather than by importing it:
|
|
100
|
+
*
|
|
101
|
+
* ```js
|
|
102
|
+
* // jest.config.js
|
|
103
|
+
* module.exports = {
|
|
104
|
+
* snapshotSerializers: ['@platform-sec/sensitive-string-testing/serializer'],
|
|
105
|
+
* };
|
|
106
|
+
* ```
|
|
107
|
+
*
|
|
108
|
+
* That path is loaded with `require`, which is what this export is for. Code
|
|
109
|
+
* that imports the module should use the named `sensitiveSerializer` instead:
|
|
110
|
+
* this package builds to CommonJS, and a default import of a CommonJS module
|
|
111
|
+
* from ES module code yields the module's exports rather than this value.
|
|
112
|
+
*/
|
|
113
|
+
exports.default = exports.sensitiveSerializer;
|
|
114
|
+
/**
|
|
115
|
+
* The format to render with, after checking the options.
|
|
116
|
+
*
|
|
117
|
+
* `showLength` and `showExpiration` are shorthand for adding a placeholder to
|
|
118
|
+
* the default format, so they have nothing to say once a format is given.
|
|
119
|
+
*/
|
|
120
|
+
function resolveFormat(options) {
|
|
121
|
+
const { showExpiration = false, showLength = false, format } = options;
|
|
122
|
+
checkBoolean(showExpiration, 'showExpiration');
|
|
123
|
+
checkBoolean(showLength, 'showLength');
|
|
124
|
+
if (format === undefined) {
|
|
125
|
+
return [
|
|
126
|
+
'SensitiveString<{class}{label}',
|
|
127
|
+
showLength ? '{length}' : '',
|
|
128
|
+
showExpiration ? '{expired}' : '',
|
|
129
|
+
'>',
|
|
130
|
+
].join('');
|
|
131
|
+
}
|
|
132
|
+
if (typeof format !== 'string') {
|
|
133
|
+
throw new TypeError(`format must be a string, but got ${(0, describe_type_js_1.describeType)(format)}.`);
|
|
134
|
+
}
|
|
135
|
+
for (const match of format.matchAll(PLACEHOLDER_PATTERN)) {
|
|
136
|
+
const name = match[1];
|
|
137
|
+
if (name !== undefined && !isPlaceholder(name)) {
|
|
138
|
+
throw new TypeError([
|
|
139
|
+
`format contains an unknown placeholder '{${name}}'. `,
|
|
140
|
+
`The known placeholders are ${PLACEHOLDERS.map((known) => `{${known}}`).join(', ')}. `,
|
|
141
|
+
'There is none for the value: a snapshot is committed to version control, ',
|
|
142
|
+
'so the serializer has no way to print one.',
|
|
143
|
+
].join(''));
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return format;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Expand the placeholders in one pass.
|
|
150
|
+
*
|
|
151
|
+
* One pass with a replacement function, rather than a `replace` per
|
|
152
|
+
* placeholder, for two reasons. A label is arbitrary text, so a label of
|
|
153
|
+
* `{class}`, or one holding `$&`, would otherwise be expanded by a later pass
|
|
154
|
+
* or read as a replacement pattern. And a format may name a placeholder twice,
|
|
155
|
+
* which a `String.prototype.replace` per placeholder would honour only the
|
|
156
|
+
* first time.
|
|
157
|
+
*/
|
|
158
|
+
function render(format, value) {
|
|
159
|
+
return format.replace(PLACEHOLDER_PATTERN, (whole, name) => isPlaceholder(name) ? expand(name, value) : whole);
|
|
160
|
+
}
|
|
161
|
+
function expand(placeholder, value) {
|
|
162
|
+
switch (placeholder) {
|
|
163
|
+
case 'class':
|
|
164
|
+
return value.klass;
|
|
165
|
+
case 'label':
|
|
166
|
+
return value.label === undefined ? '' : `:${escapeLabel(value.label)}`;
|
|
167
|
+
case 'length':
|
|
168
|
+
return `:len=${value.length}`;
|
|
169
|
+
case 'expired':
|
|
170
|
+
// `ttlRemaining()` rather than `isExpired()`, which asks the same question
|
|
171
|
+
// without the side effect: the first `isExpired()` on a lapsed value fires
|
|
172
|
+
// the `onExpire` callback of every source it derives from. Printing a
|
|
173
|
+
// snapshot must not be what triggers an expiry hook, and a snapshot that
|
|
174
|
+
// is printed twice must not fire it twice.
|
|
175
|
+
return value.ttlRemaining() === -1 ? ':EXPIRED' : '';
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* A label with its control characters escaped.
|
|
180
|
+
*
|
|
181
|
+
* A label is developer-supplied text rather than a value, so it prints as it
|
|
182
|
+
* stands. A newline or a tab in one would break the line being rendered into
|
|
183
|
+
* and silently corrupt the indentation of the whole snapshot, so those become
|
|
184
|
+
* escapes. Everything printable is left alone, including a `{`, which cannot be
|
|
185
|
+
* re-expanded because the format expands in a single pass.
|
|
186
|
+
*/
|
|
187
|
+
function escapeLabel(label) {
|
|
188
|
+
return label.replace(CONTROL_CHARACTERS, (character) => CONTROL_ESCAPES[character] ?? `\\x${character.charCodeAt(0).toString(16).padStart(2, '0')}`);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Whether the value is a `SensitiveString`, as a predicate rather than a bare
|
|
192
|
+
* `instanceof`.
|
|
193
|
+
*
|
|
194
|
+
* `instanceof SensitiveString` narrows to `SensitiveString<any>`, because the
|
|
195
|
+
* class is generic in its sensitivity class and the check says nothing about
|
|
196
|
+
* which one. The predicate names the union instead, so nothing downstream of
|
|
197
|
+
* the narrowing is typed `any`.
|
|
198
|
+
*/
|
|
199
|
+
function isSensitiveString(value) {
|
|
200
|
+
return value instanceof sensitive_string_core_1.SensitiveString;
|
|
201
|
+
}
|
|
202
|
+
function isPlaceholder(name) {
|
|
203
|
+
return PLACEHOLDERS.includes(name);
|
|
204
|
+
}
|
|
205
|
+
function checkBoolean(value, name) {
|
|
206
|
+
if (typeof value !== 'boolean') {
|
|
207
|
+
throw new TypeError(`${name} must be a boolean, but got ${(0, describe_type_js_1.describeType)(value)}.`);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
//# sourceMappingURL=serializer.js.map
|
|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ACvC,OAAO,KAAK,YAAY,uCAAe,CAAC;AAC1C,CAAC;AAED,SAAS,aAAa,CAAC,IAAY;IACjC,OAAQ,YAAkC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AAC5D,CAAC;AAED,SAAS,YAAY,CAAC,KAAc,EAAE,IAAY;IAChD,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE,CAAC;QAC/B,MAAM,IAAI,SAAS,CAAC,GAAG,IAAI,+BAA+B,IAAA,+BAAY,EAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACpF,CAAC;AACH,CAAC"}
|
package/dist/vitest.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { Assertion as VitestAssertion, expect as vitestExpect } from 'vitest';
|
|
2
|
+
import type { SensitiveMatchers } from './matchers.js';
|
|
3
|
+
import type { SnapshotSerializerPlugin } from './serializer.js';
|
|
4
|
+
/**
|
|
5
|
+
* Ready-made Vitest type augmentation.
|
|
6
|
+
*
|
|
7
|
+
* Import it once, from a setup file or from a `.d.ts` in the consuming project:
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* import '@platform-sec/sensitive-string-testing/vitest';
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* Registering the matchers is separate and still required; see
|
|
14
|
+
* `setupSensitiveMatchers`. This module only teaches TypeScript about them, and
|
|
15
|
+
* emits nothing at runtime.
|
|
16
|
+
*
|
|
17
|
+
* The type parameter list has to match Vitest's own declaration exactly for the
|
|
18
|
+
* interfaces to merge, which is where `T = any` comes from.
|
|
19
|
+
*
|
|
20
|
+
* @packageDocumentation
|
|
21
|
+
*/
|
|
22
|
+
declare module 'vitest' {
|
|
23
|
+
interface Assertion<T = any> extends SensitiveMatchers<T> {
|
|
24
|
+
}
|
|
25
|
+
interface AsymmetricMatchersContaining extends SensitiveMatchers {
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Vitest's assertion type, re-exported.
|
|
30
|
+
*
|
|
31
|
+
* The re-export is what puts Vitest's own declarations into the program. Under
|
|
32
|
+
* CommonJS resolution, `vitest` resolves to a re-export barrel that carries no
|
|
33
|
+
* declarations of its own, and an augmentation of a module nothing else pulls
|
|
34
|
+
* in fails to resolve. A consumer whose project is CommonJS therefore needs
|
|
35
|
+
* this import as much as this package's own build does.
|
|
36
|
+
*/
|
|
37
|
+
export type SensitiveAssertion<T> = VitestAssertion<T>;
|
|
38
|
+
/**
|
|
39
|
+
* The plugin type Vitest's `expect.addSnapshotSerializer` accepts, which is
|
|
40
|
+
* `pretty-format`'s own.
|
|
41
|
+
*/
|
|
42
|
+
type VitestSnapshotSerializer = Parameters<typeof vitestExpect.addSnapshotSerializer>[0];
|
|
43
|
+
/** Fails to compile unless `T` is `true`. */
|
|
44
|
+
type Assert<T extends true> = T;
|
|
45
|
+
/**
|
|
46
|
+
* A compile-time proof that `sensitiveSerializer` is the shape Vitest accepts.
|
|
47
|
+
*
|
|
48
|
+
* `SnapshotSerializerPlugin` is declared structurally in `serializer.ts` rather
|
|
49
|
+
* than imported from `pretty-format`, which is what keeps this package free of
|
|
50
|
+
* a dependency on a test framework. The cost of writing a type out by hand is
|
|
51
|
+
* that it can drift from the one it is meant to match, and nothing would say
|
|
52
|
+
* so: the test suite runs through esbuild, which strips types without checking
|
|
53
|
+
* them, so a serializer Vitest rejects would still pass every test in this
|
|
54
|
+
* repository. This alias is checked by `tsc` during the build, so the drift is
|
|
55
|
+
* a failed build instead.
|
|
56
|
+
*/
|
|
57
|
+
export type SensitiveSerializerFitsVitest = Assert<SnapshotSerializerPlugin extends VitestSnapshotSerializer ? true : false>;
|
|
58
|
+
export {};
|
|
59
|
+
//# sourceMappingURL=vitest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vitest.d.ts","sourceRoot":"","sources":["../src/vitest.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,IAAI,eAAe,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,QAAQ,CAAC;AACnF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAEhE;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,QAAQ,QAAQ,CAAC;IACtB,UAAU,SAAS,CAAC,CAAC,GAAG,GAAG,CAAE,SAAQ,iBAAiB,CAAC,CAAC,CAAC;KAAG;IAC5D,UAAU,4BAA6B,SAAQ,iBAAiB;KAAG;CACpE;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,kBAAkB,CAAC,CAAC,IAAI,eAAe,CAAC,CAAC,CAAC,CAAC;AAEvD;;;GAGG;AACH,KAAK,wBAAwB,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,CAAC;AAEzF,6CAA6C;AAC7C,KAAK,MAAM,CAAC,CAAC,SAAS,IAAI,IAAI,CAAC,CAAC;AAEhC;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,6BAA6B,GAAG,MAAM,CAChD,wBAAwB,SAAS,wBAAwB,GAAG,IAAI,GAAG,KAAK,CACzE,CAAC"}
|
package/dist/vitest.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vitest.js","sourceRoot":"","sources":["../src/vitest.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platform-sec/sensitive-string-testing",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Test secrets, leak assertions, matchers, and audit mocks for SensitiveString",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -22,11 +22,6 @@
|
|
|
22
22
|
"files": [
|
|
23
23
|
"dist"
|
|
24
24
|
],
|
|
25
|
-
"scripts": {
|
|
26
|
-
"build": "tsc",
|
|
27
|
-
"test": "vitest run --root ../.. packages/sensitive-testing/",
|
|
28
|
-
"test:watch": "vitest --root ../.. packages/sensitive-testing/"
|
|
29
|
-
},
|
|
30
25
|
"keywords": [
|
|
31
26
|
"testing",
|
|
32
27
|
"vitest",
|
|
@@ -50,9 +45,14 @@
|
|
|
50
45
|
"@platform-sec/sensitive-string-core": "^0.6.0"
|
|
51
46
|
},
|
|
52
47
|
"devDependencies": {
|
|
53
|
-
"@
|
|
54
|
-
"@types/node": "^22.20.1",
|
|
48
|
+
"@types/node": "^22.20.5",
|
|
55
49
|
"typescript": "^5.9.3",
|
|
56
|
-
"vitest": "^4.1.
|
|
50
|
+
"vitest": "^4.1.12",
|
|
51
|
+
"@platform-sec/sensitive-string-core": "0.6.1"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "tsc",
|
|
55
|
+
"test": "vitest run --root ../.. packages/sensitive-testing/",
|
|
56
|
+
"test:watch": "vitest --root ../.. packages/sensitive-testing/"
|
|
57
57
|
}
|
|
58
|
-
}
|
|
58
|
+
}
|