@@ -23,6 +23,7 @@ import (
2323 "errors"
2424 "fmt"
2525 "io"
26+ "net"
2627 "net/http"
2728 "os"
2829 "path"
@@ -32,6 +33,7 @@ import (
3233 "testing"
3334 "time"
3435
36+ "github.com/foxcpp/go-mockdns"
3537 . "github.com/onsi/gomega"
3638 coptions "github.com/sigstore/cosign/v2/cmd/cosign/cli/options"
3739 "github.com/sigstore/cosign/v2/cmd/cosign/cli/sign"
@@ -1295,6 +1297,7 @@ func TestHelmChartReconciler_buildFromOCIHelmRepository(t *testing.T) {
12951297 Timeout : & metav1.Duration {Duration : timeout },
12961298 Provider : helmv1 .GenericOCIProvider ,
12971299 Type : helmv1 .HelmRepositoryTypeOCI ,
1300+ Insecure : true ,
12981301 },
12991302 }
13001303 obj := & helmv1.HelmChart {
@@ -1314,12 +1317,14 @@ func TestHelmChartReconciler_buildFromOCIHelmRepository(t *testing.T) {
13141317 }
13151318 got , err := r .buildFromHelmRepository (context .TODO (), obj , repository , & b )
13161319
1317- g .Expect (err != nil ).To (Equal (tt .wantErr != nil ))
13181320 if tt .wantErr != nil {
1321+ g .Expect (err ).To (HaveOccurred ())
13191322 g .Expect (reflect .TypeOf (err ).String ()).To (Equal (reflect .TypeOf (tt .wantErr ).String ()))
13201323 g .Expect (err .Error ()).To (ContainSubstring (tt .wantErr .Error ()))
1324+ } else {
1325+ g .Expect (err ).ToNot (HaveOccurred ())
1326+ g .Expect (got ).To (Equal (tt .want ))
13211327 }
1322- g .Expect (got ).To (Equal (tt .want ))
13231328
13241329 if tt .assertFunc != nil {
13251330 tt .assertFunc (g , obj , b )
@@ -1333,6 +1338,14 @@ func TestHelmChartReconciler_buildFromTarballArtifact(t *testing.T) {
13331338
13341339 tmpDir := t .TempDir ()
13351340
1341+ // Unpatch the changes we make to the default DNS resolver in `setupRegistryServer()`.
1342+ // This is required because the changes somehow also cause remote lookups to fail and
1343+ // this test tests functionality related to remote dependencies.
1344+ mockdns .UnpatchNet (net .DefaultResolver )
1345+ defer func () {
1346+ testRegistryServer .dnsServer .PatchNet (net .DefaultResolver )
1347+ }()
1348+
13361349 storage , err := NewStorage (tmpDir , "example.com" , retentionTTL , retentionRecords )
13371350 g .Expect (err ).ToNot (HaveOccurred ())
13381351
@@ -2430,9 +2443,6 @@ func TestHelmChartReconciler_reconcileSourceFromOCI_authStrategy(t *testing.T) {
24302443
24312444 workspaceDir := t .TempDir ()
24322445
2433- if tt .insecure {
2434- tt .registryOpts .disableDNSMocking = true
2435- }
24362446 server , err := setupRegistryServer (ctx , workspaceDir , tt .registryOpts )
24372447 g .Expect (err ).NotTo (HaveOccurred ())
24382448 t .Cleanup (func () {
@@ -2457,6 +2467,7 @@ func TestHelmChartReconciler_reconcileSourceFromOCI_authStrategy(t *testing.T) {
24572467 Type : helmv1 .HelmRepositoryTypeOCI ,
24582468 Provider : helmv1 .GenericOCIProvider ,
24592469 URL : fmt .Sprintf ("oci://%s/testrepo" , server .registryHost ),
2470+ Insecure : tt .insecure ,
24602471 },
24612472 }
24622473
@@ -2726,9 +2737,7 @@ func TestHelmChartReconciler_reconcileSourceFromOCI_verifySignature(t *testing.T
27262737 g := NewWithT (t )
27272738
27282739 tmpDir := t .TempDir ()
2729- server , err := setupRegistryServer (ctx , tmpDir , registryOptions {
2730- disableDNSMocking : true ,
2731- })
2740+ server , err := setupRegistryServer (ctx , tmpDir , registryOptions {})
27322741 g .Expect (err ).ToNot (HaveOccurred ())
27332742 t .Cleanup (func () {
27342743 server .Close ()
@@ -2871,6 +2880,7 @@ func TestHelmChartReconciler_reconcileSourceFromOCI_verifySignature(t *testing.T
28712880 Timeout : & metav1.Duration {Duration : timeout },
28722881 Provider : helmv1 .GenericOCIProvider ,
28732882 Type : helmv1 .HelmRepositoryTypeOCI ,
2883+ Insecure : true ,
28742884 },
28752885 }
28762886
@@ -2925,7 +2935,7 @@ func TestHelmChartReconciler_reconcileSourceFromOCI_verifySignature(t *testing.T
29252935 Upload : true ,
29262936 SkipConfirmation : true ,
29272937 TlogUpload : false ,
2928- Registry : coptions.RegistryOptions {Keychain : oci.Anonymous {}, AllowInsecure : true },
2938+ Registry : coptions.RegistryOptions {Keychain : oci.Anonymous {}, AllowHTTPRegistry : true },
29292939 },
29302940 []string {fmt .Sprintf ("%s/testrepo/%s:%s" , server .registryHost , metadata .Name , metadata .Version )})
29312941 g .Expect (err ).ToNot (HaveOccurred ())
0 commit comments