yadflow 4.6.0 → 4.8.0
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 +259 -0
- package/README.md +46 -4
- package/bin/commands.mjs +9 -2
- package/bin/yad.mjs +309 -30
- package/cli/agent-guard.mjs +511 -0
- package/cli/agent-guide.mjs +83 -0
- package/cli/agent-rules.mjs +381 -0
- package/cli/argv-flags.mjs +7 -0
- package/cli/artifact-status.mjs +88 -20
- package/cli/build.mjs +1372 -0
- package/cli/checkpoint.mjs +2 -2
- package/cli/ci-check.mjs +492 -0
- package/cli/commit.mjs +1 -0
- package/cli/dial.mjs +21 -1
- package/cli/docs.mjs +7 -2
- package/cli/doctor.mjs +176 -33
- package/cli/epic-state.mjs +360 -12
- package/cli/errors.mjs +3 -0
- package/cli/find-product.mjs +36 -2
- package/cli/fold.mjs +9 -5
- package/cli/gate-local.mjs +9 -1
- package/cli/gate.mjs +364 -22
- package/cli/guide.mjs +549 -0
- package/cli/history.mjs +22 -2
- package/cli/hook.mjs +35 -4
- package/cli/index-command.mjs +2 -2
- package/cli/ledger.mjs +60 -0
- package/cli/lib.mjs +46 -0
- package/cli/lifecycle/defaults/2.json +124 -0
- package/cli/lifecycle/lifecycle.schema.json +5 -2
- package/cli/lifecycle.mjs +16 -3
- package/cli/manifest.mjs +75 -0
- package/cli/marked-block.mjs +48 -0
- package/cli/members.mjs +19 -5
- package/cli/migrate.mjs +17 -19
- package/cli/next.mjs +35 -12
- package/cli/openpr.mjs +81 -5
- package/cli/plan.mjs +326 -22
- package/cli/platform.mjs +21 -0
- package/cli/pr-list.mjs +5 -3
- package/cli/product-index.mjs +6 -3
- package/cli/product-token.mjs +186 -0
- package/cli/productcommit.mjs +33 -0
- package/cli/protection.mjs +50 -0
- package/cli/recommend.mjs +3 -1
- package/cli/reconcile.mjs +187 -26
- package/cli/repo-publish.mjs +2 -2
- package/cli/report.mjs +62 -14
- package/cli/run-checks.mjs +586 -0
- package/cli/setup.mjs +244 -25
- package/cli/ship-drift.mjs +49 -18
- package/cli/signing.mjs +377 -0
- package/cli/standup.mjs +1 -1
- package/cli/status.mjs +282 -0
- package/cli/test-agents-file.mjs +993 -0
- package/cli/test-build.mjs +1559 -0
- package/cli/test-ci-check.mjs +616 -0
- package/cli/test-guide.mjs +1267 -0
- package/cli/test-node.mjs +129 -0
- package/cli/test-run-checks.mjs +603 -0
- package/cli/test-setup-agent.mjs +352 -0
- package/cli/test-signing.mjs +524 -0
- package/cli/test-worktree.mjs +520 -0
- package/cli/thread.mjs +4 -0
- package/cli/tidy.mjs +2 -2
- package/cli/toolbox.mjs +37 -6
- package/cli/update-commit.mjs +313 -11
- package/cli/workspace.mjs +38 -10
- package/cli/worktree-record.mjs +53 -0
- package/cli/worktree.mjs +379 -0
- package/package.json +6 -4
- package/skills/sdlc/config.yaml +5 -5
- package/skills/sdlc/module-help.csv +2 -1
- package/skills/yad-backfill/templates/checks/backfill-check.sh +9 -9
- package/skills/yad-change/SKILL.md +5 -1
- package/skills/yad-checks/SKILL.md +61 -12
- package/skills/yad-checks/references/check-gates.md +78 -14
- package/skills/yad-checks/templates/checks/build-test-lint.sh +22 -3
- package/skills/yad-checks/templates/checks/commit-message.sh +8 -2
- package/skills/yad-checks/templates/checks/contract-check.sh +61 -33
- package/skills/yad-checks/templates/checks/epic-open.sh +87 -14
- package/skills/yad-checks/templates/checks/ledger-guard.sh +3 -3
- package/skills/yad-checks/templates/checks/lineage-check.sh +88 -15
- package/skills/yad-checks/templates/checks/member-check.mjs +206 -35
- package/skills/yad-checks/templates/checks/package-manager.sh +42 -5
- package/skills/yad-checks/templates/checks/product-checkout.sh +161 -13
- package/skills/yad-checks/templates/checks/reconcile-debt-check.sh +94 -15
- package/skills/yad-checks/templates/checks/risk-map-check.sh +2 -2
- package/skills/yad-checks/templates/checks/spec-link.sh +63 -4
- package/skills/yad-checks/templates/checks/verified-commits.sh +23 -5
- package/skills/yad-checks/templates/github/yad-checks.yml +9 -9
- package/skills/yad-checks/templates/gitlab/.gitlab-ci.yml +4 -1
- package/skills/yad-checks/templates/gitlab/yad-checks.gitlab-ci.yml +5 -5
- package/skills/yad-checks/templates/gitlab/yad-product-checks.gitlab-ci.yml +16 -3
- package/skills/yad-checks/templates/gitlab/yad-update-guard.gitlab-ci.yml +5 -1
- package/skills/yad-checks/templates/gitlab/yad-verified-commits.gitlab-ci.yml +5 -1
- package/skills/yad-checks/templates/hooks/agent-guard.mjs +116 -0
- package/skills/yad-commit/SKILL.md +8 -5
- package/skills/yad-connect-repos/SKILL.md +5 -3
- package/skills/yad-connect-repos/references/code-context.md +2 -1
- package/skills/yad-connect-repos/references/repos-registry.md +2 -1
- package/skills/yad-docs/templates/app/package-lock.json +395 -106
- package/skills/yad-docs/templates/app/package.json +2 -2
- package/skills/yad-docs-overview/references/pipeline-model.md +2 -2
- package/skills/yad-engineer-review/SKILL.md +55 -25
- package/skills/yad-engineer-review/references/ship-and-record.md +49 -12
- package/skills/yad-epic/SKILL.md +2 -1
- package/skills/yad-epic/references/state-schema.md +76 -17
- package/skills/yad-guide/SKILL.md +192 -0
- package/skills/yad-implement/SKILL.md +75 -13
- package/skills/yad-implement/references/implement-conventions.md +8 -1
- package/skills/yad-implement/templates/.gitmessage +3 -0
- package/skills/yad-open-pr/SKILL.md +21 -0
- package/skills/yad-pair-review/SKILL.md +14 -5
- package/skills/yad-pr-template/SKILL.md +6 -2
- package/skills/yad-pr-template/templates/checks/pr-template.sh +85 -4
- package/skills/yad-pr-template/templates/checks/pr-title.sh +1 -1
- package/skills/yad-pr-template/templates/github/pull_request_template.md +1 -1
- package/skills/yad-pr-template/templates/gitlab/merge_request_templates/Default.md +1 -1
- package/skills/yad-product-bridge/SKILL.md +44 -12
- package/skills/yad-product-bridge/references/bridge.md +11 -5
- package/skills/yad-product-bridge/templates/github/yad-gate-sync.yml +2 -2
- package/skills/yad-product-bridge/templates/gitlab/yad-gate-sync.gitlab-ci.yml +9 -4
- package/skills/yad-reconcile/SKILL.md +9 -3
- package/skills/yad-report/SKILL.md +15 -0
- package/skills/yad-review-companion/SKILL.md +5 -3
- package/skills/yad-review-gate/SKILL.md +16 -8
- package/skills/yad-review-gate/references/gating.md +26 -1
- package/skills/yad-run/SKILL.md +61 -33
- package/skills/yad-run/references/run-loop.md +44 -22
- package/skills/yad-spec/SKILL.md +137 -16
- package/skills/yad-spec/references/spec-handoff.md +50 -3
- package/skills/yad-status/SKILL.md +7 -0
- package/skills/yad-stories/references/story-schema.md +1 -1
- package/skills/yad-sync-repos/SKILL.md +2 -1
- package/skills/yad-ui/SKILL.md +2 -2
|
@@ -0,0 +1,524 @@
|
|
|
1
|
+
// E160a: `yad signing check`. The rules each test pins (the case list is in the E160 roadmap row):
|
|
2
|
+
// - this machine: signing on, the format, the email, the key (SSH: the file and ssh-keygen, git 2.34+;
|
|
3
|
+
// GPG: gpg finds the secret key), and a suggestion for the allowed-signers file;
|
|
4
|
+
// - the account: the key listed for SIGNING (an authentication-only key is a gap), and a verified email;
|
|
5
|
+
// - a read that fails is `unknown` with the fix, never `ok`; no login, no CLI or reads off: `unknown`;
|
|
6
|
+
// - `yad doctor` has one line for it, from the git config alone.
|
|
7
|
+
import { test } from 'node:test';
|
|
8
|
+
import assert from 'node:assert/strict';
|
|
9
|
+
import { spawnSync, execFileSync } from 'node:child_process';
|
|
10
|
+
import fs from 'node:fs';
|
|
11
|
+
import os from 'node:os';
|
|
12
|
+
import path from 'node:path';
|
|
13
|
+
import { fileURLToPath } from 'node:url';
|
|
14
|
+
|
|
15
|
+
if (process.env.NODE_TEST_CONTEXT) {
|
|
16
|
+
const write = process.stdout.write;
|
|
17
|
+
for (const k of ['log', 'info']) {
|
|
18
|
+
const orig = console[k];
|
|
19
|
+
console[k] = (...a) => (process.stdout.write === write ? console.error(...a) : orig(...a));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
process.env.YAD_NO_UPDATE_NOTIFIER = '1';
|
|
23
|
+
|
|
24
|
+
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
25
|
+
const { signingCheck, signingDoctorLine, sshPublicKey, gpgIds } = await import('./signing.mjs');
|
|
26
|
+
const { run } = await import('./lib.mjs');
|
|
27
|
+
const { classify, readAllowList } = await import('./agent-rules.mjs');
|
|
28
|
+
|
|
29
|
+
const tmp = () => fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'yad-signing-')));
|
|
30
|
+
const put = (file, data) => { fs.mkdirSync(path.dirname(file), { recursive: true }); fs.writeFileSync(file, typeof data === 'string' ? data : JSON.stringify(data)); };
|
|
31
|
+
const PUB = 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJ5vFakeKeyForYadTestsOnly0000000000000000 me@example.com';
|
|
32
|
+
const OTHER = 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOtherKeyForYadTestsOnly11111111111111111 x@y';
|
|
33
|
+
|
|
34
|
+
// A repo with its own git config, and a global config that is empty (nothing from this machine leaks in).
|
|
35
|
+
function setup({ config = {}, product = null } = {}) {
|
|
36
|
+
const T = tmp();
|
|
37
|
+
const home = path.join(T, 'home');
|
|
38
|
+
fs.mkdirSync(home);
|
|
39
|
+
const global = path.join(T, 'gitconfig');
|
|
40
|
+
fs.writeFileSync(global, '');
|
|
41
|
+
const env = { ...process.env, GIT_CONFIG_GLOBAL: global, GIT_CONFIG_NOSYSTEM: '1', HOME: home, YAD_PLATFORM_READ: '' };
|
|
42
|
+
const dir = path.join(T, 'repo');
|
|
43
|
+
fs.mkdirSync(dir);
|
|
44
|
+
execFileSync('git', ['init', '-q'], { cwd: dir, env });
|
|
45
|
+
for (const [k, v] of Object.entries(config)) execFileSync('git', ['config', k, v.replace('<home>', home)], { cwd: dir, env });
|
|
46
|
+
if (product) put(path.join(dir, '.sdlc/product.json'), product);
|
|
47
|
+
return { T, dir, home, env };
|
|
48
|
+
}
|
|
49
|
+
const sshConfig = { 'commit.gpgsign': 'true', 'gpg.format': 'ssh', 'user.email': 'me@example.com', 'user.signingkey': '<home>/.ssh/id_ed25519.pub' };
|
|
50
|
+
const GH = { platform: 'github', git_url: 'git@github.com:acme/p.git', default_branch: 'main' };
|
|
51
|
+
const GL = { platform: 'gitlab', git_url: 'git@gitlab.com:acme/p.git', default_branch: 'main' };
|
|
52
|
+
|
|
53
|
+
// The platform CLIs: `auth status` and `api … <path>` answered from a table; everything asked is kept.
|
|
54
|
+
function platform({ authed = true, calls = {} } = {}) {
|
|
55
|
+
const asked = [];
|
|
56
|
+
const runner = (cmd, args) => {
|
|
57
|
+
asked.push([cmd, ...args].join(' '));
|
|
58
|
+
if (args[0] === 'auth') return { ok: authed, stdout: '', stderr: '' };
|
|
59
|
+
const p = args[3];
|
|
60
|
+
const hit = Object.entries(calls).find(([re]) => new RegExp(re).test(p));
|
|
61
|
+
if (!hit) return { ok: false, stdout: '', stderr: 'gh: Not Found (HTTP 404)' };
|
|
62
|
+
const [status, body] = hit[1];
|
|
63
|
+
return status === 200 ? { ok: true, stdout: JSON.stringify(body), stderr: '' } : { ok: false, stdout: '', stderr: `gh: Refused (HTTP ${status})` };
|
|
64
|
+
};
|
|
65
|
+
return { runner, asked };
|
|
66
|
+
}
|
|
67
|
+
const tools = (...names) => (t) => names.includes(t);
|
|
68
|
+
const byId = (r) => Object.fromEntries(r.findings.map((f) => [f.id, f]));
|
|
69
|
+
const check = (s, opts) => signingCheck(s.dir, { root: s.dir, env: s.env, home: s.home, gitRun: (c, a, o = {}) => run(c, a, { ...o, env: s.env }), haveTool: tools('gh', 'glab', 'ssh-keygen'), ...opts });
|
|
70
|
+
|
|
71
|
+
test('E160 case 1: signing off is a gap with the command to turn it on', () => {
|
|
72
|
+
const s = setup({ config: { 'user.email': 'me@example.com' } });
|
|
73
|
+
try {
|
|
74
|
+
const r = check(s, { root: null });
|
|
75
|
+
assert.equal(byId(r).gpgsign.status, 'gap');
|
|
76
|
+
assert.deepEqual(byId(r).gpgsign.fix.commands, ['git config --global commit.gpgsign true']);
|
|
77
|
+
assert.equal(byId(r).gpgsign.fix.actor, 'person');
|
|
78
|
+
assert.ok(r.summary.gaps >= 1);
|
|
79
|
+
assert.match(r.notes[0], /no Product here/);
|
|
80
|
+
assert.ok(!r.findings.some((f) => f.id.startsWith('platform-')), 'case 10: no Product, no account rows');
|
|
81
|
+
} finally { fs.rmSync(s.T, { recursive: true, force: true }); }
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test('E160 case 2: SSH set up, the key listed for signing on GitHub, the email verified → all ok', () => {
|
|
85
|
+
const s = setup({ config: { ...sshConfig, 'gpg.ssh.allowedSignersFile': '<home>/.ssh/allowed_signers' }, product: GH });
|
|
86
|
+
try {
|
|
87
|
+
put(path.join(s.home, '.ssh/id_ed25519.pub'), `${PUB}\n`);
|
|
88
|
+
const { runner, asked } = platform({ calls: { '^user/ssh_signing_keys': [200, [{ key: OTHER }, { key: PUB.split(' ').slice(0, 2).join(' ') }]], '^user/emails': [200, [{ email: 'me@example.com', verified: true }]] } });
|
|
89
|
+
const r = check(s, { runner });
|
|
90
|
+
for (const f of r.findings) assert.equal(f.status, 'ok', JSON.stringify(f));
|
|
91
|
+
assert.deepEqual(r.summary, { gaps: 0, suggestions: 0, unknown: 0, complete: true, accountChecked: true });
|
|
92
|
+
assert.ok(asked.every((a) => /^gh (auth status|api --hostname github\.com user)/.test(a)), 'only reads');
|
|
93
|
+
} finally { fs.rmSync(s.T, { recursive: true, force: true }); }
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test('E160 case 3: the SSH key file missing, a key:: value, ssh-keygen missing, an old git', () => {
|
|
97
|
+
assert.match(sshPublicKey('/nowhere/id_ed25519').problem, /does not exist/);
|
|
98
|
+
assert.equal(sshPublicKey(`key::${PUB}`).key, PUB.split(' ').slice(0, 2).join(' '));
|
|
99
|
+
const s = setup({ config: sshConfig });
|
|
100
|
+
try {
|
|
101
|
+
assert.equal(byId(check(s, { root: null })).key.status, 'gap', 'the .pub is not there');
|
|
102
|
+
put(path.join(s.home, '.ssh/id_ed25519.pub'), `${PUB}\n`);
|
|
103
|
+
assert.equal(byId(check(s, { root: null })).key.status, 'ok');
|
|
104
|
+
assert.equal(byId(check(s, { root: null, haveTool: tools() })).key.status, 'gap', 'no ssh-keygen');
|
|
105
|
+
assert.equal(byId(check(s, { root: null }))['allowed-signers'].status, 'suggest');
|
|
106
|
+
const old = check(s, { root: null, gitRun: (c, a, o = {}) => (a[0] === '--version' ? { ok: true, stdout: 'git version 2.30.1' } : run(c, a, { ...o, env: s.env })) });
|
|
107
|
+
assert.equal(byId(old)['git-version'].status, 'gap');
|
|
108
|
+
} finally { fs.rmSync(s.T, { recursive: true, force: true }); }
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test('E160 case 4: a GPG key found and not found; a subkey matches the account', () => {
|
|
112
|
+
assert.deepEqual([...gpgIds('sec:u:255:22:AAAABBBBCCCCDDDD:1::::::scESC:\nfpr:::::::::0123456789ABCDEF0123456789ABCDEF01234567:\nssb:u:255:18:1111222233334444:1::::::e:')].sort(),
|
|
113
|
+
['0123456789ABCDEF0123456789ABCDEF01234567', '1111222233334444', 'AAAABBBBCCCCDDDD']);
|
|
114
|
+
const s = setup({ config: { 'commit.gpgsign': 'true', 'user.email': 'me@example.com', 'user.signingkey': 'AAAABBBBCCCCDDDD' }, product: GH });
|
|
115
|
+
try {
|
|
116
|
+
const gpg = (found) => (c, a, o = {}) => (c === 'gpg' ? (found ? { ok: true, stdout: 'sec:u:255:22:AAAABBBBCCCCDDDD:1::::::scESC:\nssb:u:255:22:5555666677778888:1::::::s:' } : { ok: false, stdout: '' }) : run(c, a, { ...o, env: s.env }));
|
|
117
|
+
const none = check(s, { gitRun: gpg(false), haveTool: tools('gh', 'gpg'), runner: platform().runner });
|
|
118
|
+
assert.equal(byId(none).key.status, 'gap');
|
|
119
|
+
assert.equal(byId(none)['platform-key'].status, 'unknown', 'no local key: nothing to match');
|
|
120
|
+
const { runner } = platform({ calls: { '^user/gpg_keys': [200, [{ key_id: '9999999999999999', subkeys: [{ key_id: '5555666677778888' }] }]], '^user/emails': [200, [{ email: 'me@example.com', verified: true }]] } });
|
|
121
|
+
const r = check(s, { gitRun: gpg(true), haveTool: tools('gh', 'gpg'), runner });
|
|
122
|
+
assert.equal(byId(r).key.status, 'ok');
|
|
123
|
+
assert.equal(byId(r)['platform-key'].status, 'ok', 'matched by the subkey');
|
|
124
|
+
// The account's copy expired or was revoked: a gap, never ok, even when the key here is in force.
|
|
125
|
+
for (const copy of [{ key_id: '9999999999999999', expires_at: '2000-01-01T00:00:00Z', subkeys: [{ key_id: '5555666677778888' }] }, { key_id: '9999999999999999', revoked: true, subkeys: [{ key_id: '5555666677778888' }] }, { key_id: '9999999999999999', subkeys: [{ key_id: '5555666677778888', expires_at: '2000-01-01T00:00:00Z' }] }]) {
|
|
126
|
+
const old = byId(check(s, { gitRun: gpg(true), haveTool: tools('gh', 'gpg'), runner: platform({ calls: { '^user/gpg_keys': [200, [copy]], '^user/emails': [200, [{ email: 'me@example.com', verified: true }]] } }).runner }))['platform-key'];
|
|
127
|
+
assert.equal(old.status, 'gap', JSON.stringify(copy));
|
|
128
|
+
assert.match(old.message, /expired, was revoked or is not valid/);
|
|
129
|
+
}
|
|
130
|
+
assert.equal(byId(check(s, { gitRun: gpg(true), haveTool: tools('gh') })).key.status, 'gap', 'no gpg: a gap, with the SSH way named');
|
|
131
|
+
} finally { fs.rmSync(s.T, { recursive: true, force: true }); }
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test('E160 case 5: a key the account has for logging in only is a gap, on GitHub and GitLab', () => {
|
|
135
|
+
for (const [product, calls, url] of [
|
|
136
|
+
[GH, { '^user/ssh_signing_keys': [200, []], '^user/keys': [200, [{ key: PUB }]], '^user/emails': [200, [{ email: 'me@example.com', verified: true }]] }, 'https://github.com/settings/keys'],
|
|
137
|
+
[GL, { '^user/keys': [200, [{ key: PUB, usage_type: 'auth' }]], '^user$': [200, { email: 'me@example.com' }], '^user/emails': [200, []] }, 'https://gitlab.com/-/user_settings/ssh_keys'],
|
|
138
|
+
]) {
|
|
139
|
+
const s = setup({ config: sshConfig, product });
|
|
140
|
+
try {
|
|
141
|
+
put(path.join(s.home, '.ssh/id_ed25519.pub'), `${PUB}\n`);
|
|
142
|
+
const f = byId(check(s, { runner: platform({ calls }).runner }))['platform-key'];
|
|
143
|
+
assert.equal(f.status, 'gap', product.platform);
|
|
144
|
+
assert.match(f.message, /logging in only/);
|
|
145
|
+
assert.equal(f.fix.url, url);
|
|
146
|
+
} finally { fs.rmSync(s.T, { recursive: true, force: true }); }
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
test('E160 case 6: a refused read is unknown with the scope to add, never ok', () => {
|
|
151
|
+
const s = setup({ config: sshConfig, product: GH });
|
|
152
|
+
try {
|
|
153
|
+
put(path.join(s.home, '.ssh/id_ed25519.pub'), `${PUB}\n`);
|
|
154
|
+
for (const status of [403, 404]) {
|
|
155
|
+
const r = check(s, { runner: platform({ calls: { '^user/ssh_signing_keys': [status], '^user/emails': [status] } }).runner });
|
|
156
|
+
assert.equal(byId(r)['platform-key'].status, 'unknown');
|
|
157
|
+
assert.deepEqual(byId(r)['platform-key'].fix.commands, ['gh auth refresh -h github.com -s read:ssh_signing_key']);
|
|
158
|
+
assert.deepEqual(byId(r)['platform-email'].fix.commands, ['gh auth refresh -h github.com -s user:email']);
|
|
159
|
+
assert.equal(r.summary.complete, false);
|
|
160
|
+
}
|
|
161
|
+
} finally { fs.rmSync(s.T, { recursive: true, force: true }); }
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
test('E160 case 7: not logged in, no gh, or reads off: the account rows are unknown', () => {
|
|
165
|
+
const s = setup({ config: sshConfig, product: GH });
|
|
166
|
+
try {
|
|
167
|
+
put(path.join(s.home, '.ssh/id_ed25519.pub'), `${PUB}\n`);
|
|
168
|
+
const out = byId(check(s, { runner: platform({ authed: false }).runner }));
|
|
169
|
+
assert.equal(out['platform-key'].status, 'unknown');
|
|
170
|
+
assert.deepEqual(out['platform-key'].fix.commands, ['gh auth login --hostname github.com']);
|
|
171
|
+
assert.equal(byId(check(s, { haveTool: tools('ssh-keygen') }))['platform-email'].status, 'unknown');
|
|
172
|
+
const off = check(s, { env: { ...s.env, YAD_PLATFORM_READ: '0' }, runner: () => { throw new Error('no platform call when reads are off'); } });
|
|
173
|
+
assert.equal(byId(off)['platform-key'].status, 'unknown');
|
|
174
|
+
assert.equal(off.summary.complete, false);
|
|
175
|
+
} finally { fs.rmSync(s.T, { recursive: true, force: true }); }
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
test('E160 case 8: GitLab — a key for signing, GPG keys read through gpg, confirmed emails', () => {
|
|
179
|
+
const s = setup({ config: sshConfig, product: GL });
|
|
180
|
+
try {
|
|
181
|
+
put(path.join(s.home, '.ssh/id_ed25519.pub'), `${PUB}\n`);
|
|
182
|
+
const { runner } = platform({ calls: { '^user/keys': [200, [{ key: PUB, usage_type: 'auth_and_signing' }]], '^user$': [200, { email: 'other@example.com' }], '^user/emails': [200, [{ email: 'me@example.com', confirmed_at: '2026-01-01' }]] } });
|
|
183
|
+
const r = byId(check(s, { runner }));
|
|
184
|
+
assert.equal(r['platform-key'].status, 'ok');
|
|
185
|
+
assert.equal(r['platform-email'].status, 'ok');
|
|
186
|
+
} finally { fs.rmSync(s.T, { recursive: true, force: true }); }
|
|
187
|
+
const g = setup({ config: { 'commit.gpgsign': 'true', 'user.email': 'me@example.com', 'user.signingkey': 'AAAABBBBCCCCDDDD' }, product: GL });
|
|
188
|
+
try {
|
|
189
|
+
const gitRun = (c, a, o = {}) => {
|
|
190
|
+
if (c !== 'gpg') return run(c, a, { ...o, env: g.env });
|
|
191
|
+
if (a.includes('--import')) return { ok: true, stdout: o.input === 'ARMORED' ? 'pub:-:255:22:AAAABBBBCCCCDDDD:1::::::scESC:' : '' };
|
|
192
|
+
return { ok: true, stdout: 'sec:u:255:22:AAAABBBBCCCCDDDD:1::::::scESC:' };
|
|
193
|
+
};
|
|
194
|
+
const { runner } = platform({ calls: { '^user/gpg_keys': [200, [{ key: 'ARMORED' }]], '^user$': [200, { email: 'me@example.com' }], '^user/emails': [200, []] } });
|
|
195
|
+
assert.equal(byId(check(g, { gitRun, haveTool: tools('glab', 'gpg'), runner }))['platform-key'].status, 'ok');
|
|
196
|
+
const expiredCopy = (c, a, o = {}) => (c === 'gpg' && a.includes('--import') ? { ok: true, stdout: 'pub:e:255:22:AAAABBBBCCCCDDDD:1::::::scESC:' } : gitRun(c, a, o));
|
|
197
|
+
const gone = byId(check(g, { gitRun: expiredCopy, haveTool: tools('glab', 'gpg'), runner }))['platform-key'];
|
|
198
|
+
assert.equal(gone.status, 'gap', 'GitLab\'s copy expired');
|
|
199
|
+
assert.match(gone.message, /expired, was revoked or is not valid/);
|
|
200
|
+
} finally { fs.rmSync(g.T, { recursive: true, force: true }); }
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
test('E160 case 9: an email not verified, or not on the account, is a gap', () => {
|
|
204
|
+
const s = setup({ config: sshConfig, product: GH });
|
|
205
|
+
try {
|
|
206
|
+
put(path.join(s.home, '.ssh/id_ed25519.pub'), `${PUB}\n`);
|
|
207
|
+
const keys = { '^user/ssh_signing_keys': [200, [{ key: PUB }]] };
|
|
208
|
+
const unverified = byId(check(s, { runner: platform({ calls: { ...keys, '^user/emails': [200, [{ email: 'Me@Example.com', verified: false }]] } }).runner }))['platform-email'];
|
|
209
|
+
assert.equal(unverified.status, 'gap');
|
|
210
|
+
assert.match(unverified.message, /not verified/);
|
|
211
|
+
const absent = byId(check(s, { runner: platform({ calls: { ...keys, '^user/emails': [200, [{ email: 'else@example.com', verified: true }]] } }).runner }))['platform-email'];
|
|
212
|
+
assert.equal(absent.status, 'gap');
|
|
213
|
+
assert.equal(absent.fix.url, 'https://github.com/settings/emails');
|
|
214
|
+
} finally { fs.rmSync(s.T, { recursive: true, force: true }); }
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
test('E160 case 10: a Product with no platform: only this machine, with a note', () => {
|
|
218
|
+
const s = setup({ config: sshConfig, product: { platform: null } });
|
|
219
|
+
try {
|
|
220
|
+
const r = check(s, { runner: () => { throw new Error('no platform call'); } });
|
|
221
|
+
assert.ok(!r.findings.some((f) => f.id.startsWith('platform-')));
|
|
222
|
+
assert.match(r.notes[0], /names no platform/);
|
|
223
|
+
} finally { fs.rmSync(s.T, { recursive: true, force: true }); }
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
test('E160 case 11: the doctor line reads the git config only', () => {
|
|
227
|
+
const off = setup();
|
|
228
|
+
const on = setup({ config: sshConfig });
|
|
229
|
+
try {
|
|
230
|
+
const gitOnly = (env) => (c, a, o = {}) => { assert.equal(c, 'git', 'only git is asked'); return run(c, a, { ...o, env }); };
|
|
231
|
+
assert.equal(signingDoctorLine(off.dir, { gitRun: gitOnly(off.env) }).status, 'warn');
|
|
232
|
+
const line = signingDoctorLine(on.dir, { gitRun: gitOnly(on.env) });
|
|
233
|
+
assert.deepEqual([line.status, line.message], ['ok', 'commits made here are signed (SSH)']);
|
|
234
|
+
} finally { for (const s of [off, on]) fs.rmSync(s.T, { recursive: true, force: true }); }
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
test('E160 case 12: `signing check` is a read the agent runs without asking, and the CLI answers --json', () => {
|
|
238
|
+
assert.equal(classify(['signing', 'check']), 'read');
|
|
239
|
+
assert.equal(classify(['signing']), 'read', 'its default action');
|
|
240
|
+
assert.ok(readAllowList().includes('Bash(yad signing check:*)'));
|
|
241
|
+
const s = setup({ config: { 'user.email': 'me@example.com' } });
|
|
242
|
+
try {
|
|
243
|
+
const r = spawnSync(process.execPath, [path.join(ROOT, 'bin/yad.mjs'), 'signing', 'check', '--json'], { cwd: s.dir, env: { ...s.env, NO_COLOR: '1', YAD_PLATFORM_READ: '0' }, encoding: 'utf8' });
|
|
244
|
+
const out = JSON.parse(r.stdout);
|
|
245
|
+
assert.equal(r.status, 1, 'a gap exits 1');
|
|
246
|
+
assert.equal(out.command, 'signing check');
|
|
247
|
+
assert.equal(out.summary.gaps >= 1, true);
|
|
248
|
+
assert.match(spawnSync(process.execPath, [path.join(ROOT, 'bin/yad.mjs'), 'signing', 'nope'], { cwd: s.dir, env: s.env, encoding: 'utf8' }).stdout, /unknown signing action/);
|
|
249
|
+
} finally { fs.rmSync(s.T, { recursive: true, force: true }); }
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
// ---- review 1: no false ok ------------------------------------------------------------------------------
|
|
253
|
+
|
|
254
|
+
test('E160 review 1: with no account read, the check is never complete', () => {
|
|
255
|
+
const s = setup({ config: { ...sshConfig, 'gpg.ssh.allowedSignersFile': '<home>/a' } });
|
|
256
|
+
try {
|
|
257
|
+
put(path.join(s.home, '.ssh/id_ed25519.pub'), `${PUB}\n`);
|
|
258
|
+
const r = check(s, { root: null });
|
|
259
|
+
assert.equal(r.summary.gaps, 0);
|
|
260
|
+
assert.deepEqual([r.summary.complete, r.summary.accountChecked], [false, false]);
|
|
261
|
+
// Not logged in: unknown, and not complete either.
|
|
262
|
+
const p = setup({ config: sshConfig, product: GH });
|
|
263
|
+
try {
|
|
264
|
+
put(path.join(p.home, '.ssh/id_ed25519.pub'), `${PUB}\n`);
|
|
265
|
+
assert.equal(check(p, { runner: platform({ authed: false }).runner }).summary.complete, false);
|
|
266
|
+
} finally { fs.rmSync(p.T, { recursive: true, force: true }); }
|
|
267
|
+
} finally { fs.rmSync(s.T, { recursive: true, force: true }); }
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
test('E160 review 1: a GitHub no-reply address counts only when it is this account\'s', () => {
|
|
271
|
+
const s = setup({ config: { ...sshConfig, 'user.email': '999+someoneelse@users.noreply.github.com' }, product: GH });
|
|
272
|
+
try {
|
|
273
|
+
put(path.join(s.home, '.ssh/id_ed25519.pub'), `${PUB}\n`);
|
|
274
|
+
const calls = { '^user/ssh_signing_keys': [200, [{ key: PUB }]], '^user$': [200, { login: 'me', id: 42 }] };
|
|
275
|
+
const other = byId(check(s, { runner: platform({ calls }).runner }))['platform-email'];
|
|
276
|
+
assert.equal(other.status, 'gap');
|
|
277
|
+
assert.match(other.fix.steps[0], /42\+me@users\.noreply\.github\.com/);
|
|
278
|
+
execFileSync('git', ['config', 'user.email', '42+me@users.noreply.github.com'], { cwd: s.dir, env: s.env });
|
|
279
|
+
assert.equal(byId(check(s, { runner: platform({ calls }).runner }))['platform-email'].status, 'ok');
|
|
280
|
+
// A login but no id: `42+me@` may be this account's (unknown); `me@` still matches.
|
|
281
|
+
assert.equal(byId(check(s, { runner: platform({ calls: { '^user/ssh_signing_keys': [200, [{ key: PUB }]], '^user$': [200, { login: 'me' }] } }).runner }))['platform-email'].status, 'unknown');
|
|
282
|
+
execFileSync('git', ['config', 'user.email', 'me@users.noreply.github.com'], { cwd: s.dir, env: s.env });
|
|
283
|
+
assert.equal(byId(check(s, { runner: platform({ calls: { '^user/ssh_signing_keys': [200, [{ key: PUB }]], '^user$': [200, { login: 'me' }] } }).runner }))['platform-email'].status, 'ok');
|
|
284
|
+
execFileSync('git', ['config', 'user.email', '42+me@users.noreply.github.com'], { cwd: s.dir, env: s.env });
|
|
285
|
+
// An answer with no login: unknown, never a gap or an ok.
|
|
286
|
+
assert.equal(byId(check(s, { runner: platform({ calls: { '^user/ssh_signing_keys': [200, [{ key: PUB }]], '^user$': [200, {}] } }).runner }))['platform-email'].status, 'unknown');
|
|
287
|
+
// The account could not be read: unknown, never ok.
|
|
288
|
+
assert.equal(byId(check(s, { runner: platform({ calls: { '^user/ssh_signing_keys': [200, [{ key: PUB }]] } }).runner }))['platform-email'].status, 'unknown');
|
|
289
|
+
} finally { fs.rmSync(s.T, { recursive: true, force: true }); }
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
test('E160 review 1: a GPG key is looked up by the exact email; several keys, or one that cannot sign, is a gap', () => {
|
|
293
|
+
const s = setup({ config: { 'commit.gpgsign': 'true', 'user.email': 'me@example.com' }, product: GH });
|
|
294
|
+
try {
|
|
295
|
+
let asked = null;
|
|
296
|
+
const gpg = (out) => (c, a, o = {}) => { if (c !== 'gpg') return run(c, a, { ...o, env: s.env }); asked = a.at(-1); return { ok: true, stdout: out }; };
|
|
297
|
+
const two = 'sec:u:255:22:AAAABBBBCCCCDDDD:1::::::scESC:\nsec:u:255:22:1111222233334444:1::::::scESC:';
|
|
298
|
+
const r = byId(check(s, { gitRun: gpg(two), haveTool: tools('gh', 'gpg'), runner: platform().runner }));
|
|
299
|
+
assert.equal(asked, '<me@example.com>', 'the exact address, never a part of one');
|
|
300
|
+
assert.equal(r.key.status, 'gap');
|
|
301
|
+
assert.match(r.key.message, /2 secret keys/);
|
|
302
|
+
for (const [line, why] of [['sec:e:255:22:AAAABBBBCCCCDDDD:1::::::scESC:', 'expired'], ['sec:r:255:22:AAAABBBBCCCCDDDD:1::::::scESC:', 'revoked'], ['sec:u:255:22:AAAABBBBCCCCDDDD:1::::::eE:', 'no sign capability']]) {
|
|
303
|
+
const k = byId(check(s, { gitRun: gpg(line), haveTool: tools('gh', 'gpg'), runner: platform().runner })).key;
|
|
304
|
+
assert.equal(k.status, 'gap', why);
|
|
305
|
+
assert.match(k.message, /cannot sign now/, why);
|
|
306
|
+
}
|
|
307
|
+
} finally { fs.rmSync(s.T, { recursive: true, force: true }); }
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
test('E160 review 2: only a key that can sign here counts: a certify-only primary with a signing subkey, a stub', () => {
|
|
311
|
+
const certifyOnly = 'sec:u:255:22:AAAABBBBCCCCDDDD:1::::::cSC:::+:\nfpr:::::::::0123456789ABCDEF0123456789ABCDEFAAAABBBB:\nssb:u:255:22:5555666677778888:1::::::s:::+:\nfpr:::::::::FEDCBA9876543210FEDCBA987654321055556666:';
|
|
312
|
+
assert.deepEqual([...gpgIds(certifyOnly, { signing: true })].sort(), ['5555666677778888', 'FEDCBA9876543210FEDCBA987654321055556666'], 'the subkey signs, the primary only certifies');
|
|
313
|
+
assert.equal(gpgIds(certifyOnly, { signing: true }).keys, 1);
|
|
314
|
+
assert.equal(gpgIds('sec:u:255:22:AAAABBBBCCCCDDDD:1::::::scSC:::#:', { signing: true }).size, 0, 'a stub: its secret is not here');
|
|
315
|
+
assert.equal(gpgIds('sec:u:255:22:AAAABBBBCCCCDDDD:1::::::scSC:\nsec:r:255:22:1111222233334444:1::::::scSC:', { signing: true }).keys, 1, 'a revoked key is not one git may pick');
|
|
316
|
+
assert.equal(gpgIds('sec:u:255:22:AAAABBBBCCCCDDDD:1::::::scSC:\nsec:u:255:22:1111222233334444:1::::::eE:', { signing: true }).keys, 1, 'an encrypt-only key is not one git may pick');
|
|
317
|
+
// Without `signing`, every id is listed, dead keys too; with `live`, only keys still in force.
|
|
318
|
+
const expired = 'pub:e:255:22:AAAABBBBCCCCDDDD:1::::::scSC:\nfpr:::::::::0123456789ABCDEF0123456789ABCDEFAAAABBBB:\nsub:e:255:22:5555666677778888:1::::::s:';
|
|
319
|
+
assert.deepEqual([...gpgIds(expired)].sort(), ['0123456789ABCDEF0123456789ABCDEFAAAABBBB', '5555666677778888', 'AAAABBBBCCCCDDDD']);
|
|
320
|
+
assert.deepEqual([...gpgIds(expired, { live: true })], []);
|
|
321
|
+
assert.deepEqual([...gpgIds('pub:u:255:22:AAAABBBBCCCCDDDD:1::::::scSC:\nsub:e:255:22:5555666677778888:1::::::s:', { live: true })], ['AAAABBBBCCCCDDDD'], 'only the expired subkey drops');
|
|
322
|
+
assert.equal(gpgIds('sec:u:255:22:AAAABBBBCCCCDDDD:1::::::scSCD:', { signing: true }).size, 0, 'a disabled key (D in field 12)');
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
test('E160 review 3: an offline primary, a stub or a smartcard through the whole check; a valid key beside a revoked one', () => {
|
|
326
|
+
const s = setup({ config: { 'commit.gpgsign': 'true', 'user.email': 'me@example.com' }, product: GH });
|
|
327
|
+
try {
|
|
328
|
+
const gpg = (out) => (c, a, o = {}) => (c === 'gpg' ? { ok: true, stdout: out } : run(c, a, { ...o, env: s.env }));
|
|
329
|
+
const key = (out) => byId(check(s, { gitRun: gpg(out), haveTool: tools('gh', 'gpg'), runner: platform().runner })).key;
|
|
330
|
+
// The usual offline-primary setup: the primary is a stub, the signing subkey is here.
|
|
331
|
+
const offline = 'sec:u:255:22:AAAABBBBCCCCDDDD:1::::::scSC:::#:\nssb:u:255:22:5555666677778888:1::::::s:::+:';
|
|
332
|
+
assert.equal(gpgIds(offline, { signing: true }).size, 1);
|
|
333
|
+
assert.equal(key(offline).status, 'ok');
|
|
334
|
+
const stub = key('sec:u:255:22:AAAABBBBCCCCDDDD:1::::::scSC:::#:');
|
|
335
|
+
assert.equal(stub.status, 'gap');
|
|
336
|
+
assert.match(stub.message, /cannot sign now .*not on this machine/);
|
|
337
|
+
assert.equal(key('sec:u:255:22:AAAABBBBCCCCDDDD:1::::::scSC:\nsec:r:255:22:1111222233334444:1::::::scSC:').status, 'ok', 'a revoked key beside it is not "several keys"');
|
|
338
|
+
assert.equal(gpgIds('sec:u:255:22:AAAABBBBCCCCDDDD:1::::::scSC:\nsec:r:255:22:1111222233334444:1::::::scSC:', { signing: true }).keys, 1);
|
|
339
|
+
// A disabled, revoked or expired primary takes its signing subkey with it.
|
|
340
|
+
for (const head of ['sec:u:255:22:AAAABBBBCCCCDDDD:1::::::scSCD:::+:', 'sec:r:255:22:AAAABBBBCCCCDDDD:1::::::scSC:::+:', 'sec:e:255:22:AAAABBBBCCCCDDDD:1::::::scSC:::+:']) {
|
|
341
|
+
assert.equal(key(`${head}\nssb:u:255:22:5555666677778888:1::::::s:::+:`).status, 'gap', head);
|
|
342
|
+
}
|
|
343
|
+
// A subkey listed before any primary belongs to no key.
|
|
344
|
+
assert.equal(gpgIds('ssb:u:255:22:5555666677778888:1::::::s:::+:\nsec:u:255:22:AAAABBBBCCCCDDDD:1::::::scSC:::+:', { signing: true }).keys, 1);
|
|
345
|
+
assert.deepEqual([...gpgIds('ssb:u:255:22:5555666677778888:1::::::s:::+:', { signing: true })], []);
|
|
346
|
+
const card = key('sec:u:255:22:AAAABBBBCCCCDDDD:1::::::scSC:::D2760001240100000006:');
|
|
347
|
+
assert.equal(card.status, 'ok');
|
|
348
|
+
assert.match(card.message, /on a smartcard, so the card must be inserted/);
|
|
349
|
+
// The card is named only when the part gpg signs with (the newest signing subkey) is on it.
|
|
350
|
+
assert.match(key('sec:u:255:22:AAAABBBBCCCCDDDD:1::::::scSC:::+:\nssb:u:255:22:5555666677778888:1::::::s:::D2760001240100000006:').message, /smartcard/);
|
|
351
|
+
assert.doesNotMatch(key('sec:u:255:22:AAAABBBBCCCCDDDD:1::::::scSC:::D2760001240100000006:\nssb:u:255:22:5555666677778888:1::::::s:::+:').message, /smartcard/);
|
|
352
|
+
} finally { fs.rmSync(s.T, { recursive: true, force: true }); }
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
test('E160 review 1: the older ssh- form, a relative key path, and a key command', () => {
|
|
356
|
+
assert.equal(sshPublicKey(PUB).key, PUB.split(' ').slice(0, 2).join(' '));
|
|
357
|
+
const s = setup({ config: { ...sshConfig, 'user.signingkey': 'keys/id.pub' } });
|
|
358
|
+
try {
|
|
359
|
+
put(path.join(s.dir, 'keys/id.pub'), `${PUB}\n`);
|
|
360
|
+
assert.equal(byId(check(s, { root: null })).key.status, 'ok', 'read from the repo folder, not where yad started');
|
|
361
|
+
execFileSync('git', ['config', '--unset', 'user.signingkey'], { cwd: s.dir, env: s.env });
|
|
362
|
+
execFileSync('git', ['config', 'gpg.ssh.defaultKeyCommand', 'ssh-add -L'], { cwd: s.dir, env: s.env });
|
|
363
|
+
assert.equal(byId(check(s, { root: null })).key.status, 'unknown');
|
|
364
|
+
assert.equal(signingDoctorLine(s.dir, { gitRun: (c, a, o = {}) => run(c, a, { ...o, env: s.env }) }).status, 'ok');
|
|
365
|
+
// The key:: form through the whole check.
|
|
366
|
+
execFileSync('git', ['config', 'user.signingkey', `key::${PUB}`], { cwd: s.dir, env: s.env });
|
|
367
|
+
assert.equal(byId(check(s, { root: null })).key.status, 'ok');
|
|
368
|
+
} finally { fs.rmSync(s.T, { recursive: true, force: true }); }
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
test('E160 review 1: the doctor line names X.509 and an unknown format; odd answers and full pages are not ok', () => {
|
|
372
|
+
const x = setup({ config: { 'commit.gpgsign': 'true', 'gpg.format': 'x509' } });
|
|
373
|
+
const bad = setup({ config: { 'commit.gpgsign': 'true', 'gpg.format': 'pgp2' } });
|
|
374
|
+
try {
|
|
375
|
+
const g = (s) => (c, a, o = {}) => run(c, a, { ...o, env: s.env });
|
|
376
|
+
assert.match(signingDoctorLine(x.dir, { gitRun: g(x) }).message, /X\.509/);
|
|
377
|
+
assert.equal(signingDoctorLine(bad.dir, { gitRun: g(bad) }).status, 'warn');
|
|
378
|
+
} finally { for (const s of [x, bad]) fs.rmSync(s.T, { recursive: true, force: true }); }
|
|
379
|
+
const s = setup({ config: sshConfig, product: GH });
|
|
380
|
+
try {
|
|
381
|
+
put(path.join(s.home, '.ssh/id_ed25519.pub'), `${PUB}\n`);
|
|
382
|
+
const odd = byId(check(s, { runner: platform({ calls: { '^user/ssh_signing_keys': [200, [{ key: PUB }]], '^user/emails': [200, { not: 'a list' }] } }).runner }));
|
|
383
|
+
assert.equal(odd['platform-email'].status, 'gap', 'an answer that is not a list holds no verified email');
|
|
384
|
+
const full = Array.from({ length: 100 }, () => ({ key: OTHER }));
|
|
385
|
+
assert.equal(byId(check(s, { runner: platform({ calls: { '^user/ssh_signing_keys': [200, full], '^user/emails': [200, []] } }).runner }))['platform-key'].status, 'unknown');
|
|
386
|
+
} finally { fs.rmSync(s.T, { recursive: true, force: true }); }
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
test('E160 review 1: GitLab — a refused read asks for a read_user token; an unconfirmed email is a gap', () => {
|
|
390
|
+
const s = setup({ config: sshConfig, product: GL });
|
|
391
|
+
try {
|
|
392
|
+
put(path.join(s.home, '.ssh/id_ed25519.pub'), `${PUB}\n`);
|
|
393
|
+
const refused = byId(check(s, { runner: platform({ calls: { '^user/keys': [401], '^user$': [403] } }).runner }));
|
|
394
|
+
assert.equal(refused['platform-key'].status, 'unknown');
|
|
395
|
+
assert.match(refused['platform-key'].fix.steps[0], /read_user/);
|
|
396
|
+
assert.equal(refused['platform-email'].status, 'unknown');
|
|
397
|
+
const pending = byId(check(s, { runner: platform({ calls: { '^user/keys': [200, [{ key: PUB, usage_type: 'signing' }]], '^user$': [200, { email: 'other@example.com' }], '^user/emails': [200, [{ email: 'me@example.com', confirmed_at: null }]] } }).runner }))['platform-email'];
|
|
398
|
+
assert.equal(pending.status, 'gap');
|
|
399
|
+
assert.match(pending.message, /not verified/);
|
|
400
|
+
} finally { fs.rmSync(s.T, { recursive: true, force: true }); }
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
test('E160 review 6: the part gpg signs with must be on the account and in force', () => {
|
|
404
|
+
const s = setup({ config: { 'commit.gpgsign': 'true', 'user.email': 'me@example.com', 'user.signingkey': 'AAAABBBBCCCCDDDD' }, product: GH });
|
|
405
|
+
try {
|
|
406
|
+
// The primary can sign here, and so can a subkey: gpg signs with the subkey.
|
|
407
|
+
const local = 'sec:u:255:22:AAAABBBBCCCCDDDD:1::::::scSC:::+:\nssb:u:255:22:5555666677778888:1::::::s:::+:';
|
|
408
|
+
const gitRun = (c, a, o = {}) => (c === 'gpg' ? { ok: true, stdout: local } : run(c, a, { ...o, env: s.env }));
|
|
409
|
+
const row = (copy) => byId(check(s, { gitRun, haveTool: tools('gh', 'gpg'), runner: platform({ calls: { '^user/gpg_keys': [200, [copy]], '^user/emails': [200, [{ email: 'me@example.com', verified: true }]] } }).runner }))['platform-key'];
|
|
410
|
+
const later = new Date(Date.now() + 864e5 * 365).toISOString();
|
|
411
|
+
assert.equal(row({ key_id: 'AAAABBBBCCCCDDDD', expires_at: null, subkeys: [{ key_id: '5555666677778888', expires_at: later }] }).status, 'ok', 'never expires, or expires later');
|
|
412
|
+
const subExpired = row({ key_id: 'AAAABBBBCCCCDDDD', subkeys: [{ key_id: '5555666677778888', expires_at: '2000-01-01T00:00:00Z' }] });
|
|
413
|
+
assert.equal(subExpired.status, 'gap', 'the primary is in force, but gpg signs with the expired subkey');
|
|
414
|
+
assert.match(subExpired.message, /expired/);
|
|
415
|
+
assert.equal(row({ key_id: 'AAAABBBBCCCCDDDD', subkeys: [{ key_id: '5555666677778888', revoked: true }] }).status, 'gap', 'a revoked subkey');
|
|
416
|
+
const missing = row({ key_id: 'AAAABBBBCCCCDDDD', subkeys: [] });
|
|
417
|
+
assert.equal(missing.status, 'gap', 'the subkey was added after the upload');
|
|
418
|
+
assert.match(missing.message, /not the part gpg signs with/);
|
|
419
|
+
// Only the newest signing subkey counts: an older one expired on the account does not matter.
|
|
420
|
+
const two = 'sec:u:255:22:AAAABBBBCCCCDDDD:100::::::scSC:::+:\nssb:u:255:22:1111222233334444:200::::::s:::+:\nssb:u:255:22:5555666677778888:300::::::s:::+:';
|
|
421
|
+
const twoRun = (c, a, o = {}) => (c === 'gpg' ? { ok: true, stdout: two } : run(c, a, { ...o, env: s.env }));
|
|
422
|
+
const rowTwo = (copy) => byId(check(s, { gitRun: twoRun, haveTool: tools('gh', 'gpg'), runner: platform({ calls: { '^user/gpg_keys': [200, [copy]], '^user/emails': [200, [{ email: 'me@example.com', verified: true }]] } }).runner }))['platform-key'];
|
|
423
|
+
assert.equal(rowTwo({ key_id: 'AAAABBBBCCCCDDDD', subkeys: [{ key_id: '1111222233334444', expires_at: '2000-01-01T00:00:00Z' }, { key_id: '5555666677778888' }] }).status, 'ok');
|
|
424
|
+
assert.equal(rowTwo({ key_id: 'AAAABBBBCCCCDDDD', subkeys: [{ key_id: '1111222233334444' }, { key_id: '5555666677778888', expires_at: '2000-01-01T00:00:00Z' }] }).status, 'gap');
|
|
425
|
+
assert.equal(row({ key_id: 'AAAABBBBCCCCDDDD', expires_at: 'soon', subkeys: [{ key_id: '5555666677778888' }] }).status, 'unknown', 'a date yad cannot read');
|
|
426
|
+
// `<id>!` pins the part gpg signs with: only that part counts.
|
|
427
|
+
execFileSync('git', ['config', 'user.signingkey', 'AAAABBBBCCCCDDDD!'], { cwd: s.dir, env: s.env });
|
|
428
|
+
assert.equal(row({ key_id: 'AAAABBBBCCCCDDDD', subkeys: [{ key_id: '5555666677778888', expires_at: '2000-01-01T00:00:00Z' }] }).status, 'ok', 'pinned to the primary');
|
|
429
|
+
} finally { fs.rmSync(s.T, { recursive: true, force: true }); }
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
test('E160 review 7: a pinned part that cannot sign is a gap; one subkey wins a tie; the hint reads every id', () => {
|
|
433
|
+
const s = setup({ config: { 'commit.gpgsign': 'true', 'user.email': 'me@example.com' }, product: GH });
|
|
434
|
+
const cfg = (v) => execFileSync('git', ['config', 'user.signingkey', v], { cwd: s.dir, env: s.env });
|
|
435
|
+
try {
|
|
436
|
+
const on = (out) => (c, a, o = {}) => (c === 'gpg' ? { ok: true, stdout: out } : run(c, a, { ...o, env: s.env }));
|
|
437
|
+
const emails = { '^user/emails': [200, [{ email: 'me@example.com', verified: true }]] };
|
|
438
|
+
const rows = (out, copy = { key_id: 'AAAABBBBCCCCDDDD', subkeys: [{ key_id: '5555666677778888' }] }) => byId(check(s, { gitRun: on(out), haveTool: tools('gh', 'gpg'), runner: platform({ calls: { '^user/gpg_keys': [200, [copy]], ...emails } }).runner }));
|
|
439
|
+
// The pinned subkey expired here; the primary still signs, but gpg never falls back to it.
|
|
440
|
+
const expiredSub = 'sec:u:255:22:AAAABBBBCCCCDDDD:100::::::scSC:::+:\nssb:e:255:22:5555666677778888:200::::::s:::+:';
|
|
441
|
+
cfg('5555666677778888!');
|
|
442
|
+
let r = rows(expiredSub);
|
|
443
|
+
assert.equal(r.key.status, 'gap');
|
|
444
|
+
assert.match(r.key.message, /gpg signs with that part only/);
|
|
445
|
+
assert.equal(r['platform-key'].status, 'unknown', 'no key to match');
|
|
446
|
+
cfg('77778888!'); // an 8-digit short id, pinned
|
|
447
|
+
assert.equal(rows(expiredSub).key.status, 'gap', 'a short id with "!"');
|
|
448
|
+
// A pinned primary that only certifies.
|
|
449
|
+
cfg('AAAABBBBCCCCDDDD!');
|
|
450
|
+
assert.equal(rows('sec:u:255:22:AAAABBBBCCCCDDDD:100::::::cSC:::+:\nssb:u:255:22:5555666677778888:200::::::s:::+:').key.status, 'gap');
|
|
451
|
+
// A "!" on something that is not a key id: unknown, never ok.
|
|
452
|
+
cfg('me@example.com!');
|
|
453
|
+
assert.equal(rows('sec:u:255:22:AAAABBBBCCCCDDDD:100::::::scSC:::+:').key.status, 'unknown');
|
|
454
|
+
// Two signing subkeys made in the same second: gpg takes the first listed.
|
|
455
|
+
cfg('AAAABBBBCCCCDDDD');
|
|
456
|
+
const tie = 'sec:u:255:22:AAAABBBBCCCCDDDD:100::::::cSC:::+:\nssb:u:255:22:1111222233334444:200::::::s:::+:\nssb:u:255:22:5555666677778888:200::::::s:::+:';
|
|
457
|
+
assert.equal(rows(tie, { key_id: 'AAAABBBBCCCCDDDD', subkeys: [{ key_id: '1111222233334444' }, { key_id: '5555666677778888', revoked: true }] })['platform-key'].status, 'ok');
|
|
458
|
+
// A certify-only primary with a new subkey never uploaded: the account has the key, not that part.
|
|
459
|
+
const fresh = 'sec:u:255:22:AAAABBBBCCCCDDDD:100::::::cSC:::+:\nssb:u:255:22:5555666677778888:300::::::s:::+:';
|
|
460
|
+
const notPart = rows(fresh, { key_id: 'AAAABBBBCCCCDDDD', subkeys: [{ key_id: '1111222233334444' }] })['platform-key'];
|
|
461
|
+
assert.equal(notPart.status, 'gap');
|
|
462
|
+
assert.match(notPart.message, /not the part gpg signs with/);
|
|
463
|
+
// GitHub: a dead primary takes a live subkey with it; a copy unclear here and dead there is unknown.
|
|
464
|
+
assert.equal(rows(fresh, { key_id: 'AAAABBBBCCCCDDDD', revoked: true, subkeys: [{ key_id: '5555666677778888' }] })['platform-key'].status, 'gap');
|
|
465
|
+
assert.equal(byId(check(s, { gitRun: on(fresh), haveTool: tools('gh', 'gpg'), runner: platform({ calls: { '^user/gpg_keys': [200, [{ key_id: 'AAAABBBBCCCCDDDD', expires_at: 'soon', subkeys: [{ key_id: '5555666677778888' }] }, { key_id: 'AAAABBBBCCCCDDDD', revoked: true, subkeys: [{ key_id: '5555666677778888' }] }]], ...emails } }).runner }))['platform-key'].status, 'unknown');
|
|
466
|
+
} finally { fs.rmSync(s.T, { recursive: true, force: true }); }
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
test('E160 review 8: a pin by short id, fingerprint or 0x picks that part; another key with the same email is not "the part"', () => {
|
|
470
|
+
const s = setup({ config: { 'commit.gpgsign': 'true', 'user.email': 'me@example.com' }, product: GH });
|
|
471
|
+
const cfg = (v) => execFileSync('git', ['config', 'user.signingkey', v], { cwd: s.dir, env: s.env });
|
|
472
|
+
try {
|
|
473
|
+
const on = (out) => (c, a, o = {}) => (c === 'gpg' ? { ok: true, stdout: out } : run(c, a, { ...o, env: s.env }));
|
|
474
|
+
const emails = { '^user/emails': [200, [{ email: 'me@example.com', verified: true }]] };
|
|
475
|
+
const rows = (out, copy) => byId(check(s, { gitRun: on(out), haveTool: tools('gh', 'gpg'), runner: platform({ calls: { '^user/gpg_keys': [200, [copy]], ...emails } }).runner }));
|
|
476
|
+
// Two signing subkeys; the account has only the OLDER one. Unpinned, gpg signs with the newer: a gap.
|
|
477
|
+
const key = 'sec:u:255:22:AAAABBBBCCCCDDDD:100::::::cSC:::+:\nssb:u:255:22:1111222233334444:200::::::s:::+:\nfpr:::::::::0123456789ABCDEF012345671111222233334444:\nssb:u:255:22:5555666677778888:300::::::s:::+:';
|
|
478
|
+
const older = { key_id: 'AAAABBBBCCCCDDDD', subkeys: [{ key_id: '1111222233334444' }] };
|
|
479
|
+
cfg('AAAABBBBCCCCDDDD');
|
|
480
|
+
assert.equal(rows(key, older)['platform-key'].status, 'gap');
|
|
481
|
+
// Pinned to the older one, by short id, long id with 0x, or fingerprint: ok.
|
|
482
|
+
for (const pin of ['33334444!', '0x1111222233334444!', '0123456789ABCDEF012345671111222233334444!']) {
|
|
483
|
+
cfg(pin);
|
|
484
|
+
const r = rows(key, older);
|
|
485
|
+
assert.equal(r.key.status, 'ok', pin);
|
|
486
|
+
assert.equal(r['platform-key'].status, 'ok', pin);
|
|
487
|
+
}
|
|
488
|
+
// A fingerprint pin on a part listed with no fingerprint line (older gpg): the long id still matches.
|
|
489
|
+
cfg('0123456789ABCDEF012345675555666677778888!');
|
|
490
|
+
assert.equal(rows(key, older).key.status, 'ok');
|
|
491
|
+
// A short id that two keys share (gpg lists both). Only A's matching part signs: gpg signs with it.
|
|
492
|
+
cfg('33334444!');
|
|
493
|
+
const shared = 'sec:u:255:22:AAAABBBBCCCCDDDD:100::::::cSC:::+:\nssb:u:255:22:1111222233334444:200::::::s:::+:\nsec:u:255:22:9999000011112222:100::::::cSC:::+:\nssb:u:255:22:7777888833334444:200::::::e:::+:\nssb:u:255:22:6666777788889999:300::::::s:::+:';
|
|
494
|
+
const one = rows(shared, older);
|
|
495
|
+
assert.equal(one.key.status, 'ok', 'the pin settles which key');
|
|
496
|
+
assert.equal(one['platform-key'].status, 'ok', 'judged on the pinned part of A only');
|
|
497
|
+
// Both keys have a matching part that signs: gpg may pick either.
|
|
498
|
+
const both = rows(shared.replace('7777888833334444:200::::::e:', '7777888833334444:200::::::s:'), older).key;
|
|
499
|
+
assert.equal(both.status, 'gap');
|
|
500
|
+
assert.match(both.message, /2 secret keys/);
|
|
501
|
+
// A pin to a key gpg does not have: "no secret key".
|
|
502
|
+
cfg('ABABABABABABABAB!');
|
|
503
|
+
assert.match(rows('', older).key.message, /no secret key/);
|
|
504
|
+
// Real gpg exits 2 when it has no such key.
|
|
505
|
+
const missing = byId(check(s, { gitRun: (c, a, o = {}) => (c === 'gpg' ? { ok: false, stdout: '' } : run(c, a, { ...o, env: s.env })), haveTool: tools('gh', 'gpg'), runner: platform().runner })).key;
|
|
506
|
+
assert.match(missing.message, /no secret key/);
|
|
507
|
+
assert.match(missing.fix.steps[0], /typo/);
|
|
508
|
+
// The same without "!".
|
|
509
|
+
cfg('ABABABABABABABAB');
|
|
510
|
+
const noBang = byId(check(s, { gitRun: (c, a, o = {}) => (c === 'gpg' ? { ok: false, stdout: '' } : run(c, a, { ...o, env: s.env })), haveTool: tools('gh', 'gpg'), runner: platform().runner })).key;
|
|
511
|
+
assert.match(noBang.message, /no secret key/);
|
|
512
|
+
assert.match(noBang.fix.steps[0], /typo/);
|
|
513
|
+
// By email: key A signs; an old expired key B has the same email. The account has only B: "does not list".
|
|
514
|
+
execFileSync('git', ['config', '--unset', 'user.signingkey'], { cwd: s.dir, env: s.env });
|
|
515
|
+
// Looked up by email and not found: no user.signingkey to check for a typo.
|
|
516
|
+
const byEmail = byId(check(s, { gitRun: (c, a, o = {}) => (c === 'gpg' ? { ok: false, stdout: '' } : run(c, a, { ...o, env: s.env })), haveTool: tools('gh', 'gpg'), runner: platform().runner })).key;
|
|
517
|
+
assert.match(byEmail.message, /no secret key/);
|
|
518
|
+
assert.match(byEmail.fix.steps[0], /^Make a key/);
|
|
519
|
+
const twoKeys = 'sec:u:255:22:AAAABBBBCCCCDDDD:100::::::scSC:::+:\nsec:e:255:22:9999000011112222:50::::::scSC:::+:';
|
|
520
|
+
const r = rows(twoKeys, { key_id: '9999000011112222' })['platform-key'];
|
|
521
|
+
assert.equal(r.status, 'gap');
|
|
522
|
+
assert.match(r.message, /does not list your GPG key/);
|
|
523
|
+
} finally { fs.rmSync(s.T, { recursive: true, force: true }); }
|
|
524
|
+
});
|