Merge pull request #11595 from matejvasek/fix-auth-ep

Fix /auth compat endpoint
This commit is contained in:
OpenShift Merge Robot 2021-09-15 15:46:58 -04:00 committed by GitHub
commit 505c9718cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 5 deletions

View file

@ -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,
})
}
}

View file

@ -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/ \