-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
6 changed files
with
113 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,5 +21,13 @@ jobs: | |
runs-on: ubuntu-20.04 | ||
steps: | ||
- uses: actions/[email protected] | ||
- uses: 030/[email protected] | ||
- uses: 030/[email protected] | ||
``` | ||
|
||
## unit tests | ||
|
||
```bash | ||
docker run -it -v "${PWD}:/code" --entrypoint=bash bats/bats:v1.10.0 | ||
apk add --no-cache coreutils | ||
bats --tap test --print-output-on-failure | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/usr/bin/env bash | ||
|
||
readonly filename=".trivyignore" | ||
|
||
createEmptyDotTrivyignoreIfAbsent() { | ||
if test -f "${filename}"; then | ||
echo "found a ${filename} file..."; | ||
return | ||
fi | ||
|
||
echo "no ${filename} file found. Creating empty one..." | ||
touch "${filename}" | ||
exit 0 | ||
} | ||
|
||
inspectCveExpiry() { | ||
echo "checking whether an expiry has been attached..." | ||
|
||
if ! echo ${1} | grep -qE "^CVE\-.*exp:[0-9]{4}(\-[0-9]{2}){2}$"; then | ||
echo "no expiry associated to: '${1}'. Add it by adding: 'exp:yyyy-mm-dd'" | ||
exit 1 | ||
fi | ||
} | ||
|
||
inspectCveExpiryMaxOneMonth() { | ||
echo "checking whether the expiry will take place in one month..." | ||
current=$(echo "${1}" | sed -e "s|CVE\-.*exp:\(.*\)|\1|g") | ||
max=$(date +"%F" --date="$(date +%F) next month") | ||
|
||
if [[ "${current}" > "${max}" ]]; then | ||
echo "current date: '${current}' in line: '${1}' exceeds" | ||
echo "the maximum date of one month. Choose a new date that is" | ||
echo "before: ${max}" | ||
exit 1 | ||
fi | ||
} | ||
|
||
inspectCveExpiryAndMaxOneMonth() { | ||
while read -r line; do | ||
if echo "${line}" | grep -qE "^CVE\-"; then | ||
echo "found a 'CVE-' entry in the ${filename}..."; | ||
|
||
inspectCveExpiry "${line}" | ||
inspectCveExpiryMaxOneMonth "${line}" | ||
fi | ||
done < "${filename}" | ||
} | ||
|
||
main() { | ||
createEmptyDotTrivyignoreIfAbsent | ||
inspectCveExpiryAndMaxOneMonth | ||
} | ||
|
||
main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
setup() { | ||
filename=".trivyignore" | ||
} | ||
|
||
teardown() { | ||
echo "found filename: '${filename}'. Removing it..." | ||
rm "${filename}" | ||
} | ||
|
||
@test "create empty dot trivyignore if absent" { | ||
run ./src/action.sh | ||
[ "$status" -eq 0 ] | ||
regex=".*no ${filename} file found. Creating empty one.*" | ||
[[ "$output" =~ $regex ]] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
setup() { | ||
filename=".trivyignore" | ||
|
||
echo -en "CVE-123 exp:2124-02-15\nCVE-456 exp:2124-02-16" > "${filename}" | ||
} | ||
|
||
teardown() { | ||
echo "found filename: '${filename}'. Removing it..." | ||
rm "${filename}" | ||
} | ||
|
||
@test "inspect cve expiry max one month" { | ||
run ./src/action.sh | ||
[ "$status" -eq 1 ] | ||
regex=".*current date: '2124-02-15' in line: 'CVE-123 exp:2124-02-15' exceeds.*the maximum date of one month. Choose a new date that is.*before: .*" | ||
[[ "$output" =~ $regex ]] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
setup() { | ||
filename=".trivyignore" | ||
|
||
echo -en "CVE-123\nCVE-456 exp:2124-02-16" > "${filename}" | ||
} | ||
|
||
teardown() { | ||
echo "found filename: '${filename}'. Removing it..." | ||
rm "${filename}" | ||
} | ||
|
||
@test "inspect cve expiry" { | ||
run ./src/action.sh | ||
[ "$status" -eq 1 ] | ||
regex=".*no expiry associated to: 'CVE-123'. Add it by adding: 'exp:yyyy-mm-dd'.*" | ||
[[ "$output" =~ $regex ]] | ||
} |