mirror of
https://github.com/minio/minio.git
synced 2024-12-24 06:05:55 -05:00
Give more specific error message on browser for nested policies (#4488)
This commit is contained in:
parent
7dcc1e92b4
commit
45a568dd85
@ -802,6 +802,13 @@ func (web *webAPIHandlers) SetBucketPolicy(r *http.Request, args *SetBucketPolic
|
||||
policyInfo.Statements = policy.SetPolicy(policyInfo.Statements, bucketP, args.BucketName, args.Prefix)
|
||||
switch g := objectAPI.(type) {
|
||||
case GatewayLayer:
|
||||
if len(policyInfo.Statements) == 0 {
|
||||
err = g.DeleteBucketPolicies(args.BucketName)
|
||||
if err != nil {
|
||||
return toJSONError(err, args.BucketName)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
err = g.SetBucketPolicies(args.BucketName, policyInfo)
|
||||
if err != nil {
|
||||
return toJSONError(err)
|
||||
@ -1011,39 +1018,46 @@ func toWebAPIError(err error) APIError {
|
||||
}
|
||||
}
|
||||
// Convert error type to api error code.
|
||||
var apiErrCode APIErrorCode
|
||||
switch err.(type) {
|
||||
case StorageFull:
|
||||
apiErrCode = ErrStorageFull
|
||||
return getAPIError(ErrStorageFull)
|
||||
case BucketNotFound:
|
||||
apiErrCode = ErrNoSuchBucket
|
||||
return getAPIError(ErrNoSuchBucket)
|
||||
case BucketExists:
|
||||
apiErrCode = ErrBucketAlreadyOwnedByYou
|
||||
return getAPIError(ErrBucketAlreadyOwnedByYou)
|
||||
case BucketNameInvalid:
|
||||
apiErrCode = ErrInvalidBucketName
|
||||
return getAPIError(ErrInvalidBucketName)
|
||||
case BadDigest:
|
||||
apiErrCode = ErrBadDigest
|
||||
return getAPIError(ErrBadDigest)
|
||||
case IncompleteBody:
|
||||
apiErrCode = ErrIncompleteBody
|
||||
return getAPIError(ErrIncompleteBody)
|
||||
case ObjectExistsAsDirectory:
|
||||
apiErrCode = ErrObjectExistsAsDirectory
|
||||
return getAPIError(ErrObjectExistsAsDirectory)
|
||||
case ObjectNotFound:
|
||||
apiErrCode = ErrNoSuchKey
|
||||
return getAPIError(ErrNoSuchKey)
|
||||
case ObjectNameInvalid:
|
||||
apiErrCode = ErrNoSuchKey
|
||||
return getAPIError(ErrNoSuchKey)
|
||||
case InsufficientWriteQuorum:
|
||||
apiErrCode = ErrWriteQuorum
|
||||
return getAPIError(ErrWriteQuorum)
|
||||
case InsufficientReadQuorum:
|
||||
apiErrCode = ErrReadQuorum
|
||||
return getAPIError(ErrReadQuorum)
|
||||
case PolicyNesting:
|
||||
apiErrCode = ErrPolicyNesting
|
||||
default:
|
||||
// Log unexpected and unhandled errors.
|
||||
errorIf(err, errUnexpected.Error())
|
||||
apiErrCode = ErrInternalError
|
||||
return getAPIError(ErrPolicyNesting)
|
||||
case NotImplemented:
|
||||
return APIError{
|
||||
Code: "NotImplemented",
|
||||
HTTPStatusCode: http.StatusBadRequest,
|
||||
Description: "Functionality not implemented",
|
||||
}
|
||||
}
|
||||
|
||||
// Log unexpected and unhandled errors.
|
||||
errorIf(err, errUnexpected.Error())
|
||||
return APIError{
|
||||
Code: "InternalError",
|
||||
HTTPStatusCode: http.StatusInternalServerError,
|
||||
Description: err.Error(),
|
||||
}
|
||||
apiErr := getAPIError(apiErrCode)
|
||||
return apiErr
|
||||
}
|
||||
|
||||
// writeWebErrorResponse - set HTTP status code and write error description to the body.
|
||||
|
@ -86,12 +86,19 @@ func TestWriteWebErrorResponse(t *testing.T) {
|
||||
webErr: InsufficientReadQuorum{},
|
||||
apiErrCode: ErrReadQuorum,
|
||||
},
|
||||
{
|
||||
webErr: NotImplemented{},
|
||||
apiErrCode: ErrNotImplemented,
|
||||
},
|
||||
}
|
||||
|
||||
// Validate all the test cases.
|
||||
for i, testCase := range testCases {
|
||||
writeWebErrorResponse(newFlushWriter(&buffer), testCase.webErr)
|
||||
desc := getAPIError(testCase.apiErrCode).Description
|
||||
if testCase.apiErrCode == ErrNotImplemented {
|
||||
desc = "Functionality not implemented"
|
||||
}
|
||||
recvDesc := buffer.Bytes()
|
||||
// Check if the written desc is same as the one expected.
|
||||
if !bytes.Equal(recvDesc, []byte(desc)) {
|
||||
|
Loading…
Reference in New Issue
Block a user