whatcanGOwrong

This commit is contained in:
2024-09-19 21:38:24 -04:00
commit d0ae4d841d
17908 changed files with 4096831 additions and 0 deletions
@@ -0,0 +1,51 @@
#!/bin/bash
# Copyright 2021 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
# Library of useful bash functions and variables.
RED=; GREEN=; YELLOW=; NORMAL=;
MAXWIDTH=0
if tput setaf 1 >& /dev/null; then
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
YELLOW=$(tput setaf 3)
NORMAL=$(tput sgr0)
MAXWIDTH=$(( $(tput cols) - 2 ))
fi
EXIT_CODE=0
export EXIT_CODE
info() { echo -e "${GREEN}$*${NORMAL}" 1>&2; }
warn() { echo -e "${YELLOW}$*${NORMAL}" 1>&2; }
err() { echo -e "${RED}$*${NORMAL}" 1>&2; EXIT_CODE=1; }
die() {
err "$@"
exit 1
}
dryrun=false
# runcmd prints an info log describing the command that is about to be run, and
# then runs it. It sets EXIT_CODE to non-zero if the command fails, but does not exit
# the script.
runcmd() {
msg="$*"
if $dryrun; then
echo -e "${YELLOW}dryrun${GREEN}\$ $msg${NORMAL}"
return 0
fi
# Truncate command logging for narrow terminals.
# Account for the 2 characters of '$ '.
if [[ $MAXWIDTH -gt 0 && ${#msg} -gt $MAXWIDTH ]]; then
msg="${msg::$(( MAXWIDTH - 3 ))}..."
fi
echo -e "$*\n" 1>&2;
"$@" || err "command failed"
}
@@ -0,0 +1,56 @@
#!/usr/bin/env -S bash -e
# Copyright 2023 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
source devtools/lib.sh || { echo "Are you at repo root?"; exit 1; }
# Script for copying data from the v1 schema in vuln.go.dev for tests.
origin="https://vuln.go.dev"
go install golang.org/x/vulndb/cmd/indexdb@latest
# Copy files for unit tests.
copyFiles=(
"ID/GO-2021-0159.json"
"ID/GO-2022-0229.json"
"ID/GO-2022-0463.json"
"ID/GO-2022-0569.json"
"ID/GO-2022-0572.json"
"ID/GO-2021-0068.json"
"ID/GO-2022-0475.json"
"ID/GO-2022-0476.json"
"ID/GO-2021-0240.json"
"ID/GO-2021-0264.json"
"ID/GO-2022-0273.json"
)
UNIT_OUT_DIR=$(pwd)/internal/client/testdata/vulndb-v1
for f in "${copyFiles[@]}"; do
mkdir -p "$UNIT_OUT_DIR/$(dirname "$f")" && curl -L $origin/"$f" --output "$UNIT_OUT_DIR"/"$f"
done
unit_vulns="$UNIT_OUT_DIR/ID"
indexdb -out "$UNIT_OUT_DIR" -vulns "$unit_vulns"
# Copy files for integration tests.
copyFiles=(
"ID/GO-2022-0969.json"
"ID/GO-2020-0015.json"
"ID/GO-2021-0113.json"
"ID/GO-2021-0054.json"
"ID/GO-2021-0059.json"
"ID/GO-2021-0265.json"
)
INTEG_OUT_DIR=$(pwd)/cmd/govulncheck/testdata/vulndb-v1
for f in "${copyFiles[@]}"; do
mkdir -p "$INTEG_OUT_DIR"/"$(dirname "$f")" && curl -L "$origin"/"$f" --output "$INTEG_OUT_DIR"/"$f"
done
integ_vulns="$INTEG_OUT_DIR/ID"
indexdb -out "$INTEG_OUT_DIR" -vulns "$integ_vulns"