Skip to content

Commit

Permalink
chore(it): log out command output when it fails
Browse files Browse the repository at this point in the history
  • Loading branch information
j-luong committed Aug 1, 2024
1 parent 06c81df commit 4ae0876
Show file tree
Hide file tree
Showing 24 changed files with 61 additions and 52 deletions.
17 changes: 14 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,27 @@ jobs:
- name: Install Snyk CLI (Windows)
if: ${{ matrix.os == 'windows' }}
run: npm install -g snyk
run: |
npm install -g snyk
snyk -v
where snyk
- name: Run Acceptance Tests (Ubuntu/macOS)
if: ${{ matrix.os != 'windows' }}
- name: Run Acceptance Tests (Ubuntu)
if: ${{ matrix.os == 'ubuntu' }}
run: mvn -B invoker:install invoker:run
env:
SNYK_TEST_TOKEN: ${{secrets.SNYK_TEST_TOKEN}}
SNYK_CLI_EXECUTABLE: /usr/local/bin/snyk
SNYK_DOWNLOAD_DESTINATION: "downloads/snyk"

- name: Run Acceptance Tests (macOS)
if: ${{ matrix.os == 'macos' }}
run: mvn -B invoker:install invoker:run
env:
SNYK_TEST_TOKEN: ${{secrets.SNYK_TEST_TOKEN}}
SNYK_CLI_EXECUTABLE: /opt/homebrew/bin/snyk
SNYK_DOWNLOAD_DESTINATION: "downloads/snyk"

- name: Run Acceptance Tests (Windows)
if: ${{ matrix.os == 'windows' }}
run: mvn -B invoker:install invoker:run
Expand Down
2 changes: 1 addition & 1 deletion src/it/monitor-with-default-phase/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import org.codehaus.plexus.util.FileUtils;
String log = FileUtils.fileRead(new File(basedir, "build.log"));

if (!log.contains("Explore this snapshot at")) {
throw new Exception("Snapshot link not found.");
throw new Exception("Snapshot link not found. Log output:\n" + log + "\n");
}

return true;
2 changes: 1 addition & 1 deletion src/it/monitor-with-dependency/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import org.codehaus.plexus.util.FileUtils;
String log = FileUtils.fileRead(new File(basedir, "build.log"));

if (!log.contains("Explore this snapshot at")) {
throw new Exception("Snapshot link not found.");
throw new Exception("Snapshot link not found. Log output:\n" + log + "\n");
}

return true;
4 changes: 2 additions & 2 deletions src/it/test-and-monitor/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import org.codehaus.plexus.util.FileUtils;
String log = FileUtils.fileRead(new File(basedir, "build.log"));

if (!log.contains("snyk test skipped")) {
throw new Exception("skip message not found");
throw new Exception("skip message not found Log output:\n" + log + "\n");
}

if (!log.contains("Explore this snapshot at")) {
throw new Exception("Snapshot link not found.");
throw new Exception("Snapshot link not found. Log output:\n" + log + "\n");
}

return true;
4 changes: 2 additions & 2 deletions src/it/test-cli-exists-but-sha-doesnt-exist/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ String shaOfCliFile = ITUtils.computeShaOfCLIFile(basedir);
String shaFromShaFile = ITUtils.getShaFromShaFile(basedir);

if (!shaOfCliFile.equals(shaFromShaFile)) {
throw new Exception("sha256 of CLI file does not match the one in the `.sha256` file");
throw new Exception("sha256 of CLI file does not match the one in the `.sha256` file. Log output:\n" + log + "\n");
}

String log = FileUtils.fileRead(new File(basedir, "build.log"));

if (!log.contains("for known issues, no vulnerable paths found.")) {
throw new Exception("Expected dummy snyk to be replaced with updated CLI and executed.");
throw new Exception("Expected dummy snyk to be replaced with updated CLI and executed. Log output:\n" + log + "\n");
}

return true;
4 changes: 2 additions & 2 deletions src/it/test-cli-exists-but-sha-doesnt-match/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ String shaOfCliFile = ITUtils.computeShaOfCLIFile(basedir);
String shaFromShaFile = ITUtils.getShaFromShaFile(basedir);

