forked from edgd1er/nordvpn-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.sh
74 lines (64 loc) · 1.81 KB
/
tests.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
#!/usr/bin/env bash
set -e -u -o pipefail
#var
PROXY_HOST="localhost"
HTTP_PORT=88$(grep -oP '(?<=\- "88)[^:]+' docker-compose.yml)
SOCK_PORT=10$(grep -oP '(?<=\- "10)[^:]+' docker-compose.yml)
FAILED=0
INTERVAL=4
#Functions
buildAndWait() {
echo "Stopping and removing running containers"
docker compose down -v
echo "Building and starting image"
docker compose -f docker-compose.yml up -d --build
echo "Waiting for the container to be up.(every ${INTERVAL} sec)"
logs=""
n=0
while [ 0 -eq $(echo $logs | grep -c "Initialization Sequence Completed") ]; do
logs="$(docker compose logs)"
sleep ${INTERVAL}
((n+=1))
echo "loop: ${n}"
[[ ${n} -eq 15 ]] && break || true
done
docker compose logs
}
#Main
[[ -z $(which nc) ]] && echo "No nc found" && exit || true
if [[ ${HTTP_PORT} -eq 88 ]] || [[ ${SOCK_PORT} -eq 10 ]]; then
echo no docker-compose.yml found
exit
fi
if [[ "-t" != ${1:-''} ]]; then
[[ "localhost" == ${PROXY_HOST} ]] && buildAndWait
fi
for PORT in ${HTTP_PORT} ${SOCK_PORT}; do
msg="Test connection to port ${PORT}: "
if [ 0 -eq $(echo "" | nc -v -q 2 ${PROXY_HOST} ${PORT} 2>&1 | grep -c "] succeeded") ]; then
msg+=" Failed"
((FAILED += 1))
else
msg+=" OK"
fi
echo -e "$msg"
done
IP=$(curl -sqx http://${PROXY_HOST}:${HTTP_PORT} "https://ifconfig.me/ip")
if [[ $? -eq 0 ]]; then
echo "IP is ${IP}"
else
echo "curl through http proxy to https://ifconfig.me/ip failed"
((FAILED += 1))
fi
IP=$(curl -sqx socks5://${PROXY_HOST}:${SOCK_PORT} "https://ifconfig.me/ip")
if [[ $? -eq 0 ]]; then
echo "IP is ${IP}"
else
echo "curl through socks proxy to https://ifconfig.me/ip failed"
((FAILED += 1))
fi
if [[ "-t" != ${1:-''} ]]; then
[[ "localhost" == ${PROXY_HOST} ]] && docker compose down
fi
echo "# failed tests: ${FAILED}"
exit ${FAILED}