fix: auth check (#773)

* fix: auth check

Signed-off-by: Matej Vasek <mvasek@redhat.com>

* fix: auth check

Signed-off-by: Matej Vasek <mvasek@redhat.com>
This commit is contained in:
Matej Vasek 2022-01-21 21:45:04 +01:00 committed by GitHub
parent e918f74b9e
commit 153e486bc6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View File

@ -41,7 +41,7 @@ func CheckAuth(ctx context.Context, registry string, credentials docker.Credenti
serverAddress = "https://" + serverAddress
}
url := fmt.Sprintf("%s/v2", serverAddress)
url := fmt.Sprintf("%s/v2/", serverAddress)
authenticator := &authn.Basic{
Username: credentials.Username,
@ -55,6 +55,10 @@ func CheckAuth(ctx context.Context, registry string, credentials docker.Credenti
tr, err := transport.NewWithContext(ctx, reg, authenticator, trans, nil)
if err != nil {
var transportErr *transport.Error
if errors.As(err, &transportErr); transportErr.StatusCode == 401 {
return ErrUnauthorized
}
return err
}

View File

@ -170,6 +170,7 @@ func startServer(t *testing.T) (addr, addrTLS string, stopServer func()) {
addrTLS = listenerTLS.Addr().String()
handler := http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
// TODO add also test for token based auth
resp.Header().Add("WWW-Authenticate", "basic")
if user, pwd, ok := req.BasicAuth(); ok {
if user == "testuser" && pwd == "testpwd" {