@@ -37,7 +37,11 @@ const (
3737 GroupGetRealmRoles = "/auth/admin/realms/%s/groups/%s/role-mappings/realm"
3838 GroupGetAvailableRealmRoles = "/auth/admin/realms/%s/groups/%s/role-mappings/realm/available"
3939 AuthenticationFlowUpdateExecution = "/auth/admin/realms/%s/authentication/flows/%s/executions"
40+ AuthenticationFlowListExecution = "/auth/admin/realms/%s/authentication/flows/%s/executions"
41+ AuthenticationFlowCreateExecution = "/auth/admin/realms/%s/authentication/flows/%s/executions/execution"
4042 TokenPath = "/auth/realms/master/protocol/openid-connect/token" // nolint
43+ AuthenticationFlowCreatePath = "/auth/admin/realms/%s/authentication/flows"
44+ AuthenticationFlowListPath = "/auth/admin/realms/%s/authentication/flows"
4145)
4246
4347func getDummyRealm () * v1alpha1.KeycloakRealm {
@@ -572,6 +576,113 @@ func TestClient_ListAvailableGroupRealmRoles(t *testing.T) {
572576 )
573577}
574578
579+ func TestClient_CreateAuthenticationFlow (t * testing.T ) {
580+ realm := getDummyRealm ()
581+ expectedPath := fmt .Sprintf (AuthenticationFlowCreatePath , realm .Spec .Realm .Realm )
582+
583+ testClientHTTPRequest (
584+ withPathAssertion (t , 201 , expectedPath ),
585+ func (c * Client ) {
586+ _ , err := c .CreateAuthenticationFlow (AuthenticationFlow {}, realm .Spec .Realm .Realm )
587+ assert .NoError (t , err )
588+ },
589+ )
590+ }
591+
592+ func TestClient_ListAuthenticationFlows (t * testing.T ) {
593+ realm := getDummyRealm ()
594+ expectedPath := fmt .Sprintf (AuthenticationFlowListPath , realm .Spec .Realm .Realm )
595+
596+ testClientHTTPRequest (
597+ withPathAssertion (t , 200 , expectedPath ),
598+ func (c * Client ) {
599+ _ , err := c .ListAuthenticationFlows (
600+ realm .Spec .Realm .Realm )
601+
602+ assert .NoError (t , err )
603+ },
604+ )
605+ }
606+
607+ func TestClient_FindAuthenticationFlowByAlias (t * testing.T ) {
608+ const (
609+ existingAuthenticationFlowAlias string = "authdelay"
610+ existingAuthenticationFlowID string = "12345"
611+ )
612+ realm := getDummyRealm ()
613+ expectedPath := fmt .Sprintf (AuthenticationFlowListPath , realm .Spec .Realm .Realm )
614+
615+ handle := withPathAssertionBody (
616+ t ,
617+ 200 ,
618+ expectedPath ,
619+ []* AuthenticationFlow {& AuthenticationFlow {
620+ Alias : existingAuthenticationFlowAlias ,
621+ ID : existingAuthenticationFlowID ,
622+ }},
623+ )
624+
625+ request := func (c * Client ) {
626+ // when the group exists
627+ foundAuthenticationFlow , err := c .FindAuthenticationFlowByAlias (existingAuthenticationFlowAlias , realm .Spec .Realm .Realm )
628+ // then return the group instance
629+ assert .NoError (t , err )
630+ assert .NotNil (t , foundAuthenticationFlow )
631+ assert .Equal (t , existingAuthenticationFlowID , foundAuthenticationFlow .ID )
632+
633+ // when the autnetication flow doesn't exist
634+ notFoundGroup , err := c .FindAuthenticationFlowByAlias ("not-existing" , "dummy" )
635+ // then return `nil`
636+ assert .NoError (t , err )
637+ assert .Nil (t , notFoundGroup )
638+ }
639+
640+ testClientHTTPRequest (handle , request )
641+
642+ }
643+
644+ func TestClient_AddExecutionToAuthenticatonFlow (t * testing.T ) {
645+ const (
646+ authenticationFlowAlias string = "authdelay"
647+ providerID string = "delay-authentication"
648+ existingAuthenticationFlowID string = "12345"
649+ )
650+ realm := getDummyRealm ()
651+ expectedPath := fmt .Sprintf (AuthenticationFlowCreateExecution , realm .Spec .Realm .Realm , authenticationFlowAlias )
652+
653+ handle := withMethodSelection (t , map [string ]http.HandlerFunc {
654+ http .MethodPut : withPathAssertion (t , 200 , fmt .Sprintf (AuthenticationFlowUpdateExecution , realm .Spec .Realm .Realm , authenticationFlowAlias )),
655+ http .MethodPost : withPathAssertion (t , 201 , expectedPath ),
656+ http .MethodGet : withPathAssertionBody (
657+ t ,
658+ 200 ,
659+ fmt .Sprintf (AuthenticationFlowListExecution , realm .Spec .Realm .Realm , authenticationFlowAlias ),
660+ []* v1alpha1.AuthenticationExecutionInfo {
661+ & v1alpha1.AuthenticationExecutionInfo {
662+ Alias : authenticationFlowAlias ,
663+ ID : existingAuthenticationFlowID ,
664+ ProviderID : providerID ,
665+ },
666+ },
667+ ),
668+ })
669+ request := func (c * Client ) {
670+ err := c .AddExecutionToAuthenticatonFlow (authenticationFlowAlias ,
671+ realm .Spec .Realm .Realm , providerID , Required )
672+
673+ assert .NoError (t , err )
674+
675+ // // requirement empty
676+ // err = c.AddExecutionToAuthenticatonFlow(authenticationFlowAlias,
677+ // realm.Spec.Realm.Realm, providerID, "")
678+ // assert.NoError(t, err)
679+
680+ }
681+
682+ testClientHTTPRequest (handle , request )
683+
684+ }
685+
575686// Utility function to create a test server, register a given handler and perform
576687// a client function to be tested
577688func testClientHTTPRequest (
0 commit comments