From f1eada49e4d6e0386653dbc254f600aa3f425926 Mon Sep 17 00:00:00 2001 From: Tom Runyon Date: Thu, 15 Dec 2022 06:24:30 -0500 Subject: [PATCH] added test for insecure registry Signed-off-by: Tom Runyon --- pkg/registry/client.go | 20 ++---- pkg/registry/client_tls_insecure_test.go | 81 ++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 14 deletions(-) create mode 100644 pkg/registry/client_tls_insecure_test.go diff --git a/pkg/registry/client.go b/pkg/registry/client.go index 52d84619e..134bb4ff3 100644 --- a/pkg/registry/client.go +++ b/pkg/registry/client.go @@ -258,13 +258,12 @@ type ( LoginOption func(*loginOperation) loginOperation struct { - username string - password string - insecure bool - certFile string - keyFile string - caFile string - plainHTTP bool + username string + password string + insecure bool + certFile string + keyFile string + caFile string } ) @@ -300,13 +299,6 @@ func LoginOptBasicAuth(username string, password string) LoginOption { } } -// LoginOptBasicAuth returns a function that sets the username/password settings on login -func LoginOptPlainHTTP() LoginOption { - return func(operation *loginOperation) { - operation.plainHTTP = true - } -} - // LoginOptInsecure returns a function that sets the insecure setting on login func LoginOptInsecure(insecure bool) LoginOption { return func(operation *loginOperation) { diff --git a/pkg/registry/client_tls_insecure_test.go b/pkg/registry/client_tls_insecure_test.go new file mode 100644 index 000000000..ac9434daf --- /dev/null +++ b/pkg/registry/client_tls_insecure_test.go @@ -0,0 +1,81 @@ +/* +Copyright The Helm Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package registry + +import ( + "os" + "testing" + + "github.com/stretchr/testify/suite" +) + +type TLSInsecureRegistryClientTestSuite struct { + TestSuite +} + +func (suite *TLSInsecureRegistryClientTestSuite) SetupSuite() { + // init test client + dockerRegistry := setup(&suite.TestSuite, true, true) + + // Start Docker registry + go dockerRegistry.ListenAndServe() +} + +func (suite *TLSInsecureRegistryClientTestSuite) TearDownSuite() { + os.RemoveAll(suite.WorkspaceDir) +} + +func (suite *TLSInsecureRegistryClientTestSuite) Test_0_Login() { + err := suite.RegistryClient.Login(suite.DockerRegistryHost, + LoginOptBasicAuth("badverybad", "ohsobad"), + LoginOptTLSClientConfig(tlsCert, tlsKey, tlsCA)) + suite.NotNil(err, "error logging into registry with bad credentials") + + err = suite.RegistryClient.Login(suite.DockerRegistryHost, + LoginOptBasicAuth(testUsername, testPassword), + LoginOptTLSClientConfig(tlsCert, tlsKey, tlsCA)) + suite.Nil(err, "no error logging into registry with good credentials") + + err = suite.RegistryClient.Login(suite.DockerRegistryHost, + LoginOptBasicAuth(testUsername, testPassword), + LoginOptTLSClientConfig(tlsCert, tlsKey, tlsCA)) + suite.Nil(err, "no error logging into registry with good credentials, insecure mode") +} + +func (suite *TLSInsecureRegistryClientTestSuite) Test_1_Push() { + testPush(&suite.TestSuite) +} + +func (suite *TLSInsecureRegistryClientTestSuite) Test_2_Pull() { + testPull(&suite.TestSuite) +} + +func (suite *TLSInsecureRegistryClientTestSuite) Test_3_Tags() { + testTags(&suite.TestSuite) +} + +func (suite *TLSInsecureRegistryClientTestSuite) Test_4_Logout() { + err := suite.RegistryClient.Logout("this-host-aint-real:5000") + suite.NotNil(err, "error logging out of registry that has no entry") + + err = suite.RegistryClient.Logout(suite.DockerRegistryHost) + suite.Nil(err, "no error logging out of registry") +} + +func TestTLSInsecureRegistryClientTestSuite(t *testing.T) { + suite.Run(t, new(TLSInsecureRegistryClientTestSuite)) +}