2023-09-07 13:06:21 -05:00
|
|
|
# Note: Intended to be run as "make run-blackbox-tests" or "make run-blackbox-ci"
|
2023-08-30 14:24:28 -05:00
|
|
|
# Makefile target installs & checks all necessary tooling
|
|
|
|
# Extra tools that are not covered in Makefile target needs to be added in verify_prerequisites()
|
|
|
|
|
|
|
|
load helpers_zot
|
|
|
|
|
|
|
|
function verify_prerequisites {
|
|
|
|
if [ ! $(command -v curl) ]; then
|
|
|
|
echo "you need to install curl as a prerequisite to running the tests" >&3
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! $(command -v jq) ]; then
|
|
|
|
echo "you need to install jq as a prerequisite to running the tests" >&3
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2023-10-02 08:37:21 -05:00
|
|
|
if [ ! $(command -v htpasswd) ]; then
|
|
|
|
echo "you need to install htpasswd as a prerequisite to running the tests" >&3
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2023-08-30 14:24:28 -05:00
|
|
|
return 0
|
|
|
|
}
|
2023-04-24 13:13:15 -05:00
|
|
|
|
|
|
|
function setup_file() {
|
|
|
|
# Verify prerequisites are available
|
2023-08-30 14:24:28 -05:00
|
|
|
if ! $(verify_prerequisites); then
|
2023-04-24 13:13:15 -05:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Download test data to folder common for the entire suite, not just this file
|
2023-10-02 08:37:21 -05:00
|
|
|
skopeo --insecure-policy copy --format=oci docker://ghcr.io/project-zot/test-images/busybox:1.36 oci:${TEST_DATA_DIR}/busybox:1.36
|
|
|
|
|
2023-04-24 13:13:15 -05:00
|
|
|
# Setup zot server
|
|
|
|
local zot_root_dir=${BATS_FILE_TMPDIR}/zot
|
|
|
|
local zot_config_file=${BATS_FILE_TMPDIR}/zot_config.json
|
|
|
|
local oci_data_dir=${BATS_FILE_TMPDIR}/oci
|
2023-10-02 08:37:21 -05:00
|
|
|
local zot_htpasswd_file=${BATS_FILE_TMPDIR}/htpasswd
|
2023-04-24 13:13:15 -05:00
|
|
|
mkdir -p ${zot_root_dir}
|
|
|
|
mkdir -p ${oci_data_dir}
|
2023-11-15 13:44:31 -05:00
|
|
|
zot_port=$(get_free_port)
|
|
|
|
echo ${zot_port} > ${BATS_FILE_TMPDIR}/zot.port
|
2023-10-02 08:37:21 -05:00
|
|
|
htpasswd -Bbn ${AUTH_USER} ${AUTH_PASS} >> ${zot_htpasswd_file}
|
2023-04-24 13:13:15 -05:00
|
|
|
cat > ${zot_config_file}<<EOF
|
|
|
|
{
|
2024-02-20 06:27:21 -05:00
|
|
|
"distSpecVersion": "1.1.0",
|
2023-04-24 13:13:15 -05:00
|
|
|
"storage": {
|
|
|
|
"rootDirectory": "${zot_root_dir}"
|
|
|
|
},
|
|
|
|
"extensions": {
|
|
|
|
"search": {
|
|
|
|
"enable": true
|
2023-08-02 13:58:34 -05:00
|
|
|
},
|
|
|
|
"ui": {
|
|
|
|
"enable": true
|
2023-04-24 13:13:15 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
"http": {
|
|
|
|
"address": "0.0.0.0",
|
2023-11-15 13:44:31 -05:00
|
|
|
"port": "${zot_port}",
|
2023-04-24 13:13:15 -05:00
|
|
|
"auth": {
|
|
|
|
"htpasswd": {
|
2023-10-02 08:37:21 -05:00
|
|
|
"path": "${zot_htpasswd_file}"
|
2023-04-24 13:13:15 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
"accessControl": {
|
|
|
|
"repositories": {
|
|
|
|
"**": {
|
|
|
|
"anonymousPolicy": ["read"],
|
|
|
|
"policies": [
|
|
|
|
{
|
|
|
|
"users": [
|
2023-10-02 08:37:21 -05:00
|
|
|
"${AUTH_USER}"
|
2023-04-24 13:13:15 -05:00
|
|
|
],
|
|
|
|
"actions": [
|
|
|
|
"read",
|
|
|
|
"create",
|
|
|
|
"update"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"log": {
|
2023-09-07 13:06:21 -05:00
|
|
|
"level": "debug",
|
|
|
|
"output": "${BATS_FILE_TMPDIR}/zot.log"
|
2023-04-24 13:13:15 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
git -C ${BATS_FILE_TMPDIR} clone https://github.com/project-zot/helm-charts.git
|
2023-08-30 14:24:28 -05:00
|
|
|
zot_serve ${ZOT_PATH} ${zot_config_file}
|
2023-11-15 13:44:31 -05:00
|
|
|
wait_zot_reachable ${zot_port}
|
2023-04-24 13:13:15 -05:00
|
|
|
}
|
|
|
|
|
2023-09-07 13:06:21 -05:00
|
|
|
function teardown() {
|
|
|
|
# conditionally printing on failure is possible from teardown but not from from teardown_file
|
|
|
|
cat ${BATS_FILE_TMPDIR}/zot.log
|
|
|
|
}
|
|
|
|
|
2023-04-24 13:13:15 -05:00
|
|
|
function teardown_file() {
|
2023-08-30 14:24:28 -05:00
|
|
|
zot_stop_all
|
2023-04-24 13:13:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "push image user policy" {
|
2023-11-15 13:44:31 -05:00
|
|
|
zot_port=`cat ${BATS_FILE_TMPDIR}/zot.port`
|
2023-10-02 08:37:21 -05:00
|
|
|
run skopeo --insecure-policy copy --dest-creds ${AUTH_USER}:${AUTH_PASS} --dest-tls-verify=false \
|
|
|
|
oci:${TEST_DATA_DIR}/busybox:1.36 \
|
2023-11-15 13:44:31 -05:00
|
|
|
docker://127.0.0.1:${zot_port}/busybox:1.36
|
2023-04-24 13:13:15 -05:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "User metadata starredRepos" {
|
2023-11-15 13:44:31 -05:00
|
|
|
zot_port=`cat ${BATS_FILE_TMPDIR}/zot.port`
|
2023-10-02 08:37:21 -05:00
|
|
|
run skopeo --insecure-policy copy --dest-creds ${AUTH_USER}:${AUTH_PASS} --dest-tls-verify=false \
|
|
|
|
oci:${TEST_DATA_DIR}/busybox:1.36 \
|
2023-11-15 13:44:31 -05:00
|
|
|
docker://127.0.0.1:${zot_port}/busybox:1.36
|
2023-04-24 13:13:15 -05:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
USER_STAR_REPOS_QUERY='{ "query": "{ StarredRepos { Results { Name } } }"}'
|
|
|
|
|
2023-11-15 13:44:31 -05:00
|
|
|
run curl --user ${AUTH_USER}:${AUTH_PASS} -X POST -H "Content-Type: application/json" --data "${USER_STAR_REPOS_QUERY}" http://localhost:${zot_port}/v2/_zot/ext/search
|
2023-04-24 13:13:15 -05:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ $(echo "${lines[-1]}" | jq '.data.StarredRepos.Results') = '[]' ]
|
|
|
|
|
2023-11-15 13:44:31 -05:00
|
|
|
run curl --user ${AUTH_USER}:${AUTH_PASS} -X PUT "http://127.0.0.1:${zot_port}/v2/_zot/ext/userprefs?repo=busybox&action=toggleStar"
|
2023-04-24 13:13:15 -05:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
2023-11-15 13:44:31 -05:00
|
|
|
run curl --user ${AUTH_USER}:${AUTH_PASS} -X POST -H "Content-Type: application/json" --data "${USER_STAR_REPOS_QUERY}" http://localhost:${zot_port}/v2/_zot/ext/search
|
2023-04-24 13:13:15 -05:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
echo $(echo "${lines[-1]}" | jq '.data.StarredRepos.Results[0].Name')
|
2023-10-02 08:37:21 -05:00
|
|
|
[ $(echo "${lines[-1]}" | jq -r '.data.StarredRepos.Results[0].Name') = 'busybox' ]
|
2023-04-24 13:13:15 -05:00
|
|
|
|
2023-11-15 13:44:31 -05:00
|
|
|
run curl --user ${AUTH_USER}:${AUTH_PASS} -X PUT "http://127.0.0.1:${zot_port}/v2/_zot/ext/userprefs?repo=busybox&action=toggleStar"
|
2023-04-24 13:13:15 -05:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
2023-11-15 13:44:31 -05:00
|
|
|
run curl --user ${AUTH_USER}:${AUTH_PASS} -X POST -H "Content-Type: application/json" --data "${USER_STAR_REPOS_QUERY}" http://localhost:${zot_port}/v2/_zot/ext/search
|
2023-04-24 13:13:15 -05:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
echo $(echo "${lines[-1]}" | jq '.data.StarredRepos.Results')
|
|
|
|
[ $(echo "${lines[-1]}" | jq -r '.data.StarredRepos.Results') = '[]' ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "User metadata bookmarkedRepos" {
|
2023-11-15 13:44:31 -05:00
|
|
|
zot_port=`cat ${BATS_FILE_TMPDIR}/zot.port`
|
2023-10-02 08:37:21 -05:00
|
|
|
run skopeo --insecure-policy copy --dest-creds ${AUTH_USER}:${AUTH_PASS} --dest-tls-verify=false \
|
|
|
|
oci:${TEST_DATA_DIR}/busybox:1.36 \
|
2023-11-15 13:44:31 -05:00
|
|
|
docker://127.0.0.1:${zot_port}/busybox:1.36
|
2023-04-24 13:13:15 -05:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
USER_BOOKMARK_REPOS_QUERY='{ "query": "{ BookmarkedRepos { Results { Name } } }"}'
|
|
|
|
|
2023-11-15 13:44:31 -05:00
|
|
|
run curl --user ${AUTH_USER}:${AUTH_PASS} -X POST -H "Content-Type: application/json" --data "${USER_BOOKMARK_REPOS_QUERY}" http://localhost:${zot_port}/v2/_zot/ext/search
|
2023-04-24 13:13:15 -05:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ $(echo "${lines[-1]}" | jq '.data.BookmarkedRepos.Results') = '[]' ]
|
|
|
|
|
2023-11-15 13:44:31 -05:00
|
|
|
run curl --user ${AUTH_USER}:${AUTH_PASS} -X PUT "http://127.0.0.1:${zot_port}/v2/_zot/ext/userprefs?repo=busybox&action=toggleBookmark"
|
2023-04-24 13:13:15 -05:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
2023-11-15 13:44:31 -05:00
|
|
|
run curl --user ${AUTH_USER}:${AUTH_PASS} -X POST -H "Content-Type: application/json" --data "${USER_BOOKMARK_REPOS_QUERY}" http://localhost:${zot_port}/v2/_zot/ext/search
|
2023-04-24 13:13:15 -05:00
|
|
|
[ "$status" -eq 0 ]
|
2023-10-02 08:37:21 -05:00
|
|
|
[ $(echo "${lines[-1]}" | jq -r '.data.BookmarkedRepos.Results[0].Name') = 'busybox' ]
|
2023-04-24 13:13:15 -05:00
|
|
|
|
2023-11-15 13:44:31 -05:00
|
|
|
run curl --user ${AUTH_USER}:${AUTH_PASS} -X PUT "http://127.0.0.1:${zot_port}/v2/_zot/ext/userprefs?repo=busybox&action=toggleBookmark"
|
2023-04-24 13:13:15 -05:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
2023-11-15 13:44:31 -05:00
|
|
|
run curl --user ${AUTH_USER}:${AUTH_PASS} -X POST -H "Content-Type: application/json" --data "${USER_BOOKMARK_REPOS_QUERY}" http://localhost:${zot_port}/v2/_zot/ext/search
|
2023-04-24 13:13:15 -05:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ $(echo "${lines[-1]}" | jq -r '.data.BookmarkedRepos.Results') = '[]' ]
|
|
|
|
}
|