aboutsummaryrefslogtreecommitdiff
path: root/pkg/auth
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/auth')
-rw-r--r--pkg/auth/auth.go14
-rw-r--r--pkg/auth/auth_test.go8
2 files changed, 11 insertions, 11 deletions
diff --git a/pkg/auth/auth.go b/pkg/auth/auth.go
index 7cde6ef5e..c0606cf1d 100644
--- a/pkg/auth/auth.go
+++ b/pkg/auth/auth.go
@@ -32,17 +32,23 @@ const XRegistryConfigHeader HeaderAuthName = "X-Registry-Config"
// GetCredentials queries the http.Request for X-Registry-.* headers and extracts
// the necessary authentication information for libpod operations
-func GetCredentials(r *http.Request) (*types.DockerAuthConfig, string, HeaderAuthName, error) {
+func GetCredentials(r *http.Request) (*types.DockerAuthConfig, string, error) {
has := func(key HeaderAuthName) bool { hdr, found := r.Header[string(key)]; return found && len(hdr) > 0 }
switch {
case has(XRegistryConfigHeader):
c, f, err := getConfigCredentials(r)
- return c, f, XRegistryConfigHeader, err
+ if err != nil {
+ return nil, "", errors.Wrapf(err, "failed to parse %q header for %s", XRegistryConfigHeader, r.URL.String())
+ }
+ return c, f, nil
case has(XRegistryAuthHeader):
c, f, err := getAuthCredentials(r)
- return c, f, XRegistryAuthHeader, err
+ if err != nil {
+ return nil, "", errors.Wrapf(err, "failed to parse %q header for %s", XRegistryAuthHeader, r.URL.String())
+ }
+ return c, f, nil
}
- return nil, "", "", nil
+ return nil, "", nil
}
// getConfigCredentials extracts one or more docker.AuthConfig from the request's
diff --git a/pkg/auth/auth_test.go b/pkg/auth/auth_test.go
index be86a9cbd..634215acf 100644
--- a/pkg/auth/auth_test.go
+++ b/pkg/auth/auth_test.go
@@ -104,7 +104,7 @@ func TestHeaderGetCredentialsRoundtrip(t *testing.T) {
req.Header.Set(k, v)
}
- override, resPath, parsedHeader, err := GetCredentials(req)
+ override, resPath, err := GetCredentials(req)
require.NoError(t, err, name)
defer RemoveAuthfile(resPath)
if tc.expectedOverride == nil {
@@ -118,12 +118,6 @@ func TestHeaderGetCredentialsRoundtrip(t *testing.T) {
require.NoError(t, err, name)
assert.Equal(t, expectedAuth, auth, "%s, key %s", name, key)
}
- if len(headers) != 0 {
- assert.Len(t, headers, 1)
- assert.Equal(t, tc.headerName, parsedHeader)
- } else {
- assert.Equal(t, HeaderAuthName(""), parsedHeader)
- }
}
}