@raidiant/notifai 10.1.1 → 10.1.3
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/CHANGELOG.md +35 -0
- package/dist/commands-core.d.ts +4 -1
- package/dist/commands-core.js.map +1 -1
- package/dist/commands-doctor.js +2 -7
- package/dist/commands-doctor.js.map +1 -1
- package/dist/commands-hooks.d.ts +12 -0
- package/dist/commands-hooks.js +15 -1
- package/dist/commands-hooks.js.map +1 -1
- package/dist/commands-init.js +9 -6
- package/dist/commands-init.js.map +1 -1
- package/dist/commands-send-support.js +10 -11
- package/dist/commands-send-support.js.map +1 -1
- package/dist/commands-skill.js +72 -54
- package/dist/commands-skill.js.map +1 -1
- package/dist/harness-session-title.d.ts +22 -0
- package/dist/harness-session-title.js +74 -0
- package/dist/harness-session-title.js.map +1 -0
- package/dist/invocation-context.d.ts +1 -0
- package/dist/invocation-context.js +15 -1
- package/dist/invocation-context.js.map +1 -1
- package/dist/native-skills.d.ts +13 -3
- package/dist/native-skills.js +51 -12
- package/dist/native-skills.js.map +1 -1
- package/dist/node-floor.d.ts +2 -1
- package/dist/node-floor.js +9 -5
- package/dist/node-floor.js.map +1 -1
- package/dist/orca-session-title.d.ts +5 -4
- package/dist/orca-session-title.js +32 -19
- package/dist/orca-session-title.js.map +1 -1
- package/dist/platform.d.ts +11 -17
- package/dist/platform.js +20 -23
- package/dist/platform.js.map +1 -1
- package/dist/release.d.ts +5 -5
- package/dist/release.js +5 -5
- package/dist/session-labels.d.ts +2 -0
- package/dist/session-labels.js +20 -9
- package/dist/session-labels.js.map +1 -1
- package/dist/setup-destinations.js +1 -1
- package/dist/setup-destinations.js.map +1 -1
- package/dist/skill-integrity.d.ts +49 -0
- package/dist/skill-integrity.js +154 -0
- package/dist/skill-integrity.js.map +1 -0
- package/dist/skill-source/manifest.json +16 -0
- package/dist/skill-source/notifai/SKILL.md +390 -0
- package/dist/skill-source/notifai/references/harness-setup.md +220 -0
- package/package.json +11 -14
- package/src/atomic-file.ts +0 -198
- package/src/claude-wake.test.ts +0 -321
- package/src/claude-wake.ts +0 -499
- package/src/cli-bin.test.ts +0 -176
- package/src/cli-bin.ts +0 -233
- package/src/cli-release.test.ts +0 -46
- package/src/cli-release.ts +0 -78
- package/src/cli-update-contract.ts +0 -9
- package/src/cli-update.test.ts +0 -125
- package/src/client.test.ts +0 -390
- package/src/client.ts +0 -352
- package/src/codex-wake.test.ts +0 -254
- package/src/codex-wake.ts +0 -301
- package/src/command-session.ts +0 -38
- package/src/commands-agent-sessions.ts +0 -72
- package/src/commands-auth.ts +0 -238
- package/src/commands-config.ts +0 -336
- package/src/commands-core.ts +0 -312
- package/src/commands-devices.ts +0 -180
- package/src/commands-doctor.ts +0 -1501
- package/src/commands-guidance.ts +0 -181
- package/src/commands-harness-context.ts +0 -207
- package/src/commands-hook-shape.ts +0 -69
- package/src/commands-hooks.ts +0 -2318
- package/src/commands-init.ts +0 -1055
- package/src/commands-io.ts +0 -108
- package/src/commands-logs.ts +0 -243
- package/src/commands-project.ts +0 -47
- package/src/commands-send-support.test.ts +0 -156
- package/src/commands-send-support.ts +0 -311
- package/src/commands-send.ts +0 -875
- package/src/commands-setup-proof.test.ts +0 -72
- package/src/commands-setup-proof.ts +0 -124
- package/src/commands-skill.test.ts +0 -44
- package/src/commands-skill.ts +0 -204
- package/src/commands-sounds.test.ts +0 -106
- package/src/commands-sounds.ts +0 -49
- package/src/commands-update.ts +0 -180
- package/src/commands.test.ts +0 -8297
- package/src/commands.ts +0 -77
- package/src/config-schema.test.ts +0 -153
- package/src/config-schema.ts +0 -349
- package/src/config.test.ts +0 -581
- package/src/config.ts +0 -475
- package/src/credentials.test.ts +0 -403
- package/src/credentials.ts +0 -403
- package/src/file-lock-process-worker.test.ts +0 -64
- package/src/file-lock.test.ts +0 -320
- package/src/file-lock.ts +0 -393
- package/src/fixtures/hermes-0.20.6-classic-cli-local.json +0 -50
- package/src/fixtures/openclaw-2026.7.1-2-agent-local.json +0 -57
- package/src/generated-session-label.ts +0 -155
- package/src/guidance-content.ts +0 -278
- package/src/guidance-render.ts +0 -56
- package/src/guidance.test.ts +0 -327
- package/src/guidance.ts +0 -233
- package/src/harness-integration.test.ts +0 -294
- package/src/harnesses.test.ts +0 -149
- package/src/harnesses.ts +0 -164
- package/src/hook-adapter.test.ts +0 -496
- package/src/hook-adapter.ts +0 -424
- package/src/hook-input.test.ts +0 -39
- package/src/hook-input.ts +0 -72
- package/src/hooks.test.ts +0 -5824
- package/src/hooks.ts +0 -4011
- package/src/install-hooks.test.ts +0 -1614
- package/src/install-hooks.ts +0 -1501
- package/src/interactive.test.ts +0 -387
- package/src/interactive.ts +0 -858
- package/src/invocation-context.test.ts +0 -352
- package/src/invocation-context.ts +0 -197
- package/src/logging-process-worker.test.ts +0 -45
- package/src/logging.test.ts +0 -544
- package/src/logging.ts +0 -698
- package/src/main-run.ts +0 -45
- package/src/main.ts +0 -12
- package/src/native-skills.test.ts +0 -115
- package/src/native-skills.ts +0 -162
- package/src/node-floor.test.ts +0 -27
- package/src/node-floor.ts +0 -37
- package/src/onboarding-docs.test.ts +0 -25
- package/src/openclaw-plugin.ts +0 -409
- package/src/opencode-plugin.ts +0 -298
- package/src/orca-session-title.test.ts +0 -54
- package/src/orca-session-title.ts +0 -103
- package/src/pack-feedback-slice.test.ts +0 -212
- package/src/pack-feedback-slice.ts +0 -187
- package/src/platform.test.ts +0 -152
- package/src/platform.ts +0 -173
- package/src/program.test.ts +0 -317
- package/src/program.ts +0 -842
- package/src/project-enablement.test.ts +0 -55
- package/src/project-enablement.ts +0 -99
- package/src/question-caps.test.ts +0 -49
- package/src/question-settlement-process.ts +0 -47
- package/src/question-timing.ts +0 -56
- package/src/readiness.test.ts +0 -25
- package/src/readiness.ts +0 -212
- package/src/release.ts +0 -51
- package/src/send-attempts.test.ts +0 -143
- package/src/send-attempts.ts +0 -188
- package/src/send.test.ts +0 -28
- package/src/send.ts +0 -436
- package/src/session-activation.ts +0 -61
- package/src/session-end-log-lock-worker.test.ts +0 -35
- package/src/session-labels.test.ts +0 -490
- package/src/session-labels.ts +0 -474
- package/src/setup-destinations.test.ts +0 -41
- package/src/setup-destinations.ts +0 -50
- package/src/skill.test.ts +0 -426
- package/src/sound-ref.test.ts +0 -31
- package/src/sound-ref.ts +0 -34
- package/src/trust-policy.test.ts +0 -701
- package/src/ui/banner.ts +0 -95
- package/src/ui/config-view.test.ts +0 -90
- package/src/ui/config-view.ts +0 -138
- package/src/ui/help.test.ts +0 -16
- package/src/ui/help.ts +0 -128
- package/src/ui/theme.test.ts +0 -92
- package/src/ui/theme.ts +0 -265
- package/src/url-policy.ts +0 -399
- package/tsconfig.json +0 -10
package/src/credentials.test.ts
DELETED
|
@@ -1,403 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
chmodSync,
|
|
3
|
-
existsSync,
|
|
4
|
-
mkdirSync,
|
|
5
|
-
mkdtempSync,
|
|
6
|
-
readFileSync,
|
|
7
|
-
readdirSync,
|
|
8
|
-
rmSync,
|
|
9
|
-
statSync,
|
|
10
|
-
writeFileSync,
|
|
11
|
-
} from 'node:fs'
|
|
12
|
-
import os from 'node:os'
|
|
13
|
-
import path from 'node:path'
|
|
14
|
-
import { afterAll, describe, expect, it } from 'vitest'
|
|
15
|
-
import {
|
|
16
|
-
FileStore,
|
|
17
|
-
KeychainStore,
|
|
18
|
-
WindowsDpapiStore,
|
|
19
|
-
defaultCredentialStore,
|
|
20
|
-
windowsDpapiOperation,
|
|
21
|
-
type MachineCredential,
|
|
22
|
-
type ProcessRunner,
|
|
23
|
-
type RunCommandSpec,
|
|
24
|
-
} from './credentials.js'
|
|
25
|
-
|
|
26
|
-
const tmp = mkdtempSync(path.join(os.tmpdir(), 'notifai-cred-'))
|
|
27
|
-
afterAll(() => rmSync(tmp, { recursive: true, force: true }))
|
|
28
|
-
|
|
29
|
-
const SAMPLE: MachineCredential = {
|
|
30
|
-
machineId: 'mach_fixture',
|
|
31
|
-
secret: 'fixture-secret',
|
|
32
|
-
baseUrl: 'https://example.test',
|
|
33
|
-
machineName: 'fixture-machine',
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const OTHER: MachineCredential = {
|
|
37
|
-
machineId: 'mach_other',
|
|
38
|
-
secret: 'other-secret',
|
|
39
|
-
baseUrl: 'https://other.test',
|
|
40
|
-
machineName: 'other-machine',
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function sandbox(name: string): {
|
|
44
|
-
env: NodeJS.ProcessEnv
|
|
45
|
-
local: string
|
|
46
|
-
roaming: string
|
|
47
|
-
config: string
|
|
48
|
-
} {
|
|
49
|
-
const root = path.join(tmp, name)
|
|
50
|
-
const local = path.join(root, 'local')
|
|
51
|
-
const roaming = path.join(root, 'roaming')
|
|
52
|
-
const config = path.join(root, 'config')
|
|
53
|
-
mkdirSync(local, { recursive: true })
|
|
54
|
-
mkdirSync(roaming, { recursive: true })
|
|
55
|
-
mkdirSync(config, { recursive: true })
|
|
56
|
-
return {
|
|
57
|
-
local,
|
|
58
|
-
roaming,
|
|
59
|
-
config,
|
|
60
|
-
env: {
|
|
61
|
-
LOCALAPPDATA: local,
|
|
62
|
-
APPDATA: roaming,
|
|
63
|
-
XDG_CONFIG_HOME: config,
|
|
64
|
-
SystemRoot: 'C:\\Windows',
|
|
65
|
-
},
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function writeRaw(file: string, contents: string): void {
|
|
70
|
-
mkdirSync(path.dirname(file), { recursive: true })
|
|
71
|
-
writeFileSync(file, contents)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function mockDpapi(options: { failProtect?: boolean; failUnprotect?: boolean } = {}): {
|
|
75
|
-
runner: ProcessRunner
|
|
76
|
-
calls: RunCommandSpec[]
|
|
77
|
-
} {
|
|
78
|
-
const vault = new Map<string, string>()
|
|
79
|
-
const calls: RunCommandSpec[] = []
|
|
80
|
-
const runner: ProcessRunner = {
|
|
81
|
-
run(spec) {
|
|
82
|
-
calls.push({
|
|
83
|
-
command: spec.command,
|
|
84
|
-
args: spec.args,
|
|
85
|
-
input: spec.input,
|
|
86
|
-
...(spec.timeoutMs === undefined ? {} : { timeoutMs: spec.timeoutMs }),
|
|
87
|
-
})
|
|
88
|
-
const operation = windowsDpapiOperation(spec.args)
|
|
89
|
-
if (operation === 'protect') {
|
|
90
|
-
if (options.failProtect) return { status: 1, stdout: Buffer.alloc(0) }
|
|
91
|
-
const token = Buffer.from(`dpapi:${vault.size}`, 'utf8').toString('base64')
|
|
92
|
-
vault.set(token, spec.input.toString('utf8'))
|
|
93
|
-
return { status: 0, stdout: Buffer.from(token, 'utf8') }
|
|
94
|
-
}
|
|
95
|
-
if (operation === 'unprotect') {
|
|
96
|
-
if (options.failUnprotect) return { status: 1, stdout: Buffer.alloc(0) }
|
|
97
|
-
const token = spec.input.toString('utf8').trim()
|
|
98
|
-
const plain = vault.get(token)
|
|
99
|
-
if (plain === undefined) return { status: 1, stdout: Buffer.alloc(0) }
|
|
100
|
-
return { status: 0, stdout: Buffer.from(plain, 'utf8') }
|
|
101
|
-
}
|
|
102
|
-
return { status: 1, stdout: Buffer.alloc(0) }
|
|
103
|
-
},
|
|
104
|
-
}
|
|
105
|
-
return { runner, calls }
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function assertNoSecretInArgs(calls: RunCommandSpec[]): void {
|
|
109
|
-
for (const call of calls) {
|
|
110
|
-
const argv = [call.command, ...call.args].join('\0')
|
|
111
|
-
for (const credential of [SAMPLE, OTHER]) {
|
|
112
|
-
for (const value of Object.values(credential)) expect(argv).not.toContain(value)
|
|
113
|
-
expect(argv).not.toContain(JSON.stringify(credential))
|
|
114
|
-
}
|
|
115
|
-
expect(argv).not.toContain('machineId')
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
describe('defaultCredentialStore', () => {
|
|
120
|
-
it('selects the DPAPI store on win32', () => {
|
|
121
|
-
const { env } = sandbox('default-win32')
|
|
122
|
-
const store = defaultCredentialStore(env, { platform: 'win32', run: mockDpapi().runner })
|
|
123
|
-
expect(store).toBeInstanceOf(WindowsDpapiStore)
|
|
124
|
-
expect(store.describe()).toMatch(/Windows DPAPI current-user/)
|
|
125
|
-
expect(store.describe()).toContain(path.join(env.LOCALAPPDATA!, 'notifai', 'credentials.dpapi'))
|
|
126
|
-
})
|
|
127
|
-
|
|
128
|
-
it('keeps the explicit file escape hatch on win32 under APPDATA', () => {
|
|
129
|
-
const { env } = sandbox('default-file-win32')
|
|
130
|
-
const store = defaultCredentialStore(
|
|
131
|
-
{ ...env, NOTIFAI_CREDENTIALS: 'file', XDG_CONFIG_HOME: undefined },
|
|
132
|
-
{ platform: 'win32' },
|
|
133
|
-
)
|
|
134
|
-
expect(store).toBeInstanceOf(FileStore)
|
|
135
|
-
expect(store.describe()).toContain(path.join(env.APPDATA!, 'notifai', 'credentials.json'))
|
|
136
|
-
expect(store.describe()).toMatch(/plaintext file/)
|
|
137
|
-
expect(store.describe()).toMatch(/POSIX mode bits are not protection on NTFS/)
|
|
138
|
-
expect(store.describe()).not.toMatch(/0600/)
|
|
139
|
-
})
|
|
140
|
-
|
|
141
|
-
it('preserves macOS Keychain when available', () => {
|
|
142
|
-
const store = defaultCredentialStore({}, { platform: 'darwin', keychainAvailable: true })
|
|
143
|
-
expect(store.describe()).toBe('macOS Keychain (io.notifai.cli)')
|
|
144
|
-
})
|
|
145
|
-
|
|
146
|
-
it('falls back to the 0600 file store on linux', () => {
|
|
147
|
-
const { env } = sandbox('default-linux')
|
|
148
|
-
const store = defaultCredentialStore(env, { platform: 'linux' })
|
|
149
|
-
expect(store).toBeInstanceOf(FileStore)
|
|
150
|
-
expect(store.describe()).toMatch(/plaintext file/)
|
|
151
|
-
expect(store.describe()).toMatch(/mode 0600/)
|
|
152
|
-
expect(store.describe()).not.toMatch(/NTFS/)
|
|
153
|
-
})
|
|
154
|
-
|
|
155
|
-
it('uses the file store on macOS when Keychain is unavailable', () => {
|
|
156
|
-
const { env } = sandbox('default-darwin-file')
|
|
157
|
-
const store = defaultCredentialStore(env, { platform: 'darwin', keychainAvailable: false })
|
|
158
|
-
expect(store).toBeInstanceOf(FileStore)
|
|
159
|
-
expect(store.describe()).toMatch(/mode 0600/)
|
|
160
|
-
})
|
|
161
|
-
})
|
|
162
|
-
|
|
163
|
-
describe('FileStore', () => {
|
|
164
|
-
it('saves, loads, overwrites, and clears atomically', () => {
|
|
165
|
-
const { env } = sandbox('file-roundtrip')
|
|
166
|
-
const store = new FileStore(env, { platform: 'linux' })
|
|
167
|
-
expect(store.load()).toBeNull()
|
|
168
|
-
store.save(SAMPLE)
|
|
169
|
-
const file = path.join(env.XDG_CONFIG_HOME!, 'notifai', 'credentials.json')
|
|
170
|
-
expect(existsSync(file)).toBe(true)
|
|
171
|
-
if (process.platform !== 'win32') {
|
|
172
|
-
expect(statSync(file).mode & 0o777).toBe(0o600)
|
|
173
|
-
}
|
|
174
|
-
expect(JSON.parse(readFileSync(file, 'utf8'))).toEqual({
|
|
175
|
-
format: 'notifai.machine-credential.v1',
|
|
176
|
-
...SAMPLE,
|
|
177
|
-
})
|
|
178
|
-
expect(store.load()).toEqual(SAMPLE)
|
|
179
|
-
store.save(OTHER)
|
|
180
|
-
expect(store.load()).toEqual(OTHER)
|
|
181
|
-
store.clear()
|
|
182
|
-
expect(existsSync(file)).toBe(false)
|
|
183
|
-
expect(store.load()).toBeNull()
|
|
184
|
-
})
|
|
185
|
-
|
|
186
|
-
it('treats malformed JSON as missing', () => {
|
|
187
|
-
const { env } = sandbox('file-malformed')
|
|
188
|
-
const file = path.join(env.XDG_CONFIG_HOME!, 'notifai', 'credentials.json')
|
|
189
|
-
writeRaw(file, '{not-json')
|
|
190
|
-
expect(new FileStore(env).load()).toBeNull()
|
|
191
|
-
})
|
|
192
|
-
|
|
193
|
-
it('treats incomplete objects as missing', () => {
|
|
194
|
-
const { env } = sandbox('file-incomplete')
|
|
195
|
-
const file = path.join(env.XDG_CONFIG_HOME!, 'notifai', 'credentials.json')
|
|
196
|
-
writeRaw(file, `${JSON.stringify({ machineId: 'mach_fixture' })}\n`)
|
|
197
|
-
expect(new FileStore(env).load()).toBeNull()
|
|
198
|
-
})
|
|
199
|
-
|
|
200
|
-
it('reads the unversioned v1 shape while making every new save explicit', () => {
|
|
201
|
-
const { env } = sandbox('file-unversioned-v1')
|
|
202
|
-
const file = path.join(env.XDG_CONFIG_HOME!, 'notifai', 'credentials.json')
|
|
203
|
-
writeRaw(file, `${JSON.stringify(SAMPLE)}\n`)
|
|
204
|
-
const store = new FileStore(env)
|
|
205
|
-
expect(store.load()).toEqual(SAMPLE)
|
|
206
|
-
store.save(SAMPLE)
|
|
207
|
-
expect(JSON.parse(readFileSync(file, 'utf8'))).toMatchObject({
|
|
208
|
-
format: 'notifai.machine-credential.v1',
|
|
209
|
-
})
|
|
210
|
-
})
|
|
211
|
-
|
|
212
|
-
it('creates the credential directory mode 0700 on POSIX', () => {
|
|
213
|
-
if (process.platform === 'win32') return
|
|
214
|
-
const { env } = sandbox('file-dir-mode')
|
|
215
|
-
const store = new FileStore(env, { platform: 'linux' })
|
|
216
|
-
store.save(SAMPLE)
|
|
217
|
-
const dir = path.join(env.XDG_CONFIG_HOME!, 'notifai')
|
|
218
|
-
expect(statSync(dir).mode & 0o777).toBe(0o700)
|
|
219
|
-
})
|
|
220
|
-
|
|
221
|
-
it('tightens an existing world-readable credential directory on POSIX', () => {
|
|
222
|
-
if (process.platform === 'win32') return
|
|
223
|
-
const { env } = sandbox('file-dir-chmod')
|
|
224
|
-
const dir = path.join(env.XDG_CONFIG_HOME!, 'notifai')
|
|
225
|
-
mkdirSync(dir, { recursive: true, mode: 0o755 })
|
|
226
|
-
chmodSync(dir, 0o755)
|
|
227
|
-
expect(statSync(dir).mode & 0o777).toBe(0o755)
|
|
228
|
-
const store = new FileStore(env, { platform: 'linux' })
|
|
229
|
-
store.save(SAMPLE)
|
|
230
|
-
expect(statSync(dir).mode & 0o777).toBe(0o700)
|
|
231
|
-
})
|
|
232
|
-
|
|
233
|
-
it('does not interpret or erase a credential from a future format epoch', () => {
|
|
234
|
-
const { env } = sandbox('file-future-format')
|
|
235
|
-
const file = path.join(env.XDG_CONFIG_HOME!, 'notifai', 'credentials.json')
|
|
236
|
-
const future = `${JSON.stringify({ format: 'notifai.machine-credential.v2', ...SAMPLE })}\n`
|
|
237
|
-
writeRaw(file, future)
|
|
238
|
-
expect(new FileStore(env).load()).toBeNull()
|
|
239
|
-
expect(readFileSync(file, 'utf8')).toBe(future)
|
|
240
|
-
})
|
|
241
|
-
})
|
|
242
|
-
|
|
243
|
-
describe('KeychainStore', () => {
|
|
244
|
-
it('sends the serialized credential through stdin and never process argv', () => {
|
|
245
|
-
const calls: RunCommandSpec[] = []
|
|
246
|
-
const runner: ProcessRunner = {
|
|
247
|
-
run(spec) {
|
|
248
|
-
calls.push(spec)
|
|
249
|
-
return { status: 0, stdout: Buffer.alloc(0) }
|
|
250
|
-
},
|
|
251
|
-
}
|
|
252
|
-
const store = new KeychainStore({ run: runner })
|
|
253
|
-
store.save(SAMPLE)
|
|
254
|
-
store.save(OTHER)
|
|
255
|
-
|
|
256
|
-
expect(calls).toHaveLength(2)
|
|
257
|
-
for (const [index, call] of calls.entries()) {
|
|
258
|
-
expect(call.command).toBe('security')
|
|
259
|
-
expect(call.args).toEqual(['-q', '-i'])
|
|
260
|
-
expect(call.timeoutMs).toBe(15_000)
|
|
261
|
-
expect(call.input.toString('ascii')).toMatch(
|
|
262
|
-
/^add-generic-password -U -s io\.notifai\.cli -a machine -X [0-9a-f]+\n$/,
|
|
263
|
-
)
|
|
264
|
-
const encoded = call.input.toString('ascii').match(/-X ([0-9a-f]+)\n$/)?.[1]
|
|
265
|
-
expect(encoded).toBeDefined()
|
|
266
|
-
expect(JSON.parse(Buffer.from(encoded!, 'hex').toString('utf8'))).toEqual({
|
|
267
|
-
format: 'notifai.machine-credential.v1',
|
|
268
|
-
...(index === 0 ? SAMPLE : OTHER),
|
|
269
|
-
})
|
|
270
|
-
expect(call.input.toString('utf8')).not.toContain(index === 0 ? SAMPLE.secret : OTHER.secret)
|
|
271
|
-
}
|
|
272
|
-
assertNoSecretInArgs(calls)
|
|
273
|
-
})
|
|
274
|
-
|
|
275
|
-
it('fails closed when the Keychain helper rejects the write', () => {
|
|
276
|
-
const runner: ProcessRunner = {
|
|
277
|
-
run() {
|
|
278
|
-
return { status: 1, stdout: Buffer.alloc(0) }
|
|
279
|
-
},
|
|
280
|
-
}
|
|
281
|
-
expect(() => new KeychainStore({ run: runner }).save(SAMPLE)).toThrow(
|
|
282
|
-
/Keychain credential save failed/,
|
|
283
|
-
)
|
|
284
|
-
})
|
|
285
|
-
})
|
|
286
|
-
|
|
287
|
-
describe('WindowsDpapiStore', () => {
|
|
288
|
-
it('round-trips through real Windows CurrentUser DPAPI without plaintext on disk', () => {
|
|
289
|
-
if (process.platform !== 'win32') return
|
|
290
|
-
|
|
291
|
-
const local = path.join(tmp, 'real dpapi & Ω', 'local app data')
|
|
292
|
-
mkdirSync(local, { recursive: true })
|
|
293
|
-
const env = { ...process.env, LOCALAPPDATA: local }
|
|
294
|
-
const store = new WindowsDpapiStore(env)
|
|
295
|
-
store.save(SAMPLE)
|
|
296
|
-
|
|
297
|
-
const file = path.join(local, 'notifai', 'credentials.dpapi')
|
|
298
|
-
const onDisk = readFileSync(file, 'utf8')
|
|
299
|
-
expect(onDisk).not.toContain(SAMPLE.secret)
|
|
300
|
-
expect(onDisk).not.toContain(SAMPLE.machineId)
|
|
301
|
-
expect(new WindowsDpapiStore(env).load()).toEqual(SAMPLE)
|
|
302
|
-
|
|
303
|
-
store.clear()
|
|
304
|
-
expect(existsSync(file)).toBe(false)
|
|
305
|
-
})
|
|
306
|
-
|
|
307
|
-
it('protects under LOCALAPPDATA and never writes roaming or config trees', () => {
|
|
308
|
-
const { env, roaming, config } = sandbox('dpapi-location')
|
|
309
|
-
const { runner, calls } = mockDpapi()
|
|
310
|
-
const store = new WindowsDpapiStore(env, { run: runner })
|
|
311
|
-
store.save(SAMPLE)
|
|
312
|
-
const file = path.join(env.LOCALAPPDATA!, 'notifai', 'credentials.dpapi')
|
|
313
|
-
expect(existsSync(file)).toBe(true)
|
|
314
|
-
const onDisk = readFileSync(file, 'utf8')
|
|
315
|
-
expect(onDisk).not.toContain(SAMPLE.secret)
|
|
316
|
-
expect(onDisk).not.toContain(SAMPLE.machineId)
|
|
317
|
-
expect(JSON.parse(onDisk)).toMatchObject({ format: 'notifai.dpapi.current-user.v1' })
|
|
318
|
-
expect(readdirSync(roaming, { recursive: true })).toEqual([])
|
|
319
|
-
expect(existsSync(config) ? readdirSync(config, { recursive: true }) : []).toEqual([])
|
|
320
|
-
expect(store.load()).toEqual(SAMPLE)
|
|
321
|
-
expect(store.describe()).toBe(`Windows DPAPI current-user (${file})`)
|
|
322
|
-
expect(calls[0]?.command).toMatch(/powershell\.exe$/i)
|
|
323
|
-
expect(calls[0]?.args).toEqual(
|
|
324
|
-
expect.arrayContaining(['-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass']),
|
|
325
|
-
)
|
|
326
|
-
expect(calls.every((call) => call.timeoutMs === 30_000)).toBe(true)
|
|
327
|
-
assertNoSecretInArgs(calls)
|
|
328
|
-
})
|
|
329
|
-
|
|
330
|
-
it('overwrites and clears the protected blob', () => {
|
|
331
|
-
const { env } = sandbox('dpapi-overwrite')
|
|
332
|
-
const { runner, calls } = mockDpapi()
|
|
333
|
-
const store = new WindowsDpapiStore(env, { run: runner })
|
|
334
|
-
store.save(SAMPLE)
|
|
335
|
-
store.save(OTHER)
|
|
336
|
-
expect(store.load()).toEqual(OTHER)
|
|
337
|
-
store.clear()
|
|
338
|
-
expect(store.load()).toBeNull()
|
|
339
|
-
expect(
|
|
340
|
-
existsSync(path.join(env.LOCALAPPDATA!, 'notifai', 'credentials.dpapi')),
|
|
341
|
-
).toBe(false)
|
|
342
|
-
assertNoSecretInArgs(calls)
|
|
343
|
-
})
|
|
344
|
-
|
|
345
|
-
it('returns null for missing, malformed, and corrupt envelopes', () => {
|
|
346
|
-
const { env } = sandbox('dpapi-corrupt')
|
|
347
|
-
const { runner } = mockDpapi()
|
|
348
|
-
const store = new WindowsDpapiStore(env, { run: runner })
|
|
349
|
-
expect(store.load()).toBeNull()
|
|
350
|
-
const file = path.join(env.LOCALAPPDATA!, 'notifai', 'credentials.dpapi')
|
|
351
|
-
writeRaw(file, 'not-json')
|
|
352
|
-
expect(store.load()).toBeNull()
|
|
353
|
-
writeRaw(file, `${JSON.stringify({ format: 'unknown', data: 'AAAA' })}\n`)
|
|
354
|
-
expect(store.load()).toBeNull()
|
|
355
|
-
writeRaw(
|
|
356
|
-
file,
|
|
357
|
-
`${JSON.stringify({ format: 'notifai.dpapi.current-user.v1', data: '@@@' })}\n`,
|
|
358
|
-
)
|
|
359
|
-
expect(store.load()).toBeNull()
|
|
360
|
-
})
|
|
361
|
-
|
|
362
|
-
it('leaves the existing blob in place when protection fails', () => {
|
|
363
|
-
const { env } = sandbox('dpapi-protect-fail')
|
|
364
|
-
const good = mockDpapi()
|
|
365
|
-
const store = new WindowsDpapiStore(env, { run: good.runner })
|
|
366
|
-
store.save(SAMPLE)
|
|
367
|
-
const failing = mockDpapi({ failProtect: true })
|
|
368
|
-
const broken = new WindowsDpapiStore(env, { run: failing.runner })
|
|
369
|
-
expect(() => broken.save(OTHER)).toThrow(/Windows credential protection failed/)
|
|
370
|
-
expect(store.load()).toEqual(SAMPLE)
|
|
371
|
-
const onDisk = readFileSync(path.join(env.LOCALAPPDATA!, 'notifai', 'credentials.dpapi'), 'utf8')
|
|
372
|
-
expect(onDisk).not.toContain(OTHER.secret)
|
|
373
|
-
assertNoSecretInArgs([...good.calls, ...failing.calls])
|
|
374
|
-
})
|
|
375
|
-
|
|
376
|
-
it('returns null when unprotect fails', () => {
|
|
377
|
-
const { env } = sandbox('dpapi-unprotect-fail')
|
|
378
|
-
const saved = mockDpapi()
|
|
379
|
-
new WindowsDpapiStore(env, { run: saved.runner }).save(SAMPLE)
|
|
380
|
-
const failing = mockDpapi({ failUnprotect: true })
|
|
381
|
-
expect(new WindowsDpapiStore(env, { run: failing.runner }).load()).toBeNull()
|
|
382
|
-
assertNoSecretInArgs([...saved.calls, ...failing.calls])
|
|
383
|
-
})
|
|
384
|
-
|
|
385
|
-
it('refuses to save when LOCALAPPDATA is missing', () => {
|
|
386
|
-
const store = new WindowsDpapiStore({}, { run: mockDpapi().runner })
|
|
387
|
-
expect(store.load()).toBeNull()
|
|
388
|
-
expect(() => store.save(SAMPLE)).toThrow(/LOCALAPPDATA is missing/)
|
|
389
|
-
expect(store.describe()).toBe('Windows DPAPI current-user (LOCALAPPDATA unset)')
|
|
390
|
-
store.clear()
|
|
391
|
-
})
|
|
392
|
-
|
|
393
|
-
it('does not invoke a process for a missing or corrupt file', () => {
|
|
394
|
-
const { env } = sandbox('dpapi-no-process')
|
|
395
|
-
const { runner, calls } = mockDpapi()
|
|
396
|
-
const store = new WindowsDpapiStore(env, { run: runner })
|
|
397
|
-
expect(store.load()).toBeNull()
|
|
398
|
-
const file = path.join(env.LOCALAPPDATA!, 'notifai', 'credentials.dpapi')
|
|
399
|
-
writeRaw(file, 'corrupt')
|
|
400
|
-
expect(store.load()).toBeNull()
|
|
401
|
-
expect(calls).toEqual([])
|
|
402
|
-
})
|
|
403
|
-
})
|