storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/cmd/config-encrypted_test.go (about) 1 /* 2 * MinIO Cloud Storage, (C) 2019 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 "testing" 22 23 "storj.io/minio/pkg/auth" 24 "storj.io/minio/pkg/madmin" 25 ) 26 27 func TestDecryptData(t *testing.T) { 28 cred1 := auth.Credentials{ 29 AccessKey: "minio", 30 SecretKey: "minio123", 31 } 32 33 cred2 := auth.Credentials{ 34 AccessKey: "minio", 35 SecretKey: "minio1234", 36 } 37 38 data := []byte(`config data`) 39 edata1, err := madmin.EncryptData(cred1.String(), data) 40 if err != nil { 41 t.Fatal(err) 42 } 43 44 edata2, err := madmin.EncryptData(cred2.String(), data) 45 if err != nil { 46 t.Fatal(err) 47 } 48 49 tests := []struct { 50 edata []byte 51 creds []auth.Credentials 52 success bool 53 }{ 54 {edata1, []auth.Credentials{cred1, cred2}, true}, 55 {edata2, []auth.Credentials{cred1, cred2}, true}, 56 {data, []auth.Credentials{cred1, cred2}, false}, 57 } 58 59 for _, test := range tests { 60 t.Run("", func(t *testing.T) { 61 ddata, err := decryptData(test.edata, test.creds...) 62 if err != nil && test.success { 63 t.Errorf("Expected success, saw failure %v", err) 64 } 65 if err == nil && !test.success { 66 t.Error("Expected failure, saw success") 67 } 68 if test.success { 69 if !bytes.Equal(ddata, data) { 70 t.Errorf("Expected %s, got %s", string(data), string(ddata)) 71 } 72 } 73 }) 74 } 75 }