@@ -27,8 +27,8 @@ func NewRealm(name string) *gatewayv1.Realm {
2727 },
2828 },
2929 Spec : gatewayv1.RealmSpec {
30- Url : "https://realm.url" ,
31- IssuerUrl : "https://issuer.url" ,
30+ Urls : [] string { "https://realm.url" } ,
31+ IssuerUrls : [] string { "https://issuer.url" } ,
3232 DefaultConsumers : []string {
3333 "test" ,
3434 },
@@ -120,4 +120,54 @@ var _ = Describe("Realm Controller", Ordered, func() {
120120
121121 })
122122 })
123+
124+ Context ("URL Validation" , func () {
125+ It ("should reject invalid URLs" , func () {
126+ invalidRealm := & gatewayv1.Realm {
127+ ObjectMeta : metav1.ObjectMeta {
128+ Name : "invalid-realm" ,
129+ Namespace : testNamespace ,
130+ Labels : map [string ]string {
131+ config .EnvironmentLabelKey : testEnvironment ,
132+ config .BuildLabelKey ("zone" ): "test" ,
133+ },
134+ },
135+ Spec : gatewayv1.RealmSpec {
136+ Urls : []string {"not-a-valid-url" },
137+ IssuerUrls : []string {"also-not-valid" },
138+ DefaultConsumers : []string {},
139+ },
140+ }
141+
142+ By ("Attempting to create a realm with invalid URLs" )
143+ err := k8sClient .Create (ctx , invalidRealm )
144+ Expect (err ).To (HaveOccurred (), "Expected validation error for invalid URLs" )
145+ })
146+
147+ It ("should accept valid URLs" , func () {
148+ validRealm := & gatewayv1.Realm {
149+ ObjectMeta : metav1.ObjectMeta {
150+ Name : "valid-realm" ,
151+ Namespace : testNamespace ,
152+ Labels : map [string ]string {
153+ config .EnvironmentLabelKey : testEnvironment ,
154+ config .BuildLabelKey ("zone" ): "test" ,
155+ },
156+ },
157+ Spec : gatewayv1.RealmSpec {
158+ Urls : []string {"https://valid.example.com" , "http://another.example.com:8080/path" },
159+ IssuerUrls : []string {"https://issuer.example.com/auth/realms/test" },
160+ DefaultConsumers : []string {},
161+ },
162+ }
163+
164+ By ("Creating a realm with valid URLs" )
165+ err := k8sClient .Create (ctx , validRealm )
166+ Expect (err ).NotTo (HaveOccurred (), "Valid URLs should be accepted" )
167+
168+ By ("Cleaning up the valid realm" )
169+ err = k8sClient .Delete (ctx , validRealm )
170+ Expect (err ).NotTo (HaveOccurred ())
171+ })
172+ })
123173})
0 commit comments