11import { HttpHandler , HttpRequest , HttpResponse } from "@smithy/protocol-http" ;
2- import type { SignatureV4 } from "@smithy/signature-v4" ;
3- import {
4- AwsCredentialIdentity ,
5- Client ,
6- HandlerExecutionContext ,
7- HttpHandlerOptions ,
8- IdentityProvider ,
9- RequestHandler ,
10- RequestHandlerOutput ,
11- SelectedHttpAuthScheme ,
12- SMITHY_CONTEXT_KEY ,
13- } from "@smithy/types" ;
2+ import { Client , HttpHandlerOptions , RequestHandler , RequestHandlerOutput } from "@smithy/types" ;
143import { expect } from "vitest" ;
154
165/**
@@ -80,6 +69,8 @@ export class TestHttpHandler implements HttpHandler {
8069 for ( const key in RESERVED_ENVIRONMENT_VARIABLES ) {
8170 delete process . env [ key ] ;
8271 }
72+ process . env . AWS_ACCESS_KEY_ID = "INTEGRATION_TEST_MOCK" ;
73+ process . env . AWS_SECRET_ACCESS_KEY = "INTEGRATION_TEST_MOCK" ;
8374 }
8475
8576 /**
@@ -92,53 +83,6 @@ export class TestHttpHandler implements HttpHandler {
9283 this . client = client ;
9384 this . originalRequestHandler = client . config . requestHandler ;
9485 // mock credentials to avoid default chain lookup.
95- client . config . credentials = async ( ) => MOCK_CREDENTIALS ;
96- client . config . credentialDefaultProvider = ( ) => {
97- return async ( ) => {
98- return MOCK_CREDENTIALS ;
99- } ;
100- } ;
101- const signerProvider = client . config . signer ;
102- if ( typeof signerProvider === "function" ) {
103- client . config . signer = async ( ) => {
104- const _signer = await signerProvider ( ) ;
105- if ( typeof _signer . credentialProvider === "function" ) {
106- // signer is instance of SignatureV4
107- _signer . credentialProvider = async ( ) => {
108- return MOCK_CREDENTIALS ;
109- } ;
110- }
111- return _signer ;
112- } ;
113- }
114- if ( client . config . httpAuthSchemes ) {
115- for ( const authScheme of client . config . httpAuthSchemes ) {
116- authScheme . identityProvider = ( ) => {
117- return async ( ) => {
118- return MOCK_CREDENTIALS ;
119- } ;
120- } ;
121- }
122- }
123- client . middlewareStack . addRelativeTo (
124- ( next : any , context : HandlerExecutionContext ) => ( args : any ) => {
125- const scheme = context [ SMITHY_CONTEXT_KEY ] ?. selectedHttpAuthScheme as SelectedHttpAuthScheme ;
126- if ( scheme ) {
127- scheme . identity = MOCK_CREDENTIALS as AwsCredentialIdentity ;
128- if ( ( scheme . signer as any ) . credentialProvider ) {
129- ( scheme . signer as any ) . credentialProvider = ( async ( ) =>
130- MOCK_CREDENTIALS ) as IdentityProvider < AwsCredentialIdentity > ;
131- }
132- }
133- return next ( args ) ;
134- } ,
135- {
136- name : "integrationTestMiddleware" ,
137- override : true ,
138- toMiddleware : "httpSigningMiddleware" ,
139- relation : "before" ,
140- }
141- ) ;
14286
14387 client . config . requestHandler = new TestHttpHandler ( matcher ) ;
14488 if ( ! ( client as any ) [ TestHttpHandler . WATCHER ] ) {
0 commit comments