Skip to content

Commit a5a8634

Browse files
authored
test(scan): add license cases for when invalid and offline (#1835)
Among other things, this covers the fact that we currently check if we're offline _after_ we validate the licenses since we could flip that to simplify our implementation but currently doing so would not reveal that it changes our behaviour
1 parent ecf4c60 commit a5a8634

File tree

2 files changed

+59
-3
lines changed

2 files changed

+59
-3
lines changed

cmd/osv-scanner/scan/source/__snapshots__/command_test.snap

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,7 +1391,7 @@ overriding license for package npm/ms/2.1.3 with MIT WITH Bison-exception-2.2
13911391

13921392
---
13931393

1394-
[TestCommand_Licenses/Licenses_with_invalid_expression - 1]
1394+
[TestCommand_Licenses/Licenses_with_invalid_expression_in_config - 1]
13951395
Scanning dir ./fixtures/locks-licenses/package-lock.json
13961396
Scanned <rootdir>/osv-scanner/scan/source/fixtures/locks-licenses/package-lock.json file and found 4 packages
13971397
overriding license for package npm/babel/6.23.0 with MIT AND (LGPL-2.1-or-later OR BSD-3-Clause))
@@ -1414,12 +1414,21 @@ overriding license for package npm/ms/2.1.3 with MIT WITH (Bison-exception-2.2 A
14141414

14151415
---
14161416

1417-
[TestCommand_Licenses/Licenses_with_invalid_expression - 2]
1417+
[TestCommand_Licenses/Licenses_with_invalid_expression_in_config - 2]
14181418
license LGPL-2.1-only OR OR BSD-3-Clause for package npm/human-signals/5.0.0 is invalid: unexpected OR after OR
14191419
license MIT WITH (Bison-exception-2.2 AND somethingelse) for package npm/ms/2.1.3 is invalid: unexpected ( after WITH
14201420

14211421
---
14221422

1423+
[TestCommand_Licenses/Licenses_with_invalid_licenses_in_flag - 1]
1424+
1425+
---
1426+
1427+
[TestCommand_Licenses/Licenses_with_invalid_licenses_in_flag - 2]
1428+
--licenses requires comma-separated spdx licenses. The following license(s) are not recognized as spdx: something-something
1429+
1430+
---
1431+
14231432
[TestCommand_Licenses/No_license_violations_and_show-all-packages_in_json - 1]
14241433
{
14251434
"results": [
@@ -1905,6 +1914,33 @@ Scanned <rootdir>/osv-scanner/scan/source/fixtures/locks-many/package-lock.json
19051914

19061915
---
19071916

1917+
[TestCommand_Licenses/When_offline_licenses_are_still_validated - 1]
1918+
1919+
---
1920+
1921+
[TestCommand_Licenses/When_offline_licenses_are_still_validated - 2]
1922+
--licenses requires comma-separated spdx licenses. The following license(s) are not recognized as spdx: something-something
1923+
1924+
---
1925+
1926+
[TestCommand_Licenses/When_offline_licenses_cannot_be_checked - 1]
1927+
1928+
---
1929+
1930+
[TestCommand_Licenses/When_offline_licenses_cannot_be_checked - 2]
1931+
cannot retrieve licenses locally
1932+
1933+
---
1934+
1935+
[TestCommand_Licenses/When_offline_licenses_summary_cannot_be_printed - 1]
1936+
1937+
---
1938+
1939+
[TestCommand_Licenses/When_offline_licenses_summary_cannot_be_printed - 2]
1940+
cannot retrieve licenses locally
1941+
1942+
---
1943+
19081944
[TestCommand_LocalDatabases/.gitignored_files - 1]
19091945
Scanning dir ./fixtures/locks-gitignore
19101946
Scanned <rootdir>/osv-scanner/scan/source/fixtures/locks-gitignore/Gemfile.lock file and found 1 package

cmd/osv-scanner/scan/source/command_test.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,10 +600,30 @@ func TestCommand_Licenses(t *testing.T) {
600600
Exit: 1,
601601
},
602602
{
603-
Name: "Licenses with invalid expression",
603+
Name: "Licenses with invalid licenses in flag",
604+
Args: []string{"", "source", "--licenses=MIT,something-something", "./fixtures/locks-licenses/package-lock.json"},
605+
Exit: 127,
606+
},
607+
{
608+
Name: "Licenses with invalid expression in config",
604609
Args: []string{"", "source", "--config=./fixtures/osv-scanner-invalid-licenses-config.toml", "--licenses=MIT,BSD-3-Clause", "./fixtures/locks-licenses/package-lock.json"},
605610
Exit: 1,
606611
},
612+
{
613+
Name: "When offline licenses summary cannot be printed",
614+
Args: []string{"", "source", "--offline", "--licenses", "--config=./fixtures/osv-scanner-empty-config.toml", "./fixtures/locks-many/package-lock.json"},
615+
Exit: 127,
616+
},
617+
{
618+
Name: "When offline licenses cannot be checked",
619+
Args: []string{"", "source", "--offline", "--licenses=MIT", "--config=./fixtures/osv-scanner-empty-config.toml", "./fixtures/locks-many/package-lock.json"},
620+
Exit: 127,
621+
},
622+
{
623+
Name: "When offline licenses are still validated",
624+
Args: []string{"", "source", "--offline", "--licenses=MIT,something-something", "./fixtures/locks-many/package-lock.json"},
625+
Exit: 127,
626+
},
607627
}
608628

609629
for _, tt := range tests {

0 commit comments

Comments
 (0)