mirror of
https://github.com/vmware-tanzu/pinniped.git
synced 2026-01-09 23:48:00 +00:00
Extract testutil helper function
This commit is contained in:
@@ -1955,15 +1955,7 @@ func TestCallbackEndpoint(t *testing.T) {
|
||||
}
|
||||
|
||||
if test.wantAuditLogs != nil {
|
||||
var encodedStateParam stateparam.Encoded
|
||||
if test.path != "" {
|
||||
var path *url.URL
|
||||
path, err = url.Parse(test.path)
|
||||
require.NoError(t, err)
|
||||
encodedStateParam = stateparam.Encoded(path.Query().Get("state"))
|
||||
}
|
||||
|
||||
wantAuditLogs := test.wantAuditLogs(encodedStateParam, sessionID)
|
||||
wantAuditLogs := test.wantAuditLogs(testutil.GetStateParam(t, test.path), sessionID)
|
||||
testutil.CompareAuditLogs(t, wantAuditLogs, log.String())
|
||||
}
|
||||
})
|
||||
|
||||
@@ -464,15 +464,7 @@ func TestLoginEndpoint(t *testing.T) {
|
||||
require.Equal(t, test.wantBody, rsp.Body.String())
|
||||
|
||||
if test.wantAuditLogs != nil {
|
||||
var encodedStateParam stateparam.Encoded
|
||||
if test.path != "" {
|
||||
var path *url.URL
|
||||
path, err = url.Parse(test.path)
|
||||
require.NoError(t, err)
|
||||
encodedStateParam = stateparam.Encoded(path.Query().Get("state"))
|
||||
}
|
||||
|
||||
wantAuditLogs := test.wantAuditLogs(encodedStateParam)
|
||||
wantAuditLogs := test.wantAuditLogs(testutil.GetStateParam(t, test.path))
|
||||
testutil.CompareAuditLogs(t, wantAuditLogs, log.String())
|
||||
}
|
||||
})
|
||||
|
||||
@@ -6,10 +6,13 @@ package testutil
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.pinniped.dev/internal/federationdomain/stateparam"
|
||||
)
|
||||
|
||||
func RequireLogLines(t *testing.T, wantLogs []string, log *bytes.Buffer) {
|
||||
@@ -38,6 +41,17 @@ func WantAuditLog(message string, params map[string]any, auditID ...string) Want
|
||||
return result
|
||||
}
|
||||
|
||||
func GetStateParam(t *testing.T, fullURL string) stateparam.Encoded {
|
||||
var encodedStateParam stateparam.Encoded
|
||||
if fullURL != "" {
|
||||
path, err := url.Parse(fullURL)
|
||||
require.NoError(t, err)
|
||||
encodedStateParam = stateparam.Encoded(path.Query().Get("state"))
|
||||
}
|
||||
|
||||
return encodedStateParam
|
||||
}
|
||||
|
||||
func CompareAuditLogs(t *testing.T, wantAuditLogs []WantedAuditLog, actualAuditLogsOneLiner string) {
|
||||
t.Helper()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user