if (!shaOfCliFile.equals(shaFromShaFile)) {
throw new Exception("sha256 of CLI file does not match the one in the `.sha256` file");
throw new Exception("sha256 of CLI file does not match the one in the `.sha256` file. Log output:\n" + log + "\n");
}

String log = FileUtils.fileRead(new File(basedir, "build.log"));

if (!log.contains("for known issues, no vulnerable paths found.")) {
throw new Exception("Expected dummy snyk to be replaced with updated CLI and executed.");
throw new Exception("Expected dummy snyk to be replaced with updated CLI and executed. Log output:\n" + log + "\n");
}

return true;
2 changes: 1 addition & 1 deletion src/it/test-code-test/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import org.codehaus.plexus.util.FileUtils;
String log = FileUtils.fileRead(new File(basedir, "build.log"))

if (!log.contains("SQL Injection")) {
throw new Exception("no sql injection issue found")
throw new Exception("no sql injection issue found. Log output:\n" + log + "\n")
}

return true;
4 changes: 2 additions & 2 deletions src/it/test-container-test/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import org.codehaus.plexus.util.FileUtils;
String log = FileUtils.fileRead(new File(basedir, "build.log"))

if (!log.contains("Medium severity vulnerability found in tiff/libtiff5")) {
throw new Exception("Expected medium vulnerability not found")
throw new Exception("Expected medium vulnerability not found. Log output:\n" + log + "\n")
}

if (!log.contains("Critical severity vulnerability found in zlib/zlib1g")) {
throw new Exception("Expected critical vulnerability not found")
throw new Exception("Expected critical vulnerability not found. Log output:\n" + log + "\n")
}

return true
8 changes: 4 additions & 4 deletions src/it/test-multi-module-child/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import org.codehaus.plexus.util.FileUtils;
String log = FileUtils.fileRead(new File(basedir, "build.log"));

if (!log.contains("test-multi-module-child ............................ SUCCESS")) {
throw new Exception("parent should have succeeded.");
throw new Exception("parent should have succeeded. Log output:\n" + log + "\n");
}

if (!log.contains("child-module-1 ..................................... SUCCESS")) {
throw new Exception("child-module-1 should have succeeded.");
throw new Exception("child-module-1 should have succeeded. Log output:\n" + log + "\n");
}

if (!log.contains("child-module-2 ..................................... FAILURE")) {
throw new Exception("child-module-2 should have failed.");
throw new Exception("child-module-2 should have failed. Log output:\n" + log + "\n");
}

if (!log.contains("introduced by axis:[email protected]")) {
throw new Exception("Could not find expected vulnerability in child-module-2.");
throw new Exception("Could not find expected vulnerability in child-module-2. Log output:\n" + log + "\n");
}

return true;
14 changes: 7 additions & 7 deletions src/it/test-multi-module-parent/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,31 @@ import org.codehaus.plexus.util.FileUtils;
String log = FileUtils.fileRead(new File(basedir, "build.log"));

if (!log.contains("Target file: pom.xml")) {
throw new Exception("parent was not scanned.");
throw new Exception("parent was not scanned. Log output:\n" + log + "\n");
}

if (!log.contains("Target file: child-module-1")) {
throw new Exception("child-module-1 was not scanned.");
throw new Exception("child-module-1 was not scanned. Log output:\n" + log + "\n");
}

if (!log.contains("Target file: child-module-2")) {
throw new Exception("child-module-2 was not scanned.");
throw new Exception("child-module-2 was not scanned. Log output:\n" + log + "\n");
}

if (!log.contains("test-multi-module-parent ........................... FAILURE")) {
throw new Exception("parent should have failed with vulnerabilities, including from children.");
throw new Exception("parent should have failed with vulnerabilities, including from children. Log output:\n" + log + "\n");
}

if (!log.contains("child-module-1 ..................................... SKIPPED")) {
throw new Exception("child-module-1 should have been skipped.");
throw new Exception("child-module-1 should have been skipped. Log output:\n" + log + "\n");
}

