Skip to content

Commit

Permalink
fix: propagate new logic of exhort backend selection to validateToken…
Browse files Browse the repository at this point in the history
… Function

test: add integration tests for validateToken function

Signed-off-by: Zvi Grinberg <[email protected]>
  • Loading branch information
zvigrinberg committed Sep 7, 2023
1 parent 676429c commit b98136f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions integration/run_its.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ match() {
matchConstant() {
if [[ "$1" != "$2" ]]; then
echo "- FAILED"
echo "expected = $1, actual= $2"
cleanup 1
fi
echo "- PASSED"
Expand Down Expand Up @@ -141,4 +142,13 @@ if [ "$?" -ne 0 ]; then
fi
StatusCode=$(jq '.summary.providerStatuses[] | select(.provider== "snyk") ' ./responses/component.json | jq .status)
matchConstant "200" "$StatusCode"

echo "RUNNING JavaScript integration test for Validate Token Function With wrong token, expecting getting 401 http status code "
answerAboutToken=$(node testers/javascript/index.js validateToken veryBadToken)
matchConstant "401" "$answerAboutToken"

echo "RUNNING JavaScript integration test for Validate Token Function With no token at all, Expecting getting 400 http status code"
answerAboutToken=$(node testers/javascript/index.js validateToken )
matchConstant "400" "$answerAboutToken"

cleanup 0
10 changes: 10 additions & 0 deletions integration/testers/javascript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,15 @@ if ('component' === args[0]) {
process.exit(0)
}

if ('validateToken' === args[0]) {
// args[1] - the token passed
let tokens = {
"EXHORT_SNYK_TOKEN" : args[1]
}
let res = await exhort.validateToken(tokens)
console.log(res)
process.exit(0)
}

console.log(`unknown action ${args}`)
process.exit(1)
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,6 @@ async function componentAnalysis(manifestType, data, opts = {}) {
}

async function validateToken(opts = {}) {
url = selectExhortBackend(opts)
return await analysis.validateToken(url, opts) // throws error request sending failed
}

0 comments on commit b98136f

Please sign in to comment.