-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtest.sh
executable file
·253 lines (177 loc) · 8.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
set -e
# build image
docker build -t supertokens-mysql:circleci .
test_equal () {
if [[ $1 -ne $2 ]]
then
printf "\x1b[1;31merror\x1b[0m from test_equal in $3\n"
exit 1
fi
}
no_of_running_containers () {
docker ps -q | wc -l
}
test_hello () {
message=$1
STATUS_CODE=$(curl -I -X GET http://127.0.0.1:3567/hello -o /dev/null -w '%{http_code}\n' -s)
if [[ $STATUS_CODE -ne "200" ]]
then
printf "\x1b[1;31merror\xd1b[0m from test_hello in $message\n"
exit 1
fi
}
test_session_post () {
message=$1
STATUS_CODE=$(curl -X POST http://127.0.0.1:3567/recipe/session -H "Content-Type: application/json" -d '{
"userId": "testing",
"userDataInJWT": {},
"userDataInDatabase": {},
"enableAntiCsrf": true
}' -o /dev/null -w '%{http_code}\n' -s)
if [[ $STATUS_CODE -ne "200" ]]
then
printf "\x1b[1;31merror\xd1b[0m from test_session_post in $message\n"
exit 1
fi
}
test_signup_post () {
message=$1
STATUS_CODE=$(curl -X POST http://127.0.0.1:3567/recipe/signup -H "Content-Type: application/json" -d '{
"email": "[email protected]",
"password": "testpassword"
}' -o /dev/null -w '%{http_code}\n' -s)
if [[ $STATUS_CODE -ne "200" ]]
then
printf "\x1b[1;31merror\xd1b[0m from test_signup_post in $message\n"
exit 1
fi
}
test_signin_post () {
message=$1
STATUS_CODE=$(curl -X POST http://127.0.0.1:3567/recipe/signin -H "Content-Type: application/json" -d '{
"email": "[email protected]",
"password": "testpassword"
}' -o /dev/null -w '%{http_code}\n' -s)
if [[ $STATUS_CODE -ne "200" ]]
then
printf "\x1b[1;31merror\xd1b[0m from test_signin_post in $message\n"
exit 1
fi
}
test_argon2_hash_format () {
message=$1
result=$(docker exec -it mysql mysql -u root -proot "supertokens" -e "select password_hash from emailpassword_users where email = '[email protected]'")
if [[ "$result" != "$argon2"* ]] # doesn't start with $argon2
then
printf "\x1b[1;31merror\xd1b[0m from test_argon2_hash_format in $message\n"
exit 1
fi
}
test_not_argon2_hash_format () {
message=$1
result=$(docker exec -it mysql mysql -u root -proot "supertokens" -e "select password_hash from emailpassword_users where email = '[email protected]'")
if [[ "$result" =~ \$argon2* ]] # starts with $argon2
then
printf "\x1b[1;31merror\xd1b[0m from test_not_argon2_hash_format in $message\n"
exit 1
fi
}
no_of_containers_running_at_start=`no_of_running_containers`
# start mysql server
docker run -e DISABLE_TELEMETRY=true --rm -d -p 3306:3306 --name mysql -e MYSQL_ROOT_PASSWORD=root mysql
sleep 26s
docker exec mysql mysql -u root --password=root -e "CREATE DATABASE supertokens;"
# setting network options for testing
OS=`uname`
MYSQL_IP=$(ip a | grep -E "([0-9]{1,3}\.){3}[0-9]{1,3}" | grep -v 127.0.0.1 | awk '{ print $2 }' | cut -f2 -d: | head -n1 | grep -o -E "([0-9]{1,3}\.){3}[0-9]{1,3}")
NETWORK_OPTIONS="-p 3567:3567 -e MYSQL_HOST=$MYSQL_IP"
NETWORK_OPTIONS_CONNECTION_URI="-p 3567:3567 -e MYSQL_CONNECTION_URI=mysql://root:root@$MYSQL_IP:3306"
printf "\nmysql_host: \"$MYSQL_IP\"" >> $PWD/config.yaml
#---------------------------------------------------
# start with no network options
docker run -e DISABLE_TELEMETRY=true --rm -d --name supertokens supertokens-mysql:circleci --no-in-mem-db
sleep 10s
test_equal `no_of_running_containers` $((no_of_containers_running_at_start+1)) "start with no network options"
#---------------------------------------------------
# start with no network options, but in mem db
docker run -e DISABLE_TELEMETRY=true -p 3567:3567 --rm -d --name supertokens supertokens-mysql:circleci
sleep 17s
test_equal `no_of_running_containers` $((no_of_containers_running_at_start+2)) "start with no network options, but in mem db"
test_hello "start with no network options, but in mem db"
test_session_post "start with no network options, but in mem db"
docker rm supertokens -f
#---------------------------------------------------
# start with mysql password
docker run -e DISABLE_TELEMETRY=true $NETWORK_OPTIONS -e MYSQL_PASSWORD=root --rm -d --name supertokens supertokens-mysql:circleci --no-in-mem-db
sleep 10s
test_equal `no_of_running_containers` $((no_of_containers_running_at_start+1)) "start with mysql password"
#---------------------------------------------------
# start with mysql user
docker run -e DISABLE_TELEMETRY=true $NETWORK_OPTIONS -e MYSQL_USER=root --rm -d --name supertokens supertokens-mysql:circleci --no-in-mem-db
sleep 10s
test_equal `no_of_running_containers` $((no_of_containers_running_at_start+1)) "start with mysql user"
#---------------------------------------------------
# start with mysql user, mysql password
docker run -e DISABLE_TELEMETRY=true $NETWORK_OPTIONS -e MYSQL_USER=root -e MYSQL_PASSWORD=root --rm -d --name supertokens supertokens-mysql:circleci --no-in-mem-db
sleep 17s
test_equal `no_of_running_containers` $((no_of_containers_running_at_start+2)) "start with mysql user, mysql password"
test_hello "start with mysql user, mysql password"
test_session_post "start with mysql user, mysql password"
docker rm supertokens -f
#---------------------------------------------------
# start with mysql connectionURI
docker run -e DISABLE_TELEMETRY=true $NETWORK_OPTIONS_CONNECTION_URI --rm -d --name supertokens supertokens-mysql:circleci --no-in-mem-db
sleep 17s
test_equal `no_of_running_containers` $((no_of_containers_running_at_start+2)) "start with mysql connectionURI"
test_hello "start with mysql connectionURI"
test_session_post "start with mysql connectionURI"
docker rm supertokens -f
#---------------------------------------------------
# start by sharing config.yaml
docker run -e DISABLE_TELEMETRY=true $NETWORK_OPTIONS -v $PWD/config.yaml:/usr/lib/supertokens/config.yaml --rm -d --name supertokens supertokens-mysql:circleci --no-in-mem-db
sleep 17s
test_equal `no_of_running_containers` $((no_of_containers_running_at_start+2)) "start by sharing config.yaml"
test_hello "start by sharing config.yaml"
test_session_post "start by sharing config.yaml"
docker rm supertokens -f
# ---------------------------------------------------
# test info path
#making sure that the user in the container has rights to the mounted volume
mkdir $PWD/sthome
chmod a+rw sthome
docker run -e DISABLE_TELEMETRY=true $NETWORK_OPTIONS -v $PWD/sthome:/home/supertokens -e MYSQL_USER=root -e MYSQL_PASSWORD=root -e INFO_LOG_PATH=/home/supertokens/info.log -e ERROR_LOG_PATH=/home/supertokens/error.log --rm -d --name supertokens supertokens-mysql:circleci --no-in-mem-db
sleep 17s
test_equal `no_of_running_containers` $((no_of_containers_running_at_start+2)) "test info path"
test_hello "test info path"
test_session_post "test info path"
if [[ ! -f $PWD/sthome/info.log || ! -f $PWD/sthome/error.log ]]
then
exit 1
fi
docker rm supertokens -f
git checkout $PWD/config.yaml
#---------------------------------------------------
# test --read-only
docker run --read-only -e DISABLE_TELEMETRY=true $NETWORK_OPTIONS_CONNECTION_URI --tmpfs=/lib/supertokens/temp/:exec --rm -d --name supertokens supertokens-mysql:circleci --no-in-mem-db
sleep 17s
test_equal `no_of_running_containers` $((no_of_containers_running_at_start+2)) "test --read-only"
test_hello "test --read-only"
test_session_post "test --read-only"
test_signup_post "test --read-only"
test_not_argon2_hash_format "test --read-only"
test_signin_post "test --read-only"
docker rm supertokens -f
#---------------------------------------------------
# test --read-only ARGON2
docker run --read-only -e DISABLE_TELEMETRY=true $NETWORK_OPTIONS_CONNECTION_URI -e PASSWORD_HASHING_ALG=ARGON2 --tmpfs=/lib/supertokens/temp/:exec --rm -d --name supertokens supertokens-mysql:circleci --no-in-mem-db
sleep 17s
test_equal `no_of_running_containers` $((no_of_containers_running_at_start+2)) "test --read-only ARGON2"
test_hello "test --read-only ARGON2"
test_session_post "test --read-only ARGON2"
test_signup_post "test --read-only ARGON2"
test_argon2_hash_format "test --read-only ARGON2"
test_signin_post "test --read-only ARGON2"
docker rm supertokens -f
docker rm mysql -f
printf "\x1b[1;32m%s\x1b[0m\n" "success"
exit 0