summaryrefslogtreecommitdiff
path: root/tests/run-tests.sh
blob: ca931bc4ad492da96ea3e22b03957b5813a0344f (plain)
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
#! /usr/bin/env nix-shell
#! nix-shell -i bash -p jq curl

function cleanup {
    echo
    popd >/dev/null
    echo Shutting down container ...
    sudo nixos-container stop hermes
}

pushd $(dirname $0) >/dev/null
echo Stopping container for update ...
sudo nixos-container stop hermes || exit 2
echo Updating container ...
sudo nixos-container update hermes --flake .#hermes-test || exit 2
echo Starting container ...
sudo nixos-container start hermes || exit 2

trap cleanup EXIT
sleep 0.1
IP=$(nixos-container show-ip hermes)
CURL_FLAGS='--location --silent'

echo
echo Checking that all the services are running:
declare -A PORTS
PORTS[quentin]=8080
PORTS[searx]=8081
PORTS[rss]=8082
for SERVICE in "${!PORTS[@]}"
do
    URL="http://$IP:${PORTS[$SERVICE]}/"
    echo Checking connection to container version of $SERVICE.aristote.fr ...
    RESULT=$(curl "$URL" $CURL_FLAGS --output /dev/null --write-out '%{http_code}\n')
    case "$RESULT" in
        200) echo "Up and running at $URL !";;
        301) echo "Redirected.";;
        *) echo "Connection failed.";;
    esac
done
echo Checking connection to container version of mesh.aristote.fr ...
URL="http://$IP:8084/health"
RESULT=$(curl "$URL" $CURL_FLAGS)
if [[ "$RESULT" != '{"status":"pass"}' ]]
then
    echo "Connection failed."
else
    echo "Up and running at $URL !"
fi
echo Done.


echo
echo Checking web keys directory:
URL_PREFIX="http://$IP:8083/.well-known/openpgpkey/aristote.vm"
KEYS="$(ls ../config/services/web/webkeydirectory/hu)"
for KEY in $KEYS
do
    echo Checking key $KEY ...
    RESULT=$(curl "$URL_PREFIX/hu/$KEY" $CURL_FLAGS --output /dev/null --write-out '%{http_code}\n')
    if [[ ! "$RESULT" = 200 ]]
    then
        echo "Connection failed."
    fi
done
echo Checking policy file ...
RESULT=$(curl "$URL_PREFIX/policy" $CURL_FLAGS --output /dev/null --write-out '%{http_code}\n')
if [[ ! "$RESULT" = 200 ]]
then
    echo "Connection failed."
fi
echo Done.


echo
echo Checking custom RSS bridges:
BRIDGES="$(ls ../config/services/web/rss/*Bridge.php | xargs basename -s Bridge.php)"
for BRIDGE in $BRIDGES
do
    echo Checking bridge $BRIDGE ...
    RESULT=$(curl "http://$IP:${PORTS[rss]}/?action=display&bridge=$BRIDGE&format=Plaintext" $CURL_FLAGS --output /dev/null --write-out '%{http_code}\n')
    if [[ ! "$RESULT" = 200 ]]
    then
        echo "Connection failed."
    fi
done
echo Done.


# echo
# echo Checking custom Searx engines:
# declare -A QUERIES
# QUERIES[alternativeto]=Searx
# QUERIES[nlab]='Kan%20extension'
# QUERIES[wfr]=Paris
# QUERIES[wen]=Paris
# for ENGINE in "${!QUERIES[@]}"
# do
#     echo Checking engine $ENGINE ...
#     REQUEST_URL="http://$IP:${PORTS[searx]}/search?q=${QUERIES[$ENGINE]}+!$ENGINE&format=json"
#     JSON_RESULT=$(curl "$REQUEST_URL" $CURL_FLAGS)
#     RESULTS=$(echo $JSON_RESULT | jq '.results')
#     UNRESPONSIVE_ENGINES=$(echo $JSON_RESULT | jq '.unresponsive_engines')
#     if [[ ! "$UNRESPONSIVE_ENGINES" = '[]' ]]
#     then
#         echo "Engine not responsive."
#     elif [[ "$RESULTS" = [] ]]
#     then
#         echo "No results found."
#     fi
# done
# echo Done.

echo
read -n1 -srp "Press any key to stop the server."