mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-05-07 22:20:24 +00:00
Update vendored deps, including AWS SDK, openpgp, ftp, ...
This commit is contained in:
Generated
Vendored
+33
-59
@@ -1,82 +1,42 @@
|
||||
// +build integration
|
||||
|
||||
// Package s3_test runs integration tests for S3
|
||||
package s3_test
|
||||
// Package s3 runs integration tests for S3
|
||||
package s3
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/awstesting/integration"
|
||||
"github.com/aws/aws-sdk-go/service/s3"
|
||||
)
|
||||
|
||||
var bucketName *string
|
||||
var svc *s3.S3
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
setup()
|
||||
defer teardown() // only called if we panic
|
||||
result := m.Run()
|
||||
teardown()
|
||||
os.Exit(result)
|
||||
}
|
||||
|
||||
// Create a bucket for testing
|
||||
func setup() {
|
||||
svc = s3.New(integration.Session)
|
||||
bucketName = aws.String(
|
||||
fmt.Sprintf("aws-sdk-go-integration-%d-%s", time.Now().Unix(), integration.UniqueID()))
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
_, err := svc.CreateBucket(&s3.CreateBucketInput{Bucket: bucketName})
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
for {
|
||||
_, err := svc.HeadBucket(&s3.HeadBucketInput{Bucket: bucketName})
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
time.Sleep(1 * time.Second)
|
||||
}
|
||||
}
|
||||
|
||||
// Delete the bucket
|
||||
func teardown() {
|
||||
resp, _ := svc.ListObjects(&s3.ListObjectsInput{Bucket: bucketName})
|
||||
for _, o := range resp.Contents {
|
||||
svc.DeleteObject(&s3.DeleteObjectInput{Bucket: bucketName, Key: o.Key})
|
||||
}
|
||||
svc.DeleteBucket(&s3.DeleteBucketInput{Bucket: bucketName})
|
||||
}
|
||||
|
||||
func TestWriteToObject(t *testing.T) {
|
||||
_, err := svc.PutObject(&s3.PutObjectInput{
|
||||
Bucket: bucketName,
|
||||
Key: aws.String("key name"),
|
||||
Body: bytes.NewReader([]byte("hello world")),
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("expect no error, got %v", err)
|
||||
}
|
||||
|
||||
resp, err := svc.GetObject(&s3.GetObjectInput{
|
||||
Bucket: bucketName,
|
||||
Key: aws.String("key name"),
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("expect no error, got %v", err)
|
||||
}
|
||||
|
||||
b, _ := ioutil.ReadAll(resp.Body)
|
||||
assert.Equal(t, []byte("hello world"), b)
|
||||
if e, a := []byte("hello world"), b; !reflect.DeepEqual(e, a) {
|
||||
t.Errorf("expect %v, got %v", e, a)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPresignedGetPut(t *testing.T) {
|
||||
@@ -89,18 +49,26 @@ func TestPresignedGetPut(t *testing.T) {
|
||||
// Presign a PUT request
|
||||
var puturl string
|
||||
puturl, err = putreq.Presign(300 * time.Second)
|
||||
assert.NoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("expect no error, got %v", err)
|
||||
}
|
||||
|
||||
// PUT to the presigned URL with a body
|
||||
var puthttpreq *http.Request
|
||||
buf := bytes.NewReader([]byte("hello world"))
|
||||
puthttpreq, err = http.NewRequest("PUT", puturl, buf)
|
||||
assert.NoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("expect no error, got %v", err)
|
||||
}
|
||||
|
||||
var putresp *http.Response
|
||||
putresp, err = http.DefaultClient.Do(puthttpreq)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, 200, putresp.StatusCode)
|
||||
if err != nil {
|
||||
t.Errorf("expect put with presign url no error, got %v", err)
|
||||
}
|
||||
if e, a := 200, putresp.StatusCode; e != a {
|
||||
t.Errorf("expect %v, got %v", e, a)
|
||||
}
|
||||
|
||||
// Presign a GET on the same URL
|
||||
getreq, _ := svc.GetObjectRequest(&s3.GetObjectInput{
|
||||
@@ -110,15 +78,21 @@ func TestPresignedGetPut(t *testing.T) {
|
||||
|
||||
var geturl string
|
||||
geturl, err = getreq.Presign(300 * time.Second)
|
||||
assert.NoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("expect no error, got %v", err)
|
||||
}
|
||||
|
||||
// Get the body
|
||||
var getresp *http.Response
|
||||
getresp, err = http.Get(geturl)
|
||||
assert.NoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("expect no error, got %v", err)
|
||||
}
|
||||
|
||||
var b []byte
|
||||
defer getresp.Body.Close()
|
||||
b, err = ioutil.ReadAll(getresp.Body)
|
||||
assert.Equal(t, "hello world", string(b))
|
||||
if e, a := "hello world", string(b); e != a {
|
||||
t.Errorf("expect %v, got %v", e, a)
|
||||
}
|
||||
}
|
||||
|
||||
Generated
Vendored
+102
@@ -0,0 +1,102 @@
|
||||
// +build integration
|
||||
|
||||
package s3
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/md5"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/service/s3"
|
||||
)
|
||||
|
||||
func base64Sum(content []byte) string {
|
||||
sum := md5.Sum(content)
|
||||
return base64.StdEncoding.EncodeToString(sum[:])
|
||||
}
|
||||
|
||||
func SkipTestContentMD5Validate(t *testing.T) {
|
||||
body := []byte("really cool body content")
|
||||
|
||||
cases := []struct {
|
||||
Name string
|
||||
Body []byte
|
||||
Sum64 string
|
||||
RangeGet []int64
|
||||
}{
|
||||
{
|
||||
Body: body,
|
||||
Sum64: base64Sum(body),
|
||||
Name: "contentMD5validation.pop",
|
||||
},
|
||||
{
|
||||
Body: []byte{},
|
||||
Sum64: base64Sum([]byte{}),
|
||||
Name: "contentMD5validation.empty",
|
||||
},
|
||||
{
|
||||
Body: body,
|
||||
Sum64: base64Sum(body),
|
||||
RangeGet: []int64{0, 9},
|
||||
Name: "contentMD5validation.range",
|
||||
},
|
||||
}
|
||||
|
||||
for i, c := range cases {
|
||||
keyName := aws.String(c.Name)
|
||||
req, _ := svc.PutObjectRequest(&s3.PutObjectInput{
|
||||
Bucket: bucketName,
|
||||
Key: keyName,
|
||||
Body: bytes.NewReader(c.Body),
|
||||
})
|
||||
|
||||
req.Build()
|
||||
if e, a := c.Sum64, req.HTTPRequest.Header.Get("Content-Md5"); e != a {
|
||||
t.Errorf("%d, expect %v sum, got %v", i, e, a)
|
||||
}
|
||||
|
||||
if err := req.Send(); err != nil {
|
||||
t.Fatalf("%d, expect no error, got %v", i, err)
|
||||
}
|
||||
|
||||
getObjIn := &s3.GetObjectInput{
|
||||
Bucket: bucketName,
|
||||
Key: keyName,
|
||||
}
|
||||
|
||||
expectBody := c.Body
|
||||
if c.RangeGet != nil {
|
||||
getObjIn.Range = aws.String(fmt.Sprintf("bytes=%d-%d", c.RangeGet[0], c.RangeGet[1]-1))
|
||||
expectBody = c.Body[c.RangeGet[0]:c.RangeGet[1]]
|
||||
}
|
||||
|
||||
getReq, getOut := svc.GetObjectRequest(getObjIn)
|
||||
|
||||
getReq.Build()
|
||||
if e, a := "append-md5", getReq.HTTPRequest.Header.Get("X-Amz-Te"); e != a {
|
||||
t.Errorf("%d, expect %v encoding, got %v", i, e, a)
|
||||
}
|
||||
if err := getReq.Send(); err != nil {
|
||||
t.Fatalf("%d, expect no error, got %v", i, err)
|
||||
}
|
||||
defer getOut.Body.Close()
|
||||
|
||||
if e, a := "append-md5", getReq.HTTPResponse.Header.Get("X-Amz-Transfer-Encoding"); e != a {
|
||||
t.Fatalf("%d, expect response tx encoding header %v, got %v", i, e, a)
|
||||
}
|
||||
|
||||
var readBody bytes.Buffer
|
||||
_, err := io.Copy(&readBody, getOut.Body)
|
||||
if err != nil {
|
||||
t.Fatalf("%d, expect no error, got %v", i, err)
|
||||
}
|
||||
|
||||
if e, a := expectBody, readBody.Bytes(); !bytes.Equal(e, a) {
|
||||
t.Errorf("%d, expect %v body, got %v", i, e, a)
|
||||
}
|
||||
}
|
||||
}
|
||||
Generated
Vendored
+33
-12
@@ -11,7 +11,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/gucumber/gucumber"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/session"
|
||||
@@ -31,7 +30,9 @@ func init() {
|
||||
Bucket: aws.String(bucket),
|
||||
Prefix: aws.String(baseFolder + "/" + prefix),
|
||||
})
|
||||
assert.NoError(gucumber.T, err)
|
||||
if err != nil {
|
||||
gucumber.T.Errorf("expect no error, got %v", err)
|
||||
}
|
||||
|
||||
plaintexts := make(map[string][]byte)
|
||||
for _, obj := range out.Contents {
|
||||
@@ -40,10 +41,14 @@ func init() {
|
||||
Bucket: aws.String(bucket),
|
||||
Key: plaintextKey,
|
||||
})
|
||||
assert.NoError(gucumber.T, err)
|
||||
if err != nil {
|
||||
gucumber.T.Errorf("expect no error, got %v", err)
|
||||
}
|
||||
caseKey := strings.TrimPrefix(*plaintextKey, baseFolder+"/"+prefix)
|
||||
plaintext, err := ioutil.ReadAll(ptObj.Body)
|
||||
assert.NoError(gucumber.T, err)
|
||||
if err != nil {
|
||||
gucumber.T.Errorf("expect no error, got %v", err)
|
||||
}
|
||||
|
||||
plaintexts[caseKey] = plaintext
|
||||
}
|
||||
@@ -84,10 +89,14 @@ func init() {
|
||||
Key: &cipherKey,
|
||||
},
|
||||
)
|
||||
assert.NoError(gucumber.T, err)
|
||||
if err != nil {
|
||||
gucumber.T.Errorf("expect no error, got %v", err)
|
||||
}
|
||||
|
||||
ciphertext, err := ioutil.ReadAll(ctObj.Body)
|
||||
assert.NoError(gucumber.T, err)
|
||||
if err != nil {
|
||||
gucumber.T.Errorf("expect no error, got %v", err)
|
||||
}
|
||||
ciphertexts[caseKey] = ciphertext
|
||||
}
|
||||
gucumber.World["decrypted"] = ciphertexts
|
||||
@@ -97,8 +106,12 @@ func init() {
|
||||
plaintexts := gucumber.World["plaintexts"].(map[string][]byte)
|
||||
ciphertexts := gucumber.World["decrypted"].(map[string][]byte)
|
||||
for caseKey, ciphertext := range ciphertexts {
|
||||
assert.Equal(gucumber.T, len(plaintexts[caseKey]), len(ciphertext))
|
||||
assert.True(gucumber.T, bytes.Equal(plaintexts[caseKey], ciphertext))
|
||||
if e, a := len(plaintexts[caseKey]), len(ciphertext); e != a {
|
||||
gucumber.T.Errorf("expect %v, got %v", e, a)
|
||||
}
|
||||
if e, a := plaintexts[caseKey], ciphertext; !bytes.Equal(e, a) {
|
||||
gucumber.T.Errorf("expect %v, got %v", e, a)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -108,16 +121,22 @@ func init() {
|
||||
switch kek {
|
||||
case "kms":
|
||||
arn, err := getAliasInformation(v1, v2)
|
||||
assert.Nil(gucumber.T, err)
|
||||
if err != nil {
|
||||
gucumber.T.Errorf("expect nil, got %v", nil)
|
||||
}
|
||||
|
||||
b64Arn := base64.StdEncoding.EncodeToString([]byte(arn))
|
||||
assert.Nil(gucumber.T, err)
|
||||
if err != nil {
|
||||
gucumber.T.Errorf("expect nil, got %v", nil)
|
||||
}
|
||||
gucumber.World["Masterkey"] = b64Arn
|
||||
|
||||
handler = s3crypto.NewKMSKeyGenerator(kms.New(session.New(&aws.Config{
|
||||
Region: &v2,
|
||||
})), arn)
|
||||
assert.Nil(gucumber.T, err)
|
||||
if err != nil {
|
||||
gucumber.T.Errorf("expect nil, got %v", nil)
|
||||
}
|
||||
default:
|
||||
gucumber.T.Skip()
|
||||
}
|
||||
@@ -157,7 +176,9 @@ func init() {
|
||||
}
|
||||
|
||||
_, err := c.PutObject(input)
|
||||
assert.Nil(gucumber.T, err)
|
||||
if err != nil {
|
||||
gucumber.T.Errorf("expect nil, got %v", nil)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Generated
Vendored
+1
-2
@@ -12,7 +12,6 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||
@@ -52,7 +51,7 @@ func setup() error {
|
||||
|
||||
// Create a bucket for testing
|
||||
bucketName = aws.String(
|
||||
fmt.Sprintf("aws-sdk-go-integration-%d-%s", time.Now().Unix(), integration.UniqueID()))
|
||||
fmt.Sprintf("aws-sdk-go-integration-%s", integration.UniqueID()))
|
||||
|
||||
_, err := svc.CreateBucket(&s3.CreateBucketInput{Bucket: bucketName})
|
||||
if err != nil {
|
||||
|
||||
Generated
Vendored
+67
@@ -0,0 +1,67 @@
|
||||
// +build integration
|
||||
|
||||
package s3
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/awstesting/integration"
|
||||
"github.com/aws/aws-sdk-go/service/s3"
|
||||
)
|
||||
|
||||
const integBucketPrefix = "aws-sdk-go-integration"
|
||||
|
||||
var bucketName *string
|
||||
var svc *s3.S3
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
setup()
|
||||
defer teardown() // only called if we panic
|
||||
|
||||
result := m.Run()
|
||||
teardown()
|
||||
os.Exit(result)
|
||||
}
|
||||
|
||||
// Create a bucket for testing
|
||||
func setup() {
|
||||
svc = s3.New(integration.Session)
|
||||
bucketName = aws.String(
|
||||
fmt.Sprintf("%s-%s",
|
||||
integBucketPrefix, integration.UniqueID()))
|
||||
|
||||
_, err := svc.CreateBucket(&s3.CreateBucketInput{Bucket: bucketName})
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("failed to create bucket %s, %v", *bucketName, err))
|
||||
}
|
||||
|
||||
err = svc.WaitUntilBucketExists(&s3.HeadBucketInput{Bucket: bucketName})
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("failed waiting for bucket %s to be created", *bucketName))
|
||||
}
|
||||
}
|
||||
|
||||
// Delete the bucket
|
||||
func teardown() {
|
||||
resp, err := svc.ListObjects(&s3.ListObjectsInput{Bucket: bucketName})
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("failed to list s3 bucket %s objects, %v", *bucketName, err))
|
||||
}
|
||||
|
||||
errs := []error{}
|
||||
for _, o := range resp.Contents {
|
||||
_, err = svc.DeleteObject(&s3.DeleteObjectInput{Bucket: bucketName, Key: o.Key})
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
}
|
||||
|
||||
if len(errs) != 0 {
|
||||
panic(fmt.Sprintf("failed to delete objects, %s", errs))
|
||||
}
|
||||
|
||||
svc.DeleteBucket(&s3.DeleteBucketInput{Bucket: bucketName})
|
||||
}
|
||||
Reference in New Issue
Block a user