Skip to content

Commit 5f1df02

Browse files
committed
registry/errors: Parse http forbidden as denied
Signed-off-by: Paweł Gronowski <[email protected]>
1 parent 29b5e79 commit 5f1df02

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

registry/client/errors.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ func parseHTTPErrorResponse(statusCode int, r io.Reader) error {
5454
switch statusCode {
5555
case http.StatusUnauthorized:
5656
return errcode.ErrorCodeUnauthorized.WithMessage(detailsErr.Details)
57+
case http.StatusForbidden:
58+
return errcode.ErrorCodeDenied.WithMessage(detailsErr.Details)
5759
case http.StatusTooManyRequests:
5860
return errcode.ErrorCodeTooManyRequests.WithMessage(detailsErr.Details)
5961
default:

registry/client/errors_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,18 @@ func TestHandleErrorResponseUnexpectedStatusCode501(t *testing.T) {
102102
t.Errorf("Expected \"%s\", got: \"%s\"", expectedMsg, err.Error())
103103
}
104104
}
105+
106+
func TestHandleErrorResponseInsufficientPrivileges403(t *testing.T) {
107+
json := `{"details":"requesting higher privileges than access token allows"}`
108+
response := &http.Response{
109+
Status: "403 Forbidden",
110+
StatusCode: 403,
111+
Body: nopCloser{bytes.NewBufferString(json)},
112+
}
113+
err := HandleErrorResponse(response)
114+
115+
expectedMsg := "denied: requesting higher privileges than access token allows"
116+
if !strings.Contains(err.Error(), expectedMsg) {
117+
t.Errorf("Expected \"%s\", got: \"%s\"", expectedMsg, err.Error())
118+
}
119+
}

0 commit comments

Comments
 (0)