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 c43b229 commit c56d3c8
Showing 1 changed file with 37 additions and 26 deletions.
63 changes: 37 additions & 26 deletions platform-tests/broker-acceptance/s3_broker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,31 @@ var _ = Describe("S3 broker", func() {
var s3Client *s3.S3
var bucketName string
var serviceKeyName string
var allowExternalAccess string

createServiceKeyWithCleanup := func(
siName string,
skName string,
allowExternalAccessJSON string,
) {
By("creating the service key: "+serviceKeyName, func() {
Expect(cf.Cf(
"create-service-key",
siName,
skName,
"-c",
fmt.Sprintf(
`{"allow_external_access": %s, "permissions": "read-write"}`,
allowExternalAccessJSON,
),
).Wait(testConfig.DefaultTimeoutDuration())).To(Exit(0))
})

DeferCleanup(func() {
By("deleting the service key", func() {
cf.Cf("delete-service-key", siName, skName, "-f").Wait(testConfig.DefaultTimeoutDuration())
})
})
}

s3ClientFromServiceKey := func(siName string, skName string) (*s3.S3, string) {
var serviceKeyData ServiceKeyData
Expand Down Expand Up @@ -149,30 +173,13 @@ var _ = Describe("S3 broker", func() {
serviceKeyName = generator.PrefixedRandomName(testConfig.GetNamePrefix(), "test-service-key")
})

JustBeforeEach(func() {
By("creating the service key: "+serviceKeyName, func() {
Expect(cf.Cf(
"create-service-key",
serviceInstanceName,
serviceKeyName,
"-c",
fmt.Sprintf(
`{"allow_external_access": %s, "permissions": "read-write"}`,
allowExternalAccess,
),
).Wait(testConfig.DefaultTimeoutDuration())).To(Exit(0))
})

DeferCleanup(func() {
By("deleting the service key", func() {
cf.Cf("delete-service-key", serviceInstanceName, serviceKeyName, "-f").Wait(testConfig.DefaultTimeoutDuration())
})
})
})

Context("with an allow_external_access service key", func() {
BeforeEach(func() {
allowExternalAccess = `true`
createServiceKeyWithCleanup(
serviceInstanceName,
serviceKeyName,
`true`,
)
})

It("is externally accessible", func() {
Expand All @@ -183,7 +190,7 @@ var _ = Describe("S3 broker", func() {
)
})

By("Accessing the bucket from the test host", func() {
By("accessing the bucket from the test host", func() {
_, err := s3Client.PutObject(&s3.PutObjectInput{
Bucket: aws.String(bucketName),
Key: aws.String("test-key"),
Expand Down Expand Up @@ -223,7 +230,11 @@ var _ = Describe("S3 broker", func() {

Context("with a non-allow_external_access service key", func() {
BeforeEach(func() {
allowExternalAccess = `false`
createServiceKeyWithCleanup(
serviceInstanceName,
serviceKeyName,
`false`,
)
})

It("is not externally accessible", func() {
Expand All @@ -234,7 +245,7 @@ var _ = Describe("S3 broker", func() {
)
})

By("Failing to access the bucket from the test host", func() {
By("failing to access the bucket from the test host", func() {
_, err := s3Client.PutObject(&s3.PutObjectInput{
Bucket: aws.String(bucketName),
Key: aws.String("test-key"),
Expand Down

0 comments on commit c56d3c8

Please sign in to comment.