Initial SimpleHTTP test

This commit is contained in:
xenolf 2015-06-13 19:13:04 +02:00
parent fcd0fba9c7
commit 53d7b59d36
2 changed files with 35 additions and 0 deletions

View file

@ -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)

View file

@ -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)
}
}