@@ -10,10 +10,10 @@ import (
1010 "testing"
1111
1212 argopass "github.com/argoproj/argo-cd/v3/util/password"
13-
1413 configv1 "github.com/openshift/api/config/v1"
1514 routev1 "github.com/openshift/api/route/v1"
1615 "github.com/stretchr/testify/assert"
16+ "github.com/stretchr/testify/require"
1717
1818 corev1 "k8s.io/api/core/v1"
1919 testclient "k8s.io/client-go/kubernetes/fake"
@@ -362,6 +362,77 @@ func Test_ReconcileArgoCD_ReconcileShouldNotChangeWhenUpdatedAdminPass(t *testin
362362 assert .True (t , argoutil .IsTrackedByOperator (testSecret .Labels ))
363363}
364364
365+ func Test_ReconcileArgoCD_ReconcileRedisInitialPasswordSecret (t * testing.T ) {
366+ const suffix = "redis-initial-password"
367+ argocd := & argoproj.ArgoCD {
368+ ObjectMeta : metav1.ObjectMeta {
369+ Name : "argocd" ,
370+ Namespace : "argocd-operator" ,
371+ },
372+ }
373+ secretName := argoutil .NewSecretWithSuffix (argocd , suffix ).Name
374+ secretNN := types.NamespacedName {Name : secretName , Namespace : "argocd-operator" }
375+
376+ resObjs := []client.Object {argocd }
377+ subresObjs := []client.Object {argocd }
378+ runtimeObjs := []runtime.Object {}
379+ sch := makeTestReconcilerScheme (argoproj .AddToScheme )
380+ cl := makeTestReconcilerClient (sch , resObjs , subresObjs , runtimeObjs )
381+ r := makeTestReconciler (cl , sch , testclient .NewSimpleClientset ())
382+
383+ var actual corev1.Secret
384+ fetchSecret := func () error {
385+ return r .Get (t .Context (), secretNN , & actual )
386+ }
387+ assertSecretValid := func () string {
388+ assert .Equal (t , "true" , string (actual .Data ["immutable" ]))
389+ assert .Equal (t , "default" , string (actual .Data ["auth_username" ]))
390+ assert .Contains (t , string (actual .Data ["users.acl" ]), "user default on >" )
391+ assert .Contains (t , string (actual .Data ["users.acl" ]), " allchannels allkeys allcommands" )
392+ actualPwd := string (actual .Data ["auth" ])
393+ assert .NotEqual (t , "" , actualPwd )
394+ assert .Contains (t , string (actual .Data ["users.acl" ]), actualPwd , "Password is mentioned in the ACL file" )
395+ return actualPwd
396+ }
397+
398+ t .Run ("Create when does not exist" , func (t * testing.T ) {
399+ require .ErrorContains (t , fetchSecret (), fmt .Sprintf (`secrets "%s" not found` , secretName ))
400+
401+ require .NoError (t , r .reconcileRedisInitialPasswordSecret (argocd ))
402+
403+ require .NoError (t , fetchSecret ())
404+ assertSecretValid ()
405+ })
406+
407+ t .Run ("Update keys and regenerate on operator upgrade" , func (t * testing.T ) {
408+ const oldPwd = "asdfghjkl"
409+ secret := argoutil .NewSecretWithSuffix (argocd , suffix )
410+ secret .Data = map [string ][]byte {
411+ "immutable" : []byte ("true" ),
412+ common .ArgoCDKeyAdminPassword : []byte (oldPwd ),
413+ }
414+ require .NoError (t , r .Update (t .Context (), secret ))
415+
416+ require .NoError (t , r .reconcileRedisInitialPasswordSecret (argocd ))
417+
418+ require .NoError (t , fetchSecret ())
419+ actualPwd := assertSecretValid ()
420+ assert .NotEqual (t , oldPwd , actualPwd )
421+ })
422+
423+ t .Run ("Keep untouched if healthy" , func (t * testing.T ) {
424+ require .NoError (t , fetchSecret ())
425+ assertSecretValid ()
426+ oldVersion := actual .ResourceVersion
427+
428+ require .NoError (t , r .reconcileRedisInitialPasswordSecret (argocd ))
429+
430+ require .NoError (t , fetchSecret ())
431+ assertSecretValid ()
432+ assert .Equal (t , oldVersion , actual .ResourceVersion , "Resource version should not change" )
433+ })
434+ }
435+
365436func Test_ReconcileArgoCD_ReconcileRedisTLSSecret (t * testing.T ) {
366437 argocd := & argoproj.ArgoCD {
367438 ObjectMeta : metav1.ObjectMeta {
0 commit comments