@@ -67,6 +67,55 @@ describe('iac test --rules', () => {
6767 `Flag "--rules" is currently not supported for this org. To enable it, please contact snyk support.` ,
6868 ) ;
6969 } ) ;
70+
71+ describe . each ( [
72+ [ '--report flag' , 'test --report' ] ,
73+ [ 'report command' , 'report' ] ,
74+ ] ) ( 'when used with the %s' , ( _ , testedCommand ) => {
75+ it ( 'should resolve successfully' , async ( ) => {
76+ const { stderr, exitCode } = await run (
77+ `snyk iac ${ testedCommand } --rules=./iac/custom-rules/custom.tar.gz ./iac/terraform/sg_open_ssh.tf` ,
78+ ) ;
79+
80+ expect ( exitCode ) . toEqual ( 1 ) ;
81+ expect ( stderr ) . toEqual ( '' ) ;
82+ } ) ;
83+
84+ it ( 'should display a message informing of the application of custom rules' , async ( ) => {
85+ const { stdout } = await run (
86+ `snyk iac ${ testedCommand } --rules=./iac/custom-rules/custom.tar.gz ./iac/terraform/sg_open_ssh.tf` ,
87+ ) ;
88+
89+ expect ( stdout ) . toContain (
90+ 'Using custom rules to generate misconfigurations.' ,
91+ ) ;
92+ } ) ;
93+
94+ it ( 'should display a warning message for custom rules not being available on the platform' , async ( ) => {
95+ const { stdout } = await run (
96+ `snyk iac ${ testedCommand } --rules=./iac/custom-rules/custom.tar.gz ./iac/terraform/sg_open_ssh.tf` ,
97+ ) ;
98+
99+ expect ( stdout ) . toContain (
100+ "Please note that your custom rules will not be sent to the Snyk platform, and will not be available on the project's page." ,
101+ ) ;
102+ } ) ;
103+
104+ describe . each ( [ '--json' , '--sarif' ] ) (
105+ 'when the %s flag is provided' ,
106+ ( testedFormatFlag ) => {
107+ it ( 'should not display the warning message for the custom rules not being available on the platform' , async ( ) => {
108+ const { stdout } = await run (
109+ `snyk iac ${ testedCommand } --rules=./iac/custom-rules/custom.tar.gz ./iac/terraform/sg_open_ssh.tf ${ testedFormatFlag } ` ,
110+ ) ;
111+
112+ expect ( stdout ) . not . toContain (
113+ "Please note that your custom rules will not be sent to the Snyk platform, and will not be available on the project's page." ,
114+ ) ;
115+ } ) ;
116+ } ,
117+ ) ;
118+ } ) ;
70119} ) ;
71120
72121describe ( 'custom rules pull from a remote OCI registry' , ( ) => {
@@ -149,37 +198,109 @@ describe('custom rules pull from a remote OCI registry', () => {
149198 // process.env.OCI_GCR_REGISTRY_PASSWORD,
150199 // ],
151200 ] ;
152- test . each ( cases ) (
153- 'given %p as a registry and correct credentials, it returns a success exit code' ,
154- async (
201+
202+ describe . each ( cases ) (
203+ 'given %p as a registry and correct credentials' ,
204+ (
155205 SNYK_CFG_OCI_REGISTRY_NAME ,
156206 SNYK_CFG_OCI_REGISTRY_URL ,
157207 SNYK_CFG_OCI_REGISTRY_USERNAME ,
158208 SNYK_CFG_OCI_REGISTRY_PASSWORD ,
159209 ) => {
160- const { stdout, exitCode } = await run (
161- `snyk iac test ./iac/terraform/sg_open_ssh.tf` ,
162- {
163- SNYK_CFG_OCI_REGISTRY_URL : SNYK_CFG_OCI_REGISTRY_URL as string ,
164- SNYK_CFG_OCI_REGISTRY_USERNAME : SNYK_CFG_OCI_REGISTRY_USERNAME as string ,
165- SNYK_CFG_OCI_REGISTRY_PASSWORD : SNYK_CFG_OCI_REGISTRY_PASSWORD as string ,
166- } ,
167- ) ;
168- expect ( SNYK_CFG_OCI_REGISTRY_URL ) . toBeDefined ( ) ;
169- expect ( SNYK_CFG_OCI_REGISTRY_USERNAME ) . toBeDefined ( ) ;
170- expect ( SNYK_CFG_OCI_REGISTRY_PASSWORD ) . toBeDefined ( ) ;
171- expect ( exitCode ) . toBe ( 1 ) ;
210+ it ( 'should return a success exit code' , async ( ) => {
211+ const { stdout, exitCode } = await run (
212+ `snyk iac test ./iac/terraform/sg_open_ssh.tf` ,
213+ {
214+ SNYK_CFG_OCI_REGISTRY_URL : SNYK_CFG_OCI_REGISTRY_URL as string ,
215+ SNYK_CFG_OCI_REGISTRY_USERNAME : SNYK_CFG_OCI_REGISTRY_USERNAME as string ,
216+ SNYK_CFG_OCI_REGISTRY_PASSWORD : SNYK_CFG_OCI_REGISTRY_PASSWORD as string ,
217+ } ,
218+ ) ;
219+ expect ( SNYK_CFG_OCI_REGISTRY_URL ) . toBeDefined ( ) ;
220+ expect ( SNYK_CFG_OCI_REGISTRY_USERNAME ) . toBeDefined ( ) ;
221+ expect ( SNYK_CFG_OCI_REGISTRY_PASSWORD ) . toBeDefined ( ) ;
222+ expect ( exitCode ) . toBe ( 1 ) ;
172223
173- expect ( stdout ) . toContain (
174- 'Using custom rules to generate misconfigurations.' ,
175- ) ;
176- expect ( stdout ) . toContain ( 'Testing ./iac/terraform/sg_open_ssh.tf' ) ;
177- expect ( stdout ) . toContain ( 'Infrastructure as code issues:' ) ;
178- expect ( stdout ) . toContain ( 'Missing tags' ) ;
179- expect ( stdout ) . toContain ( 'CUSTOM-1' ) ;
180- expect ( stdout ) . toContain (
181- 'introduced by input > resource > aws_security_group[allow_ssh] > tags' ,
182- ) ;
224+ expect ( stdout ) . toContain (
225+ 'Using custom rules to generate misconfigurations.' ,
226+ ) ;
227+ expect ( stdout ) . toContain ( 'Testing ./iac/terraform/sg_open_ssh.tf' ) ;
228+ expect ( stdout ) . toContain ( 'Infrastructure as code issues:' ) ;
229+ expect ( stdout ) . toContain ( 'Missing tags' ) ;
230+ expect ( stdout ) . toContain ( 'CUSTOM-1' ) ;
231+ expect ( stdout ) . toContain (
232+ 'introduced by input > resource > aws_security_group[allow_ssh] > tags' ,
233+ ) ;
234+ } ) ;
235+
236+ describe . each ( [
237+ [ '--report flag' , 'test --report' ] ,
238+ [ 'report command' , 'report' ] ,
239+ ] ) ( 'when used with the %s' , ( _ , testedCommand ) => {
240+ it ( 'should resolve successfully' , async ( ) => {
241+ const { exitCode, stderr } = await run (
242+ `snyk iac ${ testedCommand } ./iac/terraform/sg_open_ssh.tf` ,
243+ {
244+ SNYK_CFG_OCI_REGISTRY_URL : SNYK_CFG_OCI_REGISTRY_URL as string ,
245+ SNYK_CFG_OCI_REGISTRY_USERNAME : SNYK_CFG_OCI_REGISTRY_USERNAME as string ,
246+ SNYK_CFG_OCI_REGISTRY_PASSWORD : SNYK_CFG_OCI_REGISTRY_PASSWORD as string ,
247+ } ,
248+ ) ;
249+
250+ expect ( exitCode ) . toEqual ( 1 ) ;
251+ expect ( stderr ) . toContain ( '' ) ;
252+ } ) ;
253+
254+ it ( 'should display a message informing of the application of custom rules' , async ( ) => {
255+ const { stdout } = await run (
256+ `snyk iac ${ testedCommand } ./iac/terraform/sg_open_ssh.tf` ,
257+ {
258+ SNYK_CFG_OCI_REGISTRY_URL : SNYK_CFG_OCI_REGISTRY_URL as string ,
259+ SNYK_CFG_OCI_REGISTRY_USERNAME : SNYK_CFG_OCI_REGISTRY_USERNAME as string ,
260+ SNYK_CFG_OCI_REGISTRY_PASSWORD : SNYK_CFG_OCI_REGISTRY_PASSWORD as string ,
261+ } ,
262+ ) ;
263+
264+ expect ( stdout ) . toContain (
265+ 'Using custom rules to generate misconfigurations.' ,
266+ ) ;
267+ } ) ;
268+
269+ it ( 'should display a warning message for custom rules not being available on the platform' , async ( ) => {
270+ const { stdout } = await run (
271+ `snyk iac ${ testedCommand } ./iac/terraform/sg_open_ssh.tf` ,
272+ {
273+ SNYK_CFG_OCI_REGISTRY_URL : SNYK_CFG_OCI_REGISTRY_URL as string ,
274+ SNYK_CFG_OCI_REGISTRY_USERNAME : SNYK_CFG_OCI_REGISTRY_USERNAME as string ,
275+ SNYK_CFG_OCI_REGISTRY_PASSWORD : SNYK_CFG_OCI_REGISTRY_PASSWORD as string ,
276+ } ,
277+ ) ;
278+
279+ expect ( stdout ) . toContain (
280+ "Please note that your custom rules will not be sent to the Snyk platform, and will not be available on the project's page." ,
281+ ) ;
282+ } ) ;
283+
284+ describe . each ( [ '--json' , '--sarif' ] ) (
285+ 'when the %s flag is provided' ,
286+ ( testedFormatFlag ) => {
287+ it ( 'should not display the warning message for the custom rules not being available on the platform' , async ( ) => {
288+ const { stdout } = await run (
289+ `snyk iac ${ testedCommand } ./iac/terraform/sg_open_ssh.tf ${ testedFormatFlag } ` ,
290+ {
291+ SNYK_CFG_OCI_REGISTRY_URL : SNYK_CFG_OCI_REGISTRY_URL as string ,
292+ SNYK_CFG_OCI_REGISTRY_USERNAME : SNYK_CFG_OCI_REGISTRY_USERNAME as string ,
293+ SNYK_CFG_OCI_REGISTRY_PASSWORD : SNYK_CFG_OCI_REGISTRY_PASSWORD as string ,
294+ } ,
295+ ) ;
296+
297+ expect ( stdout ) . not . toContain (
298+ "Please note that your custom rules will not be sent to the Snyk platform, and will not be available on the project's page." ,
299+ ) ;
300+ } ) ;
301+ } ,
302+ ) ;
303+ } ) ;
183304 } ,
184305 ) ;
185306
0 commit comments