1
1
package clusterkeycloakrealm
2
2
3
3
import (
4
+ "time"
5
+
4
6
. "github.com/onsi/ginkgo/v2"
5
7
. "github.com/onsi/gomega"
6
8
@@ -10,6 +12,8 @@ import (
10
12
11
13
"github.com/epam/edp-keycloak-operator/api/common"
12
14
keycloakAlpha "github.com/epam/edp-keycloak-operator/api/v1alpha1"
15
+ "github.com/epam/edp-keycloak-operator/internal/controller/helper"
16
+ "github.com/epam/edp-keycloak-operator/pkg/client/keycloak/adapter"
13
17
"github.com/epam/edp-keycloak-operator/pkg/objectmeta"
14
18
)
15
19
@@ -18,7 +22,7 @@ var _ = Describe("ClusterKeycloakRealm controller", func() {
18
22
clusterKeycloakCR = "test-cluster-keycloak-realm"
19
23
)
20
24
It ("Should reconcile ClusterKeycloakRealm" , func () {
21
- By ("By creating a ClusterKeycloakRealm" )
25
+ By ("Creating a ClusterKeycloakRealm" )
22
26
keycloakRealm := & keycloakAlpha.ClusterKeycloakRealm {
23
27
ObjectMeta : metav1.ObjectMeta {
24
28
Name : clusterKeycloakCR ,
@@ -53,6 +57,70 @@ var _ = Describe("ClusterKeycloakRealm controller", func() {
53
57
54
58
return createdKeycloakRealm .Status .Available
55
59
}, timeout , interval ).Should (BeTrue ())
60
+
61
+ By ("Updating ClusterKeycloakRealm with authentication flow" )
62
+ By ("Creating authentication flow" )
63
+ h := helper .MakeHelper (k8sClient , k8sClient .Scheme (), ns )
64
+
65
+ testClusterRealm := & keycloakAlpha.ClusterKeycloakRealm {
66
+ ObjectMeta : metav1.ObjectMeta {
67
+ Name : "temp-realm-for-flow" ,
68
+ },
69
+ Spec : keycloakAlpha.ClusterKeycloakRealmSpec {
70
+ ClusterKeycloakRef : ClusterKeycloakCR ,
71
+ RealmName : "test-realm" ,
72
+ },
73
+ }
74
+
75
+ keycloakClient , err := h .CreateKeycloakClientFromClusterRealm (ctx , testClusterRealm )
76
+ Expect (err ).ShouldNot (HaveOccurred ())
77
+
78
+ testFlow := & adapter.KeycloakAuthFlow {
79
+ Alias : "test-flow" ,
80
+ Description : "Test authentication flow for integration test" ,
81
+ ProviderID : "basic-flow" ,
82
+ TopLevel : true ,
83
+ BuiltIn : false ,
84
+ AuthenticationExecutions : []adapter.AuthenticationExecution {
85
+ {
86
+ Authenticator : "auth-username-password-form" ,
87
+ Requirement : "REQUIRED" ,
88
+ Priority : 10 ,
89
+ },
90
+ },
91
+ }
92
+
93
+ err = keycloakClient .SyncAuthFlow ("test-realm" , testFlow )
94
+ Expect (adapter .SkipAlreadyExistsErr (err )).ShouldNot (HaveOccurred ())
95
+
96
+ By ("Updating ClusterKeycloakRealm with authentication flow" )
97
+ By ("Getting ClusterKeycloakRealm" )
98
+ createdKeycloakRealm := & keycloakAlpha.ClusterKeycloakRealm {}
99
+ err = k8sClient .Get (ctx , types.NamespacedName {Name : clusterKeycloakCR }, createdKeycloakRealm )
100
+ Expect (err ).ShouldNot (HaveOccurred ())
101
+
102
+ createdKeycloakRealm .Spec .AuthenticationFlow = & keycloakAlpha.AuthenticationFlow {
103
+ BrowserFlow : "test-flow" ,
104
+ }
105
+ Expect (k8sClient .Update (ctx , createdKeycloakRealm )).Should (Succeed ())
106
+ Consistently (func () bool {
107
+ updatedKeycloakRealm := & keycloakAlpha.ClusterKeycloakRealm {}
108
+
109
+ Expect (k8sClient .Get (
110
+ ctx ,
111
+ types.NamespacedName {Name : clusterKeycloakCR },
112
+ updatedKeycloakRealm ,
113
+ )).ShouldNot (HaveOccurred ())
114
+
115
+ return updatedKeycloakRealm .Status .Available
116
+ }, time .Second * 3 , time .Second ).Should (BeTrue ())
117
+
118
+ By ("Checking realm configuration" )
119
+ realm , err := keycloakClient .GetRealm (ctx , "test-realm" )
120
+ Expect (err ).ShouldNot (HaveOccurred ())
121
+ Expect (realm .BrowserFlow ).ShouldNot (BeNil ())
122
+ Expect (* realm .BrowserFlow ).Should (Equal ("test-flow" ))
123
+
56
124
By ("By deleting ClusterKeycloakRealm" )
57
125
Expect (k8sClient .Delete (ctx , keycloakRealm )).Should (Succeed ())
58
126
Eventually (func () bool {
@@ -66,7 +134,7 @@ var _ = Describe("ClusterKeycloakRealm controller", func() {
66
134
By ("By creating a ClusterKeycloakRealm" )
67
135
keycloakRealm := & keycloakAlpha.ClusterKeycloakRealm {
68
136
ObjectMeta : metav1.ObjectMeta {
69
- Name : "test-cluster-keycloak-realm" ,
137
+ Name : "test-cluster-keycloak-realm-preserve-resources " ,
70
138
Annotations : map [string ]string {
71
139
objectmeta .PreserveResourcesOnDeletionAnnotation : "true" ,
72
140
},
0 commit comments