| 1 | #! /bin/sh |
| 2 | |
| 3 | DNS_PORT=5300 |
| 4 | HTTP_PORT=3053 |
| 5 | TEST_COUNT=0 |
| 6 | |
| 7 | exec 2>error.log |
| 8 | |
| 9 | t() { |
| 10 | TEST_COUNT=$((TEST_COUNT + 1)) |
| 11 | echo "Test #${TEST_COUNT}..." |
| 12 | false |
| 13 | } |
| 14 | |
| 15 | fail() ( |
| 16 | echo "*** Test #${TEST_COUNT} FAILED, line: $1 ***" >&2 |
| 17 | ) |
| 18 | |
| 19 | section() { |
| 20 | true |
| 21 | } |
| 22 | |
| 23 | rm -f blocked-names.log blocked-ips.log query.log nx.log allowed-names.log |
| 24 | |
| 25 | t || ( |
| 26 | cd ../dnscrypt-proxy |
| 27 | go test -mod vendor |
| 28 | go build -mod vendor -race |
| 29 | ) || fail $LINENO |
| 30 | |
| 31 | section |
| 32 | sed -e "s/127.0.0.1:53/127.0.0.1:${DNS_PORT}/g" -e "s/# server_names =.*/server_names = ['scaleway-fr']/" ../dnscrypt-proxy/example-dnscrypt-proxy.toml >test-dnscrypt-proxy.toml |
| 33 | ../dnscrypt-proxy/dnscrypt-proxy -loglevel 3 -config test-dnscrypt-proxy.toml -pidfile /tmp/dnscrypt-proxy.pidfile & |
| 34 | sleep 5 |
| 35 | |
| 36 | t || |
| 37 | dig -p${DNS_PORT} . @127.0.0.1 | grep -Fq 'root-servers.net.' || fail $LINENO |
| 38 | t || dig -p${DNS_PORT} +dnssec . @127.0.0.1 | grep -Fq 'root-servers.net.' || fail $LINENO |
| 39 | t || dig -p${DNS_PORT} +dnssec . @127.0.0.1 | grep -Fq 'flags: do;' || fail $LINENO |
| 40 | t || dig -p${DNS_PORT} +short one.one.one.one @127.0.0.1 | grep -Fq '1.1.1.1' || fail $LINENO |
| 41 | t || dig -p${DNS_PORT} +dnssec dnscrypt.info @127.0.0.1 | grep -Fq 'flags: qr rd ra ad' || fail $LINENO |
| 42 | t || dig -p${DNS_PORT} +dnssec dnscrypt.info @127.0.0.1 | grep -Fq 'flags: do;' || fail $LINENO |
| 43 | |
| 44 | kill $(cat /tmp/dnscrypt-proxy.pidfile) |
| 45 | sleep 5 |
| 46 | |
| 47 | section |
| 48 | ../dnscrypt-proxy/dnscrypt-proxy -loglevel 3 -config test2-dnscrypt-proxy.toml -pidfile /tmp/dnscrypt-proxy.pidfile & |
| 49 | sleep 5 |
| 50 | |
| 51 | section |
| 52 | t || dig -p${DNS_PORT} A microsoft.com @127.0.0.1 | grep -Fq "NOERROR" || fail $LINENO |
| 53 | t || dig -p${DNS_PORT} A MICROSOFT.COM @127.0.0.1 | grep -Fq "NOERROR" || fail $LINENO |
| 54 | |
| 55 | section |
| 56 | t || dig -p${DNS_PORT} AAAA ipv6.google.com @127.0.0.1 | grep -Fq 'locally blocked' || fail $LINENO |
| 57 | |
| 58 | section |
| 59 | t || dig -p${DNS_PORT} invalid. @127.0.0.1 | grep -Fq NXDOMAIN || fail $LINENO |
| 60 | t || dig -p${DNS_PORT} +dnssec invalid. @127.0.0.1 | grep -Fq 'flags: do;' || fail $LINENO |
| 61 | t || dig -p${DNS_PORT} PTR 168.192.in-addr.arpa @127.0.0.1 | grep -Fq 'NXDOMAIN' || fail $LINENO |
| 62 | t || dig -p${DNS_PORT} +dnssec PTR 168.192.in-addr.arpa @127.0.0.1 | grep -Fq 'flags: do;' || fail $LINENO |
| 63 | |
| 64 | section |
| 65 | t || dig -p${DNS_PORT} +dnssec darpa.mil @127.0.0.1 2>&1 | grep -Fvq 'RRSIG' || fail $LINENO |
| 66 | t || dig -p${DNS_PORT} +dnssec www.darpa.mil @127.0.0.1 2>&1 | grep -Fvq 'RRSIG' || fail $LINENO |
| 67 | t || dig -p${DNS_PORT} A download.windowsupdate.com @127.0.0.1 | grep -Fq "NOERROR" || fail $LINENO |
| 68 | |
| 69 | section |
| 70 | t || dig -p${DNS_PORT} +short cloakedunregistered.com @127.0.0.1 | grep -Eq '1.1.1.1|1.0.0.1' || fail $LINENO |
| 71 | t || dig -p${DNS_PORT} +short MX cloakedunregistered.com @127.0.0.1 | grep -Fq 'locally blocked' || fail $LINENO |
| 72 | t || dig -p${DNS_PORT} +short MX example.com @127.0.0.1 | grep -Fvq 'locally blocked' || fail $LINENO |
| 73 | t || dig -p${DNS_PORT} NS cloakedunregistered.com @127.0.0.1 | grep -Fiq 'gtld-servers.net' || fail $LINENO |
| 74 | t || dig -p${DNS_PORT} +short www.cloakedunregistered2.com @127.0.0.1 | grep -Eq '1.1.1.1|1.0.0.1' || fail $LINENO |
| 75 | t || dig -p${DNS_PORT} +short www.dnscrypt-test @127.0.0.1 | grep -Fq '192.168.100.100' || fail $LINENO |
| 76 | t || dig -p${DNS_PORT} a.www.dnscrypt-test @127.0.0.1 | grep -Fq 'NXDOMAIN' || fail $LINENO |
| 77 | t || dig -p${DNS_PORT} +short ptr 101.100.168.192.in-addr.arpa. @127.0.0.1 | grep -Eq 'www.dnscrypt-test.com' || fail $LINENO |
| 78 | t || dig -p${DNS_PORT} +short ptr 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.d.f.ip6.arpa. @127.0.0.1 | grep -Eq 'ipv6.dnscrypt-test.com' || fail $LINENO |
| 79 | |
| 80 | section |
| 81 | t || dig -p${DNS_PORT} telemetry.example @127.0.0.1 | grep -Fq 'locally blocked' || fail $LINENO |
| 82 | |
| 83 | section |
| 84 | t || dig -p${DNS_PORT} dns.google @127.0.0.1 | grep -Fq 'locally blocked' || fail $LINENO |
| 85 | |
| 86 | section |
| 87 | t || dig -p${DNS_PORT} tracker.xdebian.org @127.0.0.1 | grep -Fq 'locally blocked' || fail $LINENO |
| 88 | t || dig -p${DNS_PORT} tracker.debian.org @127.0.0.1 | grep -Fqv 'locally blocked' || fail $LINENO |
| 89 | |
| 90 | section |
| 91 | t || curl --insecure -siL https://127.0.0.1:${HTTP_PORT}/ | grep -Fq 'HTTP/2 404' || fail $LINENO |
| 92 | t || curl --insecure -sL https://127.0.0.1:${HTTP_PORT}/dns-query | grep -Fq 'dnscrypt-proxy local DoH server' || fail $LINENO |
| 93 | t || |
| 94 | echo yv4BAAABAAAAAAABAAACAAEAACkQAAAAgAAAAA== | base64 -d | |
| 95 | curl -H'Content-Type: application/dns-message' -H'Accept: application/dns-message' --data-binary @- -D - --insecure https://127.0.0.1:${HTTP_PORT}/dns-query 2>/dev/null | |
| 96 | grep -Fq application/dns-message || fail $LINENO |
| 97 | |
| 98 | kill $(cat /tmp/dnscrypt-proxy.pidfile) |
| 99 | |
| 100 | sleep 5 |
| 101 | |
| 102 | section |
| 103 | t || grep -Fq 'telemetry.example' blocked-names.log || fail $LINENO |
| 104 | t || grep -Fq 'telemetry.*' blocked-names.log || fail $LINENO |
| 105 | t || grep -Fq 'tracker.xdebian.org' blocked-names.log || fail $LINENO |
| 106 | t || grep -Fq 'tracker.*' blocked-names.log || fail $LINENO |
| 107 | |
| 108 | section |
| 109 | t || grep -Fq 'dns.google' blocked-ips.log || fail $LINENO |
| 110 | t || grep -Fq '8.8.8.8' blocked-ips.log || fail $LINENO |
| 111 | |
| 112 | section |
| 113 | t || grep -Fq 'a.www.dnscrypt-test' nx.log || fail $LINENO |
| 114 | |
| 115 | section |
| 116 | t || grep -Fq 'a.www.dnscrypt-test' nx.log || fail $LINENO |
| 117 | |
| 118 | section |
| 119 | t || grep -Eq 'microsoft.com.*PASS.*ms.[a-zA-Z]' query.log || fail $LINENO |
| 120 | t || grep -Eq 'microsoft.com.*PASS.*ms.-.' query.log || fail $LINENO |
| 121 | t || grep -Eq 'ipv6.google.com.*SYNTH' query.log || fail $LINENO |
| 122 | t || grep -Eq 'invalid.*SYNTH' query.log || fail $LINENO |
| 123 | t || grep -Eq '168.192.in-addr.arpa.*SYNTH' query.log || fail $LINENO |
| 124 | t || grep -Eq 'darpa.mil.*FORWARD' query.log || fail $LINENO |
| 125 | t || grep -Eq 'www.darpa.mil.*FORWARD' query.log || fail $LINENO |
| 126 | t || grep -Eq 'download.windowsupdate.com.*FORWARD' query.log || fail $LINENO |
| 127 | t || grep -Eq 'cloakedunregistered.com.*CLOAK' query.log || fail $LINENO |
| 128 | t || grep -Eq 'www.cloakedunregistered2.com.*CLOAK' query.log || fail $LINENO |
| 129 | t || grep -Eq 'www.dnscrypt-test.*CLOAK' query.log || fail $LINENO |
| 130 | t || grep -Eq 'a.www.dnscrypt-test.*NXDOMAIN' query.log || fail $LINENO |
| 131 | t || grep -Eq 'telemetry.example.*REJECT' query.log || fail $LINENO |
| 132 | t || grep -Eq 'dns.google.*REJECT' query.log || fail $LINENO |
| 133 | t || grep -Eq 'tracker.xdebian.org.*REJECT' query.log || fail $LINENO |
| 134 | t || grep -Eq 'tracker.debian.org.*PASS' query.log || fail $LINENO |
| 135 | t || grep -Eq '[.].*NS.*PASS' query.log || fail $LINENO |
| 136 | |
| 137 | section |
| 138 | t || grep -Fq 'tracker.debian.org' allowed-names.log || fail $LINENO |
| 139 | t || grep -Fq '*.tracker.debian' allowed-names.log || fail $LINENO |
| 140 | |
| 141 | section |
| 142 | ../dnscrypt-proxy/dnscrypt-proxy -loglevel 3 -config test3-dnscrypt-proxy.toml -pidfile /tmp/dnscrypt-proxy.pidfile & |
| 143 | sleep 5 |
| 144 | |
| 145 | section |
| 146 | t || dig -p${DNS_PORT} A microsoft.com @127.0.0.1 | grep -Fq "NOERROR" || fail $LINENO |
| 147 | t || dig -p${DNS_PORT} A MICROSOFT.COM @127.0.0.1 | grep -Fq "NOERROR" || fail $LINENO |
| 148 | |
| 149 | kill $(cat /tmp/dnscrypt-proxy.pidfile) |
| 150 | sleep 5 |
| 151 | |
| 152 | section |
| 153 | ../dnscrypt-proxy/dnscrypt-proxy -loglevel 3 -config test-odoh-proxied.toml -pidfile /tmp/odoh-proxied.pidfile & |
| 154 | sleep 5 |
| 155 | |
| 156 | section |
| 157 | t || dig -p${DNS_PORT} A microsoft.com @127.0.0.1 | grep -Fq "NOERROR" || fail $LINENO |
| 158 | t || dig -p${DNS_PORT} A cloudflare.com @127.0.0.1 | grep -Fq "NOERROR" || fail $LINENO |
| 159 | |
| 160 | kill $(cat /tmp/odoh-proxied.pidfile) |
| 161 | sleep 5 |
| 162 | |
| 163 | if [ -s error.log ]; then |
| 164 | cat *.log |
| 165 | exit 1 |
| 166 | fi |