unbound-cli 1.21.3 → 1.22.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unbound-cli",
3
- "version": "1.21.3",
3
+ "version": "1.22.0",
4
4
  "description": "CLI tool for Unbound - AI Gateway management",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -73,9 +73,41 @@ async function list(traceValue, opts) {
73
73
  output.logTable(HEADERS, findings.map((f) => [String(f.id), f.type, f.action, statusOf(f)]));
74
74
  }
75
75
 
76
+ // Marks every finding of the user's on the trace that is still markable; --mark-all overrides --finding.
77
+ async function markAll(trace, findings, opts) {
78
+ const targets = findings.filter((f) => f.markable);
79
+ if (targets.length === 0) throw new Error('Nothing on this trace is left to mark.');
80
+ if (!opts.yes && !(await confirm(`Mark ${targets.length} findings on trace ${trace} as false positives?`))) {
81
+ output.info('Cancelled.');
82
+ return;
83
+ }
84
+ const marked = [];
85
+ for (const finding of targets) {
86
+ try {
87
+ const data = await call('post', PATH, {
88
+ body: { trace_id: trace, guardrail_action_id: finding.id, is_false_positive: true },
89
+ });
90
+ marked.push({ id: finding.id, type: finding.type, message: data.message });
91
+ } catch (err) {
92
+ throw new Error(`Marked ${marked.length} of ${targets.length}; finding ${finding.id} failed: ${err.message}`);
93
+ }
94
+ }
95
+ if (opts.json) {
96
+ output.json({ trace_id: trace, marked });
97
+ return;
98
+ }
99
+ for (const m of marked) output.success(`${m.message}: ${m.type} finding ${m.id}.`);
100
+ }
101
+
76
102
  async function setMark(traceValue, opts, mark) {
77
103
  const trace = resolveTraceId(traceValue);
78
- const finding = chooseFinding(await fetchFindings(trace), mark, opts.finding);
104
+ const findings = await fetchFindings(trace);
105
+ if (opts.markAll) {
106
+ if (!mark) throw new Error('--mark-all works with mark only.');
107
+ if (opts.finding !== undefined) throw new Error('Use either --finding or --mark-all, not both.');
108
+ return markAll(trace, findings, opts);
109
+ }
110
+ const finding = chooseFinding(findings, mark, opts.finding);
79
111
  const verb = mark ? 'Mark' : 'Unmark';
80
112
  if (!opts.yes && !(await confirm(`${verb} ${finding.type} finding ${finding.id} on trace ${trace} as a false positive?`))) {
81
113
  output.info('Cancelled.');
@@ -114,6 +146,7 @@ Examples:
114
146
  .command('mark <trace-id>')
115
147
  .description('Mark one of your findings on a trace ID as a false positive.')
116
148
  .option('--finding <id>', 'Finding ID, when the trace has more than one (see "list")')
149
+ .option('--mark-all', 'Mark every finding of yours on the trace (overrides --finding)')
117
150
  .option('-y, --yes', 'Skip the confirmation prompt')
118
151
  .option('--json', 'Output the JSON response')
119
152
  .addHelpText('after', `
@@ -124,6 +157,7 @@ any finding in their organization, or work by action ID with
124
157
  Examples:
125
158
  $ unbound false-positive mark 3f2a6c1e-8b7d-4e2f-9a1c-5d6e7f8a9b0c
126
159
  $ unbound false-positive mark 3f2a6c1e-8b7d-4e2f-9a1c-5d6e7f8a9b0c --finding 5521 --yes
160
+ $ unbound false-positive mark 3f2a6c1e-8b7d-4e2f-9a1c-5d6e7f8a9b0c --mark-all --yes
127
161
  `)
128
162
  .action((trace, opts) => run(() => setMark(trace, opts, true)));
129
163
 
@@ -149,3 +149,40 @@ test('with no key at all it says to log in, and a refused key surfaces the refus
149
149
  await assert.rejects(freshCall({}).call('get', PATH), /unbound login/);
150
150
  await assert.rejects(freshCall({ deviceKey: 'd', refuse: ['d'] }).call('get', PATH), (e) => e.statusCode === 401);
151
151
  });
152
+
153
+ test('mark-all marks every markable finding and skips the ones already marked', async () => {
154
+ const second = { ...flagged, id: 13 };
155
+ const { server, seen, port } = await startServer((method) =>
156
+ (method === 'GET' ? [200, { findings: [flagged, marked, second] }] : [200, { message: 'False positive marked' }]));
157
+ try {
158
+ const r = await runCli(port, ['false-positive', 'mark', TRACE, '--mark-all', '--yes']);
159
+ assert.equal(r.code, 0, r.stderr);
160
+ const posts = seen.filter((s) => s.method === 'POST').map((s) => s.body.guardrail_action_id);
161
+ assert.deepEqual(posts, [11, 13]);
162
+ assert.match(r.stdout + r.stderr, /False positive marked/);
163
+ } finally {
164
+ server.close();
165
+ }
166
+ });
167
+
168
+ test('mark-all refuses to combine with --finding and posts nothing', async () => {
169
+ const { server, seen, port } = await startServer(() => [200, { findings: [flagged] }]);
170
+ try {
171
+ const r = await runCli(port, ['false-positive', 'mark', TRACE, '--mark-all', '--finding', '11', '--yes']);
172
+ assert.equal(r.code, 1);
173
+ assert.equal(seen.filter((s) => s.method === 'POST').length, 0);
174
+ } finally {
175
+ server.close();
176
+ }
177
+ });
178
+
179
+ test('mark-all with nothing left to mark exits 1 and posts nothing', async () => {
180
+ const { server, seen, port } = await startServer(() => [200, { findings: [marked] }]);
181
+ try {
182
+ const r = await runCli(port, ['false-positive', 'mark', TRACE, '--mark-all', '--yes']);
183
+ assert.equal(r.code, 1);
184
+ assert.equal(seen.filter((s) => s.method === 'POST').length, 0);
185
+ } finally {
186
+ server.close();
187
+ }
188
+ });