summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2021-09-15 15:46:58 -0400
committerGitHub <noreply@github.com>2021-09-15 15:46:58 -0400
commit505c9718cc717433780be8240250a247253ba34f (patch)
treef230f09d8e3a8d1196043fe744bbf71a255e8896
parentf38503a1a3336a87a950c1d97bf1cb9a1a883ada (diff)
parent7c5d64b4783c2bf05587b3a4672b35c1e32066c7 (diff)
downloadpodman-505c9718cc717433780be8240250a247253ba34f.tar.gz
podman-505c9718cc717433780be8240250a247253ba34f.tar.bz2
podman-505c9718cc717433780be8240250a247253ba34f.zip
Merge pull request #11595 from matejvasek/fix-auth-ep
Fix /auth compat endpoint
-rw-r--r--pkg/api/handlers/compat/auth.go16
-rw-r--r--test/apiv2/60-auth.at9
2 files changed, 20 insertions, 5 deletions
diff --git a/pkg/api/handlers/compat/auth.go b/pkg/api/handlers/compat/auth.go
index 2244adc3d..cf53e060c 100644
--- a/pkg/api/handlers/compat/auth.go
+++ b/pkg/api/handlers/compat/auth.go
@@ -50,9 +50,19 @@ func Auth(w http.ResponseWriter, r *http.Request) {
Status: "Login Succeeded",
})
} else {
- utils.WriteResponse(w, http.StatusBadRequest, entities.AuthReport{
- IdentityToken: "",
- Status: "login attempt to " + authConfig.ServerAddress + " failed with status: " + err.Error(),
+ var msg string
+
+ var unauthErr DockerClient.ErrUnauthorizedForCredentials
+ if errors.As(err, &unauthErr) {
+ msg = "401 Unauthorized"
+ } else {
+ msg = err.Error()
+ }
+
+ utils.WriteResponse(w, http.StatusInternalServerError, struct {
+ Message string `json:"message"`
+ }{
+ Message: "login attempt to " + authConfig.ServerAddress + " failed with status: " + msg,
})
}
}
diff --git a/test/apiv2/60-auth.at b/test/apiv2/60-auth.at
index cfde519c1..1e087d12b 100644
--- a/test/apiv2/60-auth.at
+++ b/test/apiv2/60-auth.at
@@ -5,10 +5,15 @@
start_registry
+# Test unreachable
+t POST /v1.40/auth username=$REGISTRY_USERNAME password=WrOnGPassWord serveraddress=does.not.exist.io:1234/ \
+ 500 \
+ .message~'.*no such host.*'
+
# Test with wrong password. Confirm bad status and appropriate error message
t POST /v1.40/auth username=$REGISTRY_USERNAME password=WrOnGPassWord serveraddress=localhost:$REGISTRY_PORT/ \
- 400 \
- .Status~'.* invalid username/password'
+ 500 \
+ .message~'.* 401 Unauthorized'
# Test with the right password. Confirm status message
t POST /v1.40/auth username=$REGISTRY_USERNAME password=$REGISTRY_PASSWORD serveraddress=localhost:$REGISTRY_PORT/ \