Skip to content

Commit 20fc148

Browse files
authored
Check method before calling external middlewareStack instance (#954)
1 parent b9b29cc commit 20fc148

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

.changeset/few-crews-brake.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@smithy/middleware-stack": patch
3+
---
4+
5+
check calls to external instances of middlewareStack

packages/middleware-stack/src/MiddlewareStack.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,22 @@ describe("MiddlewareStack", () => {
370370
});
371371
});
372372

373+
it("checks identifyOnResolve calls to external instances due to version mismatching", () => {
374+
const newStack = constructStack<input, output>();
375+
const oldStack = constructStack<input, output>();
376+
377+
delete (oldStack as any).identifyOnResolve;
378+
oldStack.clone = () => oldStack;
379+
oldStack.concat = <S>(stack: S) => oldStack as S;
380+
oldStack.applyToStack = () => void 0;
381+
382+
expect(oldStack.identifyOnResolve).toBeUndefined();
383+
expect(() => {
384+
newStack.concat(oldStack);
385+
newStack.clone();
386+
}).not.toThrow();
387+
});
388+
373389
describe("use", () => {
374390
it("should apply customizations from pluggables", async () => {
375391
const stack = constructStack<input, output>();

packages/middleware-stack/src/MiddlewareStack.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export const constructStack = <Input extends object, Output extends object>(): M
6969
//@ts-ignore
7070
toStack.addRelativeTo(entry.middleware, { ...entry });
7171
});
72-
toStack.identifyOnResolve(stack.identifyOnResolve());
72+
toStack.identifyOnResolve?.(stack.identifyOnResolve());
7373
return toStack;
7474
};
7575

@@ -239,7 +239,9 @@ export const constructStack = <Input extends object, Output extends object>(): M
239239
): MiddlewareStack<InputType, OutputType> => {
240240
const cloned = cloneTo(constructStack<InputType, OutputType>());
241241
cloned.use(from);
242-
cloned.identifyOnResolve(identifyOnResolve || cloned.identifyOnResolve() || from.identifyOnResolve());
242+
cloned.identifyOnResolve(
243+
identifyOnResolve || cloned.identifyOnResolve() || (from.identifyOnResolve?.() ?? false)
244+
);
243245
return cloned;
244246
},
245247

0 commit comments

Comments
 (0)