forked from TrueCloudLab/lego
Update tests
This commit is contained in:
parent
de29381f7a
commit
0c10083ef0
3 changed files with 30 additions and 10 deletions
|
@ -4,6 +4,7 @@ import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -66,12 +67,13 @@ func TestClientOptPort(t *testing.T) {
|
||||||
}))
|
}))
|
||||||
|
|
||||||
optPort := "1234"
|
optPort := "1234"
|
||||||
|
optHost := ""
|
||||||
client, err := NewClient(ts.URL, user, keyBits)
|
client, err := NewClient(ts.URL, user, keyBits)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Could not create client: %v", err)
|
t.Fatalf("Could not create client: %v", err)
|
||||||
}
|
}
|
||||||
client.SetHTTPPort(optPort)
|
client.SetHTTPAddress(net.JoinHostPort(optHost, optPort))
|
||||||
client.SetTLSPort(optPort)
|
client.SetTLSAddress(net.JoinHostPort(optHost, optPort))
|
||||||
|
|
||||||
httpSolver, ok := client.solvers["http-01"].(*httpChallenge)
|
httpSolver, ok := client.solvers["http-01"].(*httpChallenge)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -80,8 +82,11 @@ func TestClientOptPort(t *testing.T) {
|
||||||
if httpSolver.jws != client.jws {
|
if httpSolver.jws != client.jws {
|
||||||
t.Error("Expected http-01 to have same jws as client")
|
t.Error("Expected http-01 to have same jws as client")
|
||||||
}
|
}
|
||||||
if httpSolver.optPort != optPort {
|
if httpSolver.port != optPort {
|
||||||
t.Errorf("Expected http-01 to have optPort %s but was %s", optPort, httpSolver.optPort)
|
t.Errorf("Expected http-01 to have port %s but was %s", optPort, httpSolver.port)
|
||||||
|
}
|
||||||
|
if httpSolver.iface != optHost {
|
||||||
|
t.Errorf("Expected http-01 to have iface %s but was %s", optHost, httpSolver.iface)
|
||||||
}
|
}
|
||||||
|
|
||||||
httpsSolver, ok := client.solvers["tls-sni-01"].(*tlsSNIChallenge)
|
httpsSolver, ok := client.solvers["tls-sni-01"].(*tlsSNIChallenge)
|
||||||
|
@ -91,8 +96,23 @@ func TestClientOptPort(t *testing.T) {
|
||||||
if httpsSolver.jws != client.jws {
|
if httpsSolver.jws != client.jws {
|
||||||
t.Error("Expected tls-sni-01 to have same jws as client")
|
t.Error("Expected tls-sni-01 to have same jws as client")
|
||||||
}
|
}
|
||||||
if httpsSolver.optPort != optPort {
|
if httpsSolver.port != optPort {
|
||||||
t.Errorf("Expected tls-sni-01 to have optPort %s but was %s", optPort, httpSolver.optPort)
|
t.Errorf("Expected tls-sni-01 to have port %s but was %s", optPort, httpSolver.port)
|
||||||
|
}
|
||||||
|
if httpsSolver.port != optPort {
|
||||||
|
t.Errorf("Expected tls-sni-01 to have port %s but was %s", optHost, httpSolver.iface)
|
||||||
|
}
|
||||||
|
|
||||||
|
// test setting different host
|
||||||
|
optHost = "127.0.0.1"
|
||||||
|
client.SetHTTPAddress(net.JoinHostPort(optHost, optPort))
|
||||||
|
client.SetTLSAddress(net.JoinHostPort(optHost, optPort))
|
||||||
|
|
||||||
|
if httpSolver.iface != optHost {
|
||||||
|
t.Errorf("Expected http-01 to have iface %s but was %s", optHost, httpSolver.iface)
|
||||||
|
}
|
||||||
|
if httpsSolver.port != optPort {
|
||||||
|
t.Errorf("Expected tls-sni-01 to have port %s but was %s", optHost, httpSolver.iface)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ func TestHTTPChallenge(t *testing.T) {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
solver := &httpChallenge{jws: j, validate: mockValidate, optPort: "23457"}
|
solver := &httpChallenge{jws: j, validate: mockValidate, port: "23457"}
|
||||||
|
|
||||||
if err := solver.Solve(clientChallenge, "localhost:23457"); err != nil {
|
if err := solver.Solve(clientChallenge, "localhost:23457"); err != nil {
|
||||||
t.Errorf("Solve error: got %v, want nil", err)
|
t.Errorf("Solve error: got %v, want nil", err)
|
||||||
|
@ -46,7 +46,7 @@ func TestHTTPChallengeInvalidPort(t *testing.T) {
|
||||||
privKey, _ := generatePrivateKey(rsakey, 128)
|
privKey, _ := generatePrivateKey(rsakey, 128)
|
||||||
j := &jws{privKey: privKey.(*rsa.PrivateKey)}
|
j := &jws{privKey: privKey.(*rsa.PrivateKey)}
|
||||||
clientChallenge := challenge{Type: "http-01", Token: "http2"}
|
clientChallenge := challenge{Type: "http-01", Token: "http2"}
|
||||||
solver := &httpChallenge{jws: j, validate: stubValidate, optPort: "123456"}
|
solver := &httpChallenge{jws: j, validate: stubValidate, port: "123456"}
|
||||||
|
|
||||||
if err := solver.Solve(clientChallenge, "localhost:123456"); err == nil {
|
if err := solver.Solve(clientChallenge, "localhost:123456"); err == nil {
|
||||||
t.Errorf("Solve error: got %v, want error", err)
|
t.Errorf("Solve error: got %v, want error", err)
|
||||||
|
|
|
@ -43,7 +43,7 @@ func TestTLSSNIChallenge(t *testing.T) {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
solver := &tlsSNIChallenge{jws: j, validate: mockValidate, optPort: "23457"}
|
solver := &tlsSNIChallenge{jws: j, validate: mockValidate, port: "23457"}
|
||||||
|
|
||||||
if err := solver.Solve(clientChallenge, "localhost:23457"); err != nil {
|
if err := solver.Solve(clientChallenge, "localhost:23457"); err != nil {
|
||||||
t.Errorf("Solve error: got %v, want nil", err)
|
t.Errorf("Solve error: got %v, want nil", err)
|
||||||
|
@ -54,7 +54,7 @@ func TestTLSSNIChallengeInvalidPort(t *testing.T) {
|
||||||
privKey, _ := generatePrivateKey(rsakey, 128)
|
privKey, _ := generatePrivateKey(rsakey, 128)
|
||||||
j := &jws{privKey: privKey.(*rsa.PrivateKey)}
|
j := &jws{privKey: privKey.(*rsa.PrivateKey)}
|
||||||
clientChallenge := challenge{Type: "tls-sni-01", Token: "tlssni2"}
|
clientChallenge := challenge{Type: "tls-sni-01", Token: "tlssni2"}
|
||||||
solver := &tlsSNIChallenge{jws: j, validate: stubValidate, optPort: "123456"}
|
solver := &tlsSNIChallenge{jws: j, validate: stubValidate, port: "123456"}
|
||||||
|
|
||||||
if err := solver.Solve(clientChallenge, "localhost:123456"); err == nil {
|
if err := solver.Solve(clientChallenge, "localhost:123456"); err == nil {
|
||||||
t.Errorf("Solve error: got %v, want error", err)
|
t.Errorf("Solve error: got %v, want error", err)
|
||||||
|
|
Loading…
Reference in a new issue