if (!log.contains("child-module-2 ..................................... SKIPPED")) {
throw new Exception("child-module-2 should have been skipped.");
throw new Exception("child-module-2 should have been skipped. Log output:\n" + log + "\n");
}

if (!log.contains("introduced by axis:[email protected]")) {
throw new Exception("Could not find vulnerability in parent.");
throw new Exception("Could not find vulnerability in parent. Log output:\n" + log + "\n");
}

return true;
2 changes: 1 addition & 1 deletion src/it/test-not-fail-on-issues/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import org.codehaus.plexus.util.FileUtils;
String log = FileUtils.fileRead(new File(basedir, "build.log"))

if (!log.contains("introduced by org.postgresql:[email protected]")) {
throw new Exception("Vulnerability in dependency not found")
throw new Exception("Vulnerability in dependency not found. Log output:\n" + log + "\n")
}

return true;
2 changes: 1 addition & 1 deletion src/it/test-skip-pom/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import org.codehaus.plexus.util.FileUtils;
String log = FileUtils.fileRead(new File(basedir, "build.log"));

if (!log.contains("snyk test skipped")) {
throw new Exception("skip message not found");
throw new Exception("skip message not found. Log output:\n" + log + "\n");
}

return true;
2 changes: 1 addition & 1 deletion src/it/test-skip-property/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import org.codehaus.plexus.util.FileUtils;
String log = FileUtils.fileRead(new File(basedir, "build.log"));

if (!log.contains("snyk test skipped")) {
throw new Exception("skip message not found");
throw new Exception("skip message not found. Log output:\n" + log + "\n");
}

return true;
2 changes: 1 addition & 1 deletion src/it/test-update-policy-always/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import org.codehaus.plexus.util.FileUtils;
String log = FileUtils.fileRead(new File(basedir, "build.log"));

if (!log.contains("for known issues, no vulnerable paths found.")) {
throw new Exception("Expected dummy snyk to be replaced with updated CLI and executed.");
throw new Exception("Expected dummy snyk to be replaced with updated CLI and executed. Log output:\n" + log + "\n");
}

return true;
2 changes: 1 addition & 1 deletion src/it/test-update-policy-never/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import org.codehaus.plexus.util.FileUtils;
String log = FileUtils.fileRead(new File(basedir, "build.log"));

if (!log.contains("command execution failed")) {
throw new Exception("Expected dummy snyk to not be replaced.");
throw new Exception("Expected dummy snyk to not be replaced. Log output:\n" + log + "\n");
}

return true;
2 changes: 1 addition & 1 deletion src/it/test-with-args/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import org.codehaus.plexus.util.FileUtils;
String log = FileUtils.fileRead(new File(basedir, "build.log"));

if (!log.contains("io.snyk.it:test-with-args @ 1.0-SNAPSHOT")) {
throw new Exception("`snyk test --print-deps` --print-deps output not found");
throw new Exception("`snyk test --print-deps` --print-deps output not found. Log output:\n" + log + "\n");
}

return true;
2 changes: 1 addition & 1 deletion src/it/test-with-default-phase/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import org.codehaus.plexus.util.FileUtils;
String log = FileUtils.fileRead(new File(basedir, "build.log"));

if (!log.contains("for known issues, no vulnerable paths found.")) {
throw new Exception("`snyk test` success output not found");
throw new Exception("`snyk test` success output not found. Log output:\n" + log + "\n");
}

return true;
2 changes: 1 addition & 1 deletion src/it/test-with-dependency/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import org.codehaus.plexus.util.FileUtils;
String log = FileUtils.fileRead(new File(basedir, "build.log"));

if (!log.contains("introduced by axis:[email protected]")) {
throw new Exception("Vulnerability not found.");
throw new Exception("Vulnerability not found. Log output:\n" + log + "\n");
}

return true;
2 changes: 1 addition & 1 deletion src/it/test-with-ignores/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import org.codehaus.plexus.util.FileUtils;
String log = FileUtils.fileRead(new File(basedir, "build.log"));

