-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathcmd-scan-create.test.mts
More file actions
815 lines (772 loc) · 24.5 KB
/
cmd-scan-create.test.mts
File metadata and controls
815 lines (772 loc) · 24.5 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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
import path from 'node:path'
import { describe, expect } from 'vitest'
import constants, {
FLAG_CONFIG,
FLAG_DRY_RUN,
FLAG_HELP,
FLAG_JSON,
FLAG_MARKDOWN,
FLAG_ORG,
} from '../../../src/constants.mts'
import { cmdit, spawnSocketCli, testPath } from '../../../test/utils.mts'
const fixtureBaseDir = path.join(testPath, 'fixtures/commands/scan/create')
describe('socket scan create', async () => {
const { binCliPath } = constants
cmdit(
['scan', 'create', FLAG_HELP, FLAG_CONFIG, '{}'],
`should support ${FLAG_HELP}`,
async cmd => {
const { code, stderr, stdout } = await spawnSocketCli(binCliPath, cmd)
expect(stdout).toMatchInlineSnapshot(`
"Create a new Socket scan and report
Usage
$ socket scan create [options] [TARGET...]
API Token Requirements
- Quota: 1 unit
- Permissions: full-scans:create
Options
--auto-manifest Run \`socket manifest auto\` before collecting manifest files. This is necessary for languages like Scala, Gradle, and Kotlin, See \`socket manifest auto --help\`.
--branch Branch name
--commit-hash Commit hash
--commit-message Commit message
--committers Committers
--cwd working directory, defaults to process.cwd()
--default-branch Set the default branch of the repository to the branch of this full-scan. Should only need to be done once, for example for the "main" or "master" branch.
--interactive Allow for interactive elements, asking for input. Use --no-interactive to prevent any input questions, defaulting them to cancel/no.
--json Output as JSON
--markdown Output as Markdown
--org Force override the organization slug, overrides the default org from config
--pull-request Pull request number
--reach Run tier 1 full application reachability analysis
--read-only Similar to --dry-run except it can read from remote, stops before it would create an actual report
--repo Repository name
--report Wait for the scan creation to complete, then basically run \`socket scan report\` on it
--report-level Which policy level alerts should be reported (default 'error')
--set-as-alerts-page When true and if this is the "default branch" then this Scan will be the one reflected on your alerts page. See help for details. Defaults to true.
--tmp Set the visibility (true/false) of the scan in your dashboard.
--workspace The workspace in the Socket Organization that the repository is in to associate with the full scan.
Reachability Options (when --reach is used)
--reach-analysis-memory-limit The maximum memory in MB to use for the reachability analysis. The default is 8192MB.
--reach-analysis-timeout Set timeout for the reachability analysis. Split analysis runs may cause the total scan time to exceed this timeout significantly.
--reach-concurrency Set the maximum number of concurrent reachability analysis runs. It is recommended to choose a concurrency level that ensures each analysis run has at least the --reach-analysis-memory-limit amount of memory available. NPM reachability analysis does not support concurrent execution, so the concurrency level is ignored for NPM.
--reach-debug Enable debug mode for reachability analysis. Provides verbose logging from the reachability CLI.
--reach-detailed-analysis-log-file A log file with detailed analysis logs is written to root of each analyzed workspace.
--reach-disable-analytics Disable reachability analytics sharing with Socket. Also disables caching-based optimizations.
--reach-ecosystems List of ecosystems to conduct reachability analysis on, as either a comma separated value or as multiple flags. Defaults to all ecosystems.
--reach-enable-analysis-splitting Allow the reachability analysis to partition CVEs into buckets that are processed in separate analysis runs. May improve accuracy, but not recommended by default.
--reach-exclude-paths List of paths to exclude from reachability analysis, as either a comma separated value or as multiple flags.
--reach-skip-cache Skip caching-based optimizations. By default, the reachability analysis will use cached configurations from previous runs to speed up the analysis.
--reach-use-only-pregenerated-sboms When using this option, the scan is created based only on pre-generated CDX and SPDX files in your project.
--reach-version Override the version of @coana-tech/cli used for reachability analysis. Default: <coana-version>.
Uploads the specified dependency manifest files for Go, Gradle, JavaScript,
Kotlin, Python, and Scala. Files like "package.json" and "requirements.txt".
If any folder is specified, the ones found in there recursively are uploaded.
Details on TARGET:
- Defaults to the current dir (cwd) if none given
- Multiple targets can be specified
- If a target is a file, only that file is checked
- If it is a dir, the dir is scanned for any supported manifest files
- Dirs MUST be within the current dir (cwd), you can use --cwd to change it
- Supports globbing such as "**/package.json", "**/requirements.txt", etc.
- Ignores any file specified in your project's ".gitignore"
- Also a sensible set of default ignores from the "ignore-by-default" module
The --repo and --branch flags tell Socket to associate this Scan with that
repo/branch. The names will show up on your dashboard on the Socket website.
Note: for a first run you probably want to set --default-branch to indicate
the default branch name, like "main" or "master".
The "alerts page" (https://socket.dev/dashboard/org/YOURORG/alerts) will show
the results from the last scan designated as the "pending head" on the branch
configured on Socket to be the "default branch". When creating a scan the
--set-as-alerts-page flag will default to true to update this. You can prevent
this by using --no-set-as-alerts-page. This flag is ignored for any branch that
is not designated as the "default branch". It is disabled when using --tmp.
You can use \`socket scan setup\` to configure certain repo flag defaults.
Examples
$ socket scan create
$ socket scan create ./proj --json
$ socket scan create --repo=test-repo --branch=main ./package.json"
`)
expect(`\n ${stderr}`).toMatchInlineSnapshot(`
"
_____ _ _ /---------------
| __|___ ___| |_ ___| |_ | CLI: <redacted>
|__ | * | _| '_| -_| _| | token: <redacted>, org: <redacted>
|_____|___|___|_,_|___|_|.dev | Command: \`socket scan create\`, cwd: <redacted>"
`)
expect(code, 'explicit help should exit with code 0').toBe(0)
expect(stderr, 'banner includes base command').toContain(
'`socket scan create`',
)
},
)
cmdit(
[
'scan',
'create',
FLAG_ORG,
'fakeOrg',
'target',
FLAG_DRY_RUN,
'--repo',
'xyz',
'--branch',
'abc',
FLAG_CONFIG,
'{"apiToken":"fakeToken"}',
],
'should require args with just dry-run',
async cmd => {
const { code, stderr, stdout } = await spawnSocketCli(binCliPath, cmd)
expect(stdout).toMatchInlineSnapshot(`"[DryRun]: Bailing now"`)
expect(`\n ${stderr}`).toMatchInlineSnapshot(`
"
_____ _ _ /---------------
| __|___ ___| |_ ___| |_ | CLI: <redacted>
|__ | * | _| '_| -_| _| | token: <redacted>, org: <redacted>
|_____|___|___|_,_|___|_|.dev | Command: \`socket scan create\`, cwd: <redacted>"
`)
expect(code, 'dry-run should exit with code 0 if input ok').toBe(0)
},
)
cmdit(
[
'scan',
'create',
FLAG_ORG,
'fakeOrg',
'target',
FLAG_DRY_RUN,
'--repo',
'xyz',
'--branch',
'abc',
'--reach-disable-analytics',
FLAG_CONFIG,
'{"apiToken":"fakeToken"}',
],
'should fail when --reach-disable-analytics is used without --reach',
async cmd => {
const { code, stderr, stdout } = await spawnSocketCli(binCliPath, cmd)
const output = stdout + stderr
expect(output).toContain(
'Reachability analysis flags require --reach to be enabled',
)
expect(output).toContain('add --reach flag to use --reach-* options')
expect(
code,
'should exit with non-zero code when validation fails',
).not.toBe(0)
},
)
cmdit(
[
'scan',
'create',
FLAG_ORG,
'fakeOrg',
'target',
FLAG_DRY_RUN,
'--repo',
'xyz',
'--branch',
'abc',
'--reach-analysis-memory-limit',
'8192',
FLAG_CONFIG,
'{"apiToken":"fakeToken"}',
],
'should succeed when --reach-analysis-memory-limit is used with default value without --reach',
async cmd => {
const { code, stdout } = await spawnSocketCli(binCliPath, cmd)
expect(stdout).toMatchInlineSnapshot(`"[DryRun]: Bailing now"`)
expect(code, 'should exit with code 0 when using default value').toBe(0)
},
)
cmdit(
[
'scan',
'create',
FLAG_ORG,
'fakeOrg',
'target',
FLAG_DRY_RUN,
'--repo',
'xyz',
'--branch',
'abc',
'--reach-analysis-memory-limit',
'4096',
FLAG_CONFIG,
'{"apiToken":"fakeToken"}',
],
'should fail when --reach-analysis-memory-limit is used with non-default value without --reach',
async cmd => {
const { code, stderr, stdout } = await spawnSocketCli(binCliPath, cmd)
const output = stdout + stderr
expect(output).toContain(
'Reachability analysis flags require --reach to be enabled',
)
expect(output).toContain('add --reach flag to use --reach-* options')
expect(
code,
'should exit with non-zero code when validation fails',
).not.toBe(0)
},
)
cmdit(
[
'scan',
'create',
FLAG_ORG,
'fakeOrg',
'target',
FLAG_DRY_RUN,
'--repo',
'xyz',
'--branch',
'abc',
'--reach-analysis-timeout',
'3600',
FLAG_CONFIG,
'{"apiToken":"fakeToken"}',
],
'should fail when --reach-analysis-timeout is used without --reach',
async cmd => {
const { code, stderr, stdout } = await spawnSocketCli(binCliPath, cmd)
const output = stdout + stderr
expect(output).toContain(
'Reachability analysis flags require --reach to be enabled',
)
expect(output).toContain('add --reach flag to use --reach-* options')
expect(
code,
'should exit with non-zero code when validation fails',
).not.toBe(0)
},
)
cmdit(
[
'scan',
'create',
FLAG_ORG,
'fakeOrg',
'target',
FLAG_DRY_RUN,
'--repo',
'xyz',
'--branch',
'abc',
'--reach-ecosystems',
'npm',
'--reach-ecosystems',
'pypi',
FLAG_CONFIG,
'{"apiToken":"fakeToken"}',
],
'should fail when --reach-ecosystems is used without --reach',
async cmd => {
const { code, stderr, stdout } = await spawnSocketCli(binCliPath, cmd)
const output = stdout + stderr
expect(output).toContain(
'Reachability analysis flags require --reach to be enabled',
)
expect(output).toContain('add --reach flag to use --reach-* options')
expect(
code,
'should exit with non-zero code when validation fails',
).not.toBe(0)
},
)
cmdit(
[
'scan',
'create',
FLAG_ORG,
'fakeOrg',
'test/fixtures/commands/scan/simple-npm',
FLAG_DRY_RUN,
'--repo',
'xyz',
'--branch',
'abc',
'--reach',
'--reach-disable-analytics',
'--reach-analysis-memory-limit',
'4096',
'--reach-analysis-timeout',
'3600',
'--reach-ecosystems',
'npm',
FLAG_CONFIG,
'{"apiToken":"fakeToken"}',
],
'should succeed when reachability options are used with --reach',
async cmd => {
const { code, stdout } = await spawnSocketCli(binCliPath, cmd)
expect(stdout).toMatchInlineSnapshot(`"[DryRun]: Bailing now"`)
expect(code, 'should exit with code 0 when all flags are valid').toBe(0)
},
)
cmdit(
[
'scan',
'create',
FLAG_ORG,
'fakeOrg',
'target',
FLAG_DRY_RUN,
'--repo',
'xyz',
'--branch',
'abc',
'--reach-exclude-paths',
'node_modules',
'--reach-exclude-paths',
'dist',
FLAG_CONFIG,
'{"apiToken":"fakeToken"}',
],
'should fail when --reach-exclude-paths is used without --reach',
async cmd => {
const { code, stderr, stdout } = await spawnSocketCli(binCliPath, cmd)
const output = stdout + stderr
expect(output).toContain(
'Reachability analysis flags require --reach to be enabled',
)
expect(output).toContain('add --reach flag to use --reach-* options')
expect(
code,
'should exit with non-zero code when validation fails',
).not.toBe(0)
},
)
cmdit(
[
'scan',
'create',
FLAG_ORG,
'fakeOrg',
'test/fixtures/commands/scan/simple-npm',
FLAG_DRY_RUN,
'--repo',
'xyz',
'--branch',
'abc',
'--reach',
'--reach-disable-analytics',
'--reach-analysis-memory-limit',
'4096',
'--reach-analysis-timeout',
'3600',
'--reach-ecosystems',
'npm',
'--reach-exclude-paths',
'node_modules',
'--reach-exclude-paths',
'dist',
FLAG_CONFIG,
'{"apiToken":"fakeToken"}',
],
'should succeed when all reachability options including reachExcludePaths are used with --reach',
async cmd => {
const { code, stdout } = await spawnSocketCli(binCliPath, cmd)
expect(stdout).toMatchInlineSnapshot(`"[DryRun]: Bailing now"`)
expect(code, 'should exit with code 0 when all flags are valid').toBe(0)
},
)
cmdit(
[
'scan',
'create',
FLAG_ORG,
'fakeOrg',
'test/fixtures/commands/scan/simple-npm',
FLAG_DRY_RUN,
'--repo',
'xyz',
'--branch',
'abc',
'--reach',
'--reach-ecosystems',
'npm,pypi,cargo',
FLAG_CONFIG,
'{"apiToken":"fakeToken"}',
],
'should succeed when --reach-ecosystems is used with comma-separated values',
async cmd => {
const { code, stdout } = await spawnSocketCli(binCliPath, cmd)
expect(stdout).toMatchInlineSnapshot(`"[DryRun]: Bailing now"`)
expect(
code,
'should exit with code 0 when comma-separated values are used',
).toBe(0)
},
)
cmdit(
[
'scan',
'create',
FLAG_ORG,
'fakeOrg',
'test/fixtures/commands/scan/simple-npm',
FLAG_DRY_RUN,
'--repo',
'xyz',
'--branch',
'abc',
'--reach',
'--reach-exclude-paths',
'node_modules,dist,build',
FLAG_CONFIG,
'{"apiToken":"fakeToken"}',
],
'should succeed when --reach-exclude-paths is used with comma-separated values',
async cmd => {
const { code, stdout } = await spawnSocketCli(binCliPath, cmd)
expect(stdout).toMatchInlineSnapshot(`"[DryRun]: Bailing now"`)
expect(
code,
'should exit with code 0 when comma-separated values are used',
).toBe(0)
},
)
cmdit(
[
'scan',
'create',
FLAG_ORG,
'fakeOrg',
'target',
FLAG_DRY_RUN,
'--repo',
'xyz',
'--branch',
'abc',
'--reach-ecosystems',
'npm,pypi',
FLAG_CONFIG,
'{"apiToken":"fakeToken"}',
],
'should fail when --reach-ecosystems with comma-separated values is used without --reach',
async cmd => {
const { code, stderr, stdout } = await spawnSocketCli(binCliPath, cmd)
const output = stdout + stderr
expect(output).toContain(
'Reachability analysis flags require --reach to be enabled',
)
expect(output).toContain('add --reach flag to use --reach-* options')
expect(
code,
'should exit with non-zero code when validation fails',
).not.toBe(0)
},
)
cmdit(
[
'scan',
'create',
FLAG_ORG,
'fakeOrg',
'target',
FLAG_DRY_RUN,
'--repo',
'xyz',
'--branch',
'abc',
'--reach-exclude-paths',
'node_modules,dist',
FLAG_CONFIG,
'{"apiToken":"fakeToken"}',
],
'should fail when --reach-exclude-paths with comma-separated values is used without --reach',
async cmd => {
const { code, stderr, stdout } = await spawnSocketCli(binCliPath, cmd)
const output = stdout + stderr
expect(output).toContain(
'Reachability analysis flags require --reach to be enabled',
)
expect(output).toContain('add --reach flag to use --reach-* options')
expect(
code,
'should exit with non-zero code when validation fails',
).not.toBe(0)
},
)
cmdit(
[
'scan',
'create',
FLAG_ORG,
'fakeOrg',
'test/fixtures/commands/scan/simple-npm',
FLAG_DRY_RUN,
'--repo',
'xyz',
'--branch',
'abc',
'--reach',
'--reach-ecosystems',
'npm,invalid-ecosystem',
FLAG_CONFIG,
'{"apiToken":"fakeToken"}',
],
'should fail when --reach-ecosystems contains invalid values',
async cmd => {
const { code, stderr, stdout } = await spawnSocketCli(binCliPath, cmd)
const output = stdout + stderr
expect(output).toContain('Invalid ecosystem: "invalid-ecosystem"')
expect(
code,
'should exit with non-zero code when invalid ecosystem is provided',
).not.toBe(0)
},
)
cmdit(
['scann', 'create', FLAG_HELP],
'should suggest similar command for typos',
async cmd => {
const { code, stderr, stdout } = await spawnSocketCli(binCliPath, cmd)
const output = stdout + stderr
expect(output).toContain('Unknown command "scann". Did you mean "scan"?')
expect(
code,
'should exit with non-zero code when command is not found',
).toBe(2)
},
)
cmdit(
[
'scan',
'create',
path.join(fixtureBaseDir, 'nonexistent'),
FLAG_ORG,
'test-org',
FLAG_CONFIG,
'{"apiToken":"fake-token"}',
],
'should show helpful error message for directories with no manifest files',
async cmd => {
const { code, stderr, stdout } = await spawnSocketCli(binCliPath, cmd)
const output = stdout + stderr
expect(output).toMatch(
/found no eligible files to scan|An error was thrown while requesting/,
)
expect(
code,
'should exit with non-zero code when no files found',
).not.toBe(0)
},
)
cmdit(
[
'scan',
'create',
FLAG_ORG,
'fakeOrg',
'test/fixtures/commands/scan/simple-npm',
FLAG_DRY_RUN,
'--repo',
'xyz',
'--branch',
'abc',
'--reach',
'--reach-analysis-memory-limit',
'1',
FLAG_CONFIG,
'{"apiToken":"fakeToken"}',
],
'should succeed with minimal positive reachability memory limit',
async cmd => {
const { code, stdout } = await spawnSocketCli(binCliPath, cmd)
expect(stdout).toMatchInlineSnapshot(`"[DryRun]: Bailing now"`)
expect(code, 'should exit with code 0').toBe(0)
},
)
cmdit(
[
'scan',
'create',
FLAG_ORG,
'fakeOrg',
'test/fixtures/commands/scan/simple-npm',
FLAG_DRY_RUN,
'--repo',
'xyz',
'--branch',
'abc',
'--reach',
'--reach-analysis-timeout',
'0',
FLAG_CONFIG,
'{"apiToken":"fakeToken"}',
],
'should succeed with zero timeout (unlimited)',
async cmd => {
const { code, stdout } = await spawnSocketCli(binCliPath, cmd)
expect(stdout).toMatchInlineSnapshot(`"[DryRun]: Bailing now"`)
expect(code, 'should exit with code 0').toBe(0)
},
)
cmdit(
[
'scan',
'create',
FLAG_ORG,
'fakeOrg',
'test/fixtures/commands/scan/simple-npm',
FLAG_DRY_RUN,
'--repo',
'xyz',
'--branch',
'abc',
'--reach',
'--reach-ecosystems',
'npm,invalid,pypi',
FLAG_CONFIG,
'{"apiToken":"fakeToken"}',
],
'should fail when invalid ecosystem mixed with valid ones in --reach mode',
async cmd => {
const { code, stderr, stdout } = await spawnSocketCli(binCliPath, cmd)
const output = stdout + stderr
expect(output).toContain('Invalid ecosystem: "invalid"')
expect(
code,
'should exit with non-zero code when invalid ecosystem provided',
).not.toBe(0)
},
)
cmdit(
[
'scan',
'create',
FLAG_ORG,
'fakeOrg',
'test/fixtures/commands/scan/simple-npm',
FLAG_DRY_RUN,
'--repo',
'xyz',
'--branch',
'abc',
'--reach',
'--reach-ecosystems',
'npm',
'--reach-exclude-paths',
'vendor,build,dist,target',
'--reach-analysis-memory-limit',
'16384',
'--reach-analysis-timeout',
'7200',
'--reach-disable-analytics',
FLAG_CONFIG,
'{"apiToken":"fakeToken"}',
],
'should succeed with comprehensive reachability configuration',
async cmd => {
const { code, stdout } = await spawnSocketCli(binCliPath, cmd)
expect(stdout).toMatchInlineSnapshot(`"[DryRun]: Bailing now"`)
expect(code, 'should exit with code 0 when all flags are valid').toBe(0)
},
)
cmdit(
[
'scan',
'create',
FLAG_ORG,
'fakeOrg',
'test/fixtures/commands/scan/simple-npm',
FLAG_DRY_RUN,
'--repo',
'xyz',
'--branch',
'abc',
'--reach',
'--json',
FLAG_CONFIG,
'{"apiToken":"fakeToken"}',
],
'should succeed with --reach and --json output format',
async cmd => {
const { code, stdout } = await spawnSocketCli(binCliPath, cmd)
expect(stdout).toMatchInlineSnapshot(`"[DryRun]: Bailing now"`)
expect(code, 'should exit with code 0').toBe(0)
},
)
cmdit(
[
'scan',
'create',
FLAG_ORG,
'fakeOrg',
'test/fixtures/commands/scan/simple-npm',
FLAG_DRY_RUN,
'--repo',
'xyz',
'--branch',
'abc',
'--reach',
'--markdown',
FLAG_CONFIG,
'{"apiToken":"fakeToken"}',
],
'should succeed with --reach and --markdown output format',
async cmd => {
const { code, stdout } = await spawnSocketCli(binCliPath, cmd)
expect(stdout).toMatchInlineSnapshot(`"[DryRun]: Bailing now"`)
expect(code, 'should exit with code 0').toBe(0)
},
)
cmdit(
[
'scan',
'create',
FLAG_ORG,
'fakeOrg',
'test/fixtures/commands/scan/simple-npm',
FLAG_DRY_RUN,
'--repo',
'xyz',
'--branch',
'abc',
'--reach',
'--json',
'--markdown',
FLAG_CONFIG,
'{"apiToken":"fakeToken"}',
],
'should fail when both --json and --markdown are used with --reach',
async cmd => {
const { code, stderr, stdout } = await spawnSocketCli(binCliPath, cmd)
const output = stdout + stderr
expect(output).toContain('The json and markdown flags cannot be both set')
expect(
code,
'should exit with non-zero code when conflicting flags are used',
).not.toBe(0)
},
)
cmdit(
[
'scan',
'create',
FLAG_ORG,
'fakeOrg',
'test/fixtures/commands/scan/simple-npm',
FLAG_DRY_RUN,
'--repo',
'xyz',
'--branch',
'abc',
'--reach',
'--read-only',
FLAG_CONFIG,
'{"apiToken":"fakeToken"}',
],
'should succeed when combining --reach with --read-only',
async cmd => {
const { code, stdout } = await spawnSocketCli(binCliPath, cmd)
expect(stdout).toMatchInlineSnapshot(`"[DryRun]: Bailing now"`)
expect(code, 'should exit with code 0').toBe(0)
},
)
})