scheme and host mandatory in baseurl

Signed-off-by: Andrew Hsu <andrewhsu@acm.org> (github: andrewhsu)
This commit is contained in:
Andrew Hsu 2016-04-25 10:28:32 -07:00 committed by Andrew Hsu
parent cec7248bd1
commit fba2e3a206
2 changed files with 10 additions and 13 deletions

View file

@ -3,7 +3,6 @@ package middleware
import (
"fmt"
"net/url"
"strings"
"github.com/docker/distribution/context"
storagedriver "github.com/docker/distribution/registry/storage/driver"
@ -27,12 +26,15 @@ func newRedirectStorageMiddleware(sd storagedriver.StorageDriver, options map[st
if !ok {
return nil, fmt.Errorf("baseurl must be a string")
}
if !strings.Contains(b, "://") {
b = "https://" + b
}
u, err := url.Parse(b)
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

View file

@ -17,16 +17,11 @@ func (s *MiddlewareSuite) TestNoConfig(c *check.C) {
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["baseurl"] = "example.com"
middleware, err := newRedirectStorageMiddleware(nil, options)
c.Assert(err, check.Equals, nil)
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")
_, err := newRedirectStorageMiddleware(nil, options)
c.Assert(err, check.ErrorMatches, "no scheme specified for redirect baseurl")
}
func (s *MiddlewareSuite) TestHTTPS(c *check.C) {