Review fixes
This commit is contained in:
parent
e629c61d5d
commit
810c9dc7f4
|
|
@ -17,6 +17,7 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -153,19 +154,26 @@ func (d *dialer) Dial(_, _ string) (net.Conn, error) {
|
||||||
|
|
||||||
// resolveAndConstructDialer gets the prefered address using va.getAddr and returns
|
// resolveAndConstructDialer gets the prefered address using va.getAddr and returns
|
||||||
// the chosen address and dialer for that address and correct port.
|
// the chosen address and dialer for that address and correct port.
|
||||||
func (va ValidationAuthorityImpl) resolveAndConstructDialer(name, port string) (dialer, *core.ProblemDetails) {
|
func (va ValidationAuthorityImpl) resolveAndConstructDialer(name, defaultPort string) (dialer, *core.ProblemDetails) {
|
||||||
addr, allAddrs, err := va.getAddr(name)
|
port := "80"
|
||||||
if err != nil {
|
if va.TestMode {
|
||||||
return dialer{}, err
|
port = "5001"
|
||||||
|
} else if defaultPort != "" {
|
||||||
|
port = defaultPort
|
||||||
}
|
}
|
||||||
d := dialer{
|
d := dialer{
|
||||||
record: core.ValidationRecord{
|
record: core.ValidationRecord{
|
||||||
Hostname: name,
|
Hostname: name,
|
||||||
Port: port,
|
Port: port,
|
||||||
AddressesResolved: allAddrs,
|
|
||||||
AddressUsed: addr,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addr, allAddrs, err := va.getAddr(name)
|
||||||
|
if err != nil {
|
||||||
|
return d, err
|
||||||
|
}
|
||||||
|
d.record.AddressesResolved = allAddrs
|
||||||
|
d.record.AddressUsed = addr
|
||||||
return d, nil
|
return d, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -217,10 +225,8 @@ func (va ValidationAuthorityImpl) validateSimpleHTTP(identifier core.AcmeIdentif
|
||||||
}
|
}
|
||||||
|
|
||||||
httpRequest.Host = hostName
|
httpRequest.Host = hostName
|
||||||
port := "80"
|
var port string
|
||||||
if va.TestMode {
|
if scheme == "https" {
|
||||||
port = "5001"
|
|
||||||
} else if strings.ToLower(scheme) == "https" {
|
|
||||||
port = "443"
|
port = "443"
|
||||||
}
|
}
|
||||||
dialer, prob := va.resolveAndConstructDialer(hostName, port)
|
dialer, prob := va.resolveAndConstructDialer(hostName, port)
|
||||||
|
|
@ -250,22 +256,24 @@ func (va ValidationAuthorityImpl) validateSimpleHTTP(identifier core.AcmeIdentif
|
||||||
}
|
}
|
||||||
|
|
||||||
host := req.URL.Host
|
host := req.URL.Host
|
||||||
port = "80"
|
port = ""
|
||||||
if va.TestMode {
|
|
||||||
port = "5001"
|
|
||||||
}
|
|
||||||
if strings.Contains(host, ":") {
|
if strings.Contains(host, ":") {
|
||||||
splitHost := strings.SplitN(host, ":", 2)
|
splitHost := strings.SplitN(host, ":", 2)
|
||||||
if len(splitHost) <= 1 {
|
if len(splitHost) <= 1 {
|
||||||
return fmt.Errorf("Malformed host")
|
return fmt.Errorf("Malformed host")
|
||||||
}
|
}
|
||||||
host, port = splitHost[0], splitHost[1]
|
host, port = splitHost[0], splitHost[1]
|
||||||
if port < 0 || port > 65535 {
|
portNum, err := strconv.Atoi(port)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if portNum < 0 || portNum > 65535 {
|
||||||
return fmt.Errorf("Invalid port number in redirect")
|
return fmt.Errorf("Invalid port number in redirect")
|
||||||
}
|
}
|
||||||
} else if strings.ToLower(req.URL.Scheme) == "https" {
|
} else if strings.ToLower(req.URL.Scheme) == "https" {
|
||||||
port = "443"
|
port = "443"
|
||||||
}
|
}
|
||||||
|
|
||||||
dialer, err := va.resolveAndConstructDialer(host, port)
|
dialer, err := va.resolveAndConstructDialer(host, port)
|
||||||
dialer.record.URL = req.URL.String()
|
dialer.record.URL = req.URL.String()
|
||||||
challenge.ValidationRecord = append(challenge.ValidationRecord, dialer.record)
|
challenge.ValidationRecord = append(challenge.ValidationRecord, dialer.record)
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,7 @@ func simpleSrv(t *testing.T, token string, stopChan, waitChan chan bool, enableT
|
||||||
currentToken := defaultToken
|
currentToken := defaultToken
|
||||||
|
|
||||||
m.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
m.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Host != "localhost" && r.Host != "other.valid" {
|
if r.Host != "localhost" && r.Host != "other.valid" && r.Host != "other.valid:8080" {
|
||||||
t.Errorf("Bad Host header: " + r.Host)
|
t.Errorf("Bad Host header: " + r.Host)
|
||||||
}
|
}
|
||||||
if strings.HasSuffix(r.URL.Path, path404) {
|
if strings.HasSuffix(r.URL.Path, path404) {
|
||||||
|
|
@ -410,6 +410,7 @@ func TestSimpleHttpRedirectLookup(t *testing.T) {
|
||||||
log.Clear()
|
log.Clear()
|
||||||
chall.Token = pathRedirectPort
|
chall.Token = pathRedirectPort
|
||||||
finChall, err = va.validateSimpleHTTP(ident, chall, AccountKey)
|
finChall, err = va.validateSimpleHTTP(ident, chall, AccountKey)
|
||||||
|
fmt.Println(finChall.ValidationRecord)
|
||||||
test.AssertEquals(t, finChall.Status, core.StatusInvalid)
|
test.AssertEquals(t, finChall.Status, core.StatusInvalid)
|
||||||
test.AssertError(t, err, chall.Token)
|
test.AssertError(t, err, chall.Token)
|
||||||
test.AssertEquals(t, len(log.GetAllMatching(`redirect from ".*/port-redirect" to ".*other.valid:8080/path"`)), 1)
|
test.AssertEquals(t, len(log.GetAllMatching(`redirect from ".*/port-redirect" to ".*other.valid:8080/path"`)), 1)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue