0
Fork 0
mirror of https://github.com/project-zot/zot.git synced 2024-12-16 21:56:37 -05:00

Merge pull request #45 from rchincha/issue-15

test/data: remove htpasswd file
This commit is contained in:
Serge Hallyn 2019-12-13 13:48:16 -06:00 committed by GitHub
commit 7de21820d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 2 deletions

View file

@ -27,12 +27,26 @@ const (
SecurePort2 = "8082" SecurePort2 = "8082"
username = "test" username = "test"
passphrase = "test" passphrase = "test"
htpasswdPath = "../../test/data/htpasswd" // nolint (gosec) - this is just test data
ServerCert = "../../test/data/server.cert" ServerCert = "../../test/data/server.cert"
ServerKey = "../../test/data/server.key" ServerKey = "../../test/data/server.key"
CACert = "../../test/data/ca.crt" 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) { func TestNew(t *testing.T) {
Convey("Make a new controller", t, func() { Convey("Make a new controller", t, func() {
config := api.NewConfig() config := api.NewConfig()
@ -45,6 +59,9 @@ func TestBasicAuth(t *testing.T) {
Convey("Make a new controller", t, func() { Convey("Make a new controller", t, func() {
config := api.NewConfig() config := api.NewConfig()
config.HTTP.Port = SecurePort1 config.HTTP.Port = SecurePort1
htpasswdPath := makeHtpasswdFile()
defer os.Remove(htpasswdPath)
config.HTTP.Auth = &api.AuthConfig{ config.HTTP.Auth = &api.AuthConfig{
HTPasswd: api.AuthHTPasswd{ HTPasswd: api.AuthHTPasswd{
Path: htpasswdPath, Path: htpasswdPath,
@ -104,6 +121,8 @@ func TestTLSWithBasicAuth(t *testing.T) {
So(err, ShouldBeNil) So(err, ShouldBeNil)
caCertPool := x509.NewCertPool() caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM(caCert) caCertPool.AppendCertsFromPEM(caCert)
htpasswdPath := makeHtpasswdFile()
defer os.Remove(htpasswdPath)
resty.SetTLSClientConfig(&tls.Config{RootCAs: caCertPool}) resty.SetTLSClientConfig(&tls.Config{RootCAs: caCertPool})
defer func() { resty.SetTLSClientConfig(nil) }() defer func() { resty.SetTLSClientConfig(nil) }()
@ -179,6 +198,8 @@ func TestTLSWithBasicAuthAllowReadAccess(t *testing.T) {
So(err, ShouldBeNil) So(err, ShouldBeNil)
caCertPool := x509.NewCertPool() caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM(caCert) caCertPool.AppendCertsFromPEM(caCert)
htpasswdPath := makeHtpasswdFile()
defer os.Remove(htpasswdPath)
resty.SetTLSClientConfig(&tls.Config{RootCAs: caCertPool}) resty.SetTLSClientConfig(&tls.Config{RootCAs: caCertPool})
defer func() { resty.SetTLSClientConfig(nil) }() defer func() { resty.SetTLSClientConfig(nil) }()
@ -432,6 +453,8 @@ func TestTLSMutualAndBasicAuth(t *testing.T) {
So(err, ShouldBeNil) So(err, ShouldBeNil)
caCertPool := x509.NewCertPool() caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM(caCert) caCertPool.AppendCertsFromPEM(caCert)
htpasswdPath := makeHtpasswdFile()
defer os.Remove(htpasswdPath)
resty.SetTLSClientConfig(&tls.Config{RootCAs: caCertPool}) resty.SetTLSClientConfig(&tls.Config{RootCAs: caCertPool})
defer func() { resty.SetTLSClientConfig(nil) }() defer func() { resty.SetTLSClientConfig(nil) }()
@ -524,6 +547,8 @@ func TestTLSMutualAndBasicAuthAllowReadAccess(t *testing.T) {
So(err, ShouldBeNil) So(err, ShouldBeNil)
caCertPool := x509.NewCertPool() caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM(caCert) caCertPool.AppendCertsFromPEM(caCert)
htpasswdPath := makeHtpasswdFile()
defer os.Remove(htpasswdPath)
resty.SetTLSClientConfig(&tls.Config{RootCAs: caCertPool}) resty.SetTLSClientConfig(&tls.Config{RootCAs: caCertPool})
defer func() { resty.SetTLSClientConfig(nil) }() defer func() { resty.SetTLSClientConfig(nil) }()

View file

@ -1 +0,0 @@
test:$2y$05$hlbSXDp6hzDLu6VwACS39ORvVRpr3OMR4RlJ31jtlaOEGnPjKZI1m