Skip to content

Commit c99417d

Browse files
committed
Add subdomain redirect test script
1 parent 122f8f0 commit c99417d

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

test/subdomain_redirects.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
3+
# Simple script testing that the different ledger-cli.org subdomain redirects work as expected.
4+
5+
# Tests consists of 2 lines (blank lines are ignored)
6+
# The first line starting with a octorhorpe (#) is a brief description of the test that will be echoed.
7+
# The second list must be quoted with single quotes and consists of:
8+
# 1. an URL to query
9+
# 2. a single space ( )
10+
# 3. the expected HTTP status code
11+
# 4. a single colon (:)
12+
# 5. the expected redirect URL
13+
#
14+
# For example the following test:
15+
# 'git.ledger-cli.org/ledger/releases/latest 302:https://github.com/ledger/ledger/releases/latest'
16+
# can be read as
17+
# When requesting the URL `https://git.ledger-cli.org/ledger/releases/latest`
18+
# it is expected that the server responds with a `302` and a location header value of
19+
# `https://github.com/ledger/ledger/releases/latest`
20+
21+
tests=$(grep -Ev '^[ ]*$' <<< "\
22+
# Verify that the apex domain is served directly
23+
'ledger-cli.org/index.html 200:'
24+
25+
# Verify that the www subdomain is redirected to the apex domain and retains the URL path
26+
'www.ledger-cli.org/docs.html 301:https://ledger-cli.org/docs.html'
27+
28+
# Verify that the git subdomain is redirected to github organization and retains the URL path
29+
'git.ledger-cli.org/ledger/releases/latest 302:https://github.com/ledger/ledger/releases/latest'
30+
31+
# Verify that the bugs subdomain is redirected to github ledger repo issues page and retains the URL path
32+
'bugs.ledger-cli.org/2222 302:https://github.com/ledger/ledger/issues/2222'
33+
34+
# Verify that the wiki subdomain is redirected to the github wiki and retains the URL path
35+
'wiki.ledger-cli.org/Post 302:https://github.com/ledger/ledger/wiki/Post'
36+
37+
# Verify that the list subdomain is redirected to the Google group mailling list and retains the URL path
38+
'list.ledger-cli.org/c/xM3EEukxYys 302:https://groups.google.com/g/ledger-cli/c/xM3EEukxYys'
39+
")
40+
41+
exit_code=0
42+
echo "$tests" | while read info; do
43+
echo -n "${info#\# }... "
44+
read test
45+
t=(${test//\'/})
46+
result=$(curl -sI -w '%{response_code}:%{redirect_url}' "https://${t[0]}" -o /dev/null)
47+
if [ "${t[1]}" == "${result}" ]; then
48+
echo OK
49+
else
50+
echo -e "Failed!\nExpected »${t[1]}« got »${result}«"
51+
exit_code=-1
52+
fi
53+
done
54+
55+
exit $exit_code

0 commit comments

Comments
 (0)