From b658dc4ffd5feb9212e27c37fd86b18a1440d30f Mon Sep 17 00:00:00 2001 From: Luke Watts Date: Mon, 6 Jan 2025 15:02:49 +0100 Subject: [PATCH] smoke/validate-removal --- test/smoke/.shellspec | 1 - test/smoke/README.md | 7 - test/smoke/install-shellspec.sh | 301 -------------------------- test/smoke/install-snyk-binary-win.sh | 5 - test/smoke/run-shellspec-win.sh | 3 - test/smoke/spec/sanity_spec.sh | 54 ----- test/smoke/spec/snyk_auth_spec.sh | 57 ----- test/smoke/spec/snyk_basic_spec.sh | 53 ----- test/smoke/spec/snyk_code_spec.sh | 31 --- test/smoke/spec/snyk_fix_spec.sh | 30 --- test/smoke/spec/snyk_monitor_spec.sh | 44 ---- test/smoke/spec/snyk_test_spec.sh | 127 ----------- test/smoke/spec/spec_helper.sh | 77 ------- 13 files changed, 790 deletions(-) delete mode 100644 test/smoke/.shellspec delete mode 100755 test/smoke/install-shellspec.sh delete mode 100644 test/smoke/install-snyk-binary-win.sh delete mode 100644 test/smoke/run-shellspec-win.sh delete mode 100644 test/smoke/spec/sanity_spec.sh delete mode 100644 test/smoke/spec/snyk_auth_spec.sh delete mode 100644 test/smoke/spec/snyk_basic_spec.sh delete mode 100644 test/smoke/spec/snyk_code_spec.sh delete mode 100644 test/smoke/spec/snyk_fix_spec.sh delete mode 100644 test/smoke/spec/snyk_monitor_spec.sh delete mode 100644 test/smoke/spec/snyk_test_spec.sh delete mode 100644 test/smoke/spec/spec_helper.sh diff --git a/test/smoke/.shellspec b/test/smoke/.shellspec deleted file mode 100644 index c99d2e7396..0000000000 --- a/test/smoke/.shellspec +++ /dev/null @@ -1 +0,0 @@ ---require spec_helper diff --git a/test/smoke/README.md b/test/smoke/README.md index 0233c28112..63f5e069de 100644 --- a/test/smoke/README.md +++ b/test/smoke/README.md @@ -21,13 +21,6 @@ To run these tests locally you may use `npm run test:smoke`: 1. Install: - - [Shellspec](https://shellspec.info) reccomended installation is through brew: - - - ### Install the latest stable version of shell spec - - brew tap shellspec/shellspec - - brew install shellspec - - - [jq](https://stedolan.github.io/jq/) - timeout (if not available on your platform) 2. Install dependencies for the local fixture `test/fixtures/basic-npm` with `npm install --prefix test/fixtures/basic-npm` diff --git a/test/smoke/install-shellspec.sh b/test/smoke/install-shellspec.sh deleted file mode 100755 index 344c33f8d0..0000000000 --- a/test/smoke/install-shellspec.sh +++ /dev/null @@ -1,301 +0,0 @@ -#!/bin/sh -# shellcheck disable=SC2034 -# MIT License -# -# Copyright (c) 2018 Koichi Nakashima -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -test || __() { :; } - -installer="https://github.com/shellspec/shellspec/blob/22a80af088c939e03599821b7e9721b51cb1bd82/install.sh" -repo="https://github.com/shellspec/shellspec.git" -archive="https://github.com/shellspec/shellspec/archive" -project="shellspec" -exec="shellspec" - -set -eu && :<<'USAGE' -Usage: [sudo] ${0##*/} [VERSION] [OPTIONS...] - or : wget -O- $installer | [sudo] sh - or : wget -O- $installer | [sudo] sh -s -- [OPTIONS...] - or : wget -O- $installer | [sudo] sh -s VERSION [OPTIONS...] - or : curl -fsSL $installer | [sudo] sh - or : curl -fsSL $installer | [sudo] sh -s -- [OPTIONS...] - or : curl -fsSL $installer | [sudo] sh -s VERSION [OPTIONS...] - -VERSION: - Specify install version and method - - e.g - 1.0.0 Install 1.0.0 from git - master Install master from git - 1.0.0.tar.gz Install 1.0.0 from tar.gz archive - . Install from local directory - -OPTIONS: - -p, --prefix PREFIX Specify prefix [default: \$HOME/.local] - -b, --bin BIN Specify bin directory [default: /bin] - -d, --dir DIR Specify installation directory [default: /lib/$project] - -s, --switch Switch version (requires installation via git) - -l, --list List available versions (tags) - --pre Include pre-release - --fetch FETCH Force command to use when installing from archive (curl or wget) - -y, --yes Automatic yes to prompts - -h, --help You're looking at it -USAGE - -usage() { - while IFS= read -r line && [ ! "${line#*:}" = \<\<"'$1'" ]; do :; done - while IFS= read -r line && [ ! "$line" = "$1" ]; do set "$@" "$line"; done - shift && [ $# -eq 0 ] || printf '%s\n' cat\<\<"$line" "$@" "$line" -} - -CDPATH='' -[ "${ZSH_VERSION:-}" ] && setopt shwordsplit - -finish() { done=1; exit "${1:-0}"; } -error() { printf '\033[31m%s\033[0m\n' "$1"; } -abort() { [ "${1:-}" ] && error "$1" >&2; finish 1; } -finished() { [ "$done" ] || error "Failed to install"; } - -exists() { - type "$1" >/dev/null 2>&1 && return 0 - ( IFS=:; for p in $PATH; do [ -x "${p%/}/$1" ] && return 0; done; return 1 ) -} - -prompt() { - set -- "$1" "$2" "${3:-/dev/tty}" - printf "%s " "$1" - if eval "[ \"\$$2\" ] && :"; then - eval "printf \"%s\n\" \"\$$2\"" - else - IFS= read -r "$2" < "$3" || return 1 - [ "$3" = "/dev/tty" ] || eval "printf \"%s\n\" \"\$$2\"" - fi -} - -is_yes() { - case $1 in ( [Yy] | [Yy][Ee][Ss] ) return 0; esac - return 1 -} - -confirm() { - prompt "$@" || return 1 - eval "is_yes \"\$$2\" &&:" -} - -fetch() { - tmpfile="${TMPDIR:-${TMP:-/tmp}}/${1##*/}.$$" - case $FETCH in - curl) curl --head -sSfL -o /dev/null "$1" && curl -SfL "$1" ;; - wget) wget --spider -q "$1" && wget -O- "$1" ;; - esac > "$tmpfile" &&: - error=$? - if [ "$error" -eq 0 ]; then - unarchive "$tmpfile" "$1" "$2" &&: - error=$? - [ "$error" -ne 0 ] && [ -d "$2" ] && rm -rf "$2" - fi - rm "$tmpfile" - return "$error" -} - -unarchive() { - mkdir -p "${3%/*}" - gunzip -c "$1" | (cd "${3%/*}"; tar xf -) - set -- "$1" "${2##*/}" "$3" - mv "$(components_path "${3%/*}/$project-${2%.tar.gz}"*)" "$3" -} - -components_path() { - ( set +u - cd "${1%/*}" - for p in *; do - case $p in (${1##*/}*) echo "${1%/*}/$p"; break ; esac - done - ) -} - -git_remote_tags() { - git ls-remote --tags "$repo" | while read -r line; do - tag=${line##*/} && pre=${tag#${tag%%[-+]*}} - [ "${1:-}" = "--pre" ] || case $pre in (-*) continue; esac - echo "${tag%\^\{\}}" - done | uniq -} - -get_versions() { - git_remote_tags "${PRE:+--pre}" -} - -sort_by_first_key() { - # Retry if sort is Windows version - ( export LC_ALL=C; sort -k 1 2>/dev/null || command -p sort -k 1 ) -} - -version_sort() { - while read -r version; do - ver=${version%%+*} && num=${ver%%-*} && pre=${ver#$num} - #shellcheck disable=SC2086 - case $num in - *[!0-9.]*) set -- 0 0 0 0 ;; - *) IFS=. && set -- $num ;; - esac - printf '%08d%08d%08d%08d' "${1:-0}" "${2:-0}" "${3:-0}" "${4:-0}" - printf '%s %s\n' "${pre:-=}" "$version" - done | sort_by_first_key | while read -r kv; do echo "${kv#* }"; done -} - -join() { - s='' - while read -r v; do - s="$s$v$1" - done - echo "${s%"$1"}" -} - -last() { - version='' - while read -r v; do - version=$v - done - echo "$version" -} - -list_versions() { - get_versions | version_sort | join ", " -} - -latest_version() { - get_versions | version_sort | last -} - -${__SOURCED__:+false} : || return 0 - -trap finished EXIT -VERSION='' PREFIX=$HOME/.local BIN='' DIR='' SWITCH='' PRE='' YES='' FETCH='' -done='' mode=install - -__ parse_option __ - -while [ $# -gt 0 ]; do - case $1 in - -p | --prefix ) [ "${2:-}" ] || abort "PREFIX not specified" - PREFIX=$2 && shift ;; - -b | --bin ) [ "${2:-}" ] || abort "BIN not specified" - BIN=$2 && shift ;; - -d | --dir ) [ "${2:-}" ] || abort "DIR not specified" - DIR=$2 && shift ;; - -s | --switch ) SWITCH=1 ;; - -y | --yes ) YES=y ;; - -l | --list ) mode=list ;; - --pre ) PRE=1 ;; - --fetch ) [ "${2:-}" ] || abort "FETCH not specified" - case $2 in ( curl | wget ) FETCH=$2 && shift ;; - *) abort "FETCH must be 'curl' or 'wget'." - esac ;; - -h | --help ) eval "$(usage "USAGE" < "$0")" && finish ;; - -* ) abort "Unknown option $1" ;; - * ) VERSION=$1 ;; - esac - shift -done - -if [ "$mode" = "list" ]; then - list_versions - finish -fi - -BIN=${BIN:-${PREFIX%/}/bin} DIR=${DIR:-${PREFIX%/}/lib/$project} - -__ main __ - -case $VERSION in - .) - method=local DIR=$PWD - [ -x "$DIR/$exec" ] || abort "Not found '$exec' in installation directory: '$DIR'" - VERSION=$("$DIR/$exec" --version) - ;; - *.tar.gz) - [ "$SWITCH" ] && abort "Can not switch version when install from archive" - [ -e "$DIR" ] && abort "Already exists installation directory: '$DIR'" - method=archive - [ ! "$FETCH" ] && exists curl && FETCH=curl - [ ! "$FETCH" ] && exists wget && FETCH=wget - [ "$FETCH" ] || abort "Requires 'curl' or 'wget' when install from archive" - exists tar || abort "Not found 'tar' when install from archive" - ;; - *) - if [ "$SWITCH" ]; then - method=switch - [ -d "$DIR" ] || abort "Not found installation directory: '$DIR'" - [ -d "$DIR/.git" ] || abort "Can't switch it's not a git repository: '$DIR'" - else - method=git - [ -e "$DIR" ] && abort "Already exists installation directory: '$DIR'" - fi - # requires git >= 1.7.10.4 - exists git || abort "Requires 'git' when install from git repository" - [ "$VERSION" ] || VERSION=$(latest_version) -esac - -echo "Executable file : $BIN/$exec" -echo "Installation directory : $DIR" -echo "Version (tag or commit): $VERSION" -case $method in - git) echo "[git] $repo" ;; - archive) echo "[$FETCH] $archive/$VERSION" ;; -esac -echo - -confirm "Do you want to continue? [y/N]" YES || abort "Canceled" - -case $method in - git) - git init "$DIR" && cd "$DIR" - git remote add origin "$repo" - git fetch --depth=1 origin "$VERSION" - git checkout -b "$VERSION" FETCH_HEAD - ;; - archive) - fetch "$archive/$VERSION" "$DIR" - ;; - switch) - cd "$DIR" - if message=$(git checkout "$VERSION" 2>&1); then - echo "$message" - else - git fetch --depth=1 origin "$VERSION" - git checkout -b "$VERSION" FETCH_HEAD - fi - ;; - local) # Do nothing -esac - -mkdir -p "$BIN" -ln -sf "$DIR/$exec" "$BIN/$exec" - -if [ ! -L "$BIN/$exec" ]; then - rm "$BIN/$exec" - printf '#!/bin/sh\nexec "%s" "$@"\n' "$DIR/$exec" > "$BIN/$exec" - chmod +x "$BIN/$exec" -fi - -echo "Done" -finish diff --git a/test/smoke/install-snyk-binary-win.sh b/test/smoke/install-snyk-binary-win.sh deleted file mode 100644 index 6e51370028..0000000000 --- a/test/smoke/install-snyk-binary-win.sh +++ /dev/null @@ -1,5 +0,0 @@ -curl -Lo ./snyk-cli.exe 'https://downloads.snyk.io/cli/latest/snyk-win.exe' -./snyk-cli.exe --version -chmod -R +x ./snyk-cli -mv ./snyk-cli.exe "/bin/snyk.exe" -snyk --version diff --git a/test/smoke/run-shellspec-win.sh b/test/smoke/run-shellspec-win.sh deleted file mode 100644 index 2fc87e74cb..0000000000 --- a/test/smoke/run-shellspec-win.sh +++ /dev/null @@ -1,3 +0,0 @@ -echo "run-shellscript-win.sh" - -/c/Users/runneradmin/.local/bin/shellspec -f d --skip-message quiet --no-warning-as-failure diff --git a/test/smoke/spec/sanity_spec.sh b/test/smoke/spec/sanity_spec.sh deleted file mode 100644 index ab8e5f872b..0000000000 --- a/test/smoke/spec/sanity_spec.sh +++ /dev/null @@ -1,54 +0,0 @@ -#shellcheck shell=sh - -: ' - Since we are dealing with multiple utilities and environments - we should have a sanity test in place to test them -' - -Describe "Snyk CLI" - It "have Snyk CLI available" - When run ${TEST_SNYK_COMMAND} --help - The output should include "/snyk" - The status should be success - The stderr should equal "" - End -End - -Describe "sanity checks for tooling" - Describe "timeout" - It "have timeout available" - When run which timeout - The output should include "/timeout" - The status should be success - The stderr should equal "" - End - End - - Describe "jq" - It "have jq available" - When run which jq - The output should include "/jq" - The status should be success - The stderr should equal "" - End - - It "validates JSON" - When run echo '{"k": [1,2]}' - The result of function check_valid_json should be success - End - - It "validates JSON when called as When-function" - When run check_valid_json '{"k": [1,2]}' - The status should be success - The stdout should equal 0 - The stderr should equal "" - End - - # Only way to capture parse error - It "fails on invalid JSON" - When run check_valid_json '{"k": [1,2' - The status should be failure - The stderr should include "parse error" - End - End -End diff --git a/test/smoke/spec/snyk_auth_spec.sh b/test/smoke/spec/snyk_auth_spec.sh deleted file mode 100644 index 37edfb10e4..0000000000 --- a/test/smoke/spec/snyk_auth_spec.sh +++ /dev/null @@ -1,57 +0,0 @@ -#shellcheck shell=sh - -Describe "Snyk CLI Authorization" - After snyk_logout - - It "fails when run in CI without token set" - When run snyk auth --auth-type=token - The output should include "Snyk is missing auth token in order to run inside CI" - The status should be failure - # TODO: unusable with our current docker issues - The stderr should equal "" - End - - Describe "auth outside of CI environment" - Before disable_is_ci_flags - After restore_is_ci_flags - - It "fails when run without token set" - # Alpine can't open browser, misses xdg-open utility and errors out - is_alpine_or_disabled() { - if [ -n "$SMOKE_TESTS_SKIP_TEST_THAT_OPENS_BROWSER" ]; then - echo "Won't test auth command that opens browser" >&2 - exit 0 - fi - grep "Alpine Linux" /etc/os-release > /dev/null 2>&1 - return $? - } - Skip if "test is disabled" is_alpine_or_disabled - - # Using timeout to not wait for browser confirmation - When run timeout 5 snyk auth --auth-type=token - The result of function check_auth_output should be success - The result of function verify_login_url should include "snyk.io/login?token=" # URL found - The status should be failure - # TODO: unusable with our current docker issues - The stderr should equal "" - End - End - - - It "fails if given bogus token" - When run snyk auth 00000000-0000-0000-0000-000000000000 - The output should include "Authentication failed. Please check the API token" - The status should be failure - # TODO: unusable with our current docker issues - The stderr should equal "" - End - - It "updates config file if given legit token" - When run snyk auth "${TEST_SNYK_TOKEN}" - The output should include "Your account has been authenticated. Snyk is now ready to be used." - The status should be success - # TODO: unusable with our current docker issues - The stderr should equal "" - The result of "print_snyk_config()" should include "api: ${TEST_SNYK_TOKEN}" - End -End diff --git a/test/smoke/spec/snyk_basic_spec.sh b/test/smoke/spec/snyk_basic_spec.sh deleted file mode 100644 index 2ea9bdcdf6..0000000000 --- a/test/smoke/spec/snyk_basic_spec.sh +++ /dev/null @@ -1,53 +0,0 @@ -#shellcheck shell=sh - -Describe "Snyk CLI basics" - Describe "snyk version" - It "prints version" - When run snyk version - The output should include "1." # Version should start with a (major) 1 - The status should be success - # TODO: unusable with our current docker issues - The stderr should equal "" - End - - It "prints version with --version flag" - When run snyk --version - The output should include "1." # Version should start with a (major) 1 - The status should be success - # TODO: unusable with our current docker issues - The stderr should equal "" - End - End - - Describe "snyk config" - It "prints config" - When run snyk config - The stdout should equal "" - The status should be success - End - - It "sets config" - When run snyk config set newkey=newvalue - The output should include "newkey updated" - The status should be success - The result of "print_snyk_config()" should include "newkey: newvalue" - End - - It "unsets config" - When run snyk config unset newkey - The output should include "newkey deleted" - The status should be success - The result of "print_snyk_config()" should not include "newkey" - The result of "print_snyk_config()" should not include "newvalue" - End - End - - Describe "snyk --about" - It "prints license attributions" - When run snyk --about - The output should include "Snyk CLI Open Source Attributions" # Version should start with a (major) 1 - The status should be success - The stderr should equal "" - End - End -End diff --git a/test/smoke/spec/snyk_code_spec.sh b/test/smoke/spec/snyk_code_spec.sh deleted file mode 100644 index 07e4fed34d..0000000000 --- a/test/smoke/spec/snyk_code_spec.sh +++ /dev/null @@ -1,31 +0,0 @@ -#shellcheck shell=sh - -Describe "Snyk Code test command" - Before snyk_login - After snyk_logout - - Describe "snyk code test" - run_test_in_subfolder() { - cd ../fixtures/sast/shallow_sast_webgoat || return - snyk code test . - } - - It "finds vulns in a project in the same folder" - When run run_test_in_subfolder - The output should include "Static code analysis" - The output should include "✗ [High] SQL Injection" - The status should be failure - End - End - - Describe "code test with SARIF output" - It "outputs a valid SARIF with vulns" - When run snyk code test ../fixtures/sast/shallow_sast_webgoat --sarif - The status should be failure # issues found - The output should include '"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json"' - The output should include '"name": "SnykCode"' - The result of function check_valid_json should be success - End - End - -End diff --git a/test/smoke/spec/snyk_fix_spec.sh b/test/smoke/spec/snyk_fix_spec.sh deleted file mode 100644 index c7ab5c9e10..0000000000 --- a/test/smoke/spec/snyk_fix_spec.sh +++ /dev/null @@ -1,30 +0,0 @@ -#shellcheck shell=sh - -Describe "Snyk fix command logged in" - Before snyk_login - After snyk_logout - - Describe "supported only with FF" - - It "by default snyk fix is not supported" - When run snyk fix - The status should be failure - The output should include "is not supported" - The stderr should equal "" - End - End -End - -Describe "Snyk fix command logged out" - Before snyk_logout - - Describe "Bubbles up auth error" - - It "not authed" - When run snyk fix - The status should be failure - The output should include "is not supported" - The stderr should equal "" - End - End -End diff --git a/test/smoke/spec/snyk_monitor_spec.sh b/test/smoke/spec/snyk_monitor_spec.sh deleted file mode 100644 index 7b238550e0..0000000000 --- a/test/smoke/spec/snyk_monitor_spec.sh +++ /dev/null @@ -1,44 +0,0 @@ -#shellcheck shell=sh - -Describe "Snyk monitor command" - Before snyk_login - After snyk_logout - - Describe "monitor npm project" - run_monitor_in_subfolder() { - cd ../fixtures/basic-npm || return - snyk monitor - } - - It "monitors a project in the same folder" - When run run_monitor_in_subfolder - The status should be success - The output should include "Explore this snapshot at https://app.eu.snyk.io/org/" - The output should include "Notifications about newly disclosed issues related to these dependencies will be emailed to you." - End - - It "monitors a project when pointing to a folder" - When run snyk monitor ../fixtures/basic-npm - The status should be success - The output should include "Explore this snapshot at https://app.eu.snyk.io/org/" - The output should include "Notifications about newly disclosed issues related to these dependencies will be emailed to you." - End - - It "monitors a project when pointing to a file" - When run snyk monitor --file=../fixtures/basic-npm/package.json - The status should be success - The output should include "Explore this snapshot at https://app.eu.snyk.io/org/" - The output should include "Notifications about newly disclosed issues related to these dependencies will be emailed to you." - End - End - - Describe "monitor npm project with JSON output" - It "monitors a project and outputs a valid JSON" - When run snyk monitor ../fixtures/basic-npm --json - The status should be success # issues found - The output should include '"ok": true,' - The stderr should equal "" - The result of function check_valid_json should be success - End - End -End diff --git a/test/smoke/spec/snyk_test_spec.sh b/test/smoke/spec/snyk_test_spec.sh deleted file mode 100644 index 398bd4d0b1..0000000000 --- a/test/smoke/spec/snyk_test_spec.sh +++ /dev/null @@ -1,127 +0,0 @@ -#shellcheck shell=sh - -Describe "Snyk test command" - Before snyk_login - After snyk_logout - - Describe "Java Gradle test" - It "finds vulns in a project when pointing to a folder" - Skip if "execute only in regression test" check_if_regression_test - When run snyk test ../fixtures/gradle-prune-repeated-deps/ - The status should be failure # issues found - The output should include "Upgrade com.google.guava:guava@18.0" - The stderr should equal "" - End - End - - Describe "Python pip test" - install_pip_and_run_snyk_test() { - cd ../acceptance/workspaces/pip-app/ || return - pip install -r requirements.txt - snyk test - } - It "finds vulns in a project when pointing to a folder" - Skip if "execute only in regression test" check_if_regression_test - When run install_pip_and_run_snyk_test - The status should be failure # issues found - The output should include "Upgrade jinja2@2.7.2" - The stderr should equal "" - End - End - - - Describe "npm test" - run_test_in_subfolder() { - cd ../fixtures/basic-npm || return - snyk test - } - - run_test_in_empty_subfolder() { - cd ../fixtures/empty || return - snyk test - } - - It "throws error when file does not exist" - When run snyk test --file=non-existent/package.json - The status should equal 2 - The output should include "Could not find the specified file" - The stderr should equal "" - End - - It "throws error when no suppored manifests detected" - When run run_test_in_empty_subfolder - The status should equal 3 - The output should include "Could not detect supported target files in" - The stderr should equal "" - End - - It "finds vulns in a project in the same folder" - When run run_test_in_subfolder - The status should equal 1 - The output should include "https://security.snyk.io/vuln/npm:minimatch:20160620" - End - - It "finds vulns in a project when pointing to a folder" - When run snyk test ../fixtures/basic-npm - The status should be failure # issues found - The output should include "https://security.snyk.io/vuln/npm:minimatch:20160620" - End - - It "finds vulns in a project when pointing to a file" - When run snyk test --file=../fixtures/basic-npm/package.json - The status should be failure # issues found - The output should include "https://security.snyk.io/vuln/npm:minimatch:20160620" - End - - It "tests a library on a specific version when passed a library@version" - Skip if "execute only in regression test" check_if_regression_test - When run snyk test lodash@4.17.15 - The status should be failure # issues found - The output should include "Testing lodash@4.17.15" - The stderr should equal "" - End - - It "fails with a correct user message on a non-existent library" - Skip if "execute only in regression test" check_if_regression_test - When run snyk test nonexistentpackage123456789 - The status should be failure - The output should include "Couldn't find the requested package or version" - The stderr should equal "" - End - - It "fails with a correct user message on a non-existent library" - Skip if "execute only in regression test" check_if_regression_test - When run snyk test lodash --org=nope - The status should be failure - The output should include "Org nope was not found or you may not have the correct permissions" - The stderr should equal "" - End - End - - Describe "npm test with JSON output" - It "outputs a valid JSON with vulns" - When run snyk test ../fixtures/basic-npm --json - The status should be failure # issues found - The output should include "npm:minimatch:20160620" - The output should include '"vulnerabilities": [' - The stderr should equal "" - The result of function check_valid_json should be success - End - End - - Describe "npm test with JSON output and all-projects flag" - snyk_test_json_all() { - cd ../fixtures || return - snyk test --json --all-projects - } - - # https://github.com/snyk/snyk/pull/1324 - # Captures an issue with extra output in stderr when json flag was set and some project failed to test - It "won't output to stderr when one project fails and json flag is set" - When run snyk_test_json_all - The status should be failure # issues found - The stderr should equal "" - The result of function check_valid_json should be success - End - End -End diff --git a/test/smoke/spec/spec_helper.sh b/test/smoke/spec/spec_helper.sh deleted file mode 100644 index 86df174dfd..0000000000 --- a/test/smoke/spec/spec_helper.sh +++ /dev/null @@ -1,77 +0,0 @@ -#shellcheck shell=sh -set -e - -spec_helper_precheck() { - setenv CI=1 # This flag influences behavior of `snyk auth` so it needs to be explicitly set - setenv ORIGINAL_SNYK_EXECUTABLE="$(which snyk)" -} - -spec_helper_configure() { - print_snyk_config() { - snyk config - } - - snyk_login() { - snyk config set api="${TEST_SNYK_TOKEN}" 1> /dev/null - } - - snyk_logout() { - snyk config clear > /dev/null 2>&1 - } - - verify_login_url() { - # https://snyk.io/login?token=uuid-token&utm_medium=cli&utm_source=cli&utm_campaign=cli&os=darwin&docker=false - echo "$1" | grep https | grep -E "snyk\.io/login\?token=[a-z0-9]{8}-([a-z0-9]{4}-){3}[a-z0-9]{12}\&.*$" - } - - # Consume stdout and checks validates whether it's a valid JSON - check_valid_json() { - printf %s "$1" | jq . > /dev/null - echo $? - } - - # These 2 commands should run in succession, some CLI functionality uses isCI detection - disable_is_ci_flags() { - # save original value and unset - if [ -n "${CI}" ]; then CI_BACKUP_VALUE="$CI"; unset CI; fi - if [ -n "${CIRCLECI}" ]; then CIRCLECI_BACKUP_VALUE="$CIRCLECI"; unset CIRCLECI; fi - } - restore_is_ci_flags() { - # recover the original value - if [ -n "${CI}" ]; then CI="$CI_BACKUP_VALUE"; unset CI_BACKUP_VALUE; fi - if [ -n "${CIRCLECI}" ]; then CIRCLECI="$CIRCLECI_BACKUP_VALUE"; unset CIRCLECI_BACKUP_VALUE; fi - } - - check_if_regression_test() { ! [ "${REGRESSION_TEST}" = "1" ]; } - - check_auth_output() { - printf %s "$1" | grep -F -e "To authenticate your account, open the below URL in your browser." -e "Now redirecting you to our auth page, go ahead and log in," > /dev/null - echo $? - } - - echo " -\033[1mS n y k C L I\033[0m -███████╗███╗ ███╗ ██████╗ ██╗ ██╗███████╗ ████████╗███████╗███████╗████████╗███████╗ -██╔════╝████╗ ████║██╔═══██╗██║ ██╔╝██╔════╝ ╚══██╔══╝██╔════╝██╔════╝╚══██╔══╝██╔════╝ -███████╗██╔████╔██║██║ ██║█████╔╝ █████╗ ██║ █████╗ ███████╗ ██║ ███████╗ -╚════██║██║╚██╔╝██║██║ ██║██╔═██╗ ██╔══╝ ██║ ██╔══╝ ╚════██║ ██║ ╚════██║ -███████║██║ ╚═╝ ██║╚██████╔╝██║ ██╗███████╗ ██║ ███████╗███████║ ██║ ███████║ -╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝ ╚═╝ ╚══════╝╚══════╝ ╚═╝ ╚══════╝ -" - - echo "------------------------------------------------------------------------------------------------------" - echo " Binary under test [TEST_SNYK_COMMAND] ............ ${TEST_SNYK_COMMAND:=$ORIGINAL_SNYK_EXECUTABLE}" - echo " API Endpoint [TEST_SNYK_API] ................ ${TEST_SNYK_API}" - echo " Token [TEST_SNYK_TOKEN] .............. ***" - echo "------------------------------------------------------------------------------------------------------" - echo " " - - # ensure a clean test environment - unset SNYK_API - unset SNYK_API_KEY - export SNYK_API=${TEST_SNYK_API} - - snyk() { - eval "${TEST_SNYK_COMMAND:=$ORIGINAL_SNYK_EXECUTABLE}" "$@" - } -}