Make solvers private + remove random from crypto tests

This commit is contained in:
xenolf 2015-06-14 02:33:21 +02:00
parent ed78dc8a1d
commit 98e23bab07
3 changed files with 18 additions and 7 deletions

View file

@ -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)

View file

@ -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")
}

View file

@ -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)
}