Skip to content

Commit

Permalink
test: add test for GetAuthenticationExecutions, DeleteAuthenticationE…
Browse files Browse the repository at this point in the history
…xecution and CreateAuthenticationExecutionFlow
  • Loading branch information
huangweixiao committed Jan 3, 2022
1 parent 52627eb commit 9c2bc34
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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")
}

0 comments on commit 9c2bc34

Please sign in to comment.