Skip to content

Commit

Permalink
TMP
Browse files Browse the repository at this point in the history
  • Loading branch information
risicle committed Oct 16, 2023
1 parent 53eb869 commit 67c9924
Showing 1 changed file with 39 additions and 31 deletions.
70 changes: 39 additions & 31 deletions platform-tests/broker-acceptance/s3_broker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -126,67 +158,43 @@ 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"),
})
Expect(err).ToNot(HaveOccurred())

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())
Expand Down

0 comments on commit 67c9924

Please sign in to comment.