storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/cmd/bucket-encryption_test.go (about) 1 /* 2 * MinIO Cloud Storage, (C) 2020 MinIO, Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package cmd 18 19 import ( 20 "bytes" 21 "errors" 22 "testing" 23 ) 24 25 func TestValidateBucketSSEConfig(t *testing.T) { 26 testCases := []struct { 27 inputXML string 28 expectedErr error 29 shouldPass bool 30 }{ 31 // MinIO supported XML 32 { 33 inputXML: `<ServerSideEncryptionConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> 34 <Rule> 35 <ApplyServerSideEncryptionByDefault> 36 <SSEAlgorithm>AES256</SSEAlgorithm> 37 </ApplyServerSideEncryptionByDefault> 38 </Rule> 39 </ServerSideEncryptionConfiguration>`, 40 expectedErr: nil, 41 shouldPass: true, 42 }, 43 // Unsupported XML 44 { 45 inputXML: `<ServerSideEncryptionConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> 46 <Rule> 47 <ApplyServerSideEncryptionByDefault> 48 <SSEAlgorithm>aws:kms</SSEAlgorithm> 49 <KMSMasterKeyID>arn:aws:kms:us-east-1:1234/5678example</KMSMasterKeyID> 50 </ApplyServerSideEncryptionByDefault> 51 </Rule> 52 </ServerSideEncryptionConfiguration>`, 53 expectedErr: errors.New("Unsupported bucket encryption configuration"), 54 shouldPass: false, 55 }, 56 } 57 58 for i, tc := range testCases { 59 _, err := validateBucketSSEConfig(bytes.NewReader([]byte(tc.inputXML))) 60 if tc.shouldPass && err != nil { 61 t.Fatalf("Test case %d: Expected to succeed but got %s", i+1, err) 62 } 63 64 if !tc.shouldPass { 65 if err == nil || err != nil && err.Error() != tc.expectedErr.Error() { 66 t.Fatalf("Test case %d: Expected %s but got %s", i+1, tc.expectedErr, err) 67 } 68 } 69 } 70 }