Skip to content

Commit 483ad69

Browse files
committed
registry/errors: Parse http forbidden as denied
Signed-off-by: Paweł Gronowski <[email protected]> (cherry picked from commit 5f1df02) Signed-off-by: Paweł Gronowski <[email protected]>
1 parent 320d6a1 commit 483ad69

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

Diff for: registry/client/errors.go

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ func parseHTTPErrorResponse(statusCode int, r io.Reader) error {
5555
switch statusCode {
5656
case http.StatusUnauthorized:
5757
return errcode.ErrorCodeUnauthorized.WithMessage(detailsErr.Details)
58+
case http.StatusForbidden:
59+
return errcode.ErrorCodeDenied.WithMessage(detailsErr.Details)
5860
case http.StatusTooManyRequests:
5961
return errcode.ErrorCodeTooManyRequests.WithMessage(detailsErr.Details)
6062
default:

Diff for: registry/client/errors_test.go

+15
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)