0
Fork 0
mirror of https://github.com/project-zot/zot.git synced 2024-12-16 21:56:37 -05:00

test(bats): fix CVE bats test failure if zot runs on different port than 8080 (#2072)

resolves #2008

Signed-off-by: Andrei Aaron <aaaron@luxoft.com>
This commit is contained in:
Andrei Aaron 2023-11-21 16:31:12 +02:00 committed by GitHub
parent 8b2d4fb7ef
commit 0dfff561f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 10 deletions

View file

@ -31,6 +31,8 @@ function setup_file() {
local zot_root_dir=${BATS_FILE_TMPDIR}/zot
local zot_config_file=${BATS_FILE_TMPDIR}/zot_config.json
mkdir -p ${zot_root_dir}
zot_port=$(get_free_port)
echo ${zot_port} > ${BATS_FILE_TMPDIR}/zot.port
cat >${zot_config_file} <<EOF
{
"distSpecVersion": "1.1.0-dev",
@ -39,7 +41,7 @@ function setup_file() {
},
"http": {
"address": "0.0.0.0",
"port": "8080"
"port": "${zot_port}"
},
"log": {
"level": "debug",
@ -56,12 +58,11 @@ function setup_file() {
}
EOF
zot_serve ${ZOT_PATH} ${zot_config_file}
wait_zot_reachable 8080
wait_zot_reachable ${zot_port}
# setup zli to add zot registry to configs
local registry_name=main
local registry_url="http://127.0.0.1:8080/"
zli_add_config ${registry_name} ${registry_url}
local registry_url="http://127.0.0.1:${zot_port}/"
zli_add_config ${REGISTRY_NAME} ${registry_url}
}
function teardown() {
@ -74,14 +75,15 @@ function teardown_file() {
}
@test "cve by image name and tag" {
zot_port=`cat ${BATS_FILE_TMPDIR}/zot.port`
run skopeo --insecure-policy copy --dest-tls-verify=false \
oci:${TEST_DATA_DIR}/golang:1.20 \
docker://127.0.0.1:8080/golang:1.20
docker://127.0.0.1:${zot_port}/golang:1.20
[ "$status" -eq 0 ]
run curl http://127.0.0.1:8080/v2/_catalog
run curl http://127.0.0.1:${zot_port}/v2/_catalog
[ "$status" -eq 0 ]
[ $(echo "${lines[-1]}" | jq '.repositories[]') = '"golang"' ]
run curl http://127.0.0.1:8080/v2/golang/tags/list
run curl http://127.0.0.1:${zot_port}/v2/golang/tags/list
[ "$status" -eq 0 ]
[ $(echo "${lines[-1]}" | jq '.tags[]') = '"1.20"' ]
run ${ZLI_PATH} cve list golang:1.20 --config ${REGISTRY_NAME}

View file

@ -53,9 +53,12 @@ function wait_zot_reachable() {
function zli_add_config() {
local registry_name=${1}
local registry_url=${2}
if ! ${ZLI_PATH} config --list | grep -q main; then
${ZLI_PATH} config add ${registry_name} ${registry_url}
# Clean up old configuration for the same registry
if ${ZLI_PATH} config --list | grep -q ${registry_name}; then
${ZLI_PATH} config remove ${registry_name}
fi
# Add the new registry
${ZLI_PATH} config add ${registry_name} ${registry_url}
}
function zb_run() {