feat: CORS enable button...ish still now understanding this
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
import {describe, expect, test} from 'bun:test'
|
||||
import {
|
||||
GetBucketNotificationConfigurationCommand,
|
||||
GetBucketLocationCommand,
|
||||
GetBucketTaggingCommand,
|
||||
GetBucketWebsiteCommand,
|
||||
ListBucketsCommand,
|
||||
PutBucketNotificationConfigurationCommand,
|
||||
PutBucketWebsiteCommand,
|
||||
type S3Client,
|
||||
} from '@aws-sdk/client-s3'
|
||||
import {AddPermissionCommand, GetFunctionCommand, RemovePermissionCommand, type LambdaClient} from '@aws-sdk/client-lambda'
|
||||
@@ -29,6 +32,7 @@ function fakeS3(overrides: Partial<{
|
||||
if (overrides.taggingError) throw overrides.taggingError
|
||||
return {TagSet: overrides.tagSet ?? [{Key: 'Environment', Value: 'dev'}]}
|
||||
}
|
||||
if (command instanceof GetBucketLocationCommand) return {LocationConstraint: 'us-west-2'}
|
||||
throw new Error(`Unexpected command: ${command?.constructor?.name}`)
|
||||
},
|
||||
} as unknown as S3Client
|
||||
@@ -104,6 +108,38 @@ describe('AwsStorageAdapter', () => {
|
||||
expect(requestedBuckets.sort()).toEqual(['prod-assets', 'prod-logs'])
|
||||
})
|
||||
|
||||
test('gets normalized website configuration and maps no website configuration to null', async () => {
|
||||
const s3 = {
|
||||
send: async (command: unknown) => {
|
||||
if (command instanceof GetBucketWebsiteCommand) {
|
||||
return {RedirectAllRequestsTo: {HostName: 'www.example.com', Protocol: 'https'}}
|
||||
}
|
||||
throw new Error(`Unexpected command: ${command?.constructor?.name}`)
|
||||
},
|
||||
} as unknown as S3Client
|
||||
const adapter = new AwsStorageAdapter(s3)
|
||||
|
||||
expect(await adapter.getS3BucketWebsite('website-bucket')).toEqual({mode: 'redirect', hostName: 'www.example.com', protocol: 'https'})
|
||||
|
||||
const absent = new Error('No website configuration')
|
||||
absent.name = 'NoSuchWebsiteConfiguration'
|
||||
const missing = new AwsStorageAdapter({send: async () => { throw absent }} as unknown as S3Client)
|
||||
expect(await missing.getS3BucketWebsite('website-bucket')).toBeNull()
|
||||
})
|
||||
|
||||
test('puts mutually exclusive S3 website configuration shapes', async () => {
|
||||
const sent: unknown[] = []
|
||||
const s3 = {send: async (command: unknown) => { sent.push(command); return {} }} as unknown as S3Client
|
||||
const adapter = new AwsStorageAdapter(s3)
|
||||
|
||||
await adapter.putS3BucketWebsite('website-bucket', {mode: 'index', indexDocument: 'index.html', errorDocument: 'error.html'})
|
||||
await adapter.putS3BucketWebsite('website-bucket', {mode: 'redirect', hostName: 'www.example.com', protocol: 'https'})
|
||||
|
||||
const [index, redirect] = sent as PutBucketWebsiteCommand[]
|
||||
expect(index.input.WebsiteConfiguration).toEqual({IndexDocument: {Suffix: 'index.html'}, ErrorDocument: {Key: 'error.html'}})
|
||||
expect(redirect.input.WebsiteConfiguration).toEqual({RedirectAllRequestsTo: {HostName: 'www.example.com', Protocol: 'https'}})
|
||||
})
|
||||
|
||||
test('adds an S3 Lambda trigger without replacing other bucket notifications', async () => {
|
||||
const sent: unknown[] = []
|
||||
const s3 = {
|
||||
|
||||
Reference in New Issue
Block a user