Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rdjson_formatter/rdjson_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

package_name = advisory['module_name']
title = advisory['title']
cve_id = advisory['cves']&.first || advisory['id']
cve_id = (advisory['cves']&.first || advisory['id'])&.to_s
url = advisory['url']
severity = advisory['severity'].to_s.downcase

Expand Down
14 changes: 13 additions & 1 deletion test/rdjson_formatter/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
set -eux
CWD=$(pwd)

compare_json() {
diff -u <(jq -S -c . "$1") <(jq -S -c . "$2")
Comment thread
burisu marked this conversation as resolved.
Outdated
}

cd ./test/rdjson_formatter/testdata

yarn audit --json 2>/dev/null \
Expand All @@ -12,4 +16,12 @@ yarn audit --json 2>/dev/null \
> result.out

cd "${CWD}"
diff -u ./test/rdjson_formatter/testdata/result.ok ./test/rdjson_formatter/testdata/result.out
compare_json ./test/rdjson_formatter/testdata/result.ok ./test/rdjson_formatter/testdata/result.out

ruby "${CWD}/rdjson_formatter/rdjson_formatter.rb" ./test/rdjson_formatter/testdata/yarn.lock \
< ./test/rdjson_formatter/testdata/advisory_without_cve.jsonl \
| jq . \
| sed -e "s!${CWD}/!!g" \
> ./test/rdjson_formatter/testdata/advisory_without_cve.out

Comment thread
burisu marked this conversation as resolved.
Outdated
compare_json ./test/rdjson_formatter/testdata/advisory_without_cve.ok ./test/rdjson_formatter/testdata/advisory_without_cve.out
1 change: 1 addition & 0 deletions test/rdjson_formatter/testdata/advisory_without_cve.jsonl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type":"auditAdvisory","data":{"advisory":{"id":1116454,"module_name":"minimist","severity":"moderate","title":"Prototype Pollution in minimist","url":"https://github.com/advisories/GHSA-vh95-rmgr-6w4m","recommendation":"Upgrade to version 0.2.1 or later","cves":[]}}}
26 changes: 26 additions & 0 deletions test/rdjson_formatter/testdata/advisory_without_cve.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"source": {
"name": "yarn audit",
"url": "https://github.com/yarnpkg/yarn"
},
"severity": "WARNING",
"diagnostics": [
{
"message": "[moderate] Prototype Pollution in minimist\nSolution: Upgrade to version 0.2.1 or later",
"location": {
"path": "./test/rdjson_formatter/testdata/yarn.lock",
"range": {
"start": {
"line": 5,
"column": 0
}
}
},
"severity": "WARNING",
"code": {
"value": "1116454",
"url": "https://github.com/advisories/GHSA-vh95-rmgr-6w4m"
}
}
]
}