From 53d7b59d3609e69d50966fe805526fa32bc52199 Mon Sep 17 00:00:00 2001 From: xenolf Date: Sat, 13 Jun 2015 19:13:04 +0200 Subject: [PATCH] Initial SimpleHTTP test --- acme/simple_http_challenge.go | 2 ++ acme/simple_http_challenge_test.go | 33 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 acme/simple_http_challenge_test.go diff --git a/acme/simple_http_challenge.go b/acme/simple_http_challenge.go index 0192d70c..a74bf744 100644 --- a/acme/simple_http_challenge.go +++ b/acme/simple_http_challenge.go @@ -14,6 +14,7 @@ import ( "math/big" "net" "net/http" + "strings" "time" ) @@ -37,6 +38,7 @@ func (s *simpleHTTPChallenge) CanSolve(domain string) bool { return false } ipStr := string(ip) + ipStr = strings.Replace(ipStr, "\n", "", -1) // resolve domain we should solve for resolvedIPs, err := net.LookupHost(domain) diff --git a/acme/simple_http_challenge_test.go b/acme/simple_http_challenge_test.go new file mode 100644 index 00000000..5d2e8332 --- /dev/null +++ b/acme/simple_http_challenge_test.go @@ -0,0 +1,33 @@ +package acme + +import ( + "io/ioutil" + "net/http" + "strings" + "testing" +) + +func TestSimpleHTTPCanSolve(t *testing.T) { + challenge := &simpleHTTPChallenge{} + + // determine public ip + resp, err := http.Get("https://icanhazip.com/") + if err != nil { + t.Errorf("Could not get public IP -> %v", err) + } + + ip, err := ioutil.ReadAll(resp.Body) + if err != nil { + t.Errorf("Could not get public IP -> %v", err) + } + ipStr := string(ip) + + if expected, actual := false, challenge.CanSolve("google.com"); expected != actual { + t.Errorf("Expected CanSolve to return %t for domain 'google.com' but was %t", expected, actual) + } + + localResolv := strings.Replace(ipStr, "\n", "", -1) + ".xip.io" + if expected, actual := true, challenge.CanSolve(localResolv); expected != actual { + t.Errorf("Expected CanSolve to return %t for domain 'localhost' but was %t", expected, actual) + } +}