Parse bridge blocking info from SQL database.
[tor-bridgedb.git] / scripts / test-moat
blob81999d86be7413a361b36add8d994acaf5ae3ede
1 #!/usr/bin/env bash
3 # To test a local moat server, simply do:
5 # test-moat fetch
7 # To test the production server, run the externalize-pt-client.sh script like so:
9 # ./externalize-pt-client.orig.sh /path/to/meek-client \
10 # -url https://tor-bridges-hyphae-channel.appspot.com/ -front www.google.com
12 # and then call this script with:
14 # TEST_PRODUCTION_MOAT=1 test-moat fetch
16 set -ex
18 CHALLENGE=
19 SOLUTION=
20 METHOD=http
21 URL_PREFIX=/meek/moat
23 if test -n "$TEST_PRODUCTION_MOAT" ; then
24 METHOD=https
25 SERVER=bridges.torproject.org
26 PORT=443
27 URL_PREFIX=/moat
28 PROXY='--proxy socks4a://127.0.0.1:10000/'
31 function usage() {
32 printf "Usage: %s [fetch] [check [challenge solution]]\n" "$(basename $0)"
35 if test "$#" -lt 1 ; then
36 usage
37 exit 1
40 function do_fetch() {
41 curl \
42 ${PROXY} \
43 -H 'Content-Type: application/vnd.api+json' \
44 -H 'Accept: application/vnd.api+json' \
45 -H 'X-Forwarded-For: 1.2.3.4' \
46 --data '{"data": [{"supported": ["obfs4"], "version": "0.1.0", "type": "client-transports"}]}' \
47 $METHOD://${SERVER:=127.0.0.1}:${PORT:=6790}$URL_PREFIX/fetch
48 echo
51 function do_check() {
52 curl \
53 ${PROXY} \
54 -H 'Content-Type: application/vnd.api+json' \
55 -H 'Accept: application/vnd.api+json' \
56 -H 'X-Forwarded-For: 1.2.3.4' \
57 --data '{"data": [{"challenge": "'${CHALLENGE:=foo}'", "solution": "'${SOLUTION:=bar}'", "version": "0.1.0", "qrcode": "false", "type": "moat-solution", "id": 2, "transport": "obfs4"}]}' \
58 $METHOD://${SERVER:=127.0.0.1}:${PORT:=6790}$URL_PREFIX/check
59 echo
62 while test -n "$1" ; do
63 OPTSHIFT=1
65 case "$1" in
66 fetch) do_fetch ;;
67 check) if [[ "$2" != "fetch" ]] ; then
68 CHALLENGE="$2"
69 if [[ "$3" != "fetch" ]] ; then
70 SOLUTION="$3"
73 for var in "$CHALLENGE" "$SOLUTION" ; do
74 if test -n "$var"; then
75 OPTSHIFT=$(( OPTSHIFT + 1 ))
77 done
78 do_check ;;
80 *) usage ;;
81 esac
83 shift $OPTSHIFT
84 OPTSHIFT=1
85 done