forked from airbytehq/airbyte-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
executable file
·140 lines (120 loc) · 4.19 KB
/
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/bin/bash
NAME="airbyte-proxy-test-container"
BASIC_AUTH_USERNAME=airbyte
BASIC_AUTH_PASSWORD=password
BASIC_AUTH_UPDATED_PASSWORD=pa55w0rd
BASIC_AUTH_PROXY_TIMEOUT=120
if [[ -z "${DAGGER}" ]]; then
# If DAGGER env variable is not set
TEST_HOST_AUTH="localhost"
TEST_HOST_NEWAUTH="localhost"
TEST_HOST_NOAUTH="localhost"
else
# If DAGGER env variable is set, set TEST_HOST based on the test section
# These correspond to the hostnames we spin up in the dagger config
TEST_HOST_AUTH="airbyte-proxy-test-container"
TEST_HOST_NEWAUTH="airbyte-proxy-test-container-newauth"
TEST_HOST_NOAUTH="airbyte-proxy-test-container-noauth"
fi
VERSION="${VERSION:-dev}" # defaults to "dev", otherwise it is set by environment's $VERSION
echo "testing with proxy container airbyte/proxy:$VERSION"
function start_container () {
CMD="docker run -d -p $1:8000 --env BASIC_AUTH_USERNAME=$2 --env BASIC_AUTH_PASSWORD=$3 --env BASIC_AUTH_PROXY_TIMEOUT=$4 --env PROXY_PASS_WEB=http://localhost --env PROXY_PASS_API=http://localhost --env CONNECTOR_BUILDER_SERVER_API=http://localhost --env PROXY_PASS_AIRBYTE_API_SERVER=http://localhost --name $NAME-$1 airbyte/proxy:$VERSION"
echo $CMD
eval $CMD
wait_for_docker $NAME-$1;
}
function stop_container () {
echo "Stopping $1"
docker kill $1
docker rm $1
}
function wait_for_docker() {
until [ "`docker inspect -f {{.State.Running}} $1`"=="true" ]; do
sleep 1;
done;
sleep 1;
}
# If using Dagger in CI, we manage the lifecycle of the containers through that
# and assume they are already up. We also don't care if the service itself is up,
# only that the proxy is working.
# Here we preserve the old way for backwards compatibility
echo "Testing airbyte proxy..."
# Start container with port 8000
if [[ -z "$DAGGER" ]]; then
start_container 8000 $BASIC_AUTH_USERNAME $BASIC_AUTH_PASSWORD $BASIC_AUTH_PROXY_TIMEOUT
fi
# Test on port 8000
echo "Testing access without auth"
RESPONSE=`curl "http://$TEST_HOST_AUTH:8000" -i -v`
if [[ $RESPONSE == *"401 Unauthorized"* ]]; then
echo "✔️ access without auth blocked"
else
echo "Auth not working"
echo $RESPONSE
exit 1
fi
echo "Testing access with auth"
RESPONSE=`curl "http://$BASIC_AUTH_USERNAME:$BASIC_AUTH_PASSWORD@$TEST_HOST_AUTH:8000" -i -v`
if [[ $RESPONSE != *"401 Unauthorized"* ]]; then
echo "✔️ access with auth worked"
else
echo "Auth not working"
echo $RESPONSE
exit 1
fi
# Start container with updated password on port 8001
if [[ -z "$DAGGER" ]]; then
stop_container $NAME-8000
start_container 8001 $BASIC_AUTH_USERNAME $BASIC_AUTH_UPDATED_PASSWORD $BASIC_AUTH_PROXY_TIMEOUT
fi
# Test on port 8001
echo "Testing access with original password"
RESPONSE=`curl "http://$BASIC_AUTH_USERNAME:$BASIC_AUTH_PASSWORD@$TEST_HOST_NEWAUTH:8001" -i -v`
if [[ $RESPONSE == *"401 Unauthorized"* ]]; then
echo "✔️ access with original auth blocked"
else
echo "Auth not working"
echo $RESPONSE
exit 1
fi
echo "Testing access updated auth"
RESPONSE=`curl "http://$BASIC_AUTH_USERNAME:$BASIC_AUTH_UPDATED_PASSWORD@$TEST_HOST_NEWAUTH:8001" -i -v`
if [[ $RESPONSE != *"401 Unauthorized"* ]]; then
echo "✔️ access with updated auth worked"
else
echo "Auth not working"
echo $RESPONSE
exit 1
fi
# Start container with no password on port 8002
if [[ -z "$DAGGER" ]]; then
stop_container $NAME-8001
start_container 8002 "" ""
fi
# Test on port 8002
echo "Testing access without auth"
RESPONSE=`curl "http://$TEST_HOST_NOAUTH:8002" -i -v`
if [[ $RESPONSE != *"401 Unauthorized"* ]]; then
echo "✔️ access without auth allowed when configured"
else
echo "Auth not working"
echo $RESPONSE
exit 1
fi
if [[ -z "$DAGGER" ]]; then
stop_container $NAME-8002
fi
# TODO: We can't test external URLs without a resolver, but adding a resolver that isn't dynamic+local doesn't work with docker.
# echo "Testing that PROXY_PASS can be used to change the backend"
# start_container_with_proxy "http://www.google.com"
# RESPONSE=`curl "http://$TEST_HOST:$PORT" -i --silent`
# if [[ $RESPONSE == *"google.com"* ]]; then
# echo "✔️ proxy backends can be changed"
# else
# echo "Proxy update not working"
# echo $RESPONSE
# exit 1
# fi
echo "Tests Passed ✅"
exit 0