From 9c2bc34bc006e4b3810f10bb1b4fea814d86e469 Mon Sep 17 00:00:00 2001 From: huangweixiao Date: Mon, 3 Jan 2022 22:48:37 +0800 Subject: [PATCH] test: add test for GetAuthenticationExecutions, DeleteAuthenticationExecution and CreateAuthenticationExecutionFlow --- client_test.go | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/client_test.go b/client_test.go index a2222798..f202f375 100644 --- a/client_test.go +++ b/client_test.go @@ -6149,7 +6149,7 @@ func TestGocloak_GetAuthenticationFlows(t *testing.T) { require.Error(t, err) } -func TestGocloak_CreateAuthenticationFlowsAndCreateAuthenticationExecution(t *testing.T) { +func TestGocloak_CreateAuthenticationFlowsAndCreateAuthenticationExecutionAndFlow(t *testing.T) { t.Parallel() cfg := GetConfig(t) client := NewClientWithDebug(t) @@ -6166,6 +6166,13 @@ func TestGocloak_CreateAuthenticationFlowsAndCreateAuthenticationExecution(t *te ProviderID: gocloak.StringP("basic-flow"), } + authExecFlow := gocloak.CreateAuthenticationExecutionFlowRepresentation{ + Alias: gocloak.StringP("testauthexecflow"), + Description: gocloak.StringP("test"), + Provider: gocloak.StringP("basic-flow"), + Type: gocloak.StringP("basic-flow"), + } + err := client.CreateAuthenticationFlow( context.Background(), token.AccessToken, @@ -6184,6 +6191,15 @@ func TestGocloak_CreateAuthenticationFlowsAndCreateAuthenticationExecution(t *te ) require.NoError(t, err, "Failed to create authentication execution") + err = client.CreateAuthenticationExecutionFlow( + context.Background(), + token.AccessToken, + cfg.GoCloak.Realm, + *authFlow.Alias, + authExecFlow, + ) + require.NoError(t, err, "Failed to create authentication execution flow") + authExecs, err := client.GetAuthenticationExecutions( context.Background(), token.AccessToken, @@ -6229,4 +6245,32 @@ func TestGocloak_CreateAuthenticationFlowsAndCreateAuthenticationExecution(t *te } } require.True(t, deleted, "Failed to delete authentication flow, no flow was deleted") + + executions, err := client.GetAuthenticationExecutions(context.Background(), token.AccessToken, cfg.GoCloak.Realm, *authFlow.Alias) + require.NoError(t, err, "Failed to get authentication executions") + var ( + execDeleted bool + execFlowFound bool + ) + for _, execution := range executions { + if execution.DisplayName != nil && *execution.DisplayName == *authExecFlow.Alias { + execFlowFound = true + continue + } + if execution.ProviderID != nil && *execution.ProviderID == *authExec.Provider { + err = client.DeleteAuthenticationExecution( + context.Background(), + token.AccessToken, + cfg.GoCloak.Realm, + *execution.ID, + ) + require.NoError(t, err, "Failed to delete authentication execution") + execDeleted = true + } + if execDeleted && execFlowFound { + break + } + } + require.True(t, execDeleted, "Failed to delete authentication execution, no execution was deleted") + require.True(t, execFlowFound, "Failed to find authentication execution flow") }