forked from conda/conda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproxy-test.sh
110 lines (86 loc) · 3.95 KB
/
proxy-test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/bin/sh
set -uo pipefail
# Invoke with:
# $ bash ./tests/integration/proxy/proxy-test.sh
#
# NOTES:
# * PWD should be the conda project root
# * docker is required, and executable without sudo
# * squidusers file has condauser:condapass for credentials
# * to look at logs for squid proxy, use:
# $ cat ./tests/integration/proxy/squid_log/*
#
# REFERENCES:
# https://veesp.com/en/blog/squid-authentication
# https://wiki.squid-cache.org/Features/Authentication
SRC_DIR="$PWD"
[ -f "$SRC_DIR/conda/__main__.py" ] && [ -f "$SRC_DIR/conftest.py" ] || (echo "Current working directory must be conda project root." && exit 1)
which docker > /dev/null || (echo "docker required but not found" && exit 1)
docker --version > /dev/null || (echo "Cannot execute docker. Apparently needs sudo?" && exit 1)
rm -rf "$SRC_DIR"/tests/integration/proxy/squid_log/*
CID=$(docker run \
--detach \
--rm \
-v $SRC_DIR/tests/integration/proxy/squid.conf:/etc/squid/squid.conf:ro \
-v $SRC_DIR/tests/integration/proxy/squidusers:/etc/squid/squidusers:ro \
-v $SRC_DIR/tests/integration/proxy/squid_log:/var/log/squid:rw \
-p 3128:3128 \
kalefranz/squid)
echo "waiting for proxy to start"
( tail -f -n0 "$SRC_DIR/tests/integration/proxy/squid_log/cache.log" & ) | grep -q "Accepting HTTP Socket connections at"
_fail() {
echo -e "$1"
echo "removing container $CID"
docker rm --force $CID > /dev/null
exit 1
}
# Don't use repodata Cache-Control
export CONDA_LOCAL_REPODATA_TTL=0
# Ensure we have an empty package cache
export CONDA_PKGS_DIRS="$SRC_DIR/tests/integration/proxy/temp"
mkdir -p "$CONDA_PKGS_DIRS" || _fail "permissions error"
touch "$CONDA_PKGS_DIRS/permissions-check" || _fail "permissions error"
rm -rf "$CONDA_PKGS_DIRS"/*
# ###########################################################
# Test that we have failures when directing traffic through proxy with wrong password
# ###########################################################
export CONDARC="$SRC_DIR/tests/integration/proxy/condarc.proxybad"
# test for repodata failure
echo "test expecting repodata failure"
captured="$(conda search zlib 2>&1)"
rc=$?
[ $rc -eq 1 ] || _fail "'conda search zlib' was expected to fail\n$captured"
rm -rf "$CONDA_PKGS_DIRS"/*
# test for package download failure
echo "test expecting package download failure"
captured="$(conda install --mkdir -y -q -p $CONDA_PKGS_DIRS/test-env https://repo.continuum.io/pkgs/main/osx-64/six-1.11.0-py36h0e22d5e_1.tar.bz2 2>&1)"
rc=$?
[ $rc -eq 1 ] || _fail "'conda install' was expected to fail\n$captured"
rm -rf "$CONDA_PKGS_DIRS"/*
# ###########################################################
# Test that directing traffic through proxy with correct password succeeds
# ###########################################################
export CONDARC="$SRC_DIR/tests/integration/proxy/condarc.proxygood"
# test for repodata success
echo "test expecting repodata success"
captured="$(conda search zlib 2>&1)"
rc=$?
[ $rc -eq 0 ] || _fail "'conda search zlib' was expected to succeed\n$captured"
echo "$captured" | grep -q 1.2.11 || _fail "'conda search zlib' was expected to contain zlib version 1.2.11"\n$captured
rm -rf "$CONDA_PKGS_DIRS"/*
# test for package download success
echo "test expecting package download success"
captured="$(conda install --mkdir -y -q -p $CONDA_PKGS_DIRS/test-env https://repo.continuum.io/pkgs/main/osx-64/six-1.11.0-py36h0e22d5e_1.tar.bz2 2>&1)"
rc=$?
[ $rc -eq 0 ] || _fail "'conda install' was expected to succeed\n$captured"
[ -f "$CONDA_PKGS_DIRS/test-env/conda-meta/history" ] || _fail "history file expected\n$captured"
[ -f "$CONDA_PKGS_DIRS/test-env/lib/python3.6/site-packages/six.py" ] || _fail "six.py file expected\n$captured"
rm -rf "$CONDA_PKGS_DIRS"/*
# ###########################################################
# clean up
# ###########################################################
echo "removing container $CID"
docker rm --force $CID > /dev/null
echo
echo ">>>>> ALL TESTS COMPLETED <<<<<"
echo