forked from TrueCloudLab/distribution
Merge pull request #3881 from vvoland/handle-forbidden
registry/errors: Parse http forbidden as denied
This commit is contained in:
commit
788598e23f
2 changed files with 17 additions and 0 deletions
|
@ -54,6 +54,8 @@ func parseHTTPErrorResponse(statusCode int, r io.Reader) error {
|
||||||
switch statusCode {
|
switch statusCode {
|
||||||
case http.StatusUnauthorized:
|
case http.StatusUnauthorized:
|
||||||
return errcode.ErrorCodeUnauthorized.WithMessage(detailsErr.Details)
|
return errcode.ErrorCodeUnauthorized.WithMessage(detailsErr.Details)
|
||||||
|
case http.StatusForbidden:
|
||||||
|
return errcode.ErrorCodeDenied.WithMessage(detailsErr.Details)
|
||||||
case http.StatusTooManyRequests:
|
case http.StatusTooManyRequests:
|
||||||
return errcode.ErrorCodeTooManyRequests.WithMessage(detailsErr.Details)
|
return errcode.ErrorCodeTooManyRequests.WithMessage(detailsErr.Details)
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -102,3 +102,18 @@ func TestHandleErrorResponseUnexpectedStatusCode501(t *testing.T) {
|
||||||
t.Errorf("Expected \"%s\", got: \"%s\"", expectedMsg, err.Error())
|
t.Errorf("Expected \"%s\", got: \"%s\"", expectedMsg, err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestHandleErrorResponseInsufficientPrivileges403(t *testing.T) {
|
||||||
|
json := `{"details":"requesting higher privileges than access token allows"}`
|
||||||
|
response := &http.Response{
|
||||||
|
Status: "403 Forbidden",
|
||||||
|
StatusCode: 403,
|
||||||
|
Body: nopCloser{bytes.NewBufferString(json)},
|
||||||
|
}
|
||||||
|
err := HandleErrorResponse(response)
|
||||||
|
|
||||||
|
expectedMsg := "denied: requesting higher privileges than access token allows"
|
||||||
|
if !strings.Contains(err.Error(), expectedMsg) {
|
||||||
|
t.Errorf("Expected \"%s\", got: \"%s\"", expectedMsg, err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue