mirror of
https://github.com/minio/minio.git
synced 2024-12-24 22:25:54 -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)
|
policyInfo.Statements = policy.SetPolicy(policyInfo.Statements, bucketP, args.BucketName, args.Prefix)
|
||||||
switch g := objectAPI.(type) {
|
switch g := objectAPI.(type) {
|
||||||
case GatewayLayer:
|
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)
|
err = g.SetBucketPolicies(args.BucketName, policyInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return toJSONError(err)
|
return toJSONError(err)
|
||||||
@ -1011,39 +1018,46 @@ func toWebAPIError(err error) APIError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Convert error type to api error code.
|
// Convert error type to api error code.
|
||||||
var apiErrCode APIErrorCode
|
|
||||||
switch err.(type) {
|
switch err.(type) {
|
||||||
case StorageFull:
|
case StorageFull:
|
||||||
apiErrCode = ErrStorageFull
|
return getAPIError(ErrStorageFull)
|
||||||
case BucketNotFound:
|
case BucketNotFound:
|
||||||
apiErrCode = ErrNoSuchBucket
|
return getAPIError(ErrNoSuchBucket)
|
||||||
case BucketExists:
|
case BucketExists:
|
||||||
apiErrCode = ErrBucketAlreadyOwnedByYou
|
return getAPIError(ErrBucketAlreadyOwnedByYou)
|
||||||
case BucketNameInvalid:
|
case BucketNameInvalid:
|
||||||
apiErrCode = ErrInvalidBucketName
|
return getAPIError(ErrInvalidBucketName)
|
||||||
case BadDigest:
|
case BadDigest:
|
||||||
apiErrCode = ErrBadDigest
|
return getAPIError(ErrBadDigest)
|
||||||
case IncompleteBody:
|
case IncompleteBody:
|
||||||
apiErrCode = ErrIncompleteBody
|
return getAPIError(ErrIncompleteBody)
|
||||||
case ObjectExistsAsDirectory:
|
case ObjectExistsAsDirectory:
|
||||||
apiErrCode = ErrObjectExistsAsDirectory
|
return getAPIError(ErrObjectExistsAsDirectory)
|
||||||
case ObjectNotFound:
|
case ObjectNotFound:
|
||||||
apiErrCode = ErrNoSuchKey
|
return getAPIError(ErrNoSuchKey)
|
||||||
case ObjectNameInvalid:
|
case ObjectNameInvalid:
|
||||||
apiErrCode = ErrNoSuchKey
|
return getAPIError(ErrNoSuchKey)
|
||||||
case InsufficientWriteQuorum:
|
case InsufficientWriteQuorum:
|
||||||
apiErrCode = ErrWriteQuorum
|
return getAPIError(ErrWriteQuorum)
|
||||||
case InsufficientReadQuorum:
|
case InsufficientReadQuorum:
|
||||||
apiErrCode = ErrReadQuorum
|
return getAPIError(ErrReadQuorum)
|
||||||
case PolicyNesting:
|
case PolicyNesting:
|
||||||
apiErrCode = ErrPolicyNesting
|
return getAPIError(ErrPolicyNesting)
|
||||||
default:
|
case NotImplemented:
|
||||||
// Log unexpected and unhandled errors.
|
return APIError{
|
||||||
errorIf(err, errUnexpected.Error())
|
Code: "NotImplemented",
|
||||||
apiErrCode = ErrInternalError
|
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.
|
// writeWebErrorResponse - set HTTP status code and write error description to the body.
|
||||||
|
@ -86,12 +86,19 @@ func TestWriteWebErrorResponse(t *testing.T) {
|
|||||||
webErr: InsufficientReadQuorum{},
|
webErr: InsufficientReadQuorum{},
|
||||||
apiErrCode: ErrReadQuorum,
|
apiErrCode: ErrReadQuorum,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
webErr: NotImplemented{},
|
||||||
|
apiErrCode: ErrNotImplemented,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate all the test cases.
|
// Validate all the test cases.
|
||||||
for i, testCase := range testCases {
|
for i, testCase := range testCases {
|
||||||
writeWebErrorResponse(newFlushWriter(&buffer), testCase.webErr)
|
writeWebErrorResponse(newFlushWriter(&buffer), testCase.webErr)
|
||||||
desc := getAPIError(testCase.apiErrCode).Description
|
desc := getAPIError(testCase.apiErrCode).Description
|
||||||
|
if testCase.apiErrCode == ErrNotImplemented {
|
||||||
|
desc = "Functionality not implemented"
|
||||||
|
}
|
||||||
recvDesc := buffer.Bytes()
|
recvDesc := buffer.Bytes()
|
||||||
// Check if the written desc is same as the one expected.
|
// Check if the written desc is same as the one expected.
|
||||||
if !bytes.Equal(recvDesc, []byte(desc)) {
|
if !bytes.Equal(recvDesc, []byte(desc)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user