@@ -55,6 +55,8 @@ var _ = Describe("DefaultUserSecret", func() {
5555 It ("creates the necessary default-user secret" , func () {
5656 var username []byte
5757 var password []byte
58+ var host []byte
59+ var port []byte
5860 var ok bool
5961
6062 obj , err := defaultUserSecretBuilder .Build ()
@@ -86,6 +88,19 @@ var _ = Describe("DefaultUserSecret", func() {
8688 Expect (len (decodedPassword )).To (Equal (24 ))
8789 })
8890
91+ By ("Setting a host that corresponds to the service address" , func () {
92+ host , ok = secret .Data ["host" ]
93+ Expect (ok ).NotTo (BeFalse (), "Failed to find a key \" host\" in the generated Secret" )
94+ expectedHost := "a name.a namespace.svc.cluster.local"
95+ Expect (host ).To (BeEquivalentTo (expectedHost ))
96+ })
97+
98+ By ("Setting a port that corresponds to the amqp port" , func () {
99+ port , ok = secret .Data ["port" ]
100+ Expect (ok ).NotTo (BeFalse (), "Failed to find a key \" port\" in the generated Secret" )
101+ Expect (port ).To (BeEquivalentTo ("5672" ))
102+ })
103+
89104 By ("creating a default_user.conf file that contains the correct sysctl config format to be parsed by RabbitMQ" , func () {
90105 defaultUserConf , ok := secret .Data ["default_user.conf" ]
91106 Expect (ok ).NotTo (BeFalse (), "Failed to find a key \" default_user.conf\" in the generated Secret" )
@@ -114,6 +129,99 @@ var _ = Describe("DefaultUserSecret", func() {
114129 })
115130 })
116131
132+ Context ("when MQTT, STOMP, streams, WebMQTT, and WebSTOMP are enabled" , func () {
133+ It ("adds the MQTT, STOMP, stream, WebMQTT, and WebSTOMP ports to the user secret" , func () {
134+ var port []byte
135+
136+ instance .Spec .Rabbitmq .AdditionalPlugins = []rabbitmqv1beta1.Plugin {
137+ "rabbitmq_mqtt" ,
138+ "rabbitmq_stomp" ,
139+ "rabbitmq_stream" ,
140+ "rabbitmq_web_mqtt" ,
141+ "rabbitmq_web_stomp" ,
142+ }
143+
144+ obj , err := defaultUserSecretBuilder .Build ()
145+ Expect (err ).NotTo (HaveOccurred ())
146+ secret = obj .(* corev1.Secret )
147+
148+ port , ok := secret .Data ["mqtt-port" ]
149+ Expect (ok ).NotTo (BeFalse (), "Failed to find key \" mqtt-port\" in the generated Secret" )
150+ Expect (port ).To (BeEquivalentTo ("1883" ))
151+
152+ port , ok = secret .Data ["stomp-port" ]
153+ Expect (ok ).NotTo (BeFalse (), "Failed to find key \" stomp-port\" in the generated Secret" )
154+ Expect (port ).To (BeEquivalentTo ("61613" ))
155+
156+ port , ok = secret .Data ["stream-port" ]
157+ Expect (ok ).NotTo (BeFalse (), "Failed to find key \" stream-port\" in the generated Secret" )
158+ Expect (port ).To (BeEquivalentTo ("5552" ))
159+
160+ port , ok = secret .Data ["web-mqtt-port" ]
161+ Expect (ok ).NotTo (BeFalse (), "Failed to find key \" web-mqtt-port\" in the generated Secret" )
162+ Expect (port ).To (BeEquivalentTo ("15675" ))
163+
164+ port , ok = secret .Data ["web-stomp-port" ]
165+ Expect (ok ).NotTo (BeFalse (), "Failed to find key \" web-stomp-port\" in the generated Secret" )
166+ Expect (port ).To (BeEquivalentTo ("15674" ))
167+ })
168+ })
169+
170+ Context ("when TLS is enabled" , func () {
171+ It ("Uses the AMQPS port in the user secret" , func () {
172+ var port []byte
173+
174+ instance .Spec .TLS .SecretName = "tls-secret"
175+
176+ obj , err := defaultUserSecretBuilder .Build ()
177+ Expect (err ).NotTo (HaveOccurred ())
178+ secret = obj .(* corev1.Secret )
179+
180+ port , ok := secret .Data ["port" ]
181+ Expect (ok ).NotTo (BeFalse (), "Failed to find key \" port\" in the generated Secret" )
182+ Expect (port ).To (BeEquivalentTo ("5671" ))
183+ })
184+
185+ Context ("when MQTT, STOMP, streams, WebMQTT, and WebSTOMP are enabled" , func () {
186+ It ("adds the MQTTS, STOMPS, streams, WebMQTTS, and WebSTOMPS ports to the user secret" , func () {
187+ var port []byte
188+
189+ instance .Spec .TLS .SecretName = "tls-secret"
190+ instance .Spec .Rabbitmq .AdditionalPlugins = []rabbitmqv1beta1.Plugin {
191+ "rabbitmq_mqtt" ,
192+ "rabbitmq_stomp" ,
193+ "rabbitmq_stream" ,
194+ "rabbitmq_web_mqtt" ,
195+ "rabbitmq_web_stomp" ,
196+ }
197+
198+ obj , err := defaultUserSecretBuilder .Build ()
199+ Expect (err ).NotTo (HaveOccurred ())
200+ secret = obj .(* corev1.Secret )
201+
202+ port , ok := secret .Data ["mqtt-port" ]
203+ Expect (ok ).NotTo (BeFalse (), "Failed to find key \" mqtt-port\" in the generated Secret" )
204+ Expect (port ).To (BeEquivalentTo ("8883" ))
205+
206+ port , ok = secret .Data ["stomp-port" ]
207+ Expect (ok ).NotTo (BeFalse (), "Failed to find key \" stomp-port\" in the generated Secret" )
208+ Expect (port ).To (BeEquivalentTo ("61614" ))
209+
210+ port , ok = secret .Data ["stream-port" ]
211+ Expect (ok ).NotTo (BeFalse (), "Failed to find key \" stream-port\" in the generated Secret" )
212+ Expect (port ).To (BeEquivalentTo ("5551" ))
213+
214+ port , ok = secret .Data ["web-mqtt-port" ]
215+ Expect (ok ).NotTo (BeFalse (), "Failed to find key \" web-mqtt-port\" in the generated Secret" )
216+ Expect (port ).To (BeEquivalentTo ("15676" ))
217+
218+ port , ok = secret .Data ["web-stomp-port" ]
219+ Expect (ok ).NotTo (BeFalse (), "Failed to find key \" web-stomp-port\" in the generated Secret" )
220+ Expect (port ).To (BeEquivalentTo ("15673" ))
221+ })
222+ })
223+ })
224+
117225 Context ("Update with instance labels" , func () {
118226 It ("Updates the secret" , func () {
119227 instance = rabbitmqv1beta1.RabbitmqCluster {
@@ -136,6 +244,7 @@ var _ = Describe("DefaultUserSecret", func() {
136244 "this-was-the-previous-label" : "should-be-deleted" ,
137245 },
138246 },
247+ Data : map [string ][]byte {},
139248 }
140249 err := defaultUserSecretBuilder .Update (secret )
141250 Expect (err ).NotTo (HaveOccurred ())
@@ -184,6 +293,7 @@ var _ = Describe("DefaultUserSecret", func() {
184293 "k8s.io/name" : "should-stay" ,
185294 },
186295 },
296+ Data : map [string ][]byte {},
187297 }
188298 err := defaultUserSecretBuilder .Update (secret )
189299 Expect (err ).NotTo (HaveOccurred ())
@@ -203,8 +313,49 @@ var _ = Describe("DefaultUserSecret", func() {
203313 })
204314 })
205315
316+ Context ("When plugins or TLS are updated" , func () {
317+ It ("updates the secret with the only enabled ports" , func () {
318+ instance = rabbitmqv1beta1.RabbitmqCluster {
319+ ObjectMeta : metav1.ObjectMeta {
320+ Name : "rabbit-labelled" ,
321+ },
322+ }
323+ instance .Spec .Rabbitmq .AdditionalPlugins = []rabbitmqv1beta1.Plugin {
324+ "rabbitmq_mqtt" ,
325+ "rabbitmq_stream" ,
326+ }
327+ instance .Spec .TLS .SecretName = "tls-secret"
328+ secret = & corev1.Secret {
329+ Data : map [string ][]byte {
330+ "port" : []byte ("5672" ),
331+ "mqtt-port" : []byte ("1883" ),
332+ "web-mqtt-port" : []byte ("15675" ),
333+ },
334+ }
335+ err := defaultUserSecretBuilder .Update (secret )
336+ Expect (err ).NotTo (HaveOccurred ())
337+
338+ port , ok := secret .Data ["port" ]
339+ Expect (ok ).NotTo (BeFalse ())
340+ Expect (port ).To (BeEquivalentTo ("5671" ))
341+
342+ port , ok = secret .Data ["mqtt-port" ]
343+ Expect (ok ).NotTo (BeFalse ())
344+ Expect (port ).To (BeEquivalentTo ("8883" ))
345+
346+ port , ok = secret .Data ["stream-port" ]
347+ Expect (ok ).NotTo (BeFalse ())
348+ Expect (port ).To (BeEquivalentTo ("5551" ))
349+
350+ _ , ok = secret .Data ["web-mqtt-port" ]
351+ Expect (ok ).To (BeFalse ())
352+ })
353+ })
354+
206355 It ("sets owner reference" , func () {
207- secret = & corev1.Secret {}
356+ secret = & corev1.Secret {
357+ Data : map [string ][]byte {},
358+ }
208359 instance = rabbitmqv1beta1.RabbitmqCluster {
209360 ObjectMeta : metav1.ObjectMeta {
210361 Name : "rabbit1" ,
0 commit comments