|
| 1 | +# Note: Intended to be run as "make run-blackbox-tests" or "make run-blackbox-ci" |
| 2 | +# Makefile target installs & checks all necessary tooling |
| 3 | +# Extra tools that are not covered in Makefile target needs to be added in verify_prerequisites() |
| 4 | + |
| 5 | +load helpers_zot |
| 6 | + |
| 7 | +function verify_prerequisites { |
| 8 | + if [ ! $(command -v curl) ]; then |
| 9 | + echo "you need to install curl as a prerequisite to running the tests" >&3 |
| 10 | + return 1 |
| 11 | + fi |
| 12 | + |
| 13 | + if [ ! $(command -v jq) ]; then |
| 14 | + echo "you need to install jq as a prerequisite to running the tests" >&3 |
| 15 | + return 1 |
| 16 | + fi |
| 17 | + |
| 18 | + if [ ! $(command -v htpasswd) ]; then |
| 19 | + echo "you need to install htpasswd as a prerequisite to running the tests" >&3 |
| 20 | + return 1 |
| 21 | + fi |
| 22 | + |
| 23 | + return 0 |
| 24 | +} |
| 25 | + |
| 26 | +function setup_file() { |
| 27 | + # Verify prerequisites are available |
| 28 | + if ! $(verify_prerequisites); then |
| 29 | + exit 1 |
| 30 | + fi |
| 31 | + |
| 32 | + # Download test data to folder common for the entire suite, not just this file |
| 33 | + skopeo --insecure-policy copy --format=oci docker://ghcr.io/project-zot/test-images/busybox:1.36 oci:${TEST_DATA_DIR}/busybox:1.36 |
| 34 | + |
| 35 | + # Setup zot server |
| 36 | + local zot_root_dir=${BATS_FILE_TMPDIR}/zot |
| 37 | + local zot_config_file=${BATS_FILE_TMPDIR}/zot_config.json |
| 38 | + local oci_data_dir=${BATS_FILE_TMPDIR}/oci |
| 39 | + local zot_htpasswd_file=${BATS_FILE_TMPDIR}/htpasswd |
| 40 | + mkdir -p ${zot_root_dir} |
| 41 | + mkdir -p ${oci_data_dir} |
| 42 | + zot_port=$(get_free_port) |
| 43 | + echo ${zot_port} > ${BATS_FILE_TMPDIR}/zot.port |
| 44 | + htpasswd -Bbn ${AUTH_USER} ${AUTH_PASS} >> ${zot_htpasswd_file} |
| 45 | + cat > ${zot_config_file}<<EOF |
| 46 | +{ |
| 47 | + "distSpecVersion": "1.1.1", |
| 48 | + "storage": { |
| 49 | + "rootDirectory": "${zot_root_dir}" |
| 50 | + }, |
| 51 | + "extensions": { |
| 52 | + "search": { |
| 53 | + "enable": true |
| 54 | + }, |
| 55 | + "ui": { |
| 56 | + "enable": true |
| 57 | + } |
| 58 | + }, |
| 59 | + "http": { |
| 60 | + "address": "0.0.0.0", |
| 61 | + "port": "${zot_port}", |
| 62 | + "auth": { |
| 63 | + "htpasswd": { |
| 64 | + "path": "${zot_htpasswd_file}" |
| 65 | + } |
| 66 | + }, |
| 67 | + "accessControl": { |
| 68 | + "repositories": { |
| 69 | + "**": { |
| 70 | + "anonymousPolicy": ["read"], |
| 71 | + "policies": [ |
| 72 | + { |
| 73 | + "users": [ |
| 74 | + "${AUTH_USER}" |
| 75 | + ], |
| 76 | + "actions": [ |
| 77 | + "read", |
| 78 | + "create", |
| 79 | + "update" |
| 80 | + ] |
| 81 | + } |
| 82 | + ] |
| 83 | + } |
| 84 | + } |
| 85 | + } |
| 86 | + }, |
| 87 | + "log": { |
| 88 | + "level": "debug", |
| 89 | + "output": "${BATS_FILE_TMPDIR}/zot.log" |
| 90 | + } |
| 91 | +} |
| 92 | +EOF |
| 93 | + git -C ${BATS_FILE_TMPDIR} clone https://github.com/project-zot/helm-charts.git |
| 94 | + zot_serve ${ZOT_PATH} ${zot_config_file} |
| 95 | + wait_zot_reachable ${zot_port} |
| 96 | +} |
| 97 | + |
| 98 | +function teardown() { |
| 99 | + # conditionally printing on failure is possible from teardown but not from from teardown_file |
| 100 | + cat ${BATS_FILE_TMPDIR}/zot.log |
| 101 | +} |
| 102 | + |
| 103 | +function teardown_file() { |
| 104 | + zot_stop_all |
| 105 | +} |
| 106 | + |
| 107 | +@test "test various crypto hashes" { |
| 108 | + zot_port=`cat ${BATS_FILE_TMPDIR}/zot.port` |
| 109 | + run cryptotest --plain-http --registry 127.0.0.1:${zot_port} |
| 110 | + [ "$status" -eq 0 ] |
| 111 | +} |
0 commit comments