Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import (
"fmt"
"testing"

"k8s.io/klog/v2"
"k8s.io/klog/v2/ktesting"

"github.com/jetstack/preflight/pkg/internal/cyberark/servicediscovery"

_ "k8s.io/klog/v2/ktesting/init"
)

func Test_IdentityAdvanceAuthentication(t *testing.T) {
Expand Down Expand Up @@ -97,7 +102,8 @@ func Test_IdentityAdvanceAuthentication(t *testing.T) {

for name, testSpec := range tests {
t.Run(name, func(t *testing.T) {
ctx := t.Context()
logger := ktesting.NewLogger(t, ktesting.DefaultConfig)
ctx := klog.NewContext(t.Context(), logger)

identityAPI, httpClient := MockIdentityServer(t)

Expand Down
11 changes: 8 additions & 3 deletions pkg/internal/cyberark/identity/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,16 @@ var (
advanceAuthenticationFailureResponse string
)

type mockIdentityServer struct{}
type mockIdentityServer struct {
t testing.TB
}

// MockIdentityServer returns a URL of a mocked CyberArk identity server and an
// HTTP client with the CA certs needed to connect to it..
func MockIdentityServer(t *testing.T) (string, *http.Client) {
mis := &mockIdentityServer{}
func MockIdentityServer(t testing.TB) (string, *http.Client) {
mis := &mockIdentityServer{
t: t,
}
server := httptest.NewTLSServer(mis)
t.Cleanup(server.Close)
httpClient := server.Client()
Expand All @@ -68,6 +72,7 @@ func MockIdentityServer(t *testing.T) (string, *http.Client) {
}

func (mis *mockIdentityServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
mis.t.Log(r.Method, r.RequestURI)
switch r.URL.String() {
case "/Security/StartAuthentication":
mis.handleStartAuthentication(w, r)
Expand Down