-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-workflow.sh
More file actions
executable file
·441 lines (406 loc) · 16.8 KB
/
test-workflow.sh
File metadata and controls
executable file
·441 lines (406 loc) · 16.8 KB
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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
#!/usr/bin/env bash
#
# EPP-CLI Integration Test Script
# ================================
# Runs a full lifecycle test: contacts, domains, updates, transfers, cleanup.
# Requires a working .env with valid EPP credentials.
#
# Usage: ./test-workflow.sh [epp-binary]
# epp-binary defaults to "php bin/epp"
set -euo pipefail
# ---------------------------------------------------------------------------
# Configuration
# ---------------------------------------------------------------------------
EPP="${1:-php bin/epp}"
TIMESTAMP=$(date +%s%N | cut -c1-16)
DOMAIN_PREFIX="epp-test-${TIMESTAMP}"
DOMAIN1="${DOMAIN_PREFIX}-1.at"
DOMAIN2="${DOMAIN_PREFIX}-2.at"
DOMAIN3="${DOMAIN_PREFIX}-3.at"
AUTHINFO="Test!Auth${TIMESTAMP}"
PASS=0
FAIL=0
TESTS=()
CONTACT_VR=""
# ---------------------------------------------------------------------------
# Helpers
# ---------------------------------------------------------------------------
green() { printf '\033[0;32m%s\033[0m\n' "$*"; }
red() { printf '\033[0;31m%s\033[0m\n' "$*"; }
yellow() { printf '\033[0;33m%s\033[0m\n' "$*"; }
bold() { printf '\033[1m%s\033[0m\n' "$*"; }
step() {
echo
bold "── $1 ──"
}
assert_success() {
local description="$1"
shift
local output
echo " → $description"
if output=$($EPP "$@" -n 2>&1); then
if echo "$output" | grep -q "^SUCCESS:"; then
green " ✓ PASS"
PASS=$((PASS + 1))
TESTS+=("PASS: $description")
echo "$output" | sed 's/^/ /'
LAST_OUTPUT="$output"
return 0
else
red " ✗ FAIL – command succeeded but no SUCCESS line found"
echo "$output" | sed 's/^/ /'
FAIL=$((FAIL + 1))
TESTS+=("FAIL: $description")
LAST_OUTPUT="$output"
return 1
fi
else
red " ✗ FAIL – command exited with non-zero status"
echo "$output" | sed 's/^/ /'
FAIL=$((FAIL + 1))
TESTS+=("FAIL: $description")
LAST_OUTPUT="$output"
return 1
fi
}
assert_failure() {
local description="$1"
shift
local output
echo " → $description"
if output=$($EPP "$@" -n 2>&1); then
if echo "$output" | grep -q "^FAILED:"; then
green " ✓ PASS (expected failure)"
PASS=$((PASS + 1))
TESTS+=("PASS: $description")
LAST_OUTPUT="$output"
return 0
else
red " ✗ FAIL – expected failure but got success"
echo "$output" | sed 's/^/ /'
FAIL=$((FAIL + 1))
TESTS+=("FAIL: $description")
LAST_OUTPUT="$output"
return 1
fi
else
green " ✓ PASS (expected failure)"
PASS=$((PASS + 1))
TESTS+=("PASS: $description")
LAST_OUTPUT="${output:-}"
return 0
fi
}
extract_handle() {
echo "$LAST_OUTPUT" | grep -oP '(?<=ATTR: ID: ).*' | head -1 | tr -d '[:space:]'
}
# ---------------------------------------------------------------------------
# Pre-flight
# ---------------------------------------------------------------------------
bold "╔══════════════════════════════════════════════════════════════╗"
bold "║ EPP-CLI Integration Test Suite ║"
bold "╠══════════════════════════════════════════════════════════════╣"
bold "║ Domains: $DOMAIN1"
bold "║ $DOMAIN2"
bold "║ $DOMAIN3"
bold "║ Binary: $EPP"
bold "╚══════════════════════════════════════════════════════════════╝"
step "1. Server Hello – verify connectivity"
assert_success "Connect to EPP server" server:hello || {
red "Cannot connect to EPP server. Aborting."
exit 1
}
# ---------------------------------------------------------------------------
# Phase 1: Check domain availability (should be available)
# ---------------------------------------------------------------------------
step "2. Check domain availability (expect available)"
assert_success "Check ${DOMAIN1} is available" domain:check --domain "$DOMAIN1" || true
assert_success "Check ${DOMAIN2} is available" domain:check --domain "$DOMAIN2" || true
assert_success "Check ${DOMAIN3} is available" domain:check --domain "$DOMAIN3" || true
# ---------------------------------------------------------------------------
# Phase 2: Create first contact (registrant)
# ---------------------------------------------------------------------------
step "3. Create Contact #1 (registrant)"
echo " → Create registrant contact"
CONTACT1=$($EPP contact:create \
--name "Test Registrant" \
--street "Teststrasse 1" \
--city "Wien" \
--postalcode "1010" \
--country "AT" \
--email "test-registrant-${TIMESTAMP}@example.at" \
--type privateperson \
--org "" \
--voice "+43.1234567" \
--fax "" \
--disclose-phone 1 \
--disclose-fax 1 \
--disclose-email 1 \
--output-handle-only \
-n 2>&1 | tr -d '[:space:]')
if [ -n "$CONTACT1" ]; then
green " ✓ PASS"
PASS=$((PASS + 1))
TESTS+=("PASS: Create registrant contact")
else
red " ✗ FAIL – no handle returned"
FAIL=$((FAIL + 1))
TESTS+=("FAIL: Create registrant contact")
red "Cannot create registrant contact. Aborting."
exit 1
fi
bold " Contact #1 handle: ${CONTACT1}"
# ---------------------------------------------------------------------------
# Phase 3: Create domains
# ---------------------------------------------------------------------------
step "4. Create domains"
assert_success "Create ${DOMAIN1}" \
domain:create \
--domain "$DOMAIN1" \
--nameserver "ns1.nic.at" --nameserver "ns2.nic.at" \
--registrant "$CONTACT1" \
--techc "$CONTACT1" \
--authinfo "$AUTHINFO" || true
assert_success "Create ${DOMAIN2}" \
domain:create \
--domain "$DOMAIN2" \
--nameserver "ns1.nic.at" --nameserver "ns2.nic.at" \
--registrant "$CONTACT1" \
--techc "$CONTACT1" \
--authinfo "$AUTHINFO" || true
assert_success "Create ${DOMAIN3}" \
domain:create \
--domain "$DOMAIN3" \
--nameserver "ns1.nic.at" --nameserver "ns2.nic.at" \
--registrant "$CONTACT1" \
--techc "$CONTACT1" \
--authinfo "$AUTHINFO" || true
# ---------------------------------------------------------------------------
# Phase 4: Get info on domains
# ---------------------------------------------------------------------------
step "5. Get domain info"
assert_success "Info on ${DOMAIN1}" domain:info --domain "$DOMAIN1" || true
assert_success "Info on ${DOMAIN2}" domain:info --domain "$DOMAIN2" || true
assert_success "Info on ${DOMAIN3}" domain:info --domain "$DOMAIN3" || true
# ---------------------------------------------------------------------------
# Phase 5: Update domains (add/remove nameservers, change auth)
# ---------------------------------------------------------------------------
step "6. Update domains"
assert_success "Add nameserver to ${DOMAIN1}" \
domain:update --domain "$DOMAIN1" \
--addns "ns3.nic.at" || true
assert_success "Change authinfo on ${DOMAIN2}" \
domain:update --domain "$DOMAIN2" \
--authinfo "NewAuth!${TIMESTAMP}" || true
# ---------------------------------------------------------------------------
# Phase 6: Delete one domain
# ---------------------------------------------------------------------------
step "7. Delete ${DOMAIN3}"
assert_success "Delete ${DOMAIN3}" \
domain:delete --domain "$DOMAIN3" --scheduledate now || true
# ---------------------------------------------------------------------------
# Phase 7: Update Contact #1
# ---------------------------------------------------------------------------
step "8. Update Contact #1"
assert_success "Update contact ${CONTACT1}" \
contact:update \
--id "$CONTACT1" \
--street "Neue Testgasse 42" \
--city "Graz" \
--postalcode "8010" || true
# ---------------------------------------------------------------------------
# Phase 8b: Verification report – create contact with report
# ---------------------------------------------------------------------------
step "9. Verification report – create contact with report"
VERIFICATION_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
echo " → Create contact with verification report"
CONTACT_VR=$($EPP contact:create \
--name "Test Verified" \
--street "Verifystrasse 1" \
--city "Innsbruck" \
--postalcode "6020" \
--country "AT" \
--email "test-verified-${TIMESTAMP}@example.at" \
--type privateperson \
--org "" \
--voice "+43.5551234" \
--fax "" \
--disclose-phone 1 \
--disclose-fax 1 \
--disclose-email 1 \
--verification-report-status success \
--verification-report-date "$VERIFICATION_DATE" \
--verification-report-reference "REF-${TIMESTAMP}" \
--verification-report-agent "Test Verification Agent" \
--output-handle-only \
-n 2>&1 | tr -d '[:space:]')
if [ -n "$CONTACT_VR" ]; then
green " ✓ PASS"
PASS=$((PASS + 1))
TESTS+=("PASS: Create contact with verification report")
else
red " ✗ FAIL – no handle returned"
FAIL=$((FAIL + 1))
TESTS+=("FAIL: Create contact with verification report")
fi
bold " Verified contact handle: ${CONTACT_VR}"
# ---------------------------------------------------------------------------
# Phase 8c: Verification report – update contact with report
# ---------------------------------------------------------------------------
step "10. Verification report – update contact with report"
assert_success "Update contact ${CONTACT1} with verification report" \
contact:update \
--id "$CONTACT1" \
--verification-report-status success \
--verification-report-date "$VERIFICATION_DATE" \
--verification-report-reference "UPD-REF-${TIMESTAMP}" \
--verification-report-agent "Update Verification Agent" || true
# ---------------------------------------------------------------------------
# Phase 8d: Verification report – missing date should fail
# ---------------------------------------------------------------------------
step "11. Verification report – missing date should fail"
assert_failure "Create contact with verification status but no date" \
contact:create \
--name "Test NoDate" \
--street "Failstrasse 1" \
--city "Wien" \
--postalcode "1010" \
--country "AT" \
--email "test-nodate-${TIMESTAMP}@example.at" \
--type privateperson \
--org "" \
--voice "" \
--fax "" \
--disclose-phone 1 \
--disclose-fax 1 \
--disclose-email 1 \
--verification-report-status success || true
assert_failure "Update contact with verification status but no date" \
contact:update \
--id "$CONTACT1" \
--verification-report-status failure || true
# ---------------------------------------------------------------------------
# Phase 8e: Get info on Contact #1
# ---------------------------------------------------------------------------
step "12. Get info on Contact #1"
assert_success "Info on contact ${CONTACT1}" \
contact:info --id "$CONTACT1" || true
# ---------------------------------------------------------------------------
# Phase 9: Create second contact
# ---------------------------------------------------------------------------
step "13. Create Contact #2 (new tech contact)"
echo " → Create tech contact"
CONTACT2=$($EPP contact:create \
--name "Test TechC" \
--street "Techstrasse 99" \
--city "Salzburg" \
--postalcode "5020" \
--country "AT" \
--email "test-techc-${TIMESTAMP}@example.at" \
--type organisation \
--org "Test Org GmbH" \
--voice "+43.9876543" \
--fax "" \
--disclose-phone 1 \
--disclose-fax 1 \
--disclose-email 1 \
--output-handle-only \
-n 2>&1 | tr -d '[:space:]')
if [ -n "$CONTACT2" ]; then
green " ✓ PASS"
PASS=$((PASS + 1))
TESTS+=("PASS: Create tech contact")
else
red " ✗ FAIL – no handle returned"
FAIL=$((FAIL + 1))
TESTS+=("FAIL: Create tech contact")
red "Cannot create second contact. Continuing anyway."
fi
bold " Contact #2 handle: ${CONTACT2}"
# ---------------------------------------------------------------------------
# Phase 10: Change registrant on DOMAIN1
# ---------------------------------------------------------------------------
step "14. Change registrant of ${DOMAIN1} to Contact #2"
if [ -n "$CONTACT2" ]; then
assert_success "Change registrant on ${DOMAIN1}" \
domain:update --domain "$DOMAIN1" \
--registrant "$CONTACT2" || true
else
yellow " Skipped – Contact #2 handle not available"
fi
# ---------------------------------------------------------------------------
# Phase 11: Change tech-c on DOMAIN2
# ---------------------------------------------------------------------------
step "15. Change tech-c on ${DOMAIN2}"
if [ -n "$CONTACT2" ]; then
assert_success "Add tech-c ${CONTACT2} to ${DOMAIN2}" \
domain:update --domain "$DOMAIN2" \
--addtechc "$CONTACT2" || true
assert_success "Remove old tech-c ${CONTACT1} from ${DOMAIN2}" \
domain:update --domain "$DOMAIN2" \
--deltechc "$CONTACT1" || true
else
yellow " Skipped – Contact #2 handle not available"
fi
# ---------------------------------------------------------------------------
# Phase 12: Get info on contacts and remaining domains
# ---------------------------------------------------------------------------
step "16. Final info queries"
assert_success "Info on contact ${CONTACT1}" contact:info --id "$CONTACT1" || true
if [ -n "$CONTACT2" ]; then
assert_success "Info on contact ${CONTACT2}" contact:info --id "$CONTACT2" || true
fi
assert_success "Info on ${DOMAIN1}" domain:info --domain "$DOMAIN1" || true
assert_success "Info on ${DOMAIN2}" domain:info --domain "$DOMAIN2" || true
# ---------------------------------------------------------------------------
# Phase 13: Cleanup – delete remaining domains
# ---------------------------------------------------------------------------
step "17. Cleanup – delete remaining domains"
assert_success "Delete ${DOMAIN1}" \
domain:delete --domain "$DOMAIN1" --scheduledate now || true
assert_success "Delete ${DOMAIN2}" \
domain:delete --domain "$DOMAIN2" --scheduledate now || true
# ---------------------------------------------------------------------------
# Phase 14: Verify domains are available again
# ---------------------------------------------------------------------------
step "18. Verify domains are available again"
assert_success "Check ${DOMAIN1} is available" domain:check --domain "$DOMAIN1" || true
assert_success "Check ${DOMAIN2} is available" domain:check --domain "$DOMAIN2" || true
assert_success "Check ${DOMAIN3} is available" domain:check --domain "$DOMAIN3" || true
# ---------------------------------------------------------------------------
# Phase 15: Cleanup – delete contacts
# ---------------------------------------------------------------------------
step "19. Cleanup – delete contacts"
assert_success "Delete contact ${CONTACT1}" contact:delete --id "$CONTACT1" || true
if [ -n "$CONTACT2" ]; then
assert_success "Delete contact ${CONTACT2}" contact:delete --id "$CONTACT2" || true
fi
if [ -n "$CONTACT_VR" ]; then
assert_success "Delete verified contact ${CONTACT_VR}" contact:delete --id "$CONTACT_VR" || true
fi
# ---------------------------------------------------------------------------
# Summary
# ---------------------------------------------------------------------------
echo
bold "╔══════════════════════════════════════════════════════════════╗"
bold "║ Test Summary ║"
bold "╠══════════════════════════════════════════════════════════════╣"
for t in "${TESTS[@]}"; do
if [[ "$t" == PASS:* ]]; then
green "║ ✓ ${t#PASS: }"
else
red "║ ✗ ${t#FAIL: }"
fi
done
bold "╠══════════════════════════════════════════════════════════════╣"
green "║ Passed: ${PASS}"
if [ "$FAIL" -gt 0 ]; then
red "║ Failed: ${FAIL}"
else
green "║ Failed: ${FAIL}"
fi
bold "║ Total: $((PASS + FAIL))"
bold "╚══════════════════════════════════════════════════════════════╝"
if [ "$FAIL" -gt 0 ]; then
exit 1
fi