@@ -4,141 +4,26 @@ import {
44  fromCognitoIdentity , 
55  fromCognitoIdentityPool , 
66  fromIni , 
7+   fromNodeProviderChain , 
78  fromTokenFile , 
89  fromWebToken , 
910}  from  "@aws-sdk/credential-providers" ; 
10- import  {  fromNodeProviderChain  }  from  "@aws-sdk/credential-providers" ; 
11+ import  {  MockNodeHttpHandler  }  from  "@aws-sdk/credential-providers/tests/_test-lib.spec " ; 
1112import  {  NodeHttpHandler  }  from  "@smithy/node-http-handler" ; 
12- import  {  HttpResponse  }  from  "@smithy/protocol-http" ; 
1313import  {  externalDataInterceptor  }  from  "@smithy/shared-ini-file-loader" ; 
14- import  type  {  HttpRequest ,  MiddlewareStack ,  NodeHttpHandlerOptions ,   ParsedIniData  }  from  "@smithy/types" ; 
14+ import  type  {  HttpRequest ,  MiddlewareStack ,  ParsedIniData  }  from  "@smithy/types" ; 
1515import  {  AdaptiveRetryStrategy ,  StandardRetryStrategy  }  from  "@smithy/util-retry" ; 
1616import  child_process  from  "node:child_process" ; 
1717import  {  createHash  }  from  "node:crypto" ; 
1818import  {  homedir  }  from  "node:os" ; 
1919import  {  join  }  from  "node:path" ; 
20- import  {  PassThrough  }  from  "node:stream" ; 
2120import  {  afterAll ,  afterEach ,  beforeAll ,  beforeEach ,  describe ,  expect ,  test  as  it ,  vi  }  from  "vitest" ; 
2221
2322// eslint-disable-next-line no-restricted-imports 
2423import  {  defaultProvider  }  from  "../src/defaultProvider" ; 
2524
2625const  assumeRoleArns : string [ ]  =  [ ] ; 
2726
28- class  MockNodeHttpHandler  { 
29-   static  create ( instanceOrOptions ?: any )  { 
30-     if  ( typeof  instanceOrOptions ?. handle  ===  "function" )  { 
31-       return  instanceOrOptions ; 
32-     } 
33-     return  new  MockNodeHttpHandler ( ) ; 
34-   } 
35- 
36-   async  handle ( request : HttpRequest )  { 
37-     const  body  =  new  PassThrough ( { } ) ; 
38- 
39-     if  ( request . body ?. includes ( "RoleArn=" ) )  { 
40-       assumeRoleArns . push ( request . body . match ( / R o l e A r n = ( .* ?) & / ) ?. [ 1 ] ) ; 
41-     } 
42- 
43-     const  region  =  ( request . hostname . match ( / ( s t s | c o g n i t o - i d e n t i t y | p o r t a l \. s s o ) \. ( .* ?) \. / )  ||  [ ,  ,  "unknown" ] ) [ 2 ] ; 
44- 
45-     if  ( request . headers . Authorization  ===  "container-authorization" )  { 
46-       body . write ( 
47-         JSON . stringify ( { 
48-           AccessKeyId : "CONTAINER_ACCESS_KEY" , 
49-           SecretAccessKey : "CONTAINER_SECRET_ACCESS_KEY" , 
50-           Token : "CONTAINER_TOKEN" , 
51-           Expiration : "3000-01-01T00:00:00.000Z" , 
52-         } ) 
53-       ) ; 
54-     }  else  if  ( request . path ?. includes ( "/federation/credentials" ) )  { 
55-       body . write ( 
56-         JSON . stringify ( { 
57-           roleCredentials : { 
58-             accessKeyId : "SSO_ACCESS_KEY_ID" , 
59-             secretAccessKey : "SSO_SECRET_ACCESS_KEY" , 
60-             sessionToken : `SSO_SESSION_TOKEN_${ region }  , 
61-             expiration : "3000-01-01T00:00:00.000Z" , 
62-           } , 
63-         } ) 
64-       ) ; 
65-     }  else  if  ( request . body ?. includes ( "Action=AssumeRoleWithWebIdentity" ) )  { 
66-       body . write ( ` 
67- <AssumeRoleWithWebIdentityResponse xmlns="https://sts.amazonaws.com/doc/2011-06-15/"> 
68- <AssumeRoleWithWebIdentityResult> 
69-   <Credentials> 
70-     <AccessKeyId>STS_ARWI_ACCESS_KEY_ID</AccessKeyId> 
71-     <SecretAccessKey>STS_ARWI_SECRET_ACCESS_KEY</SecretAccessKey> 
72-     <SessionToken>STS_ARWI_SESSION_TOKEN_${ region }  
73-     <Expiration>3000-01-01T00:00:00.000Z</Expiration> 
74-   </Credentials> 
75- </AssumeRoleWithWebIdentityResult> 
76- <ResponseMetadata> 
77-   <RequestId>01234567-89ab-cdef-0123-456789abcdef</RequestId> 
78- </ResponseMetadata> 
79- </AssumeRoleWithWebIdentityResponse>` ) ; 
80-     }  else  if  ( request . body ?. includes ( "Action=AssumeRole" ) )  { 
81-       body . write ( ` 
82- <AssumeRoleResponse xmlns="https://sts.amazonaws.com/doc/2011-06-15/"> 
83- <AssumeRoleResult> 
84-   <Credentials> 
85-     <AccessKeyId>STS_AR_ACCESS_KEY_ID</AccessKeyId> 
86-     <SecretAccessKey>STS_AR_SECRET_ACCESS_KEY</SecretAccessKey> 
87-     <SessionToken>STS_AR_SESSION_TOKEN_${ region }  
88-     <Expiration>3000-01-01T00:00:00.000Z</Expiration> 
89-   </Credentials> 
90- </AssumeRoleResult> 
91- <ResponseMetadata> 
92-   <RequestId>01234567-89ab-cdef-0123-456789abcdef</RequestId> 
93- </ResponseMetadata> 
94- </AssumeRoleResponse>` ) ; 
95-     }  else  if  ( request . body . includes ( "Action=GetCallerIdentity" ) )  { 
96-       body . write ( ` 
97- <GetCallerIdentityResponse xmlns="https://sts.amazonaws.com/doc/2011-06-15/"> 
98- <GetCallerIdentityResult> 
99-   <Arn>arn:aws:iam::123456789012:user/Alice</Arn> 
100-   <UserId>AIDACKCEVSQ6C2EXAMPLE</UserId> 
101-   <Account>123456789012</Account> 
102- </GetCallerIdentityResult> 
103- <ResponseMetadata> 
104-   <RequestId>01234567-89ab-cdef-0123-456789abcdef</RequestId> 
105- </ResponseMetadata> 
106- </GetCallerIdentityResponse>` ) ; 
107-     }  else  if  ( request . headers [ "x-amz-target" ]  ===  "AWSCognitoIdentityService.GetCredentialsForIdentity" )  { 
108-       body . write ( `{ 
109-           "Credentials":{ 
110-             "SecretKey":"COGNITO_SECRET_KEY", 
111-             "SessionToken":"COGNITO_SESSION_TOKEN_${ region }  
112-             "Expiration":${ new  Date ( "3000-01-01T00:00:00.000Z" ) . getTime ( )  /  1000 }  
113-             "AccessKeyId":"COGNITO_ACCESS_KEY_ID" 
114-           }, 
115-           "IdentityId":"${ region }  
116-         }` ) ; 
117-     }  else  if  ( request . headers [ "x-amz-target" ]  ===  "AWSCognitoIdentityService.GetId" )  { 
118-       body . write ( `{ 
119-           "IdentityId":"${ region }  
120-         }` ) ; 
121-     }  else  { 
122-       console . log ( request ) ; 
123-       throw  new  Error ( "request not supported." ) ; 
124-     } 
125-     body . end ( ) ; 
126-     return  { 
127-       response : new  HttpResponse ( { 
128-         statusCode : 200 , 
129-         body, 
130-         headers : { } , 
131-       } ) , 
132-     } ; 
133-   } 
134- 
135-   updateHttpClientConfig ( key : keyof  NodeHttpHandlerOptions ,  value : NodeHttpHandlerOptions [ typeof  key ] ) : void { } 
136- 
137-   httpHandlerConfigs ( ) : NodeHttpHandlerOptions  { 
138-     return  null  as  any ; 
139-   } 
140- } 
141- 
14227describe ( "credential-provider-node integration test" ,  ( )  =>  { 
14328  let  sts : STS  =  null  as  any ; 
14429  let  processSnapshot : typeof  process . env  =  null  as  any ; 
0 commit comments