forked from TrueCloudLab/lego
Bind to domain:port to solve simple HTTP
This way it doesn't conflict with other processes bound to 0.0.0.0 on the same port. Refactored tests to use 127.0.0.1 instead of a bogus domain, since it must resolve to localhost to pass.
This commit is contained in:
parent
3e1a5dc04b
commit
71d0e8db6f
2 changed files with 13 additions and 13 deletions
|
@ -74,7 +74,7 @@ Loop:
|
||||||
break
|
break
|
||||||
case "invalid":
|
case "invalid":
|
||||||
if OnSimpleHTTPEnd != nil {
|
if OnSimpleHTTPEnd != nil {
|
||||||
OnSimpleHTTPEnd(true)
|
OnSimpleHTTPEnd(false)
|
||||||
}
|
}
|
||||||
return errors.New("The server could not validate our request.")
|
return errors.New("The server could not validate our request.")
|
||||||
default:
|
default:
|
||||||
|
@ -124,7 +124,7 @@ func (s *simpleHTTPChallenge) startHTTPSServer(domain string, token string) (net
|
||||||
port = ":" + s.optPort
|
port = ":" + s.optPort
|
||||||
}
|
}
|
||||||
|
|
||||||
tlsListener, err := tls.Listen("tcp", port, tlsConf)
|
tlsListener, err := tls.Listen("tcp", domain+port, tlsConf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,10 +21,10 @@ func TestSimpleHTTPNonRootBind(t *testing.T) {
|
||||||
clientChallenge := challenge{Type: "simpleHttp", Status: "pending", URI: "localhost:4000", Token: "1"}
|
clientChallenge := challenge{Type: "simpleHttp", Status: "pending", URI: "localhost:4000", Token: "1"}
|
||||||
|
|
||||||
// validate error on non-root bind to 443
|
// validate error on non-root bind to 443
|
||||||
if err := solver.Solve(clientChallenge, "test.domain"); err == nil {
|
if err := solver.Solve(clientChallenge, "127.0.0.1"); err == nil {
|
||||||
t.Error("BIND: Expected Solve to return an error but the error was nil.")
|
t.Error("BIND: Expected Solve to return an error but the error was nil.")
|
||||||
} else {
|
} else {
|
||||||
expectedError := "Could not start HTTPS server for challenge -> listen tcp :443: bind: permission denied"
|
expectedError := "Could not start HTTPS server for challenge -> listen tcp 127.0.0.1:443: bind: permission denied"
|
||||||
if err.Error() != expectedError {
|
if err.Error() != expectedError {
|
||||||
t.Errorf("Expected error %s but instead got %s", expectedError, err.Error())
|
t.Errorf("Expected error %s but instead got %s", expectedError, err.Error())
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ func TestSimpleHTTPShortRSA(t *testing.T) {
|
||||||
solver := &simpleHTTPChallenge{jws: jws, optPort: "23456"}
|
solver := &simpleHTTPChallenge{jws: jws, optPort: "23456"}
|
||||||
clientChallenge := challenge{Type: "simpleHttp", Status: "pending", URI: "http://localhost:4000", Token: "2"}
|
clientChallenge := challenge{Type: "simpleHttp", Status: "pending", URI: "http://localhost:4000", Token: "2"}
|
||||||
|
|
||||||
if err := solver.Solve(clientChallenge, "test.domain"); err == nil {
|
if err := solver.Solve(clientChallenge, "127.0.0.1"); err == nil {
|
||||||
t.Error("UNEXPECTED: Expected Solve to return an error but the error was nil.")
|
t.Error("UNEXPECTED: Expected Solve to return an error but the error was nil.")
|
||||||
} else {
|
} else {
|
||||||
expectedError := "Could not start HTTPS server for challenge -> startHTTPSServer: Failed to sign message. crypto/rsa: message too long for RSA public key size"
|
expectedError := "Could not start HTTPS server for challenge -> startHTTPSServer: Failed to sign message. crypto/rsa: message too long for RSA public key size"
|
||||||
|
@ -55,7 +55,7 @@ func TestSimpleHTTPConnectionRefusal(t *testing.T) {
|
||||||
solver := &simpleHTTPChallenge{jws: jws, optPort: "23456"}
|
solver := &simpleHTTPChallenge{jws: jws, optPort: "23456"}
|
||||||
clientChallenge := challenge{Type: "simpleHttp", Status: "pending", URI: "http://localhost:4000", Token: "3"}
|
clientChallenge := challenge{Type: "simpleHttp", Status: "pending", URI: "http://localhost:4000", Token: "3"}
|
||||||
|
|
||||||
if err := solver.Solve(clientChallenge, "test.domain"); err == nil {
|
if err := solver.Solve(clientChallenge, "127.0.0.1"); err == nil {
|
||||||
t.Error("UNEXPECTED: Expected Solve to return an error but the error was nil.")
|
t.Error("UNEXPECTED: Expected Solve to return an error but the error was nil.")
|
||||||
} else {
|
} else {
|
||||||
reg := "/Failed to post JWS message\\. -> Post http:\\/\\/localhost:4000: dial tcp 127\\.0\\.0\\.1:4000: (getsockopt: )?connection refused/g"
|
reg := "/Failed to post JWS message\\. -> Post http:\\/\\/localhost:4000: dial tcp 127\\.0\\.0\\.1:4000: (getsockopt: )?connection refused/g"
|
||||||
|
@ -79,7 +79,7 @@ func TestSimpleHTTPUnexpectedServerState(t *testing.T) {
|
||||||
solver := &simpleHTTPChallenge{jws: jws, optPort: "23456"}
|
solver := &simpleHTTPChallenge{jws: jws, optPort: "23456"}
|
||||||
clientChallenge := challenge{Type: "simpleHttp", Status: "pending", URI: ts.URL, Token: "4"}
|
clientChallenge := challenge{Type: "simpleHttp", Status: "pending", URI: ts.URL, Token: "4"}
|
||||||
|
|
||||||
if err := solver.Solve(clientChallenge, "test.domain"); err == nil {
|
if err := solver.Solve(clientChallenge, "127.0.0.1"); err == nil {
|
||||||
t.Error("UNEXPECTED: Expected Solve to return an error but the error was nil.")
|
t.Error("UNEXPECTED: Expected Solve to return an error but the error was nil.")
|
||||||
} else {
|
} else {
|
||||||
expectedError := "The server returned an unexpected state."
|
expectedError := "The server returned an unexpected state."
|
||||||
|
@ -113,7 +113,7 @@ func TestSimpleHTTPChallengeServerUnexpectedDomain(t *testing.T) {
|
||||||
solver := &simpleHTTPChallenge{jws: jws, optPort: "23456"}
|
solver := &simpleHTTPChallenge{jws: jws, optPort: "23456"}
|
||||||
clientChallenge := challenge{Type: "simpleHttp", Status: "pending", URI: ts.URL, Token: "5"}
|
clientChallenge := challenge{Type: "simpleHttp", Status: "pending", URI: ts.URL, Token: "5"}
|
||||||
|
|
||||||
if err := solver.Solve(clientChallenge, "test.domain"); err == nil {
|
if err := solver.Solve(clientChallenge, "127.0.0.1"); err == nil {
|
||||||
t.Error("UNEXPECTED: Expected Solve to return an error but the error was nil.")
|
t.Error("UNEXPECTED: Expected Solve to return an error but the error was nil.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,7 +135,7 @@ func TestSimpleHTTPServerError(t *testing.T) {
|
||||||
solver := &simpleHTTPChallenge{jws: jws, optPort: "23456"}
|
solver := &simpleHTTPChallenge{jws: jws, optPort: "23456"}
|
||||||
clientChallenge := challenge{Type: "simpleHttp", Status: "pending", URI: ts.URL, Token: "6"}
|
clientChallenge := challenge{Type: "simpleHttp", Status: "pending", URI: ts.URL, Token: "6"}
|
||||||
|
|
||||||
if err := solver.Solve(clientChallenge, "test.domain"); err == nil {
|
if err := solver.Solve(clientChallenge, "127.0.0.1"); err == nil {
|
||||||
t.Error("UNEXPECTED: Expected Solve to return an error but the error was nil.")
|
t.Error("UNEXPECTED: Expected Solve to return an error but the error was nil.")
|
||||||
} else {
|
} else {
|
||||||
expectedError := "[500] Type: urn:acme:error:unauthorized Detail: Error creating new authz :: Syntax error"
|
expectedError := "[500] Type: urn:acme:error:unauthorized Detail: Error creating new authz :: Syntax error"
|
||||||
|
@ -157,7 +157,7 @@ func TestSimpleHTTPInvalidServerState(t *testing.T) {
|
||||||
solver := &simpleHTTPChallenge{jws: jws, optPort: "23456"}
|
solver := &simpleHTTPChallenge{jws: jws, optPort: "23456"}
|
||||||
clientChallenge := challenge{Type: "simpleHttp", Status: "pending", URI: ts.URL, Token: "7"}
|
clientChallenge := challenge{Type: "simpleHttp", Status: "pending", URI: ts.URL, Token: "7"}
|
||||||
|
|
||||||
if err := solver.Solve(clientChallenge, "test.domain"); err == nil {
|
if err := solver.Solve(clientChallenge, "127.0.0.1"); err == nil {
|
||||||
t.Error("UNEXPECTED: Expected Solve to return an error but the error was nil.")
|
t.Error("UNEXPECTED: Expected Solve to return an error but the error was nil.")
|
||||||
} else {
|
} else {
|
||||||
expectedError := "The server could not validate our request."
|
expectedError := "The server could not validate our request."
|
||||||
|
@ -179,7 +179,7 @@ func TestSimpleHTTPValidServerResponse(t *testing.T) {
|
||||||
solver := &simpleHTTPChallenge{jws: jws, optPort: "23456"}
|
solver := &simpleHTTPChallenge{jws: jws, optPort: "23456"}
|
||||||
clientChallenge := challenge{Type: "simpleHttp", Status: "pending", URI: ts.URL, Token: "8"}
|
clientChallenge := challenge{Type: "simpleHttp", Status: "pending", URI: ts.URL, Token: "8"}
|
||||||
|
|
||||||
if err := solver.Solve(clientChallenge, "test.domain"); err != nil {
|
if err := solver.Solve(clientChallenge, "127.0.0.1"); err != nil {
|
||||||
t.Errorf("VALID: Expected Solve to return no error but the error was -> %v", err)
|
t.Errorf("VALID: Expected Solve to return no error but the error was -> %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -221,7 +221,7 @@ func TestSimpleHTTPValidFull(t *testing.T) {
|
||||||
reqURL := "https://localhost:23456/.well-known/acme-challenge/" + clientChallenge.Token
|
reqURL := "https://localhost:23456/.well-known/acme-challenge/" + clientChallenge.Token
|
||||||
t.Logf("Request URL is: %s", reqURL)
|
t.Logf("Request URL is: %s", reqURL)
|
||||||
req, _ := http.NewRequest("GET", reqURL, nil)
|
req, _ := http.NewRequest("GET", reqURL, nil)
|
||||||
req.Host = "test.domain"
|
req.Host = "127.0.0.1"
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Expected the solver to listen on port 23456 -> %v", err)
|
t.Errorf("Expected the solver to listen on port 23456 -> %v", err)
|
||||||
|
@ -245,7 +245,7 @@ func TestSimpleHTTPValidFull(t *testing.T) {
|
||||||
w.Write(jsonBytes)
|
w.Write(jsonBytes)
|
||||||
})
|
})
|
||||||
|
|
||||||
if err := solver.Solve(clientChallenge, "test.domain"); err != nil {
|
if err := solver.Solve(clientChallenge, "127.0.0.1"); err != nil {
|
||||||
t.Errorf("VALID: Expected Solve to return no error but the error was -> %v", err)
|
t.Errorf("VALID: Expected Solve to return no error but the error was -> %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue