mirror of
https://github.com/go-acme/lego.git
synced 2024-12-25 11:02:56 +02:00
Initial SimpleHTTP test
This commit is contained in:
parent
fcd0fba9c7
commit
53d7b59d36
@ -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)
|
||||
|
33
acme/simple_http_challenge_test.go
Normal file
33
acme/simple_http_challenge_test.go
Normal 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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user