Unverified Commit f55bf7da authored by Philipp Winter's avatar Philipp Winter
Browse files

Add test for websites.

parent 632c993f
......@@ -4,6 +4,10 @@ import (
"fmt"
)
const (
SuccessMessage = "everything as expected"
)
func testDefaultBridges() {
fmt.Println("Testing TCP port of default bridges.")
for _, addrTuple := range defaultBridges {
......@@ -39,18 +43,33 @@ func testDomains() {
}
}
if allGood {
fmt.Println("\tEverything as expected.")
fmt.Printf("\t%s\n", SuccessMessage)
}
}
func runTests() {
testDefaultBridges()
testDirAuths()
testDomains()
func testWebsites() {
fmt.Println("Testing websites.")
var allGood = true
for url, substring := range websites {
success, err := DoesWebsiteContainStr(url, substring)
if err != nil {
fmt.Println(err)
allGood = false
}
if !success {
fmt.Printf("\tno substring %q in url %q.\n", substring, url)
allGood = false
}
}
if allGood {
fmt.Printf("\t%s\n", SuccessMessage)
}
}
func main() {
runTests()
testDefaultBridges()
testDirAuths()
testDomains()
testWebsites()
}
......@@ -55,3 +55,10 @@ var domains = map[string]map[string]bool{
"116.202.120.184": true,
"2a01:4f8:fff0:4f:266:37ff:fef9:f825": true},
}
var websites = map[string]string{
"https://bridges.torproject.org": "The Tor Project",
"https://torproject.org": "Tor Browser",
"https://gettor.torproject.org": "GetTor",
"https://ajax.aspnetcdn.com": "Microsoft Ajax Content Delivery Network",
}
......@@ -2,7 +2,10 @@ package main
import (
"fmt"
"io/ioutil"
"net"
"net/http"
"strings"
"time"
)
......@@ -36,3 +39,19 @@ func DoesDomainResolve(domain string, expected map[string]bool) error {
}
return nil
}
func DoesWebsiteContainStr(domain, substring string) (bool, error) {
resp, err := http.Get(domain)
if err != nil {
return false, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return false, err
}
return strings.Contains(string(body), substring), nil
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment