2021-04-18 15:41:13 -04:00
|
|
|
// Copyright (c) 2015-2021 MinIO, Inc.
|
|
|
|
//
|
|
|
|
// This file is part of MinIO Object Storage stack
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2017-10-05 15:24:45 -04:00
|
|
|
|
2017-12-05 20:58:09 -05:00
|
|
|
package s3
|
2017-10-05 15:24:45 -04:00
|
|
|
|
|
|
|
import (
|
2017-12-05 20:58:09 -05:00
|
|
|
"fmt"
|
2017-10-05 15:24:45 -04:00
|
|
|
"testing"
|
|
|
|
|
2020-07-14 12:38:05 -04:00
|
|
|
miniogo "github.com/minio/minio-go/v7"
|
2017-10-22 01:30:34 -04:00
|
|
|
"github.com/minio/minio/pkg/hash"
|
2017-12-05 20:58:09 -05:00
|
|
|
|
|
|
|
minio "github.com/minio/minio/cmd"
|
2017-10-05 15:24:45 -04:00
|
|
|
)
|
|
|
|
|
2017-12-05 20:58:09 -05:00
|
|
|
func errResponse(code string) miniogo.ErrorResponse {
|
|
|
|
return miniogo.ErrorResponse{
|
2017-10-05 15:24:45 -04:00
|
|
|
Code: code,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestS3ToObjectError(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
inputErr error
|
|
|
|
expectedErr error
|
|
|
|
bucket, object string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
inputErr: errResponse("BucketAlreadyOwnedByYou"),
|
2017-12-05 20:58:09 -05:00
|
|
|
expectedErr: minio.BucketAlreadyOwnedByYou{},
|
2017-10-05 15:24:45 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
inputErr: errResponse("BucketNotEmpty"),
|
2017-12-05 20:58:09 -05:00
|
|
|
expectedErr: minio.BucketNotEmpty{},
|
2017-10-05 15:24:45 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
inputErr: errResponse("InvalidBucketName"),
|
2017-12-05 20:58:09 -05:00
|
|
|
expectedErr: minio.BucketNameInvalid{},
|
2017-10-05 15:24:45 -04:00
|
|
|
},
|
2018-10-17 12:20:58 -04:00
|
|
|
{
|
|
|
|
inputErr: errResponse("InvalidPart"),
|
|
|
|
expectedErr: minio.InvalidPart{},
|
|
|
|
},
|
2017-10-05 15:24:45 -04:00
|
|
|
{
|
|
|
|
inputErr: errResponse("NoSuchBucketPolicy"),
|
2018-04-24 18:53:30 -04:00
|
|
|
expectedErr: minio.BucketPolicyNotFound{},
|
2017-10-05 15:24:45 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
inputErr: errResponse("NoSuchBucket"),
|
2017-12-05 20:58:09 -05:00
|
|
|
expectedErr: minio.BucketNotFound{},
|
2017-10-05 15:24:45 -04:00
|
|
|
},
|
2017-12-05 20:58:09 -05:00
|
|
|
// with empty Object in miniogo.ErrorRepsonse, NoSuchKey
|
2017-10-05 15:24:45 -04:00
|
|
|
// is interpreted as BucketNotFound
|
|
|
|
{
|
|
|
|
inputErr: errResponse("NoSuchKey"),
|
2017-12-05 20:58:09 -05:00
|
|
|
expectedErr: minio.BucketNotFound{},
|
2017-10-05 15:24:45 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
inputErr: errResponse("NoSuchUpload"),
|
2017-12-05 20:58:09 -05:00
|
|
|
expectedErr: minio.InvalidUploadID{},
|
2017-10-05 15:24:45 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
inputErr: errResponse("XMinioInvalidObjectName"),
|
2017-12-05 20:58:09 -05:00
|
|
|
expectedErr: minio.ObjectNameInvalid{},
|
2017-10-05 15:24:45 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
inputErr: errResponse("AccessDenied"),
|
2017-12-05 20:58:09 -05:00
|
|
|
expectedErr: minio.PrefixAccessDenied{},
|
2017-10-05 15:24:45 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
inputErr: errResponse("XAmzContentSHA256Mismatch"),
|
2017-10-22 01:30:34 -04:00
|
|
|
expectedErr: hash.SHA256Mismatch{},
|
2017-10-05 15:24:45 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
inputErr: errResponse("EntityTooSmall"),
|
2017-12-05 20:58:09 -05:00
|
|
|
expectedErr: minio.PartTooSmall{},
|
2017-10-05 15:24:45 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
inputErr: nil,
|
|
|
|
expectedErr: nil,
|
|
|
|
},
|
|
|
|
// Special test case for NoSuchKey with object name
|
|
|
|
{
|
2017-12-05 20:58:09 -05:00
|
|
|
inputErr: miniogo.ErrorResponse{
|
2017-10-05 15:24:45 -04:00
|
|
|
Code: "NoSuchKey",
|
|
|
|
},
|
2017-12-05 20:58:09 -05:00
|
|
|
expectedErr: minio.ObjectNotFound{
|
|
|
|
Bucket: "bucket",
|
|
|
|
Object: "object",
|
|
|
|
},
|
|
|
|
bucket: "bucket",
|
|
|
|
object: "object",
|
2017-10-05 15:24:45 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
// N B error values that aren't of expected types
|
|
|
|
// should be left untouched.
|
|
|
|
// Special test case for error that is not of type
|
2017-12-05 20:58:09 -05:00
|
|
|
// miniogo.ErrorResponse
|
2017-10-05 15:24:45 -04:00
|
|
|
{
|
2019-01-05 17:16:43 -05:00
|
|
|
inputErr: fmt.Errorf("not a ErrorResponse"),
|
|
|
|
expectedErr: fmt.Errorf("not a ErrorResponse"),
|
2017-10-05 15:24:45 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, tc := range testCases {
|
2018-04-05 18:04:40 -04:00
|
|
|
actualErr := minio.ErrorRespToObjectError(tc.inputErr, tc.bucket, tc.object)
|
2018-04-10 12:36:37 -04:00
|
|
|
if actualErr != nil && tc.expectedErr != nil && actualErr.Error() != tc.expectedErr.Error() {
|
2018-04-05 18:04:40 -04:00
|
|
|
t.Errorf("Test case %d: Expected error %v but received error %v", i+1, tc.expectedErr, actualErr)
|
2017-10-05 15:24:45 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|