if (!log.contains("no vulnerable paths found")) {
throw new Exception("Expected vulnerabilities to be ignored.");
throw new Exception("Expected vulnerabilities to be ignored. Log output:\n" + log + "\n");
}

return true;
2 changes: 1 addition & 1 deletion src/it/test-with-invalid-cli-executable/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import org.codehaus.plexus.util.FileUtils;
String log = FileUtils.fileRead(new File(basedir, "build.log"));

if (!log.contains("command execution failed")) {
throw new Exception("`snyk test` failure output not found");
throw new Exception("`snyk test` failure output not found. Log output:\n" + log + "\n");
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion src/it/test-with-specific-cli-version/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import org.codehaus.plexus.util.FileUtils;
String log = FileUtils.fileRead(new File(basedir, "build.log"));

if (!(log =~ /Snyk CLI Version:\s+1\.487\.0/)) {
throw new Exception("snyk version log line not found");
throw new Exception("snyk version log line not found. Log output:\n" + log + "\n");
}

return true;
2 changes: 1 addition & 1 deletion src/it/test-without-cli-executable/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import org.codehaus.plexus.util.FileUtils;
String log = FileUtils.fileRead(new File(basedir, "build.log"));

if (!log.contains("for known issues, no vulnerable paths found.")) {
throw new Exception("`snyk test` success output not found");
throw new Exception("`snyk test` success output not found. Log output:\n" + log + "\n");
}

return true;
8 changes: 4 additions & 4 deletions src/it/test-without-dependency/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ String log = FileUtils.fileRead(new File(basedir, "build.log"))
String snykCliExecutable = System.getenv("SNYK_CLI_EXECUTABLE")

if (snykCliExecutable == null || snykCliExecutable.isEmpty()) {
throw new Exception("the environment variable `SNYK_CLI_EXECUTABLE` is not defined")
throw new Exception("the environment variable `SNYK_CLI_EXECUTABLE` is not defined. Log output:\n" + log + "\n")
}

if (!log.contains("Snyk Executable Path: " + System.getenv("SNYK_CLI_EXECUTABLE"))) {
throw new Exception("snyk executable path log line not found.")
throw new Exception("snyk executable path log line not found. Log output:\n" + log + "\n")
}

if (!(log =~ /Snyk CLI Version:\s+\d+\.\d+\.\d+/)) {
throw new Exception("snyk version log line not found")
throw new Exception("snyk version log line not found. Log output:\n" + log + "\n")
}

if (!log.contains("for known issues, no vulnerable paths found.")) {
throw new Exception("`snyk test` success output not found")
throw new Exception("`snyk test` success output not found. Log output:\n" + log + "\n")
}

return true
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,20 @@ public static File ensure(URL cliDownloadURL, File cliFile, String updatePolicy,

if (cliFile.exists() && checksumFile.exists()) {
if (verifyChecksum(cliFile, checksumFile)) {
if (shouldUpdate(
updatePolicy,
cliFile.lastModified(),
System.currentTimeMillis()
if (!shouldUpdate(
updatePolicy,
cliFile.lastModified(),
System.currentTimeMillis()
)) {
// cli exists, checksum verified, but cli is stale and needs updating
cliFile.delete();
checksumFile.delete();
cliFile.getParentFile().mkdirs();
} else {
// cli exists, checksum verified, cli is not stale and does not need updating
return cliFile;
}
}
}

cliFile.delete();
checksumFile.delete();
cliFile.getParentFile().mkdirs();

downloader.download(cliDownloadURL, cliFile);

URL checksumUrl = new URL(cliDownloadURL.toString() + ".sha256");
Expand Down Expand Up @@ -95,7 +93,7 @@ public static File iterateAndEnsure(List<URL> cliDownloadURLs, File cliFile, Str
return downloadedFile;
}
} catch (RuntimeException e) {
System.err.println("Failed to download from " + cliDownloadURL + ": " + e.getMessage());
System.err.println("Failed to download from '" + cliDownloadURL + "': " + e.getMessage());
}
}
throw new RuntimeException("Failed to download from URLs");
Expand Down

0 comments on commit 4ae0876

Please sign in to comment.