diff --git a/platform-tests/broker-acceptance/s3_broker_test.go b/platform-tests/broker-acceptance/s3_broker_test.go index 6dcfc9b1de..797010c7f1 100644 --- a/platform-tests/broker-acceptance/s3_broker_test.go +++ b/platform-tests/broker-acceptance/s3_broker_test.go @@ -106,9 +106,41 @@ var _ = Describe("S3 broker", func() { }) }) - It("is externally accessible from an allow_external_access service key", func() { + s3ClientFromServiceKey := func(siName string, skName string) (*s3.S3, string) { var serviceKeyData ServiceKeyData + cfSess := cf.Cf( + "service-key", + siName, + skName, + ) + Expect(cfSess.Wait(testConfig.DefaultTimeoutDuration())).To(Exit(0)) + + outContents := cfSess.Out.Contents() + err := json.Unmarshal( + outContents[bytes.IndexByte(outContents, byte('{')):], + &serviceKeyData, + ) + Expect(err).ToNot(HaveOccurred()) + + Expect(serviceKeyData.Credentials.BucketName).ToNot(Equal("")) + Expect(serviceKeyData.Credentials.AWSAccessKeyID).ToNot(Equal("")) + Expect(serviceKeyData.Credentials.AWSSecretAccessKey).ToNot(Equal("")) + Expect(serviceKeyData.Credentials.AWSRegion).ToNot(Equal("")) + + sess := session.Must(session.NewSession(&aws.Config{ + Region: aws.String(serviceKeyData.Credentials.AWSRegion), + Credentials: credentials.NewStaticCredentials( + serviceKeyData.Credentials.AWSAccessKeyID, + serviceKeyData.Credentials.AWSSecretAccessKey, + "", + ), + })) + return s3.New(sess), serviceKeyData.Credentials.BucketName + } + + It("is externally accessible from an allow_external_access service key", func() { var s3Client *s3.S3 + var bucketName string serviceKeyName := generator.PrefixedRandomName(testConfig.GetNamePrefix(), "test-service-key") By("creating the service key: "+serviceKeyName, func() { @@ -126,39 +158,15 @@ var _ = Describe("S3 broker", func() { }) By("retrieving the service key credentials", func() { - cfSess := cf.Cf( - "service-key", + s3Client, bucketName = s3ClientFromServiceKey( serviceInstanceName, serviceKeyName, ) - Expect(cfSess.Wait(testConfig.DefaultTimeoutDuration())).To(Exit(0)) - - outContents := cfSess.Out.Contents() - err := json.Unmarshal( - outContents[bytes.IndexByte(outContents, byte('{')):], - &serviceKeyData, - ) - Expect(err).ToNot(HaveOccurred()) - - Expect(serviceKeyData.Credentials.BucketName).ToNot(Equal("")) - Expect(serviceKeyData.Credentials.AWSAccessKeyID).ToNot(Equal("")) - Expect(serviceKeyData.Credentials.AWSSecretAccessKey).ToNot(Equal("")) - Expect(serviceKeyData.Credentials.AWSRegion).ToNot(Equal("")) - - sess := session.Must(session.NewSession(&aws.Config{ - Region: aws.String(serviceKeyData.Credentials.AWSRegion), - Credentials: credentials.NewStaticCredentials( - serviceKeyData.Credentials.AWSAccessKeyID, - serviceKeyData.Credentials.AWSSecretAccessKey, - "", - ), - })) - s3Client = s3.New(sess) }) By("Accessing the bucket from the test host", func() { _, err := s3Client.PutObject(&s3.PutObjectInput{ - Bucket: aws.String(serviceKeyData.Credentials.BucketName), + Bucket: aws.String(bucketName), Key: aws.String("test-key"), Body: strings.NewReader("test-content"), }) @@ -166,27 +174,27 @@ var _ = Describe("S3 broker", func() { defer func() { _, err := s3Client.DeleteObject(&s3.DeleteObjectInput{ - Bucket: aws.String(serviceKeyData.Credentials.BucketName), + Bucket: aws.String(bucketName), Key: aws.String("test-key"), }) Expect(err).ToNot(HaveOccurred()) }() listObjectsResult, err := s3Client.ListObjects(&s3.ListObjectsInput{ - Bucket: aws.String(serviceKeyData.Credentials.BucketName), + Bucket: aws.String(bucketName), }) Expect(err).ToNot(HaveOccurred()) Expect(len(listObjectsResult.Contents)).To(Equal(1)) Expect(listObjectsResult.Contents[0].Key).To(Equal(aws.String("test-key"))) _, err = s3Client.GetObject(&s3.GetObjectInput{ - Bucket: aws.String(serviceKeyData.Credentials.BucketName), + Bucket: aws.String(bucketName), Key: aws.String("test-key"), }) Expect(err).ToNot(HaveOccurred()) _, err = s3Client.GetObjectTagging(&s3.GetObjectTaggingInput{ - Bucket: aws.String(serviceKeyData.Credentials.BucketName), + Bucket: aws.String(bucketName), Key: aws.String("test-key"), }) Expect(err).ToNot(HaveOccurred())