@@ -23,6 +23,7 @@ import (
23
23
"errors"
24
24
"fmt"
25
25
"io"
26
+ "net"
26
27
"net/http"
27
28
"os"
28
29
"path"
@@ -32,6 +33,7 @@ import (
32
33
"testing"
33
34
"time"
34
35
36
+ "github.com/foxcpp/go-mockdns"
35
37
. "github.com/onsi/gomega"
36
38
coptions "github.com/sigstore/cosign/v2/cmd/cosign/cli/options"
37
39
"github.com/sigstore/cosign/v2/cmd/cosign/cli/sign"
@@ -1295,6 +1297,7 @@ func TestHelmChartReconciler_buildFromOCIHelmRepository(t *testing.T) {
1295
1297
Timeout : & metav1.Duration {Duration : timeout },
1296
1298
Provider : helmv1 .GenericOCIProvider ,
1297
1299
Type : helmv1 .HelmRepositoryTypeOCI ,
1300
+ Insecure : true ,
1298
1301
},
1299
1302
}
1300
1303
obj := & helmv1.HelmChart {
@@ -1314,12 +1317,14 @@ func TestHelmChartReconciler_buildFromOCIHelmRepository(t *testing.T) {
1314
1317
}
1315
1318
got , err := r .buildFromHelmRepository (context .TODO (), obj , repository , & b )
1316
1319
1317
- g .Expect (err != nil ).To (Equal (tt .wantErr != nil ))
1318
1320
if tt .wantErr != nil {
1321
+ g .Expect (err ).To (HaveOccurred ())
1319
1322
g .Expect (reflect .TypeOf (err ).String ()).To (Equal (reflect .TypeOf (tt .wantErr ).String ()))
1320
1323
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 ))
1321
1327
}
1322
- g .Expect (got ).To (Equal (tt .want ))
1323
1328
1324
1329
if tt .assertFunc != nil {
1325
1330
tt .assertFunc (g , obj , b )
@@ -1333,6 +1338,14 @@ func TestHelmChartReconciler_buildFromTarballArtifact(t *testing.T) {
1333
1338
1334
1339
tmpDir := t .TempDir ()
1335
1340
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
+
1336
1349
storage , err := NewStorage (tmpDir , "example.com" , retentionTTL , retentionRecords )
1337
1350
g .Expect (err ).ToNot (HaveOccurred ())
1338
1351
@@ -2430,9 +2443,6 @@ func TestHelmChartReconciler_reconcileSourceFromOCI_authStrategy(t *testing.T) {
2430
2443
2431
2444
workspaceDir := t .TempDir ()
2432
2445
2433
- if tt .insecure {
2434
- tt .registryOpts .disableDNSMocking = true
2435
- }
2436
2446
server , err := setupRegistryServer (ctx , workspaceDir , tt .registryOpts )
2437
2447
g .Expect (err ).NotTo (HaveOccurred ())
2438
2448
t .Cleanup (func () {
@@ -2457,6 +2467,7 @@ func TestHelmChartReconciler_reconcileSourceFromOCI_authStrategy(t *testing.T) {
2457
2467
Type : helmv1 .HelmRepositoryTypeOCI ,
2458
2468
Provider : helmv1 .GenericOCIProvider ,
2459
2469
URL : fmt .Sprintf ("oci://%s/testrepo" , server .registryHost ),
2470
+ Insecure : tt .insecure ,
2460
2471
},
2461
2472
}
2462
2473
@@ -2726,9 +2737,7 @@ func TestHelmChartReconciler_reconcileSourceFromOCI_verifySignature(t *testing.T
2726
2737
g := NewWithT (t )
2727
2738
2728
2739
tmpDir := t .TempDir ()
2729
- server , err := setupRegistryServer (ctx , tmpDir , registryOptions {
2730
- disableDNSMocking : true ,
2731
- })
2740
+ server , err := setupRegistryServer (ctx , tmpDir , registryOptions {})
2732
2741
g .Expect (err ).ToNot (HaveOccurred ())
2733
2742
t .Cleanup (func () {
2734
2743
server .Close ()
@@ -2871,6 +2880,7 @@ func TestHelmChartReconciler_reconcileSourceFromOCI_verifySignature(t *testing.T
2871
2880
Timeout : & metav1.Duration {Duration : timeout },
2872
2881
Provider : helmv1 .GenericOCIProvider ,
2873
2882
Type : helmv1 .HelmRepositoryTypeOCI ,
2883
+ Insecure : true ,
2874
2884
},
2875
2885
}
2876
2886
@@ -2925,7 +2935,7 @@ func TestHelmChartReconciler_reconcileSourceFromOCI_verifySignature(t *testing.T
2925
2935
Upload : true ,
2926
2936
SkipConfirmation : true ,
2927
2937
TlogUpload : false ,
2928
- Registry : coptions.RegistryOptions {Keychain : oci.Anonymous {}, AllowInsecure : true },
2938
+ Registry : coptions.RegistryOptions {Keychain : oci.Anonymous {}, AllowHTTPRegistry : true },
2929
2939
},
2930
2940
[]string {fmt .Sprintf ("%s/testrepo/%s:%s" , server .registryHost , metadata .Name , metadata .Version )})
2931
2941
g .Expect (err ).ToNot (HaveOccurred ())
0 commit comments