From 099a9e18f30db9c90a3a5e52b2af6dd630a6d757 Mon Sep 17 00:00:00 2001 From: Jesse Simpson Date: Thu, 22 May 2025 16:35:35 -0400 Subject: [PATCH 1/3] test: include tests for Login based on different protocol prefixes Signed-off-by: Jesse Simpson --- pkg/registry/client_http_test.go | 17 +++++++++++++++++ pkg/registry/utils_test.go | 7 ++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/pkg/registry/client_http_test.go b/pkg/registry/client_http_test.go index 043fd4205..fdb708fa3 100644 --- a/pkg/registry/client_http_test.go +++ b/pkg/registry/client_http_test.go @@ -28,6 +28,7 @@ import ( type HTTPRegistryClientTestSuite struct { TestSuite + protocol string } func (suite *HTTPRegistryClientTestSuite) SetupSuite() { @@ -56,14 +57,23 @@ func (suite *HTTPRegistryClientTestSuite) Test_0_Login() { } func (suite *HTTPRegistryClientTestSuite) Test_1_Push() { + if suite.protocol != "" { + return + } testPush(&suite.TestSuite) } func (suite *HTTPRegistryClientTestSuite) Test_2_Pull() { + if suite.protocol != "" { + return + } testPull(&suite.TestSuite) } func (suite *HTTPRegistryClientTestSuite) Test_3_Tags() { + if suite.protocol != "" { + return + } testTags(&suite.TestSuite) } @@ -78,4 +88,11 @@ func (suite *HTTPRegistryClientTestSuite) Test_4_ManInTheMiddle() { func TestHTTPRegistryClientTestSuite(t *testing.T) { suite.Run(t, new(HTTPRegistryClientTestSuite)) + for _, protocol := range []string{"oci://", "http://", "https://"} { + var protocolSpecificTestSuite = new(HTTPRegistryClientTestSuite) + protocolSpecificTestSuite.protocol = protocol + protocolSpecificTestSuite.DockerRegistryHost = protocol + "helm-test-registry" + suite.Run(t, protocolSpecificTestSuite) + } + } diff --git a/pkg/registry/utils_test.go b/pkg/registry/utils_test.go index bce286303..703eb127b 100644 --- a/pkg/registry/utils_test.go +++ b/pkg/registry/utils_test.go @@ -127,7 +127,12 @@ func setup(suite *TestSuite, tlsEnabled, insecure bool) *registry.Registry { // Change the registry host to another host which is not localhost. // This is required because Docker enforces HTTP if the registry // host is localhost/127.0.0.1. - suite.DockerRegistryHost = fmt.Sprintf("helm-test-registry:%d", port) + if suite.DockerRegistryHost == "" { + suite.DockerRegistryHost = fmt.Sprintf("helm-test-registry:%d", port) + } else { + // may programmatically set this for custom protocol handling + suite.DockerRegistryHost = fmt.Sprintf("%s:%d", suite.DockerRegistryHost, port) + } suite.srv, err = mockdns.NewServer(map[string]mockdns.Zone{ "helm-test-registry.": { A: []string{"127.0.0.1"}, From fe512bae439b5271dd7d2cdb75fadf3c39abd800 Mon Sep 17 00:00:00 2001 From: Jesse Simpson Date: Thu, 22 May 2025 16:49:10 -0400 Subject: [PATCH 2/3] test: tests repo stripping functionality Signed-off-by: Jesse Simpson --- pkg/registry/client_http_test.go | 9 ++++++--- pkg/registry/utils_test.go | 5 +++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/pkg/registry/client_http_test.go b/pkg/registry/client_http_test.go index fdb708fa3..a8d2c4758 100644 --- a/pkg/registry/client_http_test.go +++ b/pkg/registry/client_http_test.go @@ -57,21 +57,21 @@ func (suite *HTTPRegistryClientTestSuite) Test_0_Login() { } func (suite *HTTPRegistryClientTestSuite) Test_1_Push() { - if suite.protocol != "" { + if suite.protocol != "" || suite.Repo != "" { return } testPush(&suite.TestSuite) } func (suite *HTTPRegistryClientTestSuite) Test_2_Pull() { - if suite.protocol != "" { + if suite.protocol != "" || suite.Repo != "" { return } testPull(&suite.TestSuite) } func (suite *HTTPRegistryClientTestSuite) Test_3_Tags() { - if suite.protocol != "" { + if suite.protocol != "" || suite.Repo != "" { return } testTags(&suite.TestSuite) @@ -88,6 +88,9 @@ func (suite *HTTPRegistryClientTestSuite) Test_4_ManInTheMiddle() { func TestHTTPRegistryClientTestSuite(t *testing.T) { suite.Run(t, new(HTTPRegistryClientTestSuite)) + var suiteWithRepo = new(HTTPRegistryClientTestSuite) + suiteWithRepo.Repo = "/testrepo/" + suite.Run(t, suiteWithRepo) for _, protocol := range []string{"oci://", "http://", "https://"} { var protocolSpecificTestSuite = new(HTTPRegistryClientTestSuite) protocolSpecificTestSuite.protocol = protocol diff --git a/pkg/registry/utils_test.go b/pkg/registry/utils_test.go index 703eb127b..c47c8587d 100644 --- a/pkg/registry/utils_test.go +++ b/pkg/registry/utils_test.go @@ -65,6 +65,7 @@ type TestSuite struct { CompromisedRegistryHost string WorkspaceDir string RegistryClient *Client + Repo string // A mock DNS server needed for TLS connection testing. srv *mockdns.Server @@ -128,10 +129,10 @@ func setup(suite *TestSuite, tlsEnabled, insecure bool) *registry.Registry { // This is required because Docker enforces HTTP if the registry // host is localhost/127.0.0.1. if suite.DockerRegistryHost == "" { - suite.DockerRegistryHost = fmt.Sprintf("helm-test-registry:%d", port) + suite.DockerRegistryHost = fmt.Sprintf("helm-test-registry:%d%s", port, suite.Repo) } else { // may programmatically set this for custom protocol handling - suite.DockerRegistryHost = fmt.Sprintf("%s:%d", suite.DockerRegistryHost, port) + suite.DockerRegistryHost = fmt.Sprintf("%s:%d%s", suite.DockerRegistryHost, port, suite.Repo) } suite.srv, err = mockdns.NewServer(map[string]mockdns.Zone{ "helm-test-registry.": { From fedf5024d60bcb4efce9cf7f6f1b7bca642a66eb Mon Sep 17 00:00:00 2001 From: Jesse Simpson Date: Thu, 22 May 2025 18:48:20 -0400 Subject: [PATCH 3/3] test: Skip instead of returning early. looks more intentional Signed-off-by: Jesse Simpson --- pkg/registry/client_http_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/registry/client_http_test.go b/pkg/registry/client_http_test.go index a8d2c4758..e0cd548c3 100644 --- a/pkg/registry/client_http_test.go +++ b/pkg/registry/client_http_test.go @@ -58,21 +58,21 @@ func (suite *HTTPRegistryClientTestSuite) Test_0_Login() { func (suite *HTTPRegistryClientTestSuite) Test_1_Push() { if suite.protocol != "" || suite.Repo != "" { - return + suite.T().Skip("Skipping we don't strip protocol or repo prior to execution") } testPush(&suite.TestSuite) } func (suite *HTTPRegistryClientTestSuite) Test_2_Pull() { if suite.protocol != "" || suite.Repo != "" { - return + suite.T().Skip("Skipping we don't strip protocol or repo prior to execution") } testPull(&suite.TestSuite) } func (suite *HTTPRegistryClientTestSuite) Test_3_Tags() { if suite.protocol != "" || suite.Repo != "" { - return + suite.T().Skip("Skipping we don't strip protocol or repo prior to execution") } testTags(&suite.TestSuite) }