Skip to content

Commit 62d93a6

Browse files
committed
Apply base context to test of the ca package
1 parent 9147356 commit 62d93a6

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

ca/bootstrap_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ func startCABootstrapServer() *httptest.Server {
5353
if err != nil {
5454
panic(err)
5555
}
56+
baseContext := buildContext(ca.auth, nil, nil, nil)
5657
srv.Config.Handler = ca.srv.Handler
58+
srv.Config.BaseContext = func(net.Listener) context.Context {
59+
return baseContext
60+
}
5761
srv.TLS = ca.srv.TLSConfig
5862
srv.StartTLS()
5963
// Force the use of GetCertificate on IPs

ca/ca_test.go

+13-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package ca
22

33
import (
44
"bytes"
5+
"context"
56
"crypto"
67
"crypto/rand"
78
"crypto/sha1"
@@ -281,7 +282,8 @@ ZEp7knvU2psWRw==
281282
assert.FatalError(t, err)
282283
rr := httptest.NewRecorder()
283284

284-
tc.ca.srv.Handler.ServeHTTP(rr, rq)
285+
ctx := authority.NewContext(context.Background(), tc.ca.auth)
286+
tc.ca.srv.Handler.ServeHTTP(rr, rq.WithContext(ctx))
285287

286288
if assert.Equals(t, rr.Code, tc.status) {
287289
body := &ClosingBuffer{rr.Body}
@@ -360,7 +362,8 @@ func TestCAProvisioners(t *testing.T) {
360362
assert.FatalError(t, err)
361363
rr := httptest.NewRecorder()
362364

363-
tc.ca.srv.Handler.ServeHTTP(rr, rq)
365+
ctx := authority.NewContext(context.Background(), tc.ca.auth)
366+
tc.ca.srv.Handler.ServeHTTP(rr, rq.WithContext(ctx))
364367

365368
if assert.Equals(t, rr.Code, tc.status) {
366369
body := &ClosingBuffer{rr.Body}
@@ -426,7 +429,8 @@ func TestCAProvisionerEncryptedKey(t *testing.T) {
426429
assert.FatalError(t, err)
427430
rr := httptest.NewRecorder()
428431

429-
tc.ca.srv.Handler.ServeHTTP(rr, rq)
432+
ctx := authority.NewContext(context.Background(), tc.ca.auth)
433+
tc.ca.srv.Handler.ServeHTTP(rr, rq.WithContext(ctx))
430434

431435
if assert.Equals(t, rr.Code, tc.status) {
432436
body := &ClosingBuffer{rr.Body}
@@ -487,7 +491,8 @@ func TestCARoot(t *testing.T) {
487491
assert.FatalError(t, err)
488492
rr := httptest.NewRecorder()
489493

490-
tc.ca.srv.Handler.ServeHTTP(rr, rq)
494+
ctx := authority.NewContext(context.Background(), tc.ca.auth)
495+
tc.ca.srv.Handler.ServeHTTP(rr, rq.WithContext(ctx))
491496

492497
if assert.Equals(t, rr.Code, tc.status) {
493498
body := &ClosingBuffer{rr.Body}
@@ -534,7 +539,8 @@ func TestCAHealth(t *testing.T) {
534539
assert.FatalError(t, err)
535540
rr := httptest.NewRecorder()
536541

537-
tc.ca.srv.Handler.ServeHTTP(rr, rq)
542+
ctx := authority.NewContext(context.Background(), tc.ca.auth)
543+
tc.ca.srv.Handler.ServeHTTP(rr, rq.WithContext(ctx))
538544

539545
if assert.Equals(t, rr.Code, tc.status) {
540546
body := &ClosingBuffer{rr.Body}
@@ -628,7 +634,8 @@ func TestCARenew(t *testing.T) {
628634
rq.TLS = tc.tlsConnState
629635
rr := httptest.NewRecorder()
630636

631-
tc.ca.srv.Handler.ServeHTTP(rr, rq)
637+
ctx := authority.NewContext(context.Background(), tc.ca.auth)
638+
tc.ca.srv.Handler.ServeHTTP(rr, rq.WithContext(ctx))
632639

633640
if assert.Equals(t, rr.Code, tc.status) {
634641
body := &ClosingBuffer{rr.Body}

ca/tls_test.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"encoding/hex"
1111
"io"
1212
"log"
13+
"net"
1314
"net/http"
1415
"net/http/httptest"
1516
"reflect"
@@ -77,7 +78,12 @@ func startCATestServer() *httptest.Server {
7778
panic(err)
7879
}
7980
// Use a httptest.Server instead
80-
return startTestServer(ca.srv.TLSConfig, ca.srv.Handler)
81+
srv := startTestServer(ca.srv.TLSConfig, ca.srv.Handler)
82+
baseContext := buildContext(ca.auth, nil, nil, nil)
83+
srv.Config.BaseContext = func(net.Listener) context.Context {
84+
return baseContext
85+
}
86+
return srv
8187
}
8288

8389
func sign(domain string) (*Client, *api.SignResponse, crypto.PrivateKey) {

0 commit comments

Comments
 (0)