@@ -91,8 +91,7 @@ func TestUpdateOmAuthentication_NoAuthenticationEnabled(t *testing.T) {
91
91
92
92
kubeClient , omConnectionFactory := mock .NewDefaultFakeClient (rs )
93
93
r := newReplicaSetReconciler (ctx , kubeClient , nil , "" , "" , false , false , omConnectionFactory .GetConnectionFunc )
94
- agentCertSecretSelector := rs .GetSecurity ().AgentClientCertificateSecretName (rs .Name )
95
- r .updateOmAuthentication (ctx , conn , processNames , rs , agentCertSecretSelector , "" , "" , false , zap .S ())
94
+ r .updateOmAuthentication (ctx , conn , processNames , rs , corev1.SecretKeySelector {}, "" , "" , false , zap .S ())
96
95
97
96
ac , _ := conn .ReadAutomationConfig ()
98
97
@@ -113,8 +112,7 @@ func TestUpdateOmAuthentication_EnableX509_TlsNotEnabled(t *testing.T) {
113
112
114
113
kubeClient , omConnectionFactory := mock .NewDefaultFakeClient (rs )
115
114
r := newReplicaSetReconciler (ctx , kubeClient , nil , "" , "" , false , false , omConnectionFactory .GetConnectionFunc )
116
- agentCertSecretSelector := rs .GetSecurity ().AgentClientCertificateSecretName (rs .Name )
117
- status , isMultiStageReconciliation := r .updateOmAuthentication (ctx , conn , []string {"my-rs-0" , "my-rs-1" , "my-rs-2" }, rs , agentCertSecretSelector , "" , "" , false , zap .S ())
115
+ status , isMultiStageReconciliation := r .updateOmAuthentication (ctx , conn , []string {"my-rs-0" , "my-rs-1" , "my-rs-2" }, rs , corev1.SecretKeySelector {}, "" , "" , false , zap .S ())
118
116
119
117
assert .True (t , status .IsOK (), "configuring both options at once should not result in a failed status" )
120
118
assert .True (t , isMultiStageReconciliation , "configuring both tls and x509 at once should result in a multi stage reconciliation" )
@@ -126,8 +124,7 @@ func TestUpdateOmAuthentication_EnableX509_WithTlsAlreadyEnabled(t *testing.T) {
126
124
omConnectionFactory := om .NewCachedOMConnectionFactoryWithInitializedConnection (om .NewMockedOmConnection (deployment .CreateFromReplicaSet ("fake-mongoDBImage" , false , rs )))
127
125
kubeClient := mock .NewDefaultFakeClientWithOMConnectionFactory (omConnectionFactory , rs )
128
126
r := newReplicaSetReconciler (ctx , kubeClient , nil , "" , "" , false , false , omConnectionFactory .GetConnectionFunc )
129
- agentCertSecretSelector := rs .GetSecurity ().AgentClientCertificateSecretName (rs .Name )
130
- status , isMultiStageReconciliation := r .updateOmAuthentication (ctx , omConnectionFactory .GetConnection (), []string {"my-rs-0" , "my-rs-1" , "my-rs-2" }, rs , agentCertSecretSelector , "" , "" , false , zap .S ())
127
+ status , isMultiStageReconciliation := r .updateOmAuthentication (ctx , omConnectionFactory .GetConnection (), []string {"my-rs-0" , "my-rs-1" , "my-rs-2" }, rs , corev1.SecretKeySelector {}, "" , "" , false , zap .S ())
131
128
132
129
assert .True (t , status .IsOK (), "configuring x509 when tls has already been enabled should not result in a failed status" )
133
130
assert .False (t , isMultiStageReconciliation , "if tls is already enabled, we should be able to configure x509 is a single reconciliation" )
@@ -143,8 +140,7 @@ func TestUpdateOmAuthentication_AuthenticationIsNotConfigured_IfAuthIsNotSet(t *
143
140
kubeClient := mock .NewDefaultFakeClientWithOMConnectionFactory (omConnectionFactory , rs )
144
141
r := newReplicaSetReconciler (ctx , kubeClient , nil , "" , "" , false , false , omConnectionFactory .GetConnectionFunc )
145
142
146
- agentCertSecretSelector := rs .GetSecurity ().AgentClientCertificateSecretName (rs .Name )
147
- status , _ := r .updateOmAuthentication (ctx , omConnectionFactory .GetConnection (), []string {"my-rs-0" , "my-rs-1" , "my-rs-2" }, rs , agentCertSecretSelector , "" , "" , false , zap .S ())
143
+ status , _ := r .updateOmAuthentication (ctx , omConnectionFactory .GetConnection (), []string {"my-rs-0" , "my-rs-1" , "my-rs-2" }, rs , corev1.SecretKeySelector {}, "" , "" , false , zap .S ())
148
144
assert .True (t , status .IsOK (), "no authentication should have been configured" )
149
145
150
146
ac , _ := omConnectionFactory .GetConnection ().ReadAutomationConfig ()
@@ -213,9 +209,14 @@ func TestUpdateOmAuthentication_EnableX509_FromEmptyDeployment(t *testing.T) {
213
209
omConnectionFactory := om .NewCachedOMConnectionFactoryWithInitializedConnection (om .NewMockedOmConnection (om .NewDeployment ()))
214
210
kubeClient := mock .NewDefaultFakeClientWithOMConnectionFactory (omConnectionFactory , rs )
215
211
r := newReplicaSetReconciler (ctx , kubeClient , nil , "" , "" , false , false , omConnectionFactory .GetConnectionFunc )
216
- createAgentCSRs (t , ctx , 1 , r .client , certsv1 .CertificateApproved )
212
+ secretName := util .AgentSecretName
213
+ secretKey := "fakeAgentCertHash"
214
+ createAgentCSRs (t , ctx , r .client , secretName , secretKey , certsv1 .CertificateApproved )
217
215
218
- agentCertSecretSelector := rs .GetSecurity ().AgentClientCertificateSecretName (rs .Name )
216
+ agentCertSecretSelector := corev1.SecretKeySelector {
217
+ LocalObjectReference : corev1.LocalObjectReference {Name : secretName },
218
+ Key : secretKey ,
219
+ }
219
220
status , isMultiStageReconciliation := r .updateOmAuthentication (ctx , omConnectionFactory .GetConnection (), []string {"my-rs-0" , "my-rs-1" , "my-rs-2" }, rs , agentCertSecretSelector , "" , "" , false , zap .S ())
220
221
assert .True (t , status .IsOK (), "configuring x509 and tls when there are no processes should not result in a failed status" )
221
222
assert .False (t , isMultiStageReconciliation , "if we are enabling tls and x509 at once, this should be done in a single reconciliation" )
@@ -812,17 +813,14 @@ func Test_NoExternalDomainPresent(t *testing.T) {
812
813
}
813
814
814
815
// createAgentCSRs creates all the agent CSRs needed for x509 at the specified condition type
815
- func createAgentCSRs (t * testing.T , ctx context.Context , numAgents int , client kubernetesClient.Client , conditionType certsv1.RequestConditionType ) {
816
- if numAgents != 1 && numAgents != 3 {
817
- return
818
- }
816
+ func createAgentCSRs (t * testing.T , ctx context.Context , client kubernetesClient.Client , secretName , secretKey string , conditionType certsv1.RequestConditionType ) {
819
817
// create the secret the agent certs will exist in
820
818
certAuto , _ := os .ReadFile ("testdata/certificates/cert_auto" )
821
819
822
820
builder := secret .Builder ().
823
821
SetNamespace (mock .TestNamespace ).
824
- SetName (util . AgentSecretName ).
825
- SetField (util . AutomationAgentPemSecretKey , string (certAuto ))
822
+ SetName (secretName ).
823
+ SetField (secretKey , string (certAuto ))
826
824
827
825
err := client .CreateSecret (ctx , builder .Build ())
828
826
assert .NoError (t , err )
0 commit comments