diff --git a/acme/client.go b/acme/client.go index 39d1288a..fbc33e11 100644 --- a/acme/client.go +++ b/acme/client.go @@ -45,7 +45,7 @@ type Client struct { user User jws *jws keyBits int - Solvers map[string]solver + solvers map[string]solver } // NewClient creates a new client for the set user. @@ -62,7 +62,7 @@ func NewClient(caURL string, usr User, keyBits int, optPort string) *Client { solvers := make(map[string]solver) solvers["simpleHttps"] = &simpleHTTPChallenge{jws: jws, optPort: optPort} - return &Client{regURL: caURL, user: usr, jws: jws, keyBits: keyBits, Solvers: solvers} + return &Client{regURL: caURL, user: usr, jws: jws, keyBits: keyBits, solvers: solvers} } // Register the current account to the ACME server. @@ -172,7 +172,7 @@ func (c *Client) chooseSolvers(auth authorization, domain string) map[int]solver for _, combination := range auth.Combinations { solvers := make(map[int]solver) for _, idx := range combination { - if solver, ok := c.Solvers[auth.Challenges[idx].Type]; ok && solver.CanSolve(domain) { + if solver, ok := c.solvers[auth.Challenges[idx].Type]; ok && solver.CanSolve(domain) { solvers[idx] = solver } else { logger().Printf("Could not find solver for: %s", auth.Challenges[idx].Type) diff --git a/acme/client_test.go b/acme/client_test.go index aa762561..0c2e8c1e 100644 --- a/acme/client_test.go +++ b/acme/client_test.go @@ -34,11 +34,11 @@ func TestNewClient(t *testing.T) { t.Errorf("Expected keyBits to be %d but was %d", keyBits, client.keyBits) } - if expected, actual := 1, len(client.Solvers); actual != expected { + if expected, actual := 1, len(client.solvers); actual != expected { t.Fatal("Expected %d solver(s), got %d", expected, actual) } - simphttp, ok := client.Solvers["simpleHttps"].(*simpleHTTPChallenge) + simphttp, ok := client.solvers["simpleHttps"].(*simpleHTTPChallenge) if !ok { t.Fatal("Expected simpleHttps solver to be simpleHTTPChallenge type") } diff --git a/acme/crypto_test.go b/acme/crypto_test.go index 588d59d2..49c72e0c 100644 --- a/acme/crypto_test.go +++ b/acme/crypto_test.go @@ -1,7 +1,7 @@ package acme import ( - "crypto/rand" + "bytes" "crypto/rsa" "testing" ) @@ -32,7 +32,10 @@ func TestGenerateCSR(t *testing.T) { } func TestPEMEncode(t *testing.T) { - key, err := rsa.GenerateKey(rand.Reader, 32) + buf := bytes.NewBufferString("TestingRSAIsSoMuchFun") + + reader := MockRandReader{b: buf} + key, err := rsa.GenerateKey(reader, 32) if err != nil { t.Fatal("Error generating private key:", err) } @@ -46,3 +49,11 @@ func TestPEMEncode(t *testing.T) { t.Errorf("Expected PEM encoding to be length 127, but it was %d", len(data)) } } + +type MockRandReader struct { + b *bytes.Buffer +} + +func (r MockRandReader) Read(p []byte) (int, error) { + return r.b.Read(p) +}