/
cli-test.all-projects.spec.ts
1087 lines (1027 loc) · 32.7 KB
/
cli-test.all-projects.spec.ts
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
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import * as path from 'path';
import * as sinon from 'sinon';
import * as depGraphLib from '@snyk/dep-graph';
import { CommandResult } from '../../../src/cli/commands/types';
import { AcceptanceTests } from './cli-test.acceptance.test';
import { getWorkspaceJSON } from '../workspace-helper';
export const AllProjectsTests: AcceptanceTests = {
language: 'Mixed',
tests: {
'`test kotlin-monorepo --all-projects` scans kotlin files': (
params,
utils,
) => async (t) => {
utils.chdirWorkspaces();
const simpleGradleGraph = depGraphLib.createFromJSON({
schemaVersion: '1.2.0',
pkgManager: {
name: 'gradle',
},
pkgs: [
{
id: 'gradle-monorepo@0.0.0',
info: {
name: 'gradle-monorepo',
version: '0.0.0',
},
},
],
graph: {
rootNodeId: 'root-node',
nodes: [
{
nodeId: 'root-node',
pkgId: 'gradle-monorepo@0.0.0',
deps: [],
},
],
},
});
const plugin = {
async inspect() {
return {
plugin: {
name: 'bundled:gradle',
runtime: 'unknown',
meta: {},
},
scannedProjects: [
{
meta: {
gradleProjectName: 'root-proj',
versionBuildInfo: {
gradleVersion: '6.5',
},
},
depGraph: simpleGradleGraph,
},
{
meta: {
gradleProjectName: 'root-proj/subproj',
versionBuildInfo: {
gradleVersion: '6.5',
},
},
depGraph: simpleGradleGraph,
},
],
};
},
};
const loadPlugin = sinon.stub(params.plugins, 'loadPlugin');
t.teardown(loadPlugin.restore);
loadPlugin.withArgs('gradle').returns(plugin);
loadPlugin.callThrough();
const result: CommandResult = await params.cli.test('kotlin-monorepo', {
allProjects: true,
detectionDepth: 3,
});
t.ok(loadPlugin.withArgs('rubygems').calledOnce, 'calls rubygems plugin');
t.ok(loadPlugin.withArgs('gradle').calledOnce, 'calls gradle plugin');
params.server.popRequests(2).forEach((req) => {
t.equal(req.method, 'POST', 'makes POST request');
t.equal(
req.headers['x-snyk-cli-version'],
params.versionNumber,
'sends version number',
);
t.match(req.url, '/api/v1/test-dep-graph', 'posts to correct url');
t.ok(req.body.depGraph, 'body contains depGraph');
t.match(
req.body.depGraph.pkgManager.name,
/(gradle|rubygems)/,
'depGraph has package manager',
);
});
t.match(
result.getDisplayResults(),
'Tested 3 projects',
'Detected 3 projects',
);
t.match(
result.getDisplayResults(),
'Package manager: rubygems',
'contains package manager rubygems',
);
t.match(
result.getDisplayResults(),
'Package manager: gradle',
'contains package manager gradle',
);
t.match(
result.getDisplayResults(),
'Target file: Gemfile.lock',
'contains target file Gemfile.lock',
);
t.match(
result.getDisplayResults(),
'Target file: build.gradle.kts',
'contains target file build.gradle.kts',
);
},
'`test yarn-out-of-sync` out of sync fails': (params, utils) => async (
t,
) => {
utils.chdirWorkspaces();
try {
await params.cli.test('yarn-workspace-out-of-sync', {
allProjects: true,
});
t.fail('Should fail');
} catch (e) {
t.equal(
e.message,
'\nTesting yarn-workspace-out-of-sync...\n\nFailed to get dependencies for all 3 potential projects. Run with `-d` for debug output and contact support@snyk.io',
'Contains enough info about err',
);
}
},
'`test mono-repo-with-ignores --all-projects` respects .snyk policy': (
params,
utils,
) => async (t) => {
utils.chdirWorkspaces();
const loadPlugin = sinon.spy(params.plugins, 'loadPlugin');
t.teardown(loadPlugin.restore);
const result: CommandResult = await params.cli.test(
'mono-repo-with-ignores',
{
allProjects: true,
detectionDepth: 3,
},
);
t.ok(loadPlugin.withArgs('npm').calledTwice, 'calls npm plugin');
let policyCount = 0;
params.server.popRequests(2).forEach((req) => {
t.equal(req.method, 'POST', 'makes POST request');
t.equal(
req.headers['x-snyk-cli-version'],
params.versionNumber,
'sends version number',
);
t.match(req.url, '/api/v1/test-dep-graph', 'posts to correct url');
t.ok(req.body.depGraph, 'body contains depGraph');
const vulnerableFolderPath =
process.platform === 'win32'
? 'vulnerable\\package-lock.json'
: 'vulnerable/package-lock.json';
if (req.body.targetFileRelativePath.endsWith(vulnerableFolderPath)) {
t.match(
req.body.policy,
'npm:node-uuid:20160328',
'body contains policy',
);
policyCount += 1;
}
t.match(
req.body.depGraph.pkgManager.name,
/(npm)/,
'depGraph has package manager',
);
});
t.match(policyCount, 1, 'one policy should have been found');
// results should contain test results from both package managers
// and show only 1/2 vulnerable paths for nested one since we ignore
// it in the .snyk file
t.match(
result.getDisplayResults(),
'Package manager: npm',
'contains package manager npm',
);
t.match(
result.getDisplayResults(),
'Target file: package-lock.json',
'contains target file package-lock.json',
);
},
'`test mono-repo-project with lockfiles --all-projects`': (
params,
utils,
) => async (t) => {
utils.chdirWorkspaces();
// mock python plugin because CI tooling doesn't have pipenv installed
const mockPlugin = {
async inspect() {
return {
plugin: {
targetFile: 'Pipfile',
name: 'snyk-python-plugin',
},
package: {},
};
},
};
const loadPlugin = sinon.stub(params.plugins, 'loadPlugin');
t.teardown(loadPlugin.restore);
loadPlugin.withArgs('pip').returns(mockPlugin);
loadPlugin.callThrough(); // don't mock other plugins
const result: CommandResult = await params.cli.test('mono-repo-project', {
allProjects: true,
detectionDepth: 1,
skipUnresolved: true,
});
t.ok(loadPlugin.withArgs('rubygems').calledOnce, 'calls rubygems plugin');
t.ok(loadPlugin.withArgs('npm').calledOnce, 'calls npm plugin');
t.ok(loadPlugin.withArgs('maven').calledOnce, 'calls maven plugin');
t.ok(loadPlugin.withArgs('nuget').calledOnce, 'calls nuget plugin');
t.ok(loadPlugin.withArgs('paket').calledOnce, 'calls nuget plugin');
t.ok(loadPlugin.withArgs('pip').calledOnce, 'calls pip plugin');
t.ok(loadPlugin.withArgs('sbt').calledOnce, 'calls pip plugin');
params.server.popRequests(7).forEach((req) => {
t.equal(req.method, 'POST', 'makes POST request');
t.equal(
req.headers['x-snyk-cli-version'],
params.versionNumber,
'sends version number',
);
t.match(req.url, '/api/v1/test-dep-graph', 'posts to correct url');
t.ok(req.body.depGraph, 'body contains depGraph');
t.match(
req.body.depGraph.pkgManager.name,
/(npm|rubygems|maven|nuget|paket|pip|sbt)/,
'depGraph has package manager',
);
});
// results should contain test results from both package managers
t.match(
result.getDisplayResults(),
'Package manager: rubygems',
'contains package manager rubygems',
);
t.match(
result.getDisplayResults(),
'Target file: Gemfile.lock',
'contains target file Gemfile.lock',
);
t.match(
result.getDisplayResults(),
'Project name: shallow-goof',
'contains correct project name for npm',
);
t.match(
result.getDisplayResults(),
'Package manager: npm',
'contains package manager npm',
);
t.match(
result.getDisplayResults(),
'Target file: package-lock.json',
'contains target file package-lock.json',
);
t.match(
result.getDisplayResults(),
'Package manager: maven',
'contains package manager maven',
);
t.match(
result.getDisplayResults(),
'Target file: pom.xml',
'contains target file pom.xml',
);
t.match(
result.getDisplayResults(),
'Target file: Pipfile',
'contains target file Pipfile',
);
t.match(
result.getDisplayResults(),
'Target file: build.sbt',
'contains target file build.sbt',
);
},
'`test mono-repo-project --all-projects --detection-depth=3`': (
params,
utils,
) => async (t) => {
utils.chdirWorkspaces();
// mock python plugin becuase CI tooling doesn't have pipenv installed
const mockPipfile = {
async inspect() {
return {
plugin: {
targetFile: 'Pipfile',
name: 'snyk-python-plugin',
},
package: {},
};
},
};
const mockRequirements = {
async inspect() {
return {
plugin: {
targetFile: 'python-app-with-req-file/requirements.txt',
name: 'snyk-python-plugin',
},
package: {},
};
},
};
const loadPlugin = sinon.stub(params.plugins, 'loadPlugin');
t.teardown(loadPlugin.restore);
// detect pip plugin called only with Pipfile (and not requirement.txt)
loadPlugin
.withArgs('pip', sinon.match.has('file', 'Pipfile'))
.returns(mockPipfile)
.withArgs(
'pip',
sinon.match.has('file', 'python-app-with-req-file/requirements.txt'),
)
.returns(mockRequirements);
loadPlugin.callThrough(); // don't mock other plugins
const result: CommandResult = await params.cli.test('mono-repo-project', {
allProjects: true,
detectionDepth: 3,
allowMissing: true, // allow requirements.txt to pass when deps not installed
});
t.equals(
loadPlugin.withArgs('rubygems').callCount,
2,
'calls rubygems plugin',
);
t.equals(loadPlugin.withArgs('npm').callCount, 2, 'calls npm plugin');
t.ok(loadPlugin.withArgs('maven').calledOnce, 'calls maven plugin');
t.ok(loadPlugin.withArgs('nuget').calledOnce, 'calls nuget plugin');
t.ok(loadPlugin.withArgs('paket').calledOnce, 'calls nuget plugin');
t.ok(loadPlugin.withArgs('sbt').calledOnce, 'calls sbt plugin');
t.equals(loadPlugin.withArgs('pip').callCount, 2, 'calls pip plugin');
params.server.popRequests(10).forEach((req) => {
t.equal(req.method, 'POST', 'makes POST request');
t.equal(
req.headers['x-snyk-cli-version'],
params.versionNumber,
'sends version number',
);
t.match(req.url, '/api/v1/test-dep-graph', 'posts to correct url');
t.ok(req.body.depGraph, 'body contains depGraph');
t.match(
req.body.depGraph.pkgManager.name,
/(npm|rubygems|maven|nuget|paket|pip|sbt)/,
'depGraph has package manager',
);
});
// ruby
t.match(
result.getDisplayResults(),
'Package manager: rubygems',
'contains package manager rubygems',
);
t.match(
result.getDisplayResults(),
'Target file: Gemfile.lock',
'contains target file Gemfile.lock',
);
t.match(
result.getDisplayResults(),
`Target file: bundler-app${path.sep}Gemfile.lock`,
`contains target file bundler-app${path.sep}Gemfile.lock`,
);
// npm
t.match(
result.getDisplayResults(),
'Project name: shallow-goof',
'contains correct project name for npm',
);
t.match(
result.getDisplayResults(),
'Project name: goof',
'contains correct project name for npm',
);
t.match(
result.getDisplayResults(),
'Package manager: npm',
'contains package manager npm',
);
t.match(
result.getDisplayResults(),
'Target file: package-lock.json',
'contains target file package-lock.json',
);
t.match(
result.getDisplayResults(),
`Target file: npm-project${path.sep}package.json`,
`contains target file npm-project${path.sep}package.json`,
);
// maven
t.match(
result.getDisplayResults(),
'Package manager: maven',
'contains package manager maven',
);
t.match(
result.getDisplayResults(),
'Target file: pom.xml',
'contains target file pom.xml',
);
// nuget
t.match(
result.getDisplayResults(),
'Package manager: nuget',
'contains package manager nuget',
);
t.match(
result.getDisplayResults(),
'Target file: packages.config',
'contains target file packages.config',
);
// paket
t.match(
result.getDisplayResults(),
'Package manager: paket',
'contains package manager paket',
);
t.match(
result.getDisplayResults(),
'Target file: paket.dependencies',
'contains target file paket.dependencies',
);
// pip
t.match(
result.getDisplayResults(),
'Package manager: pip',
'contains package manager pip',
);
t.match(
result.getDisplayResults(),
'Target file: Pipfile',
'contains target file Pipfile',
);
t.match(
result.getDisplayResults(),
`Target file: python-app-with-req-file${path.sep}requirements.txt`,
`contains target file python-app-with-req-file${path.sep}requirements.txt`,
);
// sbt
t.match(
result.getDisplayResults(),
'Target file: build.sbt',
'contains target file build.sbt',
);
},
'`test mono-repo-project --all-projects and --file payloads are the same`': (
params,
utils,
) => async (t) => {
utils.chdirWorkspaces();
// mock python plugin becuase CI tooling doesn't have pipenv installed
const mockPlugin = {
async inspect() {
return {
plugin: {
targetFile: 'Pipfile',
name: 'snyk-python-plugin',
},
package: {},
};
},
};
const loadPlugin = sinon.stub(params.plugins, 'loadPlugin');
t.teardown(loadPlugin.restore);
loadPlugin.withArgs('pip').returns(mockPlugin);
loadPlugin.callThrough(); // don't mock other plugins
await params.cli.test('mono-repo-project', {
allProjects: true,
detectionDepth: 1,
});
const requests = params.server.popRequests(7);
// find each type of request
const rubyAll = requests.find(
(req) => req.body.depGraph.pkgManager.name === 'rubygems',
);
const pipAll = requests.find(
(req) => req.body.depGraph.pkgManager.name === 'pip',
);
const npmAll = requests.find(
(req) => req.body.depGraph.pkgManager.name === 'npm',
);
const nugetAll = requests.find(
(req) => req.body.depGraph.pkgManager.name === 'nuget',
);
const paketAll = requests.find(
(req) => req.body.depGraph.pkgManager.name === 'paket',
);
const mavenAll = requests.find(
(req) => req.body.depGraph.pkgManager.name === 'maven',
);
const sbtAll = requests.find(
(req) => req.body.depGraph.pkgManager.name === 'sbt',
);
await params.cli.test('mono-repo-project', {
file: 'Gemfile.lock',
});
const rubyFile = params.server.popRequest();
await params.cli.test('mono-repo-project', {
file: 'Pipfile',
});
const pipFile = params.server.popRequest();
await params.cli.test('mono-repo-project', {
file: 'paket.dependencies',
});
const paketFile = params.server.popRequest();
await params.cli.test('mono-repo-project', {
file: 'packages.config',
});
const nugetFile = params.server.popRequest();
await params.cli.test('mono-repo-project', {
file: 'package-lock.json',
});
const npmFile = params.server.popRequest();
await params.cli.test('mono-repo-project', {
file: 'pom.xml',
});
const mavenFile = params.server.popRequest();
await params.cli.test('mono-repo-project', {
file: 'build.sbt',
});
const sbtFile = params.server.popRequest();
t.same(
pipAll.body,
pipFile.body,
'Same body for --all-projects and --file=Pipfile',
);
t.same(
rubyAll.body,
rubyFile.body,
'Same body for --all-projects and --file=Gemfile.lock',
);
t.same(
npmAll.body,
npmFile.body,
'Same body for --all-projects and --file=package-lock.json',
);
t.same(
paketAll.body,
paketFile.body,
'Same body for --all-projects and --file=package-lock.json',
);
t.same(
nugetAll.body,
nugetFile.body,
'Same body for --all-projects and --file=package-lock.json',
);
t.same(
mavenAll.body,
mavenFile.body,
'Same body for --all-projects and --file=pom.xml',
);
t.same(
sbtAll.body,
sbtFile.body,
'Same body for --all-projects and --file=build.sbt',
);
},
'`test maven-multi-app --all-projects --detection-depth=2`': (
params,
utils,
) => async (t) => {
utils.chdirWorkspaces();
const spyPlugin = sinon.spy(params.plugins, 'loadPlugin');
t.teardown(spyPlugin.restore);
const result: CommandResult = await params.cli.test('maven-multi-app', {
allProjects: true,
detectionDepth: 2,
});
t.ok(spyPlugin.withArgs('maven').calledTwice, 'calls maven plugin');
t.ok(
spyPlugin.withArgs('rubygems').notCalled,
'did not call rubygems plugin',
);
t.ok(spyPlugin.withArgs('npm').notCalled, 'did not call npm plugin');
params.server.popRequests(2).forEach((req) => {
t.equal(req.method, 'POST', 'makes POST request');
t.equal(
req.headers['x-snyk-cli-version'],
params.versionNumber,
'sends version number',
);
t.match(req.url, '/api/v1/test-dep-graph', 'posts to correct url');
t.ok(req.body.depGraph, 'body contains depGraph');
t.match(
req.body.depGraph.pkgManager.name,
/maven/,
'depGraph has package manager',
);
});
t.match(
result.getDisplayResults(),
'Package manager: maven',
'contains package manager maven',
);
t.match(
result.getDisplayResults(),
'Target file: pom.xml',
'contains target file pom.xml',
);
t.match(
result.getDisplayResults(),
`Target file: simple-child${path.sep}pom.xml`,
`contains target file simple-child${path.sep}pom.xml`,
);
},
'`test large-mono-repo with --all-projects and --detection-depth=7`': (
params,
utils,
) => async (t) => {
utils.chdirWorkspaces();
const spyPlugin = sinon.spy(params.plugins, 'loadPlugin');
t.teardown(spyPlugin.restore);
await params.cli.test('large-mono-repo', {
allProjects: true,
detectionDepth: 7,
});
t.equals(
spyPlugin.withArgs('rubygems').callCount,
19,
'calls rubygems plugin 19 times',
);
t.equals(
spyPlugin.withArgs('npm').callCount,
19,
'calls npm plugin 19 times',
);
t.equals(
spyPlugin.withArgs('gradle').callCount,
2,
'calls gradle plugin 2 times',
);
t.equals(
spyPlugin.withArgs('gradle').args[0][1].allSubProjects,
true,
'calls gradle plugin with allSubProjects property',
);
t.equals(
spyPlugin.withArgs('maven').callCount,
6,
'calls maven plugin 6 times',
);
},
'`test mono-repo-project-manifests-only --all-projects`': (
params,
utils,
) => async (t) => {
utils.chdirWorkspaces();
const result: CommandResult = await params.cli.test(
'mono-repo-project-manifests-only',
{
allProjects: true,
},
);
params.server.popRequests(3).forEach((req) => {
t.equal(req.method, 'POST', 'makes POST request');
t.equal(
req.headers['x-snyk-cli-version'],
params.versionNumber,
'sends version number',
);
t.match(req.url, '/api/v1/test-dep-graph', 'posts to correct url');
t.ok(req.body.depGraph, 'body contains depGraph');
t.match(
req.body.depGraph.pkgManager.name,
/(npm|rubygems|maven)/,
'depGraph has package manager',
);
});
// results should contain test results from all package managers
t.match(
result.getDisplayResults(),
'Package manager: rubygems',
'contains package manager rubygems',
);
t.match(
result.getDisplayResults(),
'Target file: Gemfile.lock',
'contains target file Gemfile.lock',
);
t.match(
result.getDisplayResults(),
'Package manager: npm',
'contains package manager npm',
);
t.match(
result.getDisplayResults(),
'Target file: package-lock.json',
'contains target file package-lock.json',
);
t.match(
result.getDisplayResults(),
'Package manager: maven',
'contains package manager maven',
);
t.match(
result.getDisplayResults(),
'Target file: pom.xml',
'contains target file pom.xml',
);
},
'`test ruby-app --all-projects`': (params, utils) => async (t) => {
utils.chdirWorkspaces();
const spyPlugin = sinon.spy(params.plugins, 'loadPlugin');
t.teardown(spyPlugin.restore);
const res: CommandResult = await params.cli.test('ruby-app', {
allProjects: true,
});
t.ok(spyPlugin.withArgs('rubygems').calledOnce, 'calls rubygems plugin');
t.notOk(spyPlugin.withArgs('npm').calledOnce, "doesn't call npm plugin");
t.notOk(
spyPlugin.withArgs('maven').calledOnce,
"doesn't call maven plugin",
);
t.match(
res.getDisplayResults(),
'Package manager: rubygems',
'contains package manager rubygems',
);
t.match(
res.getDisplayResults(),
'Target file: Gemfile.lock',
'contains target file Gemfile.lock',
);
},
'`test ruby-app-thresholds --all-projects --ignore-policy`': (
params,
utils,
) => async (t) => {
utils.chdirWorkspaces('ruby-app-thresholds');
params.server.setNextResponse(
getWorkspaceJSON(
'ruby-app-thresholds',
'test-graph-result-medium-severity.json',
),
);
try {
await params.cli.test('./', {
'ignore-policy': true,
allProjects: true,
});
t.fail('should have thrown');
} catch (err) {
const req = params.server.popRequest();
t.equal(req.query.ignorePolicy, 'true', 'should request ignore policy');
const res = err.message;
t.match(
res,
'Tested 7 dependencies for known vulnerabilities, found 5 vulnerabilities, 6 vulnerable paths.',
'should display expected message',
);
}
},
'`test large-mono-repo with --all-projects, --detection-depth=7 and --exclude=bundler-app,maven-project-1`': (
params,
utils,
) => async (t) => {
utils.chdirWorkspaces();
const spyPlugin = sinon.spy(params.plugins, 'loadPlugin');
t.teardown(spyPlugin.restore);
await params.cli.test('large-mono-repo', {
allProjects: true,
detectionDepth: 7,
exclude: 'bundler-app,maven-project-1',
});
t.equals(
spyPlugin.withArgs('rubygems').callCount,
0,
'does not call rubygems',
);
t.equals(
spyPlugin.withArgs('npm').callCount,
19,
'calls npm plugin 19 times',
);
t.equals(
spyPlugin.withArgs('gradle').callCount,
2,
'calls gradle plugin 2 times',
);
t.equals(
spyPlugin.withArgs('maven').callCount,
1,
'calls maven plugin once, excluding the rest',
);
},
'`test empty --all-projects`': (params, utils) => async (t) => {
utils.chdirWorkspaces();
try {
await params.cli.test('empty', {
allProjects: true,
});
t.fail('expected an error to be thrown');
} catch (err) {
const res = err.message;
t.match(
res,
'Could not detect supported target files',
'should display expected message',
);
}
},
'`test monorepo-with-nuget --all-projects with Nuget, Python, Go, Npm, Cocoapods`': (
params,
utils,
) => async (t) => {
utils.chdirWorkspaces();
const mockPlugin = {
async inspect() {
return {
package: {},
plugin: {
name: 'mock',
},
};
},
};
const loadPlugin = sinon.stub(params.plugins, 'loadPlugin');
t.teardown(loadPlugin.restore);
// prevent plugin inspect from actually running (requires go to be installed)
loadPlugin.withArgs('golangdep').returns(mockPlugin);
loadPlugin.callThrough(); // don't mock other plugins
try {
const res: CommandResult = await params.cli.test(
'monorepo-with-nuget',
{
allProjects: true,
detectionDepth: 4,
},
);
t.equal(
loadPlugin.withArgs('nuget').callCount,
2,
'calls nuget plugin twice',
);
t.ok(
loadPlugin.withArgs('cocoapods').calledOnce,
'calls cocoapods plugin',
);
t.ok(loadPlugin.withArgs('npm').calledOnce, 'calls npm plugin');
t.ok(
loadPlugin.withArgs('golangdep').calledOnce,
'calls golangdep plugin',
);
t.ok(loadPlugin.withArgs('paket').calledOnce, 'calls nuget plugin');
t.match(
res.getDisplayResults(),
/Tested 6 projects, no vulnerable paths were found./,
'Six projects tested',
);
t.match(
res.getDisplayResults(),
`Target file: src${path.sep}paymentservice${path.sep}package-lock.json`,
'Npm project targetFile is as expected',
);
t.match(
res.getDisplayResults(),
`Target file: src${path.sep}cocoapods-app${path.sep}Podfile`,
'Cocoapods project targetFile is as expected',
);
t.match(
res.getDisplayResults(),
`Target file: src${path.sep}frontend${path.sep}Gopkg.lock`,
'Go dep project targetFile is as expected',
);
t.match(
res.getDisplayResults(),
`Target file: src${path.sep}cartservice-nuget${path.sep}obj${path.sep}project.assets.json`,
'Nuget project targetFile is as expected',
);
t.match(
res.getDisplayResults(),
`Target file: test${path.sep}nuget-app-4${path.sep}packages.config`,
'Nuget project targetFile is as expected',
);
t.match(
res.getDisplayResults(),
`Target file: test${path.sep}paket-app${path.sep}paket.dependencies`,
'Paket project targetFile is as expected',
);
t.match(
res.getDisplayResults(),
'Package manager: nuget',
'Nuget package manager',
);
t.match(
res.getDisplayResults(),
'Package manager: cocoapods',
'Cocoapods package manager',
);
t.match(
res.getDisplayResults(),
'Package manager: npm',
'Npm package manager',
);
t.match(
res.getDisplayResults(),
'Package manager: golangdep',
'Go dep package manager',
);
} catch (err) {
t.fail('expected to pass');
}
},
'`test composer-app --all-projects`': (params, utils) => async (t) => {
utils.chdirWorkspaces();
const spyPlugin = sinon.spy(params.plugins, 'loadPlugin');
t.teardown(spyPlugin.restore);
const result: CommandResult = await params.cli.test('composer-app', {
allProjects: true,
});
t.ok(spyPlugin.withArgs('composer').calledOnce, 'calls composer plugin');
params.server.popRequests(2).forEach((req) => {
t.equal(req.method, 'POST', 'makes POST request');
t.equal(
req.headers['x-snyk-cli-version'],
params.versionNumber,
'sends version number',
);
t.match(req.url, '/api/v1/test', 'posts to correct url');
});
t.match(
result.getDisplayResults(),
'Package manager: composer',
'contains package manager composer',
);
t.match(