scheme and host mandatory in baseurl
Signed-off-by: Andrew Hsu <andrewhsu@acm.org> (github: andrewhsu)
This commit is contained in:
parent
059bc5f5ef
commit
80248c3d3a
@ -3,7 +3,6 @@ package middleware
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/docker/distribution/context"
|
"github.com/docker/distribution/context"
|
||||||
storagedriver "github.com/docker/distribution/registry/storage/driver"
|
storagedriver "github.com/docker/distribution/registry/storage/driver"
|
||||||
@ -27,12 +26,15 @@ func newRedirectStorageMiddleware(sd storagedriver.StorageDriver, options map[st
|
|||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("baseurl must be a string")
|
return nil, fmt.Errorf("baseurl must be a string")
|
||||||
}
|
}
|
||||||
if !strings.Contains(b, "://") {
|
|
||||||
b = "https://" + b
|
|
||||||
}
|
|
||||||
u, err := url.Parse(b)
|
u, err := url.Parse(b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("invalid baseurl: %v", err)
|
return nil, fmt.Errorf("unable to parse redirect baseurl: %s", b)
|
||||||
|
}
|
||||||
|
if u.Scheme == "" {
|
||||||
|
return nil, fmt.Errorf("no scheme specified for redirect baseurl")
|
||||||
|
}
|
||||||
|
if u.Host == "" {
|
||||||
|
return nil, fmt.Errorf("no host specified for redirect baseurl")
|
||||||
}
|
}
|
||||||
|
|
||||||
return &redirectStorageMiddleware{StorageDriver: sd, scheme: u.Scheme, host: u.Host}, nil
|
return &redirectStorageMiddleware{StorageDriver: sd, scheme: u.Scheme, host: u.Host}, nil
|
||||||
|
@ -17,16 +17,11 @@ func (s *MiddlewareSuite) TestNoConfig(c *check.C) {
|
|||||||
c.Assert(err, check.ErrorMatches, "no baseurl provided")
|
c.Assert(err, check.ErrorMatches, "no baseurl provided")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MiddlewareSuite) TestDefaultScheme(c *check.C) {
|
func (s *MiddlewareSuite) TestMissingScheme(c *check.C) {
|
||||||
options := make(map[string]interface{})
|
options := make(map[string]interface{})
|
||||||
options["baseurl"] = "example.com"
|
options["baseurl"] = "example.com"
|
||||||
middleware, err := newRedirectStorageMiddleware(nil, options)
|
_, err := newRedirectStorageMiddleware(nil, options)
|
||||||
c.Assert(err, check.Equals, nil)
|
c.Assert(err, check.ErrorMatches, "no scheme specified for redirect baseurl")
|
||||||
|
|
||||||
m, ok := middleware.(*redirectStorageMiddleware)
|
|
||||||
c.Assert(ok, check.Equals, true)
|
|
||||||
c.Assert(m.scheme, check.Equals, "https")
|
|
||||||
c.Assert(m.host, check.Equals, "example.com")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MiddlewareSuite) TestHTTPS(c *check.C) {
|
func (s *MiddlewareSuite) TestHTTPS(c *check.C) {
|
||||||
|
Loading…
Reference in New Issue
Block a user