|
|
|
@ -275,59 +275,6 @@ func TestParseSSECopyCustomerRequest(t *testing.T) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var encryptedSizeTests = []struct { |
|
|
|
|
size, encsize int64 |
|
|
|
|
}{ |
|
|
|
|
{size: 0, encsize: 0}, // 0
|
|
|
|
|
{size: 1, encsize: 33}, // 1
|
|
|
|
|
{size: 1024, encsize: 1024 + 32}, // 2
|
|
|
|
|
{size: 2 * sseDAREPackageBlockSize, encsize: 2 * (sseDAREPackageBlockSize + 32)}, // 3
|
|
|
|
|
{size: 100*sseDAREPackageBlockSize + 1, encsize: 100*(sseDAREPackageBlockSize+32) + 33}, // 4
|
|
|
|
|
{size: sseDAREPackageBlockSize + 1, encsize: (sseDAREPackageBlockSize + 32) + 33}, // 5
|
|
|
|
|
{size: 5 * 1024 * 1024 * 1024, encsize: 81920 * (sseDAREPackageBlockSize + 32)}, // 6
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestEncryptedSize(t *testing.T) { |
|
|
|
|
for i, test := range encryptedSizeTests { |
|
|
|
|
objInfo := ObjectInfo{Size: test.size} |
|
|
|
|
if size := objInfo.EncryptedSize(); test.encsize != size { |
|
|
|
|
t.Errorf("Test %d: got encrypted size: #%d want: #%d", i, size, test.encsize) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var decryptSSECustomerObjectInfoTests = []struct { |
|
|
|
|
encsize, size int64 |
|
|
|
|
err error |
|
|
|
|
}{ |
|
|
|
|
{encsize: 0, size: 0, err: nil}, // 0
|
|
|
|
|
{encsize: 33, size: 1, err: nil}, // 1
|
|
|
|
|
{encsize: 1024 + 32, size: 1024, err: nil}, // 2
|
|
|
|
|
{encsize: 2 * (sseDAREPackageBlockSize + 32), size: 2 * sseDAREPackageBlockSize, err: nil}, // 3
|
|
|
|
|
{encsize: 100*(sseDAREPackageBlockSize+32) + 33, size: 100*sseDAREPackageBlockSize + 1, err: nil}, // 4
|
|
|
|
|
{encsize: (sseDAREPackageBlockSize + 32) + 33, size: sseDAREPackageBlockSize + 1, err: nil}, // 5
|
|
|
|
|
{encsize: 81920 * (sseDAREPackageBlockSize + 32), size: 5 * 1024 * 1024 * 1024, err: nil}, // 6
|
|
|
|
|
{encsize: 0, size: 0, err: nil}, // 7
|
|
|
|
|
{encsize: sseDAREPackageBlockSize + 32 + 31, size: 0, err: errObjectTampered}, // 8
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestDecryptedSize(t *testing.T) { |
|
|
|
|
for i, test := range decryptSSECustomerObjectInfoTests { |
|
|
|
|
objInfo := ObjectInfo{Size: test.encsize} |
|
|
|
|
objInfo.UserDefined = map[string]string{ |
|
|
|
|
ServerSideEncryptionSealAlgorithm: SSESealAlgorithmDareSha256, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
size, err := objInfo.DecryptedSize() |
|
|
|
|
if err != test.err || (size != test.size && err == nil) { |
|
|
|
|
t.Errorf("Test %d: decryption returned: %v want: %v", i, err, test.err) |
|
|
|
|
} |
|
|
|
|
if err == nil && size != test.size { |
|
|
|
|
t.Errorf("Test %d: got decrypted size: #%d want: #%d", i, size, test.size) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var encryptRequestTests = []struct { |
|
|
|
|
header map[string]string |
|
|
|
|
metadata map[string]string |
|
|
|
|