Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
20 changes: 20 additions & 0 deletions free/ci/internal/toolchain/drill_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,23 @@ func TestDrillVerifiesAPinnedImageRow(t *testing.T) {
t.Fatalf("vanished pinned image: exit %d %v", exit, c)
}
}

// TestDrillFailsWhenAToolRowHasNoSources: a tool row without sources has nothing to verify, so it must fail
// instead of passing with nothing checked (D-1184).
func TestDrillFailsWhenAToolRowHasNoSources(t *testing.T) {
srv := mirror(t)
for name, tail := range map[string]string{
"absent": "",
"empty": " sources: []\n",
} {
t.Run(name, func(t *testing.T) {
table := "version: 1\nrows:\n - name: nosrc\n kind: tool\n version: \"1.0.0\"\n purpose: p\n owner: o\n probe: [nosrc, --version]\n upstream: {type: github, ref: acme/demo}\n" + tail
doc, exit, raw := runDrill(t, table, srv)
validEvidence(t, raw)
c := resultsByTool(doc)["nosrc"]
if exit != 1 || doc["result"] != "fail" || c["result"] != "fail" || !strings.Contains(c["excerpt"].(string), "no sources") {
t.Fatalf("exit %d result %v check %v", exit, doc["result"], c)
}
})
}
}
7 changes: 6 additions & 1 deletion scripts/drill/toolchain-pins/run
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,16 @@ while IFS= read -r row; do
fi
continue ;;
esac
# A tool row with no sources has nothing to check. Fail it: a process substitution below would swallow the jq error.
if ! sources=$(jq -c '.sources | if type == "array" and length > 0 then .[] else error("no sources") end' <<<"$row" 2>/dev/null); then
emit "$name" "$name" "$version" true fail 1 "tool row has no sources to verify"
continue
fi
gone=()
while IFS= read -r src; do
url=$(jq -r .url <<<"$src")
head_ok "$url" || gone+=("$(jq -r '.os + "/" + .arch' <<<"$src")")
done < <(jq -c '.sources[]' <<<"$row")
done <<<"$sources"
if [ "${#gone[@]}" -gt 0 ]; then
emit "$name" "$name" "$version" true fail "${#gone[@]}" "pinned artifact no longer downloadable for: ${gone[*]}"
continue
Expand Down
Loading