Fix CloudAPL response parsing (#149)
* Fix CloudAPL response parsing * Mock signature fetch
This commit is contained in:
parent
99d7ac58e9
commit
8dccb00edd
2 changed files with 14 additions and 1 deletions
|
@ -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.
|
||||
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue