From b13332c991ce2695626eaca367dd8208b174c9ca Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 14 Apr 2016 17:59:24 +0300 Subject: Add support for repository authentication --- tests/test.sh | 398 +++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 284 insertions(+), 114 deletions(-) (limited to 'tests/test.sh') diff --git a/tests/test.sh b/tests/test.sh index 0cdcd4f..84ad8be 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -13,7 +13,7 @@ # --remote # Test using the remote repositories. Normally, you would first run the # local test in order to create the repositories, then publish them (see -# repository/publish.sh), and finally run the remote test. +# pkg/publish.sh), and finally run the remote test. # # --valgrind # Run under valgrind (takes forever). @@ -79,15 +79,18 @@ fi bpkg="$bpkg $options" -# Repository location, name, and absolute location prefixes. +# Repository location, name, and absolute location prefixes. Note that the +# local path is carefully crafted so that we end up with the same repository +# names in both cases. This is necessary for the authentication tests to work +# in both cases. # if [ "$remote" = "y" ]; then - rep=https://build2.org/pkg/1/tests - repn=build2.org/tests/ + rep=https://build2.org/bpkg/1 + repn=build2.org/ repa=$rep else - rep=repository/1 - repn=`pwd`/repository/ + rep=pkg/1/build2.org + repn=build2.org/ repa=`pwd`/$rep fi @@ -104,6 +107,11 @@ function test () ops="-d $cfg" fi + if [ "$cmd" = "cfg-fetch" -o \ + "$cmd" = "rep-info" ]; then + ops="$ops --auth all" + fi + if [ -t 0 ]; then $bpkg $cmd $ops $* else @@ -129,6 +137,11 @@ function fail () ops="-d $cfg" fi + if [ "$cmd" = "cfg-fetch" -o \ + "$cmd" = "rep-info" ]; then + ops="$ops --auth all" + fi + if [ "$verbose" = "y" ]; then $bpkg $cmd $ops $* else @@ -164,6 +177,24 @@ function gone () #if false; then +# Repository certificate fingerprint. +# +function rep_cert_fp () +{ + cat $1/repositories | \ + sed -n '/^-----BEGIN CERTIFICATE-----$/,/^-----END CERTIFICATE-----$/p' | \ + openssl x509 -sha256 -noout -fingerprint | \ + sed -n 's/^SHA256 Fingerprint=\(.*\)$/\1/p' +} + +# Edit file with sed. +# +function edit () +{ + local path=$1; shift + sed "$@" $path > $path.bak + mv $path.bak $path +} ## ## Low-level commands. @@ -175,25 +206,25 @@ function gone () ## fail pkg-verify # archive expected fail pkg-verify ./no-such-file # archive does not exist -fail pkg-verify repository/1/common/not-a-package.tar.gz -fail pkg-verify --silent repository/1/common/not-a-package.tar.gz -test pkg-verify repository/1/common/hello/libhello-1.0.0+1.tar.gz +fail pkg-verify pkg/1/build2.org/common/not-a-package.tar.gz +fail pkg-verify --silent pkg/1/build2.org/common/not-a-package.tar.gz +test pkg-verify pkg/1/build2.org/common/hello/libhello-1.0.0+1.tar.gz ## ## rep-create ## -fail rep-create # no 'repositories' file -fail rep-create repository/1/satisfy # unexpected files +fail rep-create # no 'repositories' file +fail rep-create pkg/1/build2.org/satisfy # unexpected files -test rep-create repository/1/common/hello +test rep-create pkg/1/build2.org/common/hello --key key.pem -test rep-create repository/1/common/foo/stable -test rep-create repository/1/common/foo/testing +test rep-create pkg/1/build2.org/common/foo/stable +test rep-create pkg/1/build2.org/common/foo/testing -test rep-create repository/1/common/bar/stable -test rep-create repository/1/common/bar/testing -test rep-create repository/1/common/bar/unstable +test rep-create pkg/1/build2.org/common/bar/stable +test rep-create pkg/1/build2.org/common/bar/testing +test rep-create pkg/1/build2.org/common/bar/unstable ## @@ -201,13 +232,13 @@ test rep-create repository/1/common/bar/unstable ## fail rep-info # repository location expected -test rep-info $rep/common/foo/testing <= 1.1.0) # -test rep-create repository/1/satisfy/t4a -test rep-create repository/1/satisfy/t4b -test rep-create repository/1/satisfy/t4c -test rep-create repository/1/satisfy/t4d +test rep-create pkg/1/build2.org/satisfy/t4a +test rep-create pkg/1/build2.org/satisfy/t4b +test rep-create pkg/1/build2.org/satisfy/t4c +test rep-create pkg/1/build2.org/satisfy/t4d test cfg-create --wipe test cfg-add $rep/satisfy/t4c -test cfg-fetch +test cfg-fetch --trust-yes test pkg-build -p libbaz <> pkg/1/build2.org/auth/signature-mismatch/signature << EOF +signature: \\ +XBjnmXXVHY0RqMI0gL/P4t/vuWwK9JJkLl4Qf2gMxq5k2WQ2CIE56DfG0RaGklgKcI3UxsQZvMQI +5PNtAHJDjteQ+BqY0io8A43KPX+2LKMU+I825sKmPRjCLYleGM3mNndDkWfYtAzYk5AmR2piqRz0 +D7CLq9GIoQQZO4Fw44muaQDMCRcXy8Txx2jDnretQjx/C0ZQw4M/cd6/cKEKUmLITDkBig9oVlSh +tpxHqWz5NTbO3vm8ILc03AwiOJHwZweLb6ocJ6a467IJa+F/xUm9B09k8wFWMs+jHXXzHDE0syv7 +lqWL7SvHSjVFrGVFKS6nx7lCj2b8XFiGlwWIwjY4m/VK/5QmbL/lC4f+ww5XT5NG5iYh/eMaCxCJ +zTg5iZsWNLhrx9uKNrL5xC4z0OONRVOwzu7gsqr0GLWewPyhH0AqJLgOSkw9N7FJwbv2IKNZ88YA +u2YMXNkXytcQvENLVQDX5oxvUMEurUJFOCuYB/SEnpcwkV5h9RtXzIFVy4OCTU2MhQHDEldI8s7w +Hga/ct4WupgE228gGdgwJLCbHx6AWBlS9iL10AdS8JkQ9LaZwTMHHz44f8y00X4MiT06gpgDeoQD +rUyP0KNG65tdWnVTMqg6Q/YXhtRZLHoD6+QbiYLlruR1phu4y4fDt7AKxoXfeme/a86A37UogZY= +\\ +EOF + +# cfg-fetch +# +test cfg-create --wipe +test cfg-add $rep/auth/signed +test cfg-fetch --trust `rep_cert_fp pkg/1/build2.org/auth/signed` +test cfg-fetch +test cfg-fetch --trust-no # certificate is already trusted + +test cfg-create --wipe +test cfg-add $rep/auth/signed +test cfg-fetch --trust-yes +test cfg-fetch + +test cfg-create --wipe +test cfg-add $rep/auth/signed +fail cfg-fetch --trust-no + +test cfg-create --wipe +test cfg-add $rep/auth/signed +fail cfg-fetch --trust-yes --trust-no # inconsistent options + +test cfg-create --wipe +test cfg-add $rep/auth/unsigned1 +test cfg-fetch --trust-yes +test cfg-fetch +test cfg-add $rep/auth/unsigned2 +test cfg-fetch +test cfg-fetch --trust-no # certificates are already trusted + +test cfg-create --wipe +test cfg-add $rep/auth/unsigned1 +fail cfg-fetch --trust-no + +test cfg-create --wipe +test cfg-add $rep/auth/name-mismatch +fail cfg-fetch --trust-yes # certificate name mismatch + +test cfg-create --wipe +test cfg-add $rep/auth/expired +fail cfg-fetch --trust-yes # certificate expired + +test cfg-create --wipe +test cfg-add $rep/auth/sha256sum-mismatch +fail cfg-fetch --trust-yes # packages file checksum mismatch + +test cfg-create --wipe +test cfg-add $rep/auth/signature-mismatch +fail cfg-fetch --trust-yes # packages file signature:mismatch + +# rep-info +# +test cfg-create --wipe +test rep-info --trust-yes -d $cfg $rep/auth/signed <