@@ -3,98 +3,102 @@ import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test as i
33
44const FormData = require ( "form-data" ) ;
55
6+ import { getE2eTestResources } from "@aws-sdk/aws-util-test/src" ;
67import { createReadStream , existsSync , rmSync , writeFileSync } from "fs" ;
78import { join } from "path" ;
89
9- import { getIntegTestResources } from "../../../tests/e2e/get-integ-test-resources" ;
1010import { createPresignedPost } from "./createPresignedPost" ;
1111
12- describe ( createPresignedPost . name , ( ) => {
13- let Bucket : string ;
14- let region : string ;
15-
16- beforeAll ( async ( ) => {
17- const integTestResourcesEnv = await getIntegTestResources ( ) ;
18- Object . assign ( process . env , integTestResourcesEnv ) ;
19-
20- region = process ?. env ?. AWS_SMOKE_TEST_REGION as string ;
21- Bucket = process ?. env ?. AWS_SMOKE_TEST_BUCKET as string ;
22- } ) ;
23-
24- it ( "should allow custom endpoints to be modified by endpoint resolution options" , async ( ) => {
25- const Key = "test-key" ;
26- {
27- const client = new S3 ( {
28- region,
29- forcePathStyle : true ,
30- endpoint : `https://s3.dualstack.${ region } .amazonaws.com` ,
31- } ) ;
32- const { url } = await createPresignedPost ( client , { Bucket, Key } ) ;
33- expect ( url ) . toBe ( `https://s3.dualstack.${ region } .amazonaws.com/${ Bucket } ` ) ;
34- }
35- {
36- const client = new S3 ( { region, endpoint : `https://s3.dualstack.${ region } .amazonaws.com` } ) ;
37- const { url } = await createPresignedPost ( client , { Bucket, Key } ) ;
38- expect ( url ) . toBe ( `https://${ Bucket } .s3.dualstack.${ region } .amazonaws.com/` ) ;
39- }
40- } ) ;
41-
42- describe ( "test with real bucket" , ( ) => {
43- let Key : string ;
44- let client : S3 ;
45- let contents : string ;
46- let fileLocation : string ;
12+ describe (
13+ createPresignedPost . name ,
14+ ( ) => {
15+ let Bucket : string ;
16+ let region : string ;
4717
4818 beforeAll ( async ( ) => {
49- Key = `aws-sdk-js-integration-test-s3-presigned-post-${ Date . now ( ) } .txt` ;
50- contents = "Hello, world!" ;
51- fileLocation = join ( __dirname , Key ) ;
52- client = new S3 ( { region, endpoint : `https://s3.dualstack.${ region } .amazonaws.com` } ) ;
19+ const e2eTestResourcesEnv = await getE2eTestResources ( ) ;
20+ Object . assign ( process . env , e2eTestResourcesEnv ) ;
5321
54- await client . headBucket ( { Bucket } ) ;
55- writeFileSync ( fileLocation , contents , "utf-8" ) ;
22+ region = process ?. env ?. AWS_SMOKE_TEST_REGION as string ;
23+ Bucket = process ?. env ?. AWS_SMOKE_TEST_BUCKET as string ;
5624 } ) ;
5725
58- afterAll ( async ( ) => {
59- if ( existsSync ( fileLocation ) ) {
60- rmSync ( fileLocation ) ;
26+ it ( "should allow custom endpoints to be modified by endpoint resolution options" , async ( ) => {
27+ const Key = "test-key" ;
28+ {
29+ const client = new S3 ( {
30+ region,
31+ forcePathStyle : true ,
32+ endpoint : `https://s3.dualstack.${ region } .amazonaws.com` ,
33+ } ) ;
34+ const { url } = await createPresignedPost ( client , { Bucket, Key } ) ;
35+ expect ( url ) . toBe ( `https://s3.dualstack.${ region } .amazonaws.com/${ Bucket } ` ) ;
36+ }
37+ {
38+ const client = new S3 ( { region, endpoint : `https://s3.dualstack.${ region } .amazonaws.com` } ) ;
39+ const { url } = await createPresignedPost ( client , { Bucket, Key } ) ;
40+ expect ( url ) . toBe ( `https://${ Bucket } .s3.dualstack.${ region } .amazonaws.com/` ) ;
6141 }
6242 } ) ;
6343
64- beforeEach ( async ( ) => {
65- await client . deleteObject ( { Bucket, Key } ) ;
66- } ) ;
44+ describe ( "test with real bucket" , ( ) => {
45+ let Key : string ;
46+ let client : S3 ;
47+ let contents : string ;
48+ let fileLocation : string ;
6749
68- afterEach ( async ( ) => {
69- await client . deleteObject ( { Bucket, Key } ) ;
70- } ) ;
50+ beforeAll ( async ( ) => {
51+ Key = `aws-sdk-js-integration-test-s3-presigned-post-${ Date . now ( ) } .txt` ;
52+ contents = "Hello, world!" ;
53+ fileLocation = join ( __dirname , Key ) ;
54+ client = new S3 ( { region, endpoint : `https://s3.dualstack.${ region } .amazonaws.com` } ) ;
7155
72- it ( "should put an object using a presigned post w/ custom endpoint" , async ( ) => {
73- const { url, fields } = await createPresignedPost ( client , { Bucket, Key } ) ;
56+ await client . headBucket ( { Bucket } ) ;
57+ writeFileSync ( fileLocation , contents , "utf-8" ) ;
58+ } ) ;
7459
75- expect ( url ) . toBe ( `https://${ Bucket } .s3.dualstack.${ region } .amazonaws.com/` ) ;
60+ afterAll ( async ( ) => {
61+ if ( existsSync ( fileLocation ) ) {
62+ rmSync ( fileLocation ) ;
63+ }
64+ } ) ;
7665
77- const form = new FormData ( ) ;
78- Object . entries ( fields ) . forEach ( ( [ field , value ] ) => {
79- form . append ( field , value ) ;
66+ beforeEach ( async ( ) => {
67+ await client . deleteObject ( { Bucket, Key } ) ;
8068 } ) ;
81- form . append ( "file" , createReadStream ( fileLocation ) ) ;
8269
83- const precheck = await client . getObject ( { Bucket, Key } ) . catch ( ( err ) => err ) ;
84- expect ( precheck ) . toBeInstanceOf ( NoSuchKey ) ;
70+ afterEach ( async ( ) => {
71+ await client . deleteObject ( { Bucket, Key } ) ;
72+ } ) ;
8573
86- const submit : { statusCode : number } = await new Promise ( ( resolve , reject ) => {
87- form . submit ( url , ( err : any , res : any ) => {
88- if ( err ) reject ( err ) ;
89- resolve ( res ) ;
74+ it ( "should put an object using a presigned post w/ custom endpoint" , async ( ) => {
75+ const { url, fields } = await createPresignedPost ( client , { Bucket, Key } ) ;
76+
77+ expect ( url ) . toBe ( `https://${ Bucket } .s3.dualstack.${ region } .amazonaws.com/` ) ;
78+
79+ const form = new FormData ( ) ;
80+ Object . entries ( fields ) . forEach ( ( [ field , value ] ) => {
81+ form . append ( field , value ) ;
9082 } ) ;
91- } ) ;
83+ form . append ( "file" , createReadStream ( fileLocation ) ) ;
9284
93- expect ( submit . statusCode ) . toBe ( 204 ) ;
85+ const precheck = await client . getObject ( { Bucket, Key } ) . catch ( ( err ) => err ) ;
86+ expect ( precheck ) . toBeInstanceOf ( NoSuchKey ) ;
9487
95- const check = await client . getObject ( { Bucket, Key } ) ;
88+ const submit : { statusCode : number } = await new Promise ( ( resolve , reject ) => {
89+ form . submit ( url , ( err : any , res : any ) => {
90+ if ( err ) reject ( err ) ;
91+ resolve ( res ) ;
92+ } ) ;
93+ } ) ;
9694
97- expect ( await check . Body ?. transformToString ( ) ) . toEqual ( contents ) ;
95+ expect ( submit . statusCode ) . toBe ( 204 ) ;
96+
97+ const check = await client . getObject ( { Bucket, Key } ) ;
98+
99+ expect ( await check . Body ?. transformToString ( ) ) . toEqual ( contents ) ;
100+ } ) ;
98101 } ) ;
99- } ) ;
100- } ) ;
102+ } ,
103+ 60_000
104+ ) ;
0 commit comments