Skip to content

Commit 455aefd

Browse files
committed
Make secrets integration test robust to changes in array ordering
1 parent 2169213 commit 455aefd

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

misc/integration-test-secrets.sh

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,35 +29,41 @@ if [ "$RES" -ne "$EXPECTING" ]; then
2929
exit 1
3030
fi
3131

32-
status1=`jq '.runs[0].results[0].properties.tags[1]' "${REPO_DIR}/results1.json"`
32+
read -r -d '' JQ_QUERY <<'EOF'
33+
[.runs[].results[] | select(.locations[0].physicalLocation.artifactLocation.uri == $uri)][ $idx ]
34+
| .properties.tags[]?
35+
| select(startswith("DATADOG_SECRET_VALIDATION_STATUS:"))
36+
EOF
37+
38+
status1=$(jq --arg uri "datadog-keys.sh" --argjson idx 0 "$JQ_QUERY" "${REPO_DIR}/results1.json")
3339

3440
if [ "$status1" != "\"DATADOG_SECRET_VALIDATION_STATUS:INVALID\"" ]; then
3541
echo "status1: did not find DATADOG_SECRET_VALIDATION_STATUS:INVALID in properties, found $status1"
3642
exit 1
3743
fi
3844

39-
status2=`jq '.runs[0].results[1].properties.tags[1]' "${REPO_DIR}/results1.json"`
45+
status2=$(jq --arg uri "plop/foo_test.py" --argjson idx 0 "$JQ_QUERY" "${REPO_DIR}/results1.json")
4046

4147
if [ "$status2" != "\"DATADOG_SECRET_VALIDATION_STATUS:NOT_VALIDATED\"" ]; then
4248
echo "status2: did not find DATADOG_SECRET_VALIDATION_STATUS:NOT_VALIDATED in properties, found $status2"
4349
exit 1
4450
fi
4551

46-
status3=`jq '.runs[0].results[2].properties.tags[1]' "${REPO_DIR}/results1.json"`
52+
status3=$(jq --arg uri "plop/foo_test.py" --argjson idx 1 "$JQ_QUERY" "${REPO_DIR}/results1.json")
4753

4854
if [ "$status3" != "\"DATADOG_SECRET_VALIDATION_STATUS:NOT_VALIDATED\"" ]; then
4955
echo "status3: did not find DATADOG_SECRET_VALIDATION_STATUS:NOT_VALIDATED in properties, found $status3"
5056
exit 1
5157
fi
5258

5359
## Make sure the SDS ID is added to the SARIF file
54-
status4=`jq '.runs[0].tool.driver.rules[0].properties.tags[1]' "${REPO_DIR}/results1.json"`
60+
status4=`jq '.runs[0].tool.driver.rules[0].properties.tags[] | select(startswith("DATADOG_SDS_ID:"))' "${REPO_DIR}/results1.json"`
5561

56-
if [ "$status4" != "\"DATADOG_SDS_ID:5ef83eb0-4137-48a2-a28b-2402c185863c\"" ]; then
57-
echo "status3: did not find DATADOG_SDS_ID:5ef83eb0-4137-48a2-a28b-2402c185863c in properties, found $status4"
62+
if [ -z "$status4" ]; then
63+
echo "did not find DATADOG_SDS_ID in tags"
5864
exit 1
5965
fi
6066

6167
echo "All tests passed"
6268

63-
exit 0
69+
exit 0

0 commit comments

Comments
 (0)