Fix CloudAPL response parsing (#149)

* Fix CloudAPL response parsing

* Mock signature fetch
This commit is contained in:
Krzysztof Wolski 2023-01-13 16:35:16 +01:00 committed by GitHub
parent 99d7ac58e9
commit 8dccb00edd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View file

@ -25,6 +25,15 @@ const mapAuthDataToAPIBody = (authData: AuthData) => ({
token: authData.token, 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. * 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"); debug("Failed to parse response: %s", e?.message ?? "Unknown error");
})) as unknown; })) as unknown;
const authData = authDataFromObject(parsedResponse); const authData = authDataFromObject(mapAPIResponseToAuthData(parsedResponse));
if (!authData) { if (!authData) {
debug("No auth data for given saleorApiUrl"); debug("No auth data for given saleorApiUrl");
return undefined; return undefined;

View file

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