1
0
Fork 0
mirror of https://github.com/Luzifer/cloudkeys-go.git synced 2024-11-14 17:02:43 +00:00
cloudkeys-go/vendor/github.com/aws/aws-sdk-go/service/s3/sse_test.go

112 lines
4 KiB
Go
Raw Normal View History

2015-07-30 15:43:22 +00:00
package s3_test
import (
"strings"
2015-07-30 15:43:22 +00:00
"testing"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/awstesting/unit"
2015-07-30 15:43:22 +00:00
"github.com/aws/aws-sdk-go/service/s3"
)
func TestSSECustomerKeyOverHTTPError(t *testing.T) {
s := s3.New(unit.Session, &aws.Config{DisableSSL: aws.Bool(true)})
2015-07-30 15:43:22 +00:00
req, _ := s.CopyObjectRequest(&s3.CopyObjectInput{
Bucket: aws.String("bucket"),
CopySource: aws.String("bucket/source"),
Key: aws.String("dest"),
SSECustomerKey: aws.String("key"),
})
err := req.Build()
if err == nil {
t.Error("expected an error")
}
if e, a := "ConfigError", err.(awserr.Error).Code(); e != a {
t.Errorf("expected %s, but received %s", e, a)
}
if !strings.Contains(err.(awserr.Error).Message(), "cannot send SSE keys over HTTP") {
t.Errorf("expected error to contain 'cannot send SSE keys over HTTP', but received %s", err.(awserr.Error).Message())
}
2015-07-30 15:43:22 +00:00
}
func TestCopySourceSSECustomerKeyOverHTTPError(t *testing.T) {
s := s3.New(unit.Session, &aws.Config{DisableSSL: aws.Bool(true)})
2015-07-30 15:43:22 +00:00
req, _ := s.CopyObjectRequest(&s3.CopyObjectInput{
Bucket: aws.String("bucket"),
CopySource: aws.String("bucket/source"),
Key: aws.String("dest"),
CopySourceSSECustomerKey: aws.String("key"),
})
err := req.Build()
if err == nil {
t.Error("expected an error")
}
if e, a := "ConfigError", err.(awserr.Error).Code(); e != a {
t.Errorf("expected %s, but received %s", e, a)
}
if !strings.Contains(err.(awserr.Error).Message(), "cannot send SSE keys over HTTP") {
t.Errorf("expected error to contain 'cannot send SSE keys over HTTP', but received %s", err.(awserr.Error).Message())
}
2015-07-30 15:43:22 +00:00
}
func TestComputeSSEKeys(t *testing.T) {
s := s3.New(unit.Session)
2015-07-30 15:43:22 +00:00
req, _ := s.CopyObjectRequest(&s3.CopyObjectInput{
Bucket: aws.String("bucket"),
CopySource: aws.String("bucket/source"),
Key: aws.String("dest"),
SSECustomerKey: aws.String("key"),
CopySourceSSECustomerKey: aws.String("key"),
})
err := req.Build()
if err != nil {
t.Errorf("expected no error, but received %v", err)
}
if e, a := "a2V5", req.HTTPRequest.Header.Get("x-amz-server-side-encryption-customer-key"); e != a {
t.Errorf("expected %s, but received %s", e, a)
}
if e, a := "a2V5", req.HTTPRequest.Header.Get("x-amz-copy-source-server-side-encryption-customer-key"); e != a {
t.Errorf("expected %s, but received %s", e, a)
}
if e, a := "PG4LipwVIkqCKLmpjKFTHQ==", req.HTTPRequest.Header.Get("x-amz-server-side-encryption-customer-key-md5"); e != a {
t.Errorf("expected %s, but received %s", e, a)
}
if e, a := "PG4LipwVIkqCKLmpjKFTHQ==", req.HTTPRequest.Header.Get("x-amz-copy-source-server-side-encryption-customer-key-md5"); e != a {
t.Errorf("expected %s, but received %s", e, a)
}
2015-07-30 15:43:22 +00:00
}
func TestComputeSSEKeysShortcircuit(t *testing.T) {
s := s3.New(unit.Session)
2015-07-30 15:43:22 +00:00
req, _ := s.CopyObjectRequest(&s3.CopyObjectInput{
Bucket: aws.String("bucket"),
CopySource: aws.String("bucket/source"),
Key: aws.String("dest"),
SSECustomerKey: aws.String("key"),
CopySourceSSECustomerKey: aws.String("key"),
SSECustomerKeyMD5: aws.String("MD5"),
CopySourceSSECustomerKeyMD5: aws.String("MD5"),
})
err := req.Build()
if err != nil {
t.Errorf("expected no error, but received %v", err)
}
if e, a := "a2V5", req.HTTPRequest.Header.Get("x-amz-server-side-encryption-customer-key"); e != a {
t.Errorf("expected %s, but received %s", e, a)
}
if e, a := "a2V5", req.HTTPRequest.Header.Get("x-amz-copy-source-server-side-encryption-customer-key"); e != a {
t.Errorf("expected %s, but received %s", e, a)
}
if e, a := "MD5", req.HTTPRequest.Header.Get("x-amz-server-side-encryption-customer-key-md5"); e != a {
t.Errorf("expected %s, but received %s", e, a)
}
if e, a := "MD5", req.HTTPRequest.Header.Get("x-amz-copy-source-server-side-encryption-customer-key-md5"); e != a {
t.Errorf("expected %s, but received %s", e, a)
}
2015-07-30 15:43:22 +00:00
}