File tree Expand file tree Collapse file tree 3 files changed +59
-1
lines changed
packages/credential-providers Expand file tree Collapse file tree 3 files changed +59
-1
lines changed Original file line number Diff line number Diff line change
1
+ module . exports = {
2
+ preset : "ts-jest" ,
3
+ testMatch : [ "**/*.integ.spec.ts" ] ,
4
+ } ;
Original file line number Diff line number Diff line change 16
16
"build:types:downlevel" : " downlevel-dts dist-types dist-types/ts3.4" ,
17
17
"clean" : " rimraf ./dist-* && rimraf *.tsbuildinfo" ,
18
18
"extract:docs" : " api-extractor run --local" ,
19
- "test" : " jest"
19
+ "test" : " jest" ,
20
+ "test:integration" : " jest -c jest.config.integ.js"
20
21
},
21
22
"keywords" : [
22
23
" aws" ,
Original file line number Diff line number Diff line change
1
+ import { ListBucketsCommand , S3 } from "@aws-sdk/client-s3" ;
2
+ import fs from "fs" ;
3
+ import { homedir } from "os" ;
4
+ import { join } from "path" ;
5
+
6
+ import { fromSSO } from "./fromSSO" ;
7
+
8
+ const SAMPLE_CONFIG = `[profile dev]
9
+ sso_session = my-sso
10
+ sso_account_id = 111122223333
11
+ sso_role_name = SampleRole
12
+
13
+ [sso-session my-sso]
14
+ sso_region = us-east-1
15
+ sso_start_url = https://my-sso-portal.awsapps.com/start
16
+ sso_registration_scopes = sso:account:access
17
+ ` ;
18
+
19
+ jest . mock ( "fs" , ( ) => {
20
+ return {
21
+ promises : {
22
+ readFile : jest . fn ( ) ,
23
+ } ,
24
+ } ;
25
+ } ) ;
26
+
27
+ describe ( "fromSSO integration test" , ( ) => {
28
+ beforeEach ( ( ) => {
29
+ jest . resetAllMocks ( ) ;
30
+ } ) ;
31
+
32
+ it ( "should expand relative homedir" , async ( ) => {
33
+ const mockReadFile = ( fs . promises . readFile as jest . Mock ) . mockResolvedValue ( SAMPLE_CONFIG ) ;
34
+
35
+ const client = new S3 ( {
36
+ region : "eu-west-1" ,
37
+ credentials : fromSSO ( {
38
+ profile : "dev" ,
39
+ filepath : "~/custom/path/to/credentials" ,
40
+ configFilepath : "~/custom/path/to/config" ,
41
+ } ) ,
42
+ } ) ;
43
+
44
+ try {
45
+ await client . send ( new ListBucketsCommand ( { } ) ) ;
46
+ } catch ( e ) {
47
+ // do nothing
48
+ }
49
+
50
+ expect ( mockReadFile ) . toHaveBeenCalledWith ( join ( homedir ( ) , "custom/path/to/credentials" ) , "utf8" ) ;
51
+ expect ( mockReadFile ) . toHaveBeenCalledWith ( join ( homedir ( ) , "custom/path/to/config" ) , "utf8" ) ;
52
+ } ) ;
53
+ } ) ;
You can’t perform that action at this time.
0 commit comments