From d30766de34186e264a185a55375494dff7c609c6 Mon Sep 17 00:00:00 2001 From: Ramkumar Chinchani Date: Fri, 13 Dec 2019 11:11:24 -0800 Subject: [PATCH] test/data: remove htpasswd file Fixes issue #15 --- pkg/api/controller_test.go | 27 ++++++++++++++++++++++++++- test/data/htpasswd | 1 - 2 files changed, 26 insertions(+), 2 deletions(-) delete mode 100644 test/data/htpasswd diff --git a/pkg/api/controller_test.go b/pkg/api/controller_test.go index 637af2fc..8cb9f0e5 100644 --- a/pkg/api/controller_test.go +++ b/pkg/api/controller_test.go @@ -27,12 +27,26 @@ const ( SecurePort2 = "8082" username = "test" passphrase = "test" - htpasswdPath = "../../test/data/htpasswd" // nolint (gosec) - this is just test data ServerCert = "../../test/data/server.cert" ServerKey = "../../test/data/server.key" CACert = "../../test/data/ca.crt" ) +func makeHtpasswdFile() string { + f, err := ioutil.TempFile("", "htpasswd-") + if err != nil { + panic(err) + } + + // bcrypt(username="test", passwd="test") + content := []byte("test:$2y$05$hlbSXDp6hzDLu6VwACS39ORvVRpr3OMR4RlJ31jtlaOEGnPjKZI1m\n") + if err := ioutil.WriteFile(f.Name(), content, 0644); err != nil { + panic(err) + } + + return f.Name() +} + func TestNew(t *testing.T) { Convey("Make a new controller", t, func() { config := api.NewConfig() @@ -45,6 +59,9 @@ func TestBasicAuth(t *testing.T) { Convey("Make a new controller", t, func() { config := api.NewConfig() config.HTTP.Port = SecurePort1 + htpasswdPath := makeHtpasswdFile() + defer os.Remove(htpasswdPath) + config.HTTP.Auth = &api.AuthConfig{ HTPasswd: api.AuthHTPasswd{ Path: htpasswdPath, @@ -104,6 +121,8 @@ func TestTLSWithBasicAuth(t *testing.T) { So(err, ShouldBeNil) caCertPool := x509.NewCertPool() caCertPool.AppendCertsFromPEM(caCert) + htpasswdPath := makeHtpasswdFile() + defer os.Remove(htpasswdPath) resty.SetTLSClientConfig(&tls.Config{RootCAs: caCertPool}) defer func() { resty.SetTLSClientConfig(nil) }() @@ -179,6 +198,8 @@ func TestTLSWithBasicAuthAllowReadAccess(t *testing.T) { So(err, ShouldBeNil) caCertPool := x509.NewCertPool() caCertPool.AppendCertsFromPEM(caCert) + htpasswdPath := makeHtpasswdFile() + defer os.Remove(htpasswdPath) resty.SetTLSClientConfig(&tls.Config{RootCAs: caCertPool}) defer func() { resty.SetTLSClientConfig(nil) }() @@ -432,6 +453,8 @@ func TestTLSMutualAndBasicAuth(t *testing.T) { So(err, ShouldBeNil) caCertPool := x509.NewCertPool() caCertPool.AppendCertsFromPEM(caCert) + htpasswdPath := makeHtpasswdFile() + defer os.Remove(htpasswdPath) resty.SetTLSClientConfig(&tls.Config{RootCAs: caCertPool}) defer func() { resty.SetTLSClientConfig(nil) }() @@ -524,6 +547,8 @@ func TestTLSMutualAndBasicAuthAllowReadAccess(t *testing.T) { So(err, ShouldBeNil) caCertPool := x509.NewCertPool() caCertPool.AppendCertsFromPEM(caCert) + htpasswdPath := makeHtpasswdFile() + defer os.Remove(htpasswdPath) resty.SetTLSClientConfig(&tls.Config{RootCAs: caCertPool}) defer func() { resty.SetTLSClientConfig(nil) }() diff --git a/test/data/htpasswd b/test/data/htpasswd deleted file mode 100644 index 1ae96da4..00000000 --- a/test/data/htpasswd +++ /dev/null @@ -1 +0,0 @@ -test:$2y$05$hlbSXDp6hzDLu6VwACS39ORvVRpr3OMR4RlJ31jtlaOEGnPjKZI1m