Repository navigation
371 lines (341 loc) · 14.8 KB
/
Copy pathtest-credential-backends.yml
File metadata and controls
371 lines (341 loc) · 14.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
name: Test Credential Backends
on:
pull_request:
paths:
- src/lib/**
- src/commands/auth/**
- tests/lib/**
- tests/commands/auth/**
- .github/workflows/test-credential-backends.yml
workflow_dispatch:
permissions:
contents: read
concurrency:
group: test-credential-backends-${{ github.ref }}
cancel-in-progress: true
jobs:
# ── Cross-platform vitest run for credential file plumbing ───
# The main test workflow runs Linux only. These jobs exercise the
# file-lock, atomic-write, and auth flows on Windows and macOS too,
# since POSIX-vs-NTFS semantics (inode reuse, rename, file locking)
# have already produced one cross-platform regression in this area.
config-tests:
name: "Config tests (${{ matrix.os }})"
timeout-minutes: 25
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- uses: pnpm/action-setup@0e279bb959325dab635dd2c09392533439d90093 # v6
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6
with:
node-version: 24
cache: 'pnpm'
- run: pnpm install --frozen-lockfile
- run: pnpm test tests/lib/file-lock.test.ts tests/lib/write-file-atomic.test.ts tests/lib/config.test.ts tests/lib/config-async.test.ts tests/commands/auth/
# ── Windows ──────────────────────────────────────────────
win-passwordvault:
name: "Windows: PasswordVault"
runs-on: windows-latest
timeout-minutes: 25
strategy:
matrix:
shell: [powershell]
defaults:
run:
shell: ${{ matrix.shell }}
steps:
- name: Test PasswordVault type loading
run: |
try {
$v = New-Object Windows.Security.Credentials.PasswordVault
Write-Host "PasswordVault: OK"
} catch {
Write-Host "PasswordVault: direct load failed, trying WinRT assembly - $_"
try {
[Windows.Security.Credentials.PasswordVault,Windows.Security.Credentials,ContentType=WindowsRuntime] | Out-Null
$v = New-Object Windows.Security.Credentials.PasswordVault
Write-Host "PasswordVault (WinRT load): OK"
} catch {
Write-Host "PasswordVault: FAILED - $_"
exit 1
}
}
- name: Test PasswordVault store and retrieve
run: |
try { [void](New-Object Windows.Security.Credentials.PasswordVault) } catch {
[void][Windows.Security.Credentials.PasswordVault,Windows.Security.Credentials,ContentType=WindowsRuntime]
}
try {
$v = New-Object Windows.Security.Credentials.PasswordVault
$c = New-Object Windows.Security.Credentials.PasswordCredential('resend-cli-test', 'test-account', 're_test_key_123')
$v.Add($c)
Write-Host "Store: OK"
$r = $v.Retrieve('resend-cli-test', 'test-account')
$r.RetrievePassword()
if ($r.Password -eq 're_test_key_123') {
Write-Host "Retrieve: OK"
} else {
Write-Host "Retrieve: WRONG VALUE - got $($r.Password)"
exit 1
}
$v.Remove($r)
Write-Host "Delete: OK"
} catch {
Write-Host "PasswordVault round-trip: FAILED - $_"
exit 1
}
win-credmanager:
name: "Windows: Win32 CredManager (P/Invoke)"
runs-on: windows-latest
timeout-minutes: 30
strategy:
matrix:
shell: [pwsh, powershell]
defaults:
run:
shell: ${{ matrix.shell }}
steps:
- name: Test CredWrite + CredRead + CredDelete via P/Invoke
run: |
Add-Type -TypeDefinition @"
using System;
using System.Runtime.InteropServices;
using System.Text;
public class CredManager {
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
private struct CREDENTIAL {
public int Flags;
public int Type;
public string TargetName;
public string Comment;
public long LastWritten;
public int CredentialBlobSize;
public IntPtr CredentialBlob;
public int Persist;
public int AttributeCount;
public IntPtr Attributes;
public string TargetAlias;
public string UserName;
}
[DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
private static extern bool CredWrite(ref CREDENTIAL cred, int flags);
[DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
private static extern bool CredRead(string target, int type, int flags, out IntPtr credential);
[DllImport("advapi32.dll", SetLastError = true)]
private static extern bool CredDelete(string target, int type, int flags);
[DllImport("advapi32.dll")]
private static extern void CredFree(IntPtr buffer);
public static void Write(string target, string user, string secret) {
byte[] bytes = Encoding.Unicode.GetBytes(secret);
CREDENTIAL cred = new CREDENTIAL();
cred.Type = 1; // CRED_TYPE_GENERIC
cred.TargetName = target;
cred.UserName = user;
cred.CredentialBlob = Marshal.AllocHGlobal(bytes.Length);
Marshal.Copy(bytes, 0, cred.CredentialBlob, bytes.Length);
cred.CredentialBlobSize = bytes.Length;
cred.Persist = 2; // CRED_PERSIST_LOCAL_MACHINE
try {
if (!CredWrite(ref cred, 0))
throw new Exception("CredWrite failed: " + Marshal.GetLastWin32Error());
} finally {
Marshal.FreeHGlobal(cred.CredentialBlob);
}
}
public static string Read(string target) {
IntPtr credPtr;
if (!CredRead(target, 1, 0, out credPtr))
return null;
try {
CREDENTIAL cred = (CREDENTIAL)Marshal.PtrToStructure(credPtr, typeof(CREDENTIAL));
return Marshal.PtrToStringUni(cred.CredentialBlob, cred.CredentialBlobSize / 2);
} finally {
CredFree(credPtr);
}
}
public static bool Delete(string target) {
return CredDelete(target, 1, 0);
}
}
"@
[CredManager]::Write("resend-cli:test-account", "test-account", "re_test_key_123")
Write-Host "CredWrite: OK"
$val = [CredManager]::Read("resend-cli:test-account")
if ($val -eq "re_test_key_123") {
Write-Host "CredRead: OK"
} else {
Write-Host "CredRead: FAILED - got '$val'"
exit 1
}
$deleted = [CredManager]::Delete("resend-cli:test-account")
if ($deleted) {
Write-Host "CredDelete: OK"
} else {
Write-Host "CredDelete: FAILED"
exit 1
}
$val2 = [CredManager]::Read("resend-cli:test-account")
if ($val2 -eq $null) {
Write-Host "Verify deleted: OK"
} else {
Write-Host "Verify deleted: FAILED - still exists"
exit 1
}
- name: Test stdin piping to PowerShell
shell: cmd
run: |
echo re_test_key_123 | powershell.exe -NoProfile -NonInteractive -Command "$secret = [System.Console]::ReadLine(); Write-Output $secret"
win-cmdkey:
name: "Windows: cmdkey"
runs-on: windows-latest
timeout-minutes: 15
steps:
- name: Test cmdkey store and list
shell: cmd
run: |
cmdkey /generic:resend-cli-test /user:test-account /pass:re_test_key_123
cmdkey /list:resend-cli-test
cmdkey /delete:resend-cli-test
# ── Linux ────────────────────────────────────────────────
linux-secret-tool:
name: "Linux: secret-tool (libsecret)"
runs-on: depot-ubuntu-24.04
timeout-minutes: 30
steps:
- name: Install libsecret and gnome-keyring
run: |
sudo apt-get update -qq
sudo apt-get install -y -qq libsecret-tools gnome-keyring dbus-x11
- name: Test secret-tool store + lookup + clear
run: |
dbus-run-session -- bash -c '
echo "" | gnome-keyring-daemon --unlock --components=secrets 2>/dev/null || true
# Trigger D-Bus activation of the Secret Service (gnome-keyring-daemon
# --unlock alone does not reliably register the service on the bus).
dbus-send --session --print-reply --dest=org.freedesktop.secrets \
/org/freedesktop/secrets org.freedesktop.DBus.Properties.Get \
string:org.freedesktop.Secret.Service string:Collections >/dev/null 2>&1 || true
echo -n "re_test_key_123" | secret-tool store --label="Resend CLI test" service resend-cli-test account test-account
echo "Store: OK"
val=$(secret-tool lookup service resend-cli-test account test-account)
if [ "$val" = "re_test_key_123" ]; then
echo "Lookup: OK"
else
echo "Lookup: FAILED - got $val"
exit 1
fi
secret-tool clear service resend-cli-test account test-account
echo "Clear: OK"
val2=$(secret-tool lookup service resend-cli-test account test-account || true)
if [ -z "$val2" ]; then
echo "Verify cleared: OK"
else
echo "Verify cleared: FAILED - still exists"
exit 1
fi
'
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6
with:
node-version: 24
- name: Test Node.js spawn + stdin with secret-tool
run: |
dbus-run-session -- bash -c '
echo "" | gnome-keyring-daemon --unlock --components=secrets 2>/dev/null || true
# Trigger D-Bus activation of the Secret Service
dbus-send --session --print-reply --dest=org.freedesktop.secrets \
/org/freedesktop/secrets org.freedesktop.DBus.Properties.Get \
string:org.freedesktop.Secret.Service string:Collections >/dev/null 2>&1 || true
node -e "
const { spawn, execFileSync } = require(\"child_process\");
const child = spawn(\"secret-tool\", [
\"store\", \"--label=Node test\", \"service\", \"resend-cli-node\", \"account\", \"node-test\"
], { stdio: [\"pipe\", \"ignore\", \"pipe\"] });
let stderr = \"\";
child.stderr.on(\"data\", d => stderr += d);
child.on(\"close\", code => {
if (code !== 0) { console.log(\"Node store: FAILED -\", stderr); process.exit(1); }
console.log(\"Node store via stdin: OK\");
const val = execFileSync(\"secret-tool\", [
\"lookup\", \"service\", \"resend-cli-node\", \"account\", \"node-test\"
]).toString().trim();
if (val === \"re_node_test_key\") {
console.log(\"Node lookup: OK\");
} else {
console.log(\"Node lookup: FAILED - got\", JSON.stringify(val));
process.exit(1);
}
execFileSync(\"secret-tool\", [\"clear\", \"service\", \"resend-cli-node\", \"account\", \"node-test\"]);
console.log(\"Node clear: OK\");
});
child.stdin.write(\"re_node_test_key\");
child.stdin.end();
"
'
# ── macOS ────────────────────────────────────────────────
macos-keychain:
name: "macOS: security (Keychain)"
runs-on: macos-latest
timeout-minutes: 25
steps:
- name: Test security add-generic-password + find + delete
run: |
# Store
/usr/bin/security add-generic-password -s resend-cli-test -a test-account -w re_test_key_123 -U
echo "Store: OK"
# Retrieve
val=$(/usr/bin/security find-generic-password -s resend-cli-test -a test-account -w)
if [ "$val" = "re_test_key_123" ]; then
echo "Retrieve: OK"
else
echo "Retrieve: FAILED - got '$val'"
exit 1
fi
# Delete
/usr/bin/security delete-generic-password -s resend-cli-test -a test-account
echo "Delete: OK"
# Verify deleted (exit code 44 = not found)
if /usr/bin/security find-generic-password -s resend-cli-test -a test-account -w 2>/dev/null; then
echo "Verify deleted: FAILED - still exists"
exit 1
else
echo "Verify deleted: OK"
fi
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6
with:
node-version: 24
- name: Test Node.js execFile with security command
run: |
node -e "
const { execFile } = require('child_process');
// Store
execFile('/usr/bin/security', [
'add-generic-password', '-s', 'resend-cli-node', '-a', 'node-test', '-w', 're_node_test_key', '-U'
], (err) => {
if (err) { console.log('Node store: FAILED -', err.message); process.exit(1); }
console.log('Node store: OK');
// Retrieve
execFile('/usr/bin/security', [
'find-generic-password', '-s', 'resend-cli-node', '-a', 'node-test', '-w'
], (err2, stdout) => {
if (err2) { console.log('Node retrieve: FAILED -', err2.message); process.exit(1); }
const val = stdout.trim();
if (val === 're_node_test_key') {
console.log('Node retrieve: OK');
} else {
console.log('Node retrieve: FAILED - got', JSON.stringify(val));
process.exit(1);
}
// Delete
execFile('/usr/bin/security', [
'delete-generic-password', '-s', 'resend-cli-node', '-a', 'node-test'
], (err3) => {
if (err3) { console.log('Node delete: FAILED -', err3.message); process.exit(1); }
console.log('Node delete: OK');
});
});
});
"