@@ -135,8 +135,8 @@ func TestIsNoMatchError(t *testing.T) {
135135 }
136136}
137137
138- // Test IsDisconnectedOCP scenarios
139- func TestIsDisconnectedOCP_WithICSP (t * testing.T ) {
138+ // Test HasMirrorRegistries scenarios
139+ func TestHasMirrorRegistries_WithICSP (t * testing.T ) {
140140 g := NewWithT (t )
141141 ctx := context .Background ()
142142
@@ -157,12 +157,12 @@ func TestIsDisconnectedOCP_WithICSP(t *testing.T) {
157157
158158 h := setupTestHelper (true , icsp )
159159
160- disconnected , err := IsDisconnectedOCP (ctx , h )
160+ hasMirrors , err := HasMirrorRegistries (ctx , h )
161161 g .Expect (err ).ToNot (HaveOccurred ())
162- g .Expect (disconnected ).To (BeTrue (), "Should detect disconnected environment when ICSP exists" )
162+ g .Expect (hasMirrors ).To (BeTrue (), "Should detect mirror registries when ICSP exists" )
163163}
164164
165- func TestIsDisconnectedOCP_WithIDMS (t * testing.T ) {
165+ func TestHasMirrorRegistries_WithIDMS (t * testing.T ) {
166166 g := NewWithT (t )
167167 ctx := context .Background ()
168168
@@ -185,12 +185,12 @@ func TestIsDisconnectedOCP_WithIDMS(t *testing.T) {
185185
186186 h := setupTestHelper (true , idms )
187187
188- disconnected , err := IsDisconnectedOCP (ctx , h )
188+ hasMirrors , err := HasMirrorRegistries (ctx , h )
189189 g .Expect (err ).ToNot (HaveOccurred ())
190- g .Expect (disconnected ).To (BeTrue (), "Should detect disconnected environment when IDMS exists" )
190+ g .Expect (hasMirrors ).To (BeTrue (), "Should detect mirror registries when IDMS exists" )
191191}
192192
193- func TestIsDisconnectedOCP_WithBothICSPAndIDMS (t * testing.T ) {
193+ func TestHasMirrorRegistries_WithBothICSPAndIDMS (t * testing.T ) {
194194 g := NewWithT (t )
195195 ctx := context .Background ()
196196
@@ -208,33 +208,33 @@ func TestIsDisconnectedOCP_WithBothICSPAndIDMS(t *testing.T) {
208208
209209 h := setupTestHelper (true , icsp , idms )
210210
211- disconnected , err := IsDisconnectedOCP (ctx , h )
211+ hasMirrors , err := HasMirrorRegistries (ctx , h )
212212 g .Expect (err ).ToNot (HaveOccurred ())
213- g .Expect (disconnected ).To (BeTrue (), "Should detect disconnected environment when both ICSP and IDMS exist" )
213+ g .Expect (hasMirrors ).To (BeTrue (), "Should detect mirror registries when both ICSP and IDMS exist" )
214214}
215215
216- func TestIsDisconnectedOCP_EmptyLists (t * testing.T ) {
216+ func TestHasMirrorRegistries_EmptyLists (t * testing.T ) {
217217 g := NewWithT (t )
218218 ctx := context .Background ()
219219
220220 // No ICSP or IDMS resources, but CRDs are registered
221221 h := setupTestHelper (true )
222222
223- disconnected , err := IsDisconnectedOCP (ctx , h )
223+ hasMirrors , err := HasMirrorRegistries (ctx , h )
224224 g .Expect (err ).ToNot (HaveOccurred ())
225- g .Expect (disconnected ).To (BeFalse (), "Should not detect disconnected environment when lists are empty" )
225+ g .Expect (hasMirrors ).To (BeFalse (), "Should not detect mirror registries when lists are empty" )
226226}
227227
228- func TestIsDisconnectedOCP_CRDsNotInstalled (t * testing.T ) {
228+ func TestHasMirrorRegistries_CRDsNotInstalled (t * testing.T ) {
229229 g := NewWithT (t )
230230 ctx := context .Background ()
231231
232232 // Don't register OpenShift CRDs - simulates non-OpenShift cluster
233233 h := setupTestHelper (false )
234234
235- disconnected , err := IsDisconnectedOCP (ctx , h )
235+ hasMirrors , err := HasMirrorRegistries (ctx , h )
236236 g .Expect (err ).ToNot (HaveOccurred (), "Should not return error when CRDs don't exist" )
237- g .Expect (disconnected ).To (BeFalse (), "Should return false when CRDs don't exist (graceful degradation)" )
237+ g .Expect (hasMirrors ).To (BeFalse (), "Should return false when CRDs don't exist (graceful degradation)" )
238238}
239239
240240// Test GetMCRegistryConf scenarios
@@ -290,7 +290,7 @@ func TestGetMCRegistryConf_MachineConfigNotFound(t *testing.T) {
290290 // MachineConfig CRD is registered but no resource exists
291291 // This simulates the case where MCO is installed but the specific
292292 // registry MachineConfig doesn't exist - this should be treated as an error,
293- // not a warning, because if MCO is present and disconnected env is detected,
293+ // not a warning, because if MCO is present and mirror registries are detected,
294294 // the registry config should exist.
295295 h := setupTestHelper (true )
296296
@@ -412,11 +412,11 @@ func TestGetMCRegistryConf_InvalidBase64Content(t *testing.T) {
412412}
413413
414414// Test real-world scenarios
415- func TestDisconnectedEnvironment_FullScenario (t * testing.T ) {
415+ func TestMirrorRegistryEnvironment_FullScenario (t * testing.T ) {
416416 g := NewWithT (t )
417417 ctx := context .Background ()
418418
419- // Simulate a full disconnected environment with IDMS and MachineConfig
419+ // Simulate a mirror registry environment with IDMS and MachineConfig
420420 expectedConfig := `[[registry]]
421421 prefix = ""
422422 location = "registry.redhat.io/rhosp-dev-preview"
@@ -467,10 +467,10 @@ func TestDisconnectedEnvironment_FullScenario(t *testing.T) {
467467
468468 h := setupTestHelper (true , idms , machineConfig )
469469
470- // Check for disconnected environment
471- disconnected , err := IsDisconnectedOCP (ctx , h )
470+ // Check for mirror registries
471+ hasMirrors , err := HasMirrorRegistries (ctx , h )
472472 g .Expect (err ).ToNot (HaveOccurred ())
473- g .Expect (disconnected ).To (BeTrue ())
473+ g .Expect (hasMirrors ).To (BeTrue ())
474474
475475 // Get the registry configuration
476476 config , err := GetMCRegistryConf (ctx , h )
@@ -485,14 +485,67 @@ func TestNonOpenShiftCluster_GracefulDegradation(t *testing.T) {
485485 // Simulate a non-OpenShift Kubernetes cluster (no OpenShift CRDs registered)
486486 h := setupTestHelper (false )
487487
488- // IsDisconnectedOCP should return false without error
489- disconnected , err := IsDisconnectedOCP (ctx , h )
488+ // HasMirrorRegistries should return false without error
489+ hasMirrors , err := HasMirrorRegistries (ctx , h )
490490 g .Expect (err ).ToNot (HaveOccurred (), "Should gracefully handle missing CRDs" )
491- g .Expect (disconnected ).To (BeFalse ())
491+ g .Expect (hasMirrors ).To (BeFalse ())
492492
493493 // GetMCRegistryConf should return an error that can be identified as "CRD not found"
494494 config , err := GetMCRegistryConf (ctx , h )
495495 g .Expect (err ).To (HaveOccurred ())
496496 g .Expect (IsNoMatchError (err )).To (BeTrue (), "Error should indicate CRD is not installed" )
497497 g .Expect (config ).To (BeEmpty ())
498498}
499+
500+ func TestGetMirrorRegistryCACerts (t * testing.T ) {
501+ g := NewWithT (t )
502+ ctx := context .Background ()
503+
504+ // Test successful retrieval of CA certificates
505+ imageConfig := & ocpidms.Image {
506+ ObjectMeta : metav1.ObjectMeta {Name : "cluster" },
507+ Spec : ocpidms.ImageSpec {AdditionalTrustedCA : ocpidms.ConfigMapNameReference {Name : "registry-cas" }},
508+ }
509+ caConfigMap := & k8s_corev1.ConfigMap {
510+ ObjectMeta : metav1.ObjectMeta {Name : "registry-cas" , Namespace : "openshift-config" },
511+ Data : map [string ]string {"mirror.example.com" : "-----BEGIN CERTIFICATE-----\n test\n -----END CERTIFICATE-----" },
512+ }
513+ h := setupTestHelper (true , imageConfig , caConfigMap )
514+ caCerts , err := GetMirrorRegistryCACerts (ctx , h )
515+ g .Expect (err ).ToNot (HaveOccurred ())
516+ g .Expect (caCerts ).To (HaveLen (1 ))
517+ g .Expect (caCerts ).To (HaveKey ("mirror.example.com" ))
518+
519+ // Test with no additionalTrustedCA configured - should return nil
520+ imageConfigNoCA := & ocpidms.Image {
521+ ObjectMeta : metav1.ObjectMeta {Name : "cluster" },
522+ Spec : ocpidms.ImageSpec {},
523+ }
524+ h = setupTestHelper (true , imageConfigNoCA )
525+ caCerts , err = GetMirrorRegistryCACerts (ctx , h )
526+ g .Expect (err ).ToNot (HaveOccurred ())
527+ g .Expect (caCerts ).To (BeNil ())
528+
529+ // Test non-OpenShift cluster (CRDs not registered) - should return nil without error
530+ h = setupTestHelper (false )
531+ caCerts , err = GetMirrorRegistryCACerts (ctx , h )
532+ g .Expect (err ).ToNot (HaveOccurred ())
533+ g .Expect (caCerts ).To (BeNil ())
534+ }
535+
536+ func TestGetMirrorRegistryCACerts_ConfigMapNotFound (t * testing.T ) {
537+ g := NewWithT (t )
538+ ctx := context .Background ()
539+
540+ // Test when additionalTrustedCA references a ConfigMap that doesn't exist
541+ // This should return nil, nil (graceful handling) instead of an error
542+ imageConfig := & ocpidms.Image {
543+ ObjectMeta : metav1.ObjectMeta {Name : "cluster" },
544+ Spec : ocpidms.ImageSpec {AdditionalTrustedCA : ocpidms.ConfigMapNameReference {Name : "non-existent-ca" }},
545+ }
546+ h := setupTestHelper (true , imageConfig )
547+
548+ caCerts , err := GetMirrorRegistryCACerts (ctx , h )
549+ g .Expect (err ).ToNot (HaveOccurred (), "Should not return error when ConfigMap is not found" )
550+ g .Expect (caCerts ).To (BeNil (), "Should return nil when ConfigMap is not found" )
551+ }
0 commit comments