Apply base context to test of the ca package
This commit is contained in:
parent
9147356d8a
commit
62d93a644e
3 changed files with 24 additions and 7 deletions
|
@ -53,7 +53,11 @@ func startCABootstrapServer() *httptest.Server {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
baseContext := buildContext(ca.auth, nil, nil, nil)
|
||||||
srv.Config.Handler = ca.srv.Handler
|
srv.Config.Handler = ca.srv.Handler
|
||||||
|
srv.Config.BaseContext = func(net.Listener) context.Context {
|
||||||
|
return baseContext
|
||||||
|
}
|
||||||
srv.TLS = ca.srv.TLSConfig
|
srv.TLS = ca.srv.TLSConfig
|
||||||
srv.StartTLS()
|
srv.StartTLS()
|
||||||
// Force the use of GetCertificate on IPs
|
// Force the use of GetCertificate on IPs
|
||||||
|
|
|
@ -2,6 +2,7 @@ package ca
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"crypto"
|
"crypto"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"crypto/sha1"
|
"crypto/sha1"
|
||||||
|
@ -281,7 +282,8 @@ ZEp7knvU2psWRw==
|
||||||
assert.FatalError(t, err)
|
assert.FatalError(t, err)
|
||||||
rr := httptest.NewRecorder()
|
rr := httptest.NewRecorder()
|
||||||
|
|
||||||
tc.ca.srv.Handler.ServeHTTP(rr, rq)
|
ctx := authority.NewContext(context.Background(), tc.ca.auth)
|
||||||
|
tc.ca.srv.Handler.ServeHTTP(rr, rq.WithContext(ctx))
|
||||||
|
|
||||||
if assert.Equals(t, rr.Code, tc.status) {
|
if assert.Equals(t, rr.Code, tc.status) {
|
||||||
body := &ClosingBuffer{rr.Body}
|
body := &ClosingBuffer{rr.Body}
|
||||||
|
@ -360,7 +362,8 @@ func TestCAProvisioners(t *testing.T) {
|
||||||
assert.FatalError(t, err)
|
assert.FatalError(t, err)
|
||||||
rr := httptest.NewRecorder()
|
rr := httptest.NewRecorder()
|
||||||
|
|
||||||
tc.ca.srv.Handler.ServeHTTP(rr, rq)
|
ctx := authority.NewContext(context.Background(), tc.ca.auth)
|
||||||
|
tc.ca.srv.Handler.ServeHTTP(rr, rq.WithContext(ctx))
|
||||||
|
|
||||||
if assert.Equals(t, rr.Code, tc.status) {
|
if assert.Equals(t, rr.Code, tc.status) {
|
||||||
body := &ClosingBuffer{rr.Body}
|
body := &ClosingBuffer{rr.Body}
|
||||||
|
@ -426,7 +429,8 @@ func TestCAProvisionerEncryptedKey(t *testing.T) {
|
||||||
assert.FatalError(t, err)
|
assert.FatalError(t, err)
|
||||||
rr := httptest.NewRecorder()
|
rr := httptest.NewRecorder()
|
||||||
|
|
||||||
tc.ca.srv.Handler.ServeHTTP(rr, rq)
|
ctx := authority.NewContext(context.Background(), tc.ca.auth)
|
||||||
|
tc.ca.srv.Handler.ServeHTTP(rr, rq.WithContext(ctx))
|
||||||
|
|
||||||
if assert.Equals(t, rr.Code, tc.status) {
|
if assert.Equals(t, rr.Code, tc.status) {
|
||||||
body := &ClosingBuffer{rr.Body}
|
body := &ClosingBuffer{rr.Body}
|
||||||
|
@ -487,7 +491,8 @@ func TestCARoot(t *testing.T) {
|
||||||
assert.FatalError(t, err)
|
assert.FatalError(t, err)
|
||||||
rr := httptest.NewRecorder()
|
rr := httptest.NewRecorder()
|
||||||
|
|
||||||
tc.ca.srv.Handler.ServeHTTP(rr, rq)
|
ctx := authority.NewContext(context.Background(), tc.ca.auth)
|
||||||
|
tc.ca.srv.Handler.ServeHTTP(rr, rq.WithContext(ctx))
|
||||||
|
|
||||||
if assert.Equals(t, rr.Code, tc.status) {
|
if assert.Equals(t, rr.Code, tc.status) {
|
||||||
body := &ClosingBuffer{rr.Body}
|
body := &ClosingBuffer{rr.Body}
|
||||||
|
@ -534,7 +539,8 @@ func TestCAHealth(t *testing.T) {
|
||||||
assert.FatalError(t, err)
|
assert.FatalError(t, err)
|
||||||
rr := httptest.NewRecorder()
|
rr := httptest.NewRecorder()
|
||||||
|
|
||||||
tc.ca.srv.Handler.ServeHTTP(rr, rq)
|
ctx := authority.NewContext(context.Background(), tc.ca.auth)
|
||||||
|
tc.ca.srv.Handler.ServeHTTP(rr, rq.WithContext(ctx))
|
||||||
|
|
||||||
if assert.Equals(t, rr.Code, tc.status) {
|
if assert.Equals(t, rr.Code, tc.status) {
|
||||||
body := &ClosingBuffer{rr.Body}
|
body := &ClosingBuffer{rr.Body}
|
||||||
|
@ -628,7 +634,8 @@ func TestCARenew(t *testing.T) {
|
||||||
rq.TLS = tc.tlsConnState
|
rq.TLS = tc.tlsConnState
|
||||||
rr := httptest.NewRecorder()
|
rr := httptest.NewRecorder()
|
||||||
|
|
||||||
tc.ca.srv.Handler.ServeHTTP(rr, rq)
|
ctx := authority.NewContext(context.Background(), tc.ca.auth)
|
||||||
|
tc.ca.srv.Handler.ServeHTTP(rr, rq.WithContext(ctx))
|
||||||
|
|
||||||
if assert.Equals(t, rr.Code, tc.status) {
|
if assert.Equals(t, rr.Code, tc.status) {
|
||||||
body := &ClosingBuffer{rr.Body}
|
body := &ClosingBuffer{rr.Body}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
@ -77,7 +78,12 @@ func startCATestServer() *httptest.Server {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
// Use a httptest.Server instead
|
// Use a httptest.Server instead
|
||||||
return startTestServer(ca.srv.TLSConfig, ca.srv.Handler)
|
srv := startTestServer(ca.srv.TLSConfig, ca.srv.Handler)
|
||||||
|
baseContext := buildContext(ca.auth, nil, nil, nil)
|
||||||
|
srv.Config.BaseContext = func(net.Listener) context.Context {
|
||||||
|
return baseContext
|
||||||
|
}
|
||||||
|
return srv
|
||||||
}
|
}
|
||||||
|
|
||||||
func sign(domain string) (*Client, *api.SignResponse, crypto.PrivateKey) {
|
func sign(domain string) (*Client, *api.SignResponse, crypto.PrivateKey) {
|
||||||
|
|
Loading…
Reference in a new issue