|
|
@@ -34,6 +34,7 @@ import (
|
|
|
b64 "encoding/base64"
|
|
|
"net/http"
|
|
|
"net/http/httptest"
|
|
|
+ "strings"
|
|
|
"testing"
|
|
|
|
|
|
corev1 "k8s.io/api/core/v1"
|
|
|
@@ -50,6 +51,7 @@ type mockAuthTestPackage struct {
|
|
|
MockServer mockAuthTestServer
|
|
|
Request mockAuthRequest
|
|
|
Expect string
|
|
|
+ PrefixOnly bool
|
|
|
}
|
|
|
|
|
|
type mockCreds struct {
|
|
|
@@ -70,15 +72,15 @@ func TestWebhookAuth(t *testing.T) {
|
|
|
// define test cases
|
|
|
creds := mockCreds{"correctuser123", "correctpassword123"}
|
|
|
basicAuthExpect := "Basic " + b64.StdEncoding.EncodeToString([]byte(creds.UserName+":"+creds.Password))
|
|
|
- ntlmExpect := "NTLM TlRMTVNTUAABAAAAAQCIoAAAAAAoAAAAAAAAACgAAAAGAbEdAAAADw=="
|
|
|
- negotiateExpect := "Negotiate TlRMTVNTUAABAAAAAQCIoAAAAAAoAAAAAAAAACgAAAAGAbEdAAAADw=="
|
|
|
+ ntlmExpect := "NTLM TlRMTVNTUAABAAAA"
|
|
|
+ negotiateExpect := "Negotiate TlRMTVNTUAABAAAA"
|
|
|
|
|
|
// due to integrated nature of GetSecret(), we use a mock server
|
|
|
// to return relevant parts of a request, in this case, the auth header.
|
|
|
testAuthHeaders := map[string]mockAuthTestPackage{
|
|
|
- "BasicAuth": {creds, basicAuthRequestEcho, basicAuthRequest, basicAuthExpect},
|
|
|
- "NTLM": {creds, ntlmRequestEcho, ntlmRequest, ntlmExpect},
|
|
|
- "Negotiate": {creds, negotiateRequestEcho, ntlmRequest, negotiateExpect},
|
|
|
+ "BasicAuth": {Creds: creds, MockServer: basicAuthRequestEcho, Request: basicAuthRequest, Expect: basicAuthExpect},
|
|
|
+ "NTLM": {Creds: creds, MockServer: ntlmRequestEcho, Request: ntlmRequest, Expect: ntlmExpect, PrefixOnly: true},
|
|
|
+ "Negotiate": {Creds: creds, MockServer: negotiateRequestEcho, Request: ntlmRequest, Expect: negotiateExpect, PrefixOnly: true},
|
|
|
}
|
|
|
|
|
|
// execute test cases
|
|
|
@@ -87,7 +89,7 @@ func TestWebhookAuth(t *testing.T) {
|
|
|
result := p.Request(server.URL, creds, t)
|
|
|
server.Close()
|
|
|
expect := p.Expect
|
|
|
- if result != expect {
|
|
|
+ if (!p.PrefixOnly && result != expect) || (p.PrefixOnly && !strings.HasPrefix(result, expect)) {
|
|
|
t.Errorf("Test failed. Result: '%s' / Expected: '%s'", result, expect)
|
|
|
}
|
|
|
}
|