From 0c10083ef09f17dbc95dba5e5c3c8aed87f79c85 Mon Sep 17 00:00:00 2001 From: xenolf Date: Fri, 8 Jan 2016 08:04:50 +0100 Subject: [PATCH] Update tests --- acme/client_test.go | 32 ++++++++++++++++++++++++++------ acme/http_challenge_test.go | 4 ++-- acme/tls_sni_challenge_test.go | 4 ++-- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/acme/client_test.go b/acme/client_test.go index cd89b257..3daaed5f 100644 --- a/acme/client_test.go +++ b/acme/client_test.go @@ -4,6 +4,7 @@ import ( "crypto/rand" "crypto/rsa" "encoding/json" + "net" "net/http" "net/http/httptest" "strings" @@ -66,12 +67,13 @@ func TestClientOptPort(t *testing.T) { })) optPort := "1234" + optHost := "" client, err := NewClient(ts.URL, user, keyBits) if err != nil { t.Fatalf("Could not create client: %v", err) } - client.SetHTTPPort(optPort) - client.SetTLSPort(optPort) + client.SetHTTPAddress(net.JoinHostPort(optHost, optPort)) + client.SetTLSAddress(net.JoinHostPort(optHost, optPort)) httpSolver, ok := client.solvers["http-01"].(*httpChallenge) if !ok { @@ -80,8 +82,11 @@ func TestClientOptPort(t *testing.T) { if httpSolver.jws != client.jws { t.Error("Expected http-01 to have same jws as client") } - if httpSolver.optPort != optPort { - t.Errorf("Expected http-01 to have optPort %s but was %s", optPort, httpSolver.optPort) + if httpSolver.port != 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) @@ -91,8 +96,23 @@ func TestClientOptPort(t *testing.T) { if httpsSolver.jws != client.jws { t.Error("Expected tls-sni-01 to have same jws as client") } - if httpsSolver.optPort != optPort { - t.Errorf("Expected tls-sni-01 to have optPort %s but was %s", optPort, httpSolver.optPort) + if httpsSolver.port != 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) } } diff --git a/acme/http_challenge_test.go b/acme/http_challenge_test.go index cb1aec34..9ffb27f8 100644 --- a/acme/http_challenge_test.go +++ b/acme/http_challenge_test.go @@ -35,7 +35,7 @@ func TestHTTPChallenge(t *testing.T) { 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 { t.Errorf("Solve error: got %v, want nil", err) @@ -46,7 +46,7 @@ func TestHTTPChallengeInvalidPort(t *testing.T) { privKey, _ := generatePrivateKey(rsakey, 128) j := &jws{privKey: privKey.(*rsa.PrivateKey)} 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 { t.Errorf("Solve error: got %v, want error", err) diff --git a/acme/tls_sni_challenge_test.go b/acme/tls_sni_challenge_test.go index 562cb073..f2350303 100644 --- a/acme/tls_sni_challenge_test.go +++ b/acme/tls_sni_challenge_test.go @@ -43,7 +43,7 @@ func TestTLSSNIChallenge(t *testing.T) { 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 { t.Errorf("Solve error: got %v, want nil", err) @@ -54,7 +54,7 @@ func TestTLSSNIChallengeInvalidPort(t *testing.T) { privKey, _ := generatePrivateKey(rsakey, 128) j := &jws{privKey: privKey.(*rsa.PrivateKey)} 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 { t.Errorf("Solve error: got %v, want error", err)