Adapt tests to EC changes

This commit is contained in:
xenolf 2016-01-27 02:01:58 +01:00
parent 0e26bb45ca
commit 1f777a0d77
5 changed files with 27 additions and 21 deletions

View file

@ -1,6 +1,7 @@
package acme package acme
import ( import (
"crypto"
"crypto/rand" "crypto/rand"
"crypto/rsa" "crypto/rsa"
"encoding/json" "encoding/json"
@ -13,6 +14,7 @@ import (
func TestNewClient(t *testing.T) { func TestNewClient(t *testing.T) {
keyBits := 32 // small value keeps test fast keyBits := 32 // small value keeps test fast
keyType := RSA2048
key, err := rsa.GenerateKey(rand.Reader, keyBits) key, err := rsa.GenerateKey(rand.Reader, keyBits)
if err != nil { if err != nil {
t.Fatal("Could not generate test key:", err) t.Fatal("Could not generate test key:", err)
@ -28,7 +30,7 @@ func TestNewClient(t *testing.T) {
w.Write(data) w.Write(data)
})) }))
client, err := NewClient(ts.URL, user, keyBits) client, err := NewClient(ts.URL, user, keyType)
if err != nil { if err != nil {
t.Fatalf("Could not create client: %v", err) t.Fatalf("Could not create client: %v", err)
} }
@ -40,8 +42,8 @@ func TestNewClient(t *testing.T) {
t.Errorf("Expected jws.privKey to be %p but was %p", expected, actual) t.Errorf("Expected jws.privKey to be %p but was %p", expected, actual)
} }
if client.keyBits != keyBits { if client.keyType != keyType {
t.Errorf("Expected keyBits to be %d but was %d", keyBits, client.keyBits) t.Errorf("Expected keyBits to be %d but was %d", keyType, client.keyType)
} }
if expected, actual := 2, len(client.solvers); actual != expected { if expected, actual := 2, len(client.solvers); actual != expected {
@ -68,7 +70,7 @@ func TestClientOptPort(t *testing.T) {
optPort := "1234" optPort := "1234"
optHost := "" optHost := ""
client, err := NewClient(ts.URL, user, keyBits) client, err := NewClient(ts.URL, user, RSA2048)
if err != nil { if err != nil {
t.Fatalf("Could not create client: %v", err) t.Fatalf("Could not create client: %v", err)
} }
@ -140,8 +142,8 @@ func TestValidate(t *testing.T) {
})) }))
defer ts.Close() defer ts.Close()
privKey, _ := generatePrivateKey(rsakey, 512) privKey, _ := rsa.GenerateKey(rand.Reader, 512)
j := &jws{privKey: privKey.(*rsa.PrivateKey), directoryURL: ts.URL} j := &jws{privKey: privKey, directoryURL: ts.URL}
tsts := []struct { tsts := []struct {
name string name string
@ -193,4 +195,4 @@ type mockUser struct {
func (u mockUser) GetEmail() string { return u.email } func (u mockUser) GetEmail() string { return u.email }
func (u mockUser) GetRegistration() *RegistrationResource { return u.regres } func (u mockUser) GetRegistration() *RegistrationResource { return u.regres }
func (u mockUser) GetPrivateKey() *rsa.PrivateKey { return u.privatekey } func (u mockUser) GetPrivateKey() crypto.PrivateKey { return u.privatekey }

View file

@ -2,13 +2,14 @@ package acme
import ( import (
"bytes" "bytes"
"crypto/rand"
"crypto/rsa" "crypto/rsa"
"testing" "testing"
"time" "time"
) )
func TestGeneratePrivateKey(t *testing.T) { func TestGeneratePrivateKey(t *testing.T) {
key, err := generatePrivateKey(rsakey, 32) key, err := generatePrivateKey(RSA2048)
if err != nil { if err != nil {
t.Error("Error generating private key:", err) t.Error("Error generating private key:", err)
} }
@ -18,12 +19,12 @@ func TestGeneratePrivateKey(t *testing.T) {
} }
func TestGenerateCSR(t *testing.T) { func TestGenerateCSR(t *testing.T) {
key, err := generatePrivateKey(rsakey, 512) key, err := rsa.GenerateKey(rand.Reader, 512)
if err != nil { if err != nil {
t.Fatal("Error generating private key:", err) t.Fatal("Error generating private key:", err)
} }
csr, err := generateCsr(key.(*rsa.PrivateKey), "fizz.buzz", nil) csr, err := generateCsr(key, "fizz.buzz", nil)
if err != nil { if err != nil {
t.Error("Error generating CSR:", err) t.Error("Error generating CSR:", err)
} }
@ -52,7 +53,7 @@ func TestPEMEncode(t *testing.T) {
} }
func TestPEMCertExpiration(t *testing.T) { func TestPEMCertExpiration(t *testing.T) {
privKey, err := generatePrivateKey(rsakey, 2048) privKey, err := generatePrivateKey(RSA2048)
if err != nil { if err != nil {
t.Fatal("Error generating private key:", err) t.Fatal("Error generating private key:", err)
} }

View file

@ -2,6 +2,7 @@ package acme
import ( import (
"bufio" "bufio"
"crypto/rand"
"crypto/rsa" "crypto/rsa"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
@ -76,7 +77,7 @@ func TestDNSValidServerResponse(t *testing.T) {
preCheckDNS = func(fqdn, value string) (bool, error) { preCheckDNS = func(fqdn, value string) (bool, error) {
return true, nil return true, nil
} }
privKey, _ := generatePrivateKey(rsakey, 512) privKey, _ := rsa.GenerateKey(rand.Reader, 512)
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Replay-Nonce", "12345") w.Header().Add("Replay-Nonce", "12345")
@ -84,7 +85,7 @@ func TestDNSValidServerResponse(t *testing.T) {
})) }))
manualProvider, _ := NewDNSProviderManual() manualProvider, _ := NewDNSProviderManual()
jws := &jws{privKey: privKey.(*rsa.PrivateKey), directoryURL: ts.URL} jws := &jws{privKey: privKey, directoryURL: ts.URL}
solver := &dnsChallenge{jws: jws, validate: validate, provider: manualProvider} solver := &dnsChallenge{jws: jws, validate: validate, provider: manualProvider}
clientChallenge := challenge{Type: "dns01", Status: "pending", URI: ts.URL, Token: "http8"} clientChallenge := challenge{Type: "dns01", Status: "pending", URI: ts.URL, Token: "http8"}

View file

@ -1,6 +1,7 @@
package acme package acme
import ( import (
"crypto/rand"
"crypto/rsa" "crypto/rsa"
"io/ioutil" "io/ioutil"
"strings" "strings"
@ -8,8 +9,8 @@ import (
) )
func TestHTTPChallenge(t *testing.T) { func TestHTTPChallenge(t *testing.T) {
privKey, _ := generatePrivateKey(rsakey, 512) privKey, _ := rsa.GenerateKey(rand.Reader, 512)
j := &jws{privKey: privKey.(*rsa.PrivateKey)} j := &jws{privKey: privKey}
clientChallenge := challenge{Type: HTTP01, Token: "http1"} clientChallenge := challenge{Type: HTTP01, Token: "http1"}
mockValidate := func(_ *jws, _, _ string, chlng challenge) error { mockValidate := func(_ *jws, _, _ string, chlng challenge) error {
uri := "http://localhost:23457/.well-known/acme-challenge/" + chlng.Token uri := "http://localhost:23457/.well-known/acme-challenge/" + chlng.Token
@ -43,8 +44,8 @@ func TestHTTPChallenge(t *testing.T) {
} }
func TestHTTPChallengeInvalidPort(t *testing.T) { func TestHTTPChallengeInvalidPort(t *testing.T) {
privKey, _ := generatePrivateKey(rsakey, 128) privKey, _ := rsa.GenerateKey(rand.Reader, 128)
j := &jws{privKey: privKey.(*rsa.PrivateKey)} j := &jws{privKey: privKey}
clientChallenge := challenge{Type: HTTP01, Token: "http2"} clientChallenge := challenge{Type: HTTP01, Token: "http2"}
solver := &httpChallenge{jws: j, validate: stubValidate, provider: &HTTPProviderServer{port: "123456"}} solver := &httpChallenge{jws: j, validate: stubValidate, provider: &HTTPProviderServer{port: "123456"}}

View file

@ -1,6 +1,7 @@
package acme package acme
import ( import (
"crypto/rand"
"crypto/rsa" "crypto/rsa"
"crypto/sha256" "crypto/sha256"
"crypto/tls" "crypto/tls"
@ -11,8 +12,8 @@ import (
) )
func TestTLSSNIChallenge(t *testing.T) { func TestTLSSNIChallenge(t *testing.T) {
privKey, _ := generatePrivateKey(rsakey, 512) privKey, _ := rsa.GenerateKey(rand.Reader, 512)
j := &jws{privKey: privKey.(*rsa.PrivateKey)} j := &jws{privKey: privKey}
clientChallenge := challenge{Type: TLSSNI01, Token: "tlssni1"} clientChallenge := challenge{Type: TLSSNI01, Token: "tlssni1"}
mockValidate := func(_ *jws, _, _ string, chlng challenge) error { mockValidate := func(_ *jws, _, _ string, chlng challenge) error {
conn, err := tls.Dial("tcp", "localhost:23457", &tls.Config{ conn, err := tls.Dial("tcp", "localhost:23457", &tls.Config{
@ -51,8 +52,8 @@ func TestTLSSNIChallenge(t *testing.T) {
} }
func TestTLSSNIChallengeInvalidPort(t *testing.T) { func TestTLSSNIChallengeInvalidPort(t *testing.T) {
privKey, _ := generatePrivateKey(rsakey, 128) privKey, _ := rsa.GenerateKey(rand.Reader, 128)
j := &jws{privKey: privKey.(*rsa.PrivateKey)} j := &jws{privKey: privKey}
clientChallenge := challenge{Type: TLSSNI01, Token: "tlssni2"} clientChallenge := challenge{Type: TLSSNI01, Token: "tlssni2"}
solver := &tlsSNIChallenge{jws: j, validate: stubValidate, provider: &TLSProviderServer{port: "123456"}} solver := &tlsSNIChallenge{jws: j, validate: stubValidate, provider: &TLSProviderServer{port: "123456"}}