Skip to content

Commit d314d94

Browse files
func: TOON integration
1 parent 71b965d commit d314d94

6 files changed

Lines changed: 236 additions & 146 deletions

File tree

‎cliv2-private/go.mod‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ require (
223223
github.com/snyk/container-cli v0.0.0-20260213211631-cd2b2cf8f3ea // indirect
224224
github.com/snyk/dep-graph/go v0.0.0-20260127160647-c836da762c62 // indirect
225225
github.com/snyk/error-catalog-golang-public v0.0.0-20260914083231-5ff7dfd3c70d // indirect
226-
github.com/snyk/go-application-framework v0.25.1-0.20260917100129-c6c7ac18c4e2 // indirect
226+
github.com/snyk/go-application-framework v0.25.1-0.20260917100254-1637bcbaf235 // indirect
227227
github.com/snyk/go-httpauth v0.0.0-20260810142636-0f6182aaccbc // indirect
228228
github.com/snyk/policy-engine v1.1.4 // indirect
229229
github.com/snyk/snyk-iac-capture v0.6.5 // indirect

‎cliv2-private/go.sum‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,8 +605,8 @@ github.com/snyk/dep-graph/go v0.0.0-20260127160647-c836da762c62 h1:kgZNQ5ztI4+n3
605605
github.com/snyk/dep-graph/go v0.0.0-20260127160647-c836da762c62/go.mod h1:hTr91da/4ze2nk9q6ZW1BmfM2Z8rLUZSEZ3kK+6WGpc=
606606
github.com/snyk/error-catalog-golang-public v0.0.0-20260914083231-5ff7dfd3c70d h1:w8oFrikQWtvGW2IPXHUxs5sFuqorRcxODiA5eCwUm6o=
607607
github.com/snyk/error-catalog-golang-public v0.0.0-20260914083231-5ff7dfd3c70d/go.mod h1:0dz+HUR/r7VLlQpLfF0a/F1tdHH84NLTZzCxjZ+Q1nk=
608-
github.com/snyk/go-application-framework v0.25.1-0.20260917100129-c6c7ac18c4e2 h1:iHpWTheDDYQZgT70lVL0ulIXtl5ohflb2tDsKqUfxWc=
609-
github.com/snyk/go-application-framework v0.25.1-0.20260917100129-c6c7ac18c4e2/go.mod h1:3OTJn8QqzBFOXNZxpzGs0CREubF48BRXJrszsKa2zNc=
608+
github.com/snyk/go-application-framework v0.25.1-0.20260917100254-1637bcbaf235 h1:WKGC5PLtt6rn1ucYaaGGHb4QbnOzW8kbMKBSlbhrVLw=
609+
github.com/snyk/go-application-framework v0.25.1-0.20260917100254-1637bcbaf235/go.mod h1:3OTJn8QqzBFOXNZxpzGs0CREubF48BRXJrszsKa2zNc=
610610
github.com/snyk/go-httpauth v0.0.0-20260810142636-0f6182aaccbc h1:tuZVhmJFxS4qJlwYIIIw8xgw3VaVqIR3IAV0WaaFVnI=
611611
github.com/snyk/go-httpauth v0.0.0-20260810142636-0f6182aaccbc/go.mod h1:f42qLL7WXOS0od7dXJV/hK3myjms/r6HsXgLrg1HRRY=
612612
github.com/snyk/policy-engine v1.1.4 h1:0XpaMpl7ixSk4+dlpHYg2iKEBuv+5Ci+QIcbsmhktao=

‎cliv2/go.mod‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ require (
2222
github.com/snyk/code-client-go v1.31.8
2323
github.com/snyk/container-cli v0.0.0-20260213211631-cd2b2cf8f3ea
2424
github.com/snyk/error-catalog-golang-public v0.0.0-20260914083231-5ff7dfd3c70d
25-
github.com/snyk/go-application-framework v0.25.1-0.20260917100129-c6c7ac18c4e2
25+
github.com/snyk/go-application-framework v0.25.1-0.20260917100254-1637bcbaf235
2626
github.com/snyk/go-httpauth v0.0.0-20260810142636-0f6182aaccbc
2727
github.com/snyk/snyk-iac-capture v0.6.5
2828
github.com/snyk/snyk-ls v0.0.0-20260907062128-ef4a43fa0dbf

‎cliv2/go.sum‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,8 @@ github.com/snyk/dep-graph/go v0.0.0-20260127160647-c836da762c62 h1:kgZNQ5ztI4+n3
556556
github.com/snyk/dep-graph/go v0.0.0-20260127160647-c836da762c62/go.mod h1:hTr91da/4ze2nk9q6ZW1BmfM2Z8rLUZSEZ3kK+6WGpc=
557557
github.com/snyk/error-catalog-golang-public v0.0.0-20260914083231-5ff7dfd3c70d h1:w8oFrikQWtvGW2IPXHUxs5sFuqorRcxODiA5eCwUm6o=
558558
github.com/snyk/error-catalog-golang-public v0.0.0-20260914083231-5ff7dfd3c70d/go.mod h1:0dz+HUR/r7VLlQpLfF0a/F1tdHH84NLTZzCxjZ+Q1nk=
559-
github.com/snyk/go-application-framework v0.25.1-0.20260917100129-c6c7ac18c4e2 h1:iHpWTheDDYQZgT70lVL0ulIXtl5ohflb2tDsKqUfxWc=
560-
github.com/snyk/go-application-framework v0.25.1-0.20260917100129-c6c7ac18c4e2/go.mod h1:3OTJn8QqzBFOXNZxpzGs0CREubF48BRXJrszsKa2zNc=
559+
github.com/snyk/go-application-framework v0.25.1-0.20260917100254-1637bcbaf235 h1:WKGC5PLtt6rn1ucYaaGGHb4QbnOzW8kbMKBSlbhrVLw=
560+
github.com/snyk/go-application-framework v0.25.1-0.20260917100254-1637bcbaf235/go.mod h1:3OTJn8QqzBFOXNZxpzGs0CREubF48BRXJrszsKa2zNc=
561561
github.com/snyk/go-httpauth v0.0.0-20260810142636-0f6182aaccbc h1:tuZVhmJFxS4qJlwYIIIw8xgw3VaVqIR3IAV0WaaFVnI=
562562
github.com/snyk/go-httpauth v0.0.0-20260810142636-0f6182aaccbc/go.mod h1:f42qLL7WXOS0od7dXJV/hK3myjms/r6HsXgLrg1HRRY=
563563
github.com/snyk/policy-engine v1.1.4 h1:0XpaMpl7ixSk4+dlpHYg2iKEBuv+5Ci+QIcbsmhktao=

‎test/jest/acceptance/snyk-secrets/snyk-secrets-toon.spec.ts‎

Lines changed: 100 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -41,101 +41,114 @@ describe('snyk secrets test TOON output', () => {
4141
afterAll(() => server.closePromise());
4242

4343
describe.each([0, 1])('%i findings', (count) => {
44-
test.each(['--toon', '--toon-file-output=result.toon'])(
45-
'%s preserves the result and exit code',
46-
async (flag) => {
47-
server.setEndpointResponse(testPath, {
48-
data: {
49-
id: testId,
50-
type: 'tests',
51-
attributes: {
52-
state: { execution: 'finished' },
53-
outcome: { result: count ? 'fail' : 'pass' },
54-
effective_summary: { count },
55-
raw_summary: { count },
56-
config: { scan_config: { secrets: {} } },
57-
},
44+
test.each([
45+
['--toon', ''],
46+
['--toon', '--toon=full'],
47+
['--toon-file-output=result.toon', ''],
48+
['--toon-file-output=result.toon', '--toon=full'],
49+
])('%s %s preserves the result and exit code', async (flag, fullFlag) => {
50+
server.setEndpointResponse(testPath, {
51+
data: {
52+
id: testId,
53+
type: 'tests',
54+
attributes: {
55+
state: { execution: 'finished' },
56+
outcome: { result: count ? 'fail' : 'pass' },
57+
effective_summary: { count },
58+
raw_summary: { count },
59+
config: { scan_config: { secrets: {} } },
5860
},
59-
});
60-
server.setEndpointResponse(`${testPath}/findings`, {
61-
data: count
62-
? [
63-
{
64-
id: '00000000-0000-4000-8000-000000000003',
65-
type: 'findings',
66-
attributes: {
67-
finding_type: 'secret',
68-
title: 'Synthetic secret',
69-
key: 'synthetic-secret',
70-
cause_of_failure: true,
71-
rating: { severity: 'high' },
72-
locations: [
73-
{
74-
type: 'source',
75-
file_path: 'config.txt',
76-
from_line: 1,
77-
to_line: 1,
78-
},
79-
],
80-
problems: [
81-
{
82-
id: 'synthetic-secret',
83-
source: 'secret',
84-
name: 'Synthetic secret',
85-
},
86-
],
87-
evidence: [],
88-
policy_modifications: [],
89-
risk: {},
90-
},
61+
},
62+
});
63+
server.setEndpointResponse(`${testPath}/findings`, {
64+
data: count
65+
? [
66+
{
67+
id: '00000000-0000-4000-8000-000000000003',
68+
type: 'findings',
69+
attributes: {
70+
finding_type: 'secret',
71+
title: 'Synthetic secret',
72+
key: 'synthetic-secret',
73+
cause_of_failure: true,
74+
rating: { severity: 'high' },
75+
locations: [
76+
{
77+
type: 'source',
78+
file_path: 'config.txt',
79+
from_line: 1,
80+
to_line: 1,
81+
},
82+
],
83+
problems: [
84+
{
85+
id: 'synthetic-secret',
86+
source: 'secret',
87+
name: 'Synthetic secret',
88+
},
89+
],
90+
evidence: [],
91+
policy_modifications: [],
92+
risk: {},
9193
},
92-
]
93-
: [],
94+
},
95+
]
96+
: [],
97+
});
98+
for (const endpoint of [testPath, `${testPath}/findings`]) {
99+
server.setEndpointHeaders(endpoint, {
100+
'Content-Type': 'application/vnd.api+json',
94101
});
95-
for (const endpoint of [testPath, `${testPath}/findings`]) {
96-
server.setEndpointHeaders(endpoint, {
97-
'Content-Type': 'application/vnd.api+json',
98-
});
99-
}
102+
}
100103

101-
const { code, stdout, stderr } = await runSnykCLI(
102-
`secrets test --org=${orgId} ${flag}`,
103-
{
104-
cwd: directory,
105-
env,
106-
},
107-
);
108-
expect(stderr).toBe('');
109-
expect(code).toBe(count ? 1 : 0);
110-
const output =
111-
flag === '--toon'
112-
? stdout
113-
: await fs.readFile(join(directory, 'result.toon'), 'utf8');
114-
expect(output).toContain(`org: ${orgId}`);
104+
const { code, stdout, stderr } = await runSnykCLI(
105+
`secrets test --org=${orgId} ${flag}${fullFlag ? ` ${fullFlag}` : ''}`,
106+
{
107+
cwd: directory,
108+
env,
109+
},
110+
);
111+
expect(stderr).toBe('');
112+
expect(code).toBe(count ? 1 : 0);
113+
const full = fullFlag === '--toon=full';
114+
const output =
115+
flag === '--toon'
116+
? stdout
117+
: await fs.readFile(join(directory, 'result.toon'), 'utf8');
118+
expect(output).toContain(`org: ${orgId}`);
119+
if (full) {
120+
expect(output).not.toContain('hint: add --toon=full for all fields');
121+
} else {
115122
expect(output).toContain('hint: add --toon=full for all fields');
116-
if (count) {
117-
expect(output).toContain('secrets[1]{file,line,rule,severity}:');
118-
expect(output).toContain('config.txt,1,synthetic-secret,high');
123+
}
124+
if (count) {
125+
expect(output).toContain('secrets[1]{file,line,rule,severity}:');
126+
expect(output).toContain('config.txt,1,synthetic-secret,high');
127+
} else {
128+
expect(output).toMatch(/^secrets: \[\]$/m);
129+
}
130+
if (flag !== '--toon') {
131+
if (full) {
132+
// `--toon=<mode>` also selects TOON for stdout alongside the file.
133+
expect(stdout).toContain(`org: ${orgId}`);
134+
expect(stdout).toMatch(/^secrets(?:\[\d+\]\{|:)/m);
119135
} else {
120-
expect(output).toMatch(/^secrets: \[\]$/m);
121-
}
122-
if (flag !== '--toon') {
123136
expect(stdout).not.toMatch(/^secrets(?:\[\d+\]\{|:)/m);
124137
expect(stdout).toContain('Secret Detection');
125138
}
126-
expect(server.getRequests()).toEqual(
127-
expect.arrayContaining([
128-
expect.objectContaining({
129-
method: 'POST',
130-
path: `/rest/orgs/${orgId}/tests`,
131-
}),
132-
expect.objectContaining({
133-
method: 'GET',
134-
path: `${testPath}/findings`,
135-
}),
136-
]),
137-
);
138-
},
139-
);
139+
}
140+
expect(server.getRequests()).toEqual(
141+
expect.arrayContaining([
142+
expect.objectContaining({
143+
method: 'POST',
144+
path: `/rest/orgs/${orgId}/tests`,
145+
}),
146+
expect.objectContaining({
147+
method: 'GET',
148+
path: `${testPath}/findings`,
149+
}),
150+
]),
151+
);
152+
});
140153
});
141154
});

0 commit comments

Comments
 (0)