From fc21407a121cd37151b630fc587add20e31f0f12 Mon Sep 17 00:00:00 2001 From: Richard Wall Date: Wed, 27 Aug 2025 17:10:37 +0100 Subject: [PATCH] feat(identity): enhance test logging and context handling - Integrated klog for improved logging in identity tests - Updated `MockIdentityServer` to use `testing.TB` for broader compatibility - Added request logging in `mockIdentityServer.ServeHTTP` for better debugging --- .../cyberark/identity/advance_authentication_test.go | 8 +++++++- pkg/internal/cyberark/identity/mock.go | 11 ++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/pkg/internal/cyberark/identity/advance_authentication_test.go b/pkg/internal/cyberark/identity/advance_authentication_test.go index eb2c2b37..fb0a814a 100644 --- a/pkg/internal/cyberark/identity/advance_authentication_test.go +++ b/pkg/internal/cyberark/identity/advance_authentication_test.go @@ -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) { @@ -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) diff --git a/pkg/internal/cyberark/identity/mock.go b/pkg/internal/cyberark/identity/mock.go index 991b6733..81854f44 100644 --- a/pkg/internal/cyberark/identity/mock.go +++ b/pkg/internal/cyberark/identity/mock.go @@ -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() @@ -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)