mirror of
https://github.com/minio/mc.git
synced 2025-11-10 13:42:32 +03:00
Large MC Update (new encryption flags, functional test suite, removal of session code, minor cleanup, vuln. updates ) (#4882)
This commit is contained in:
@@ -20,87 +20,8 @@ package cmd
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/minio/minio-go/v7/pkg/encrypt"
|
||||
)
|
||||
|
||||
func TestParseEncryptionKeys(t *testing.T) {
|
||||
sseKey1, err := encrypt.NewSSEC([]byte("32byteslongsecretkeymustbegiven2"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sseKey2, err := encrypt.NewSSEC([]byte("32byteslongsecretkeymustbegiven1"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sseSpaceKey1, err := encrypt.NewSSEC([]byte("32byteslongsecret mustbegiven1"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sseCommaKey1, err := encrypt.NewSSEC([]byte("32byteslongsecretkey,ustbegiven1"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
testCases := []struct {
|
||||
encryptionKey string
|
||||
expectedEncMap map[string][]prefixSSEPair
|
||||
success bool
|
||||
}{
|
||||
{
|
||||
encryptionKey: "myminio1/test2=32byteslongsecretkeymustbegiven2",
|
||||
expectedEncMap: map[string][]prefixSSEPair{"myminio1": {{
|
||||
Prefix: "myminio1/test2",
|
||||
SSE: sseKey1,
|
||||
}}},
|
||||
success: true,
|
||||
},
|
||||
{
|
||||
encryptionKey: "myminio1/test2=32byteslongsecretkeymustbegiven",
|
||||
expectedEncMap: nil,
|
||||
success: false,
|
||||
},
|
||||
{
|
||||
encryptionKey: "myminio1/test2=32byteslongsecretkey,ustbegiven1",
|
||||
expectedEncMap: map[string][]prefixSSEPair{"myminio1": {{
|
||||
Prefix: "myminio1/test2",
|
||||
SSE: sseCommaKey1,
|
||||
}}},
|
||||
success: true,
|
||||
},
|
||||
{
|
||||
encryptionKey: "myminio1/test2=32byteslongsecret mustbegiven1",
|
||||
expectedEncMap: map[string][]prefixSSEPair{"myminio1": {{
|
||||
Prefix: "myminio1/test2",
|
||||
SSE: sseSpaceKey1,
|
||||
}}},
|
||||
success: true,
|
||||
},
|
||||
{
|
||||
encryptionKey: "myminio1/test2=32byteslongsecretkeymustbegiven2,myminio1/test1/a=32byteslongsecretkeymustbegiven1",
|
||||
expectedEncMap: map[string][]prefixSSEPair{"myminio1": {{
|
||||
Prefix: "myminio1/test1/a",
|
||||
SSE: sseKey2,
|
||||
}, {
|
||||
Prefix: "myminio1/test2",
|
||||
SSE: sseKey1,
|
||||
}}},
|
||||
success: true,
|
||||
},
|
||||
}
|
||||
for i, testCase := range testCases {
|
||||
encMap, err := parseEncryptionKeys(testCase.encryptionKey)
|
||||
if err != nil && testCase.success {
|
||||
t.Fatalf("Test %d: Expected success, got %s", i+1, err)
|
||||
}
|
||||
if err == nil && !testCase.success {
|
||||
t.Fatalf("Test %d: Expected error, got success", i+1)
|
||||
}
|
||||
if testCase.success && !reflect.DeepEqual(encMap, testCase.expectedEncMap) {
|
||||
t.Errorf("Test %d: Expected %s, got %s", i+1, testCase.expectedEncMap, encMap)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseAttribute(t *testing.T) {
|
||||
metaDataCases := []struct {
|
||||
input string
|
||||
|
||||
Reference in New Issue
Block a user