-
-
Notifications
You must be signed in to change notification settings - Fork 930
/
run.sh
executable file
·217 lines (171 loc) · 6.23 KB
/
run.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
#!/bin/bash
set -euxo pipefail
cd "$( dirname "${BASH_SOURCE[0]}" )/../.."
make .bin/hydra
make .bin/yq
export PATH=.bin:$PATH
export KRATOS_PUBLIC_URL=http://127.0.0.1:4433/
export KRATOS_ADMIN_URL=http://127.0.0.1:4434/
if [ -z ${TEST_DATABASE_POSTGRESQL+x} ]; then
docker rm -f kratos_test_database_mysql kratos_test_database_postgres kratos_test_database_cockroach || true
docker run --name kratos_test_database_mysql -p 3444:3306 -e MYSQL_ROOT_PASSWORD=secret -d mysql:5.7
docker run --name kratos_test_database_postgres -p 3445:5432 -e POSTGRES_PASSWORD=secret -e POSTGRES_DB=postgres -d postgres:9.6 postgres -c log_statement=all
docker run --name kratos_test_database_cockroach -p 3446:26257 -d cockroachdb/cockroach:v20.1.1 start --insecure
export TEST_DATABASE_MYSQL="mysql://root:secret@(127.0.0.1:3444)/mysql?parseTime=true&multiStatements=true"
export TEST_DATABASE_POSTGRESQL="postgres://postgres:secret@127.0.0.1:3445/postgres?sslmode=disable"
export TEST_DATABASE_COCKROACHDB="cockroach://root@127.0.0.1:3446/defaultdb?sslmode=disable"
fi
! nc -zv 127.0.0.1 4434
! nc -zv 127.0.0.1 4433
! nc -zv 127.0.0.1 4455
base=$(pwd)
if [ -z ${KRATOS_APP_PATH+x} ]; then
dir="$(mktemp -d -t ci-XXXXXXXXXX)/kratos-selfservice-ui-node"
git clone git@github.com:ory/kratos-selfservice-ui-node.git "$dir"
(cd "$dir"; npm i && npm run build)
else
dir="${KRATOS_APP_PATH}"
fi
kratos=./test/e2e/.bin/kratos
go build -tags sqlite -o $kratos .
if [ -z ${CI+x} ]; then
docker rm mailslurper hydra hydra-ui -f || true
docker run --name mailslurper -p 4436:4436 -p 4437:4437 -p 1025:1025 oryd/mailslurper:latest-smtps > "${base}/test/e2e/mailslurper.e2e.log" 2>&1 &
fi
dev=no
for i in "$@"
do
case $i in
--dev)
dev=yes
shift # past argument=value
;;
esac
done
run() {
profile=$2
killall kratos || true
killall node || true
killall hydra || true
killall hydra-login-consent || true
DSN=memory URLS_SELF_ISSUER=http://127.0.0.1:4444 \
URLS_LOGIN=http://127.0.0.1:4446/login \
URLS_CONSENT=http://127.0.0.1:4446/consent \
hydra serve all --dangerous-force-http > "${base}/test/e2e/hydra.e2e.log" 2>&1 &
hydra clients create \
--endpoint http://127.0.0.1:4445 \
--id kratos-client \
--secret kratos-secret \
--grant-types authorization_code,refresh_token \
--response-types code,id_token \
--scope openid,offline \
--callbacks http://127.0.0.1:4455/.ory/kratos/public/self-service/browser/flows/strategies/oidc/callback/hydra
hydra clients create \
--endpoint http://127.0.0.1:4445 \
--id google-client \
--secret kratos-secret \
--grant-types authorization_code,refresh_token \
--response-types code,id_token \
--scope openid,offline \
--callbacks http://127.0.0.1:4455/.ory/kratos/public/self-service/browser/flows/strategies/oidc/callback/google
hydra clients create \
--endpoint http://127.0.0.1:4445 \
--id github-client \
--secret kratos-secret \
--grant-types authorization_code,refresh_token \
--response-types code,id_token \
--scope openid,offline \
--callbacks http://127.0.0.1:4455/.ory/kratos/public/self-service/browser/flows/strategies/oidc/callback/github
if [ -z ${KRATOS_APP_PATH+x} ]; then
(cd "$dir"; PORT=4455 SECURITY_MODE=cookie npm run serve \
> "${base}/test/e2e/secureapp.e2e.log" 2>&1 &)
else
(cd "$dir"; PORT=4455 SECURITY_MODE=cookie npm run start \
> "${base}/test/e2e/secureapp.e2e.log" 2>&1 &)
fi
(cd test/e2e/hydra-login-consent; \
go build . && \
PORT=4446 HYDRA_ADMIN_URL=http://127.0.0.1:4445 ./hydra-login-consent > "${base}/test/e2e/hydra-ui.e2e.log" 2>&1 &)
export DSN=${1}
if [ "$DSN" != "memory" ]; then
$kratos migrate sql -e --yes
fi
yq merge test/e2e/profiles/kratos.base.yml "test/e2e/profiles/${profile}/.kratos.yml" > test/e2e/kratos.generated.yml
($kratos serve --dev -c test/e2e/kratos.generated.yml > "${base}/test/e2e/kratos.${profile}.e2e.log" 2>&1 &)
npm run wait-on -- -t 10000 http-get://127.0.0.1:4434/health/ready \
http-get://127.0.0.1:4455/health \
http-get://127.0.0.1:4445/health/ready \
http-get://127.0.0.1:4446/ \
http-get://127.0.0.1:4437/mail
if [[ $dev = "yes" ]]; then
npm run test:watch -- --config integrationFolder="test/e2e/cypress/integration/profiles/$profile"
else
npm run test -- --config integrationFolder="test/e2e/cypress/integration/profiles/$profile"
fi
}
usage() {
echo $"This script runs the e2e tests.
To run the tests just pick a database name:
$0 <database>
Supported databases are 'sqlite', 'mysql', 'postgres', 'cockroach':
$0 sqlite
$0 mysql
$0 postgres
$0 cockroach
...
If you are using a database other than SQLite, you need to set
an environment variable that points to it:
export TEST_DATABASE_MYSQL=...
export TEST_DATABASE_POSTGRESQL=...
export TEST_DATABASE_COCKROACHDB=...
$0 <database>
The Makefile has a helper for that which uses Docker to start the
databases:
make test-resetdb
source scripts/test-envs.sh
$0 <database>
To run e2e tests in dev mode (useful for writing them), run:
$0 --dev <database> <profile>
Supported profiles are 'email', 'verification', 'oidc', 'recovery':
$0 --dev <database> email
$0 --dev <database> verification
...
If you are making changes to the kratos-selfservice-ui-node
project as well, point the 'KRATOS_APP_PATH' environment variable to
the path where the kratos-selfservice-ui-node project is checked out:
export KRATOS_APP_PATH=$HOME/workspace/kratos-selfservice-ui-node
$0 ..."
}
if [[ $dev = "yes" ]]; then
if [ -z ${2+x} ]; then
usage
exit 1
fi
fi
export TEST_DATABASE_SQLITE="sqlite:///$(mktemp -d -t ci-XXXXXXXXXX)/db.sqlite?_fk=true"
export TEST_DATABASE_MEMORY="memory"
case "$1" in
sqlite)
db="${TEST_DATABASE_SQLITE}"
;;
mysql)
db="${TEST_DATABASE_MYSQL}"
;;
postgres)
db="${TEST_DATABASE_POSTGRESQL}"
;;
cockroach)
db="${TEST_DATABASE_COCKROACHDB}"
;;
*)
usage
exit 1
esac
if [[ $dev = "yes" ]]; then
run "${db}" "$2"
else
run "${db}" email
run "${db}" verification
run "${db}" oidc
run "${db}" recovery
fi