Skip to content

Commit 22706ff

Browse files
committed
ci: add hash tests
Signed-off-by: Ramkumar Chinchani <[email protected]>
1 parent adb215d commit 22706ff

File tree

3 files changed

+122
-2
lines changed

3 files changed

+122
-2
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright 2019-2023 The zot project authors.
189+
Copyright [yyyy] [name of copyright owner]
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

Makefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ CRICTL := $(TOOLSDIR)/bin/crictl
2424
CRICTL_VERSION := v1.26.1
2525
ACTION_VALIDATOR := $(TOOLSDIR)/bin/action-validator
2626
ACTION_VALIDATOR_VERSION := v0.5.3
27+
CRYPTO_TEST := $(TOOLSDIR)/bin/cryptotest
28+
CRYPTO_TEST_VERSION := 0.2.1
2729
ZUI_BUILD_PATH := ""
2830
ZUI_VERSION := commit-303dfb3
2931
ZUI_REPO_OWNER := project-zot
@@ -301,6 +303,13 @@ $(ACTION_VALIDATOR):
301303
mv action-validator $(TOOLSDIR)/bin/action-validator
302304
chmod +x $(TOOLSDIR)/bin/action-validator
303305

306+
$(CRYPTO_TEST):
307+
mkdir -p $(TOOLSDIR)/bin
308+
curl -Lo registry-test.tar.gz https://github.com/shizhMSFT/registry-test/releases/download/v$(CRYPTO_TEST_VERSION)/registry-test_$(CRYPTO_TEST_VERSION)_linux_amd64.tar.gz
309+
tar xvzf registry-test.tar.gz && rm registry-test.tar.gz
310+
mv cryptotest $(TOOLSDIR)/bin/cryptotest
311+
chmod +x $(TOOLSDIR)/bin/cryptotest
312+
304313
.PHONY: check-gh-actions
305314
check-gh-actions: check-compatibility $(ACTION_VALIDATOR)
306315
for i in $$(ls .github/workflows/*); do $(ACTION_VALIDATOR) $$i; done
@@ -483,7 +492,7 @@ $(BATS):
483492
rm -rf bats-core
484493

485494
.PHONY: check-blackbox-prerequisites
486-
check-blackbox-prerequisites: check-linux check-skopeo $(BATS) $(REGCLIENT) $(ORAS) $(HELM) $(CRICTL) $(NOTATION) $(COSIGN) $(STACKER)
495+
check-blackbox-prerequisites: check-linux check-skopeo $(BATS) $(REGCLIENT) $(ORAS) $(HELM) $(CRICTL) $(NOTATION) $(COSIGN) $(STACKER) $(CRYPTO_TEST)
487496
which skopeo && skopeo --version; \
488497
which stacker && stacker --version; \
489498
which regctl && regctl version; \

test/blackbox/hash.bats

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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

Comments
 (0)