Skip to content

Commit 55995ec

Browse files
authored
fix(middleware-sdk-machinelearning): ensure request query is object (#5331)
1 parent 6e139f7 commit 55995ec

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

packages/middleware-sdk-machinelearning/src/middleware-sdk-machinelearning.integ.spec.ts

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,49 @@ describe("middleware-sdk-machine-learning", () => {
66
describe(MachineLearning.name, () => {
77
it("should use the input predict endpoint", async () => {
88
const client = new MachineLearning({
9-
region: "us-west-2",
9+
region: "us-east-1",
1010
});
1111

1212
requireRequestsFrom(client).toMatch({
13-
hostname: "predict-custom-endpoint.us-west-2.amazonaws.com",
13+
hostname: "predict-custom-endpoint.us-east-1.amazonaws.com",
1414
protocol: "https:",
1515
path: "/my-path",
16+
headers: {
17+
authorization: /.{10,}/,
18+
},
1619
query: {
1720
apples: "oranges",
1821
},
1922
});
2023

2124
await client.predict({
22-
PredictEndpoint: `https://predict-custom-endpoint.us-west-2.amazonaws.com/my-path?apples=oranges`,
25+
PredictEndpoint: `https://predict-custom-endpoint.us-east-1.amazonaws.com/my-path?apples=oranges`,
26+
MLModelId: "1",
27+
Record: {
28+
hello: "world",
29+
},
30+
});
31+
32+
expect.hasAssertions();
33+
});
34+
35+
it("should be signed when URL query is empty", async () => {
36+
const client = new MachineLearning({
37+
region: "us-east-1",
38+
});
39+
40+
requireRequestsFrom(client).toMatch({
41+
hostname: "predict-custom-endpoint.us-east-1.amazonaws.com",
42+
protocol: "https:",
43+
path: "/my-path",
44+
headers: {
45+
authorization: /.{10,}/,
46+
},
47+
query: {},
48+
});
49+
50+
await client.predict({
51+
PredictEndpoint: `https://predict-custom-endpoint.us-east-1.amazonaws.com/my-path`,
2352
MLModelId: "1",
2453
Record: {
2554
hello: "world",

packages/middleware-sdk-machinelearning/src/predict-endpoint.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ export function predictEndpointMiddleware(options: { urlParser: UrlParser }): Bu
2424
path: endpoint.path,
2525
port: endpoint.port,
2626
protocol: endpoint.protocol,
27-
query: endpoint.query,
28-
};
27+
query: endpoint.query ?? {},
28+
} as HttpRequest;
2929
}
3030
}
3131
return next({

0 commit comments

Comments
 (0)