Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit ca1f70b

Browse files
committed
Updates proxy unit tests with auditing
Signed-off-by: JoshVanL <[email protected]>
1 parent f04ebef commit ca1f70b

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

pkg/proxy/proxy_test.go

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"io/ioutil"
88
"net/http"
99
"net/http/httptest"
10+
"net/url"
1011
"reflect"
1112
"sort"
1213
"strconv"
@@ -17,8 +18,12 @@ import (
1718
"k8s.io/apiserver/pkg/authentication/authenticator"
1819
"k8s.io/apiserver/pkg/authentication/request/bearertoken"
1920
"k8s.io/apiserver/pkg/authentication/user"
21+
"k8s.io/apiserver/pkg/server"
2022

23+
"github.com/jetstack/kube-oidc-proxy/cmd/app/options"
2124
"github.com/jetstack/kube-oidc-proxy/pkg/mocks"
25+
"github.com/jetstack/kube-oidc-proxy/pkg/proxy/audit"
26+
"github.com/jetstack/kube-oidc-proxy/pkg/proxy/hooks"
2227
)
2328

2429
type fakeProxy struct {
@@ -249,7 +254,7 @@ func TestHasImpersonation(t *testing.T) {
249254
}
250255
}
251256

252-
func newTestProxy(t *testing.T) *fakeProxy {
257+
func newTestProxy(t *testing.T) (*fakeProxy, error) {
253258
ctrl := gomock.NewController(t)
254259
fakeToken := mocks.NewMockToken(ctrl)
255260
fakeRT := &fakeRT{t: t}
@@ -263,12 +268,19 @@ func newTestProxy(t *testing.T) *fakeProxy {
263268
clientTransport: fakeRT,
264269
noAuthClientTransport: fakeRT,
265270
config: new(Config),
271+
hooks: hooks.New(),
266272
},
267273
}
268274

275+
auditor, err := audit.New(new(options.AuditOptions), "0.0.0.0:1234", new(server.SecureServingInfo))
276+
if err != nil {
277+
return nil, err
278+
}
279+
p.auditor = auditor
280+
269281
p.handleError = p.newErrorHandler()
270282

271-
return p
283+
return p, nil
272284
}
273285

274286
func TestHandlers(t *testing.T) {
@@ -525,7 +537,12 @@ func TestHandlers(t *testing.T) {
525537

526538
for name, test := range tests {
527539
t.Run(name, func(t *testing.T) {
528-
p := newTestProxy(t)
540+
p, err := newTestProxy(t)
541+
if err != nil {
542+
t.Errorf("unexpected error: %s", err)
543+
t.FailNow()
544+
}
545+
529546
w := httptest.NewRecorder()
530547

531548
if test.authResponse != nil {
@@ -549,6 +566,9 @@ func TestHandlers(t *testing.T) {
549566
t.FailNow()
550567
}
551568
})
569+
570+
test.req.URL = new(url.URL)
571+
552572
handler = p.withHandlers(handler)
553573
handler.ServeHTTP(w, test.req)
554574

@@ -629,7 +649,12 @@ func TestHeadersConfig(t *testing.T) {
629649

630650
for name, test := range tests {
631651
t.Run(name, func(t *testing.T) {
632-
p := newTestProxy(t)
652+
p, err := newTestProxy(t)
653+
if err != nil {
654+
t.Errorf("unexpected error: %s", err)
655+
t.FailNow()
656+
}
657+
633658
p.config = test.config
634659
w := httptest.NewRecorder()
635660

@@ -638,6 +663,7 @@ func TestHeadersConfig(t *testing.T) {
638663
"Authorization": []string{"bearer fake-token"},
639664
},
640665
RemoteAddr: remoteAddr,
666+
URL: new(url.URL),
641667
}
642668

643669
authResponse := &authenticator.Response{
@@ -661,6 +687,7 @@ func TestHeadersConfig(t *testing.T) {
661687
t.FailNow()
662688
}
663689
})
690+
664691
handler = p.withHandlers(handler)
665692
handler.ServeHTTP(w, req)
666693

0 commit comments

Comments
 (0)