Skip to content

Commit

Permalink
Check method before calling external middlewareStack instance (#954)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe authored Sep 21, 2023
1 parent b9b29cc commit 20fc148
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/few-crews-brake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@smithy/middleware-stack": patch
---

check calls to external instances of middlewareStack
16 changes: 16 additions & 0 deletions packages/middleware-stack/src/MiddlewareStack.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,22 @@ describe("MiddlewareStack", () => {
});
});

it("checks identifyOnResolve calls to external instances due to version mismatching", () => {
const newStack = constructStack<input, output>();
const oldStack = constructStack<input, output>();

delete (oldStack as any).identifyOnResolve;
oldStack.clone = () => oldStack;
oldStack.concat = <S>(stack: S) => oldStack as S;
oldStack.applyToStack = () => void 0;

expect(oldStack.identifyOnResolve).toBeUndefined();
expect(() => {
newStack.concat(oldStack);
newStack.clone();
}).not.toThrow();
});

describe("use", () => {
it("should apply customizations from pluggables", async () => {
const stack = constructStack<input, output>();
Expand Down
6 changes: 4 additions & 2 deletions packages/middleware-stack/src/MiddlewareStack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const constructStack = <Input extends object, Output extends object>(): M
//@ts-ignore
toStack.addRelativeTo(entry.middleware, { ...entry });
});
toStack.identifyOnResolve(stack.identifyOnResolve());
toStack.identifyOnResolve?.(stack.identifyOnResolve());
return toStack;
};

Expand Down Expand Up @@ -239,7 +239,9 @@ export const constructStack = <Input extends object, Output extends object>(): M
): MiddlewareStack<InputType, OutputType> => {
const cloned = cloneTo(constructStack<InputType, OutputType>());
cloned.use(from);
cloned.identifyOnResolve(identifyOnResolve || cloned.identifyOnResolve() || from.identifyOnResolve());
cloned.identifyOnResolve(
identifyOnResolve || cloned.identifyOnResolve() || (from.identifyOnResolve?.() ?? false)
);
return cloned;
},

Expand Down

0 comments on commit 20fc148

Please sign in to comment.