Skip to content

Commit

Permalink
Fix CloudAPL response parsing (#149)
Browse files Browse the repository at this point in the history
* Fix CloudAPL response parsing

* Mock signature fetch
  • Loading branch information
krzysztofwolski authored Jan 13, 2023
1 parent 99d7ac5 commit 8dccb00
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/APL/saleor-cloud-apl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ const mapAuthDataToAPIBody = (authData: AuthData) => ({
token: authData.token,
});

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const mapAPIResponseToAuthData = (response: any): AuthData => ({
appId: response.saleor_app_id,
domain: response.domain,
jwks: response.jwks,
saleorApiUrl: response.saleor_api_url,
token: response.token,
});

/**
*
* Saleor Cloud APL - handle auth data management via REST API.
Expand Down Expand Up @@ -68,7 +77,8 @@ export class SaleorCloudAPL implements APL {
debug("Failed to parse response: %s", e?.message ?? "Unknown error");
})) as unknown;

const authData = authDataFromObject(parsedResponse);
const authData = authDataFromObject(mapAPIResponseToAuthData(parsedResponse));

if (!authData) {
debug("No auth data for given saleorApiUrl");
return undefined;
Expand Down
3 changes: 3 additions & 0 deletions src/handlers/next/process-async-saleor-webhook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ describe("processAsyncSaleorWebhook", () => {

it("Throw error on wrong signature", async () => {
mockRequest.headers["saleor-signature"] = "wrong_signature";
vi.mock("./../../fetch-remote-jwks", () => ({
fetchRemoteJwks: vi.fn(() => "wrong_signature"),
}));
await expect(
processAsyncSaleorWebhook({
req: mockRequest,
Expand Down

0 comments on commit 8dccb00

Please sign in to comment.