forked from TrueCloudLab/lego
Make solvers private + remove random from crypto tests
This commit is contained in:
parent
ed78dc8a1d
commit
98e23bab07
3 changed files with 18 additions and 7 deletions
|
@ -45,7 +45,7 @@ type Client struct {
|
||||||
user User
|
user User
|
||||||
jws *jws
|
jws *jws
|
||||||
keyBits int
|
keyBits int
|
||||||
Solvers map[string]solver
|
solvers map[string]solver
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewClient creates a new client for the set user.
|
// 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 := make(map[string]solver)
|
||||||
solvers["simpleHttps"] = &simpleHTTPChallenge{jws: jws, optPort: optPort}
|
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.
|
// 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 {
|
for _, combination := range auth.Combinations {
|
||||||
solvers := make(map[int]solver)
|
solvers := make(map[int]solver)
|
||||||
for _, idx := range combination {
|
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
|
solvers[idx] = solver
|
||||||
} else {
|
} else {
|
||||||
logger().Printf("Could not find solver for: %s", auth.Challenges[idx].Type)
|
logger().Printf("Could not find solver for: %s", auth.Challenges[idx].Type)
|
||||||
|
|
|
@ -34,11 +34,11 @@ func TestNewClient(t *testing.T) {
|
||||||
t.Errorf("Expected keyBits to be %d but was %d", keyBits, client.keyBits)
|
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)
|
t.Fatal("Expected %d solver(s), got %d", expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
simphttp, ok := client.Solvers["simpleHttps"].(*simpleHTTPChallenge)
|
simphttp, ok := client.solvers["simpleHttps"].(*simpleHTTPChallenge)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatal("Expected simpleHttps solver to be simpleHTTPChallenge type")
|
t.Fatal("Expected simpleHttps solver to be simpleHTTPChallenge type")
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package acme
|
package acme
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"bytes"
|
||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
@ -32,7 +32,10 @@ func TestGenerateCSR(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPEMEncode(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 {
|
if err != nil {
|
||||||
t.Fatal("Error generating private key:", err)
|
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))
|
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)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue