You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is an odd use of both async/await and Promise.then, it works - but can be confusing for devs not used to it.
The then() clause assigns to a variable pubKey, which works in this case because of the await (if not pubKey would always be undefined), but it could just simply be the return value for the then(), and should therefore end up to be the return value of the await.
But the problematic item is the catch() clause. It returns helpers.exportFunctions.genErrorResponse(500, error.message), which has two problems:
Since the return value of the await is not used, this return value will never be used.
helpers.exportFunctions.genErrorResponse returns an object, and this function explicitly says it should return a string in the jsdoc. This is a mismatch.
This therefore renders the test "Test Fetch Key from CloudFront with Invalid Pub Key Url -> verify for invalid pub key" in signatureUtils.test.js as an invalid test since it will never throw an error. In fact the test is bogus (it passes but it is made to pass) - it doesn't really test the (mocked) return value - it tests an error that it sets up itself.
shazron
changed the title
Incorrect implemenation and test for function signatureUtils::fetchPublicKeyFromCloudFront
Incorrect implementation and test for function signatureUtils::fetchPublicKeyFromCloudFront
Aug 18, 2023
Function signatureUtils::fetchPublicKeyFromCloudFront:
aio-lib-events/src/signatureUtils.js
Lines 147 to 167 in bfb5e17
This is an odd use of both async/await and Promise.then, it works - but can be confusing for devs not used to it.
The then() clause assigns to a variable pubKey, which works in this case because of the await (if not pubKey would always be undefined), but it could just simply be the return value for the then(), and should therefore end up to be the return value of the await.
But the problematic item is the catch() clause. It returns
helpers.exportFunctions.genErrorResponse(500, error.message)
, which has two problems:helpers.exportFunctions.genErrorResponse
returns an object, and this function explicitly says it should return a string in the jsdoc. This is a mismatch.This therefore renders the test "Test Fetch Key from CloudFront with Invalid Pub Key Url -> verify for invalid pub key" in signatureUtils.test.js as an invalid test since it will never throw an error. In fact the test is bogus (it passes but it is made to pass) - it doesn't really test the (mocked) return value - it tests an error that it sets up itself.
The test is here:
aio-lib-events/test/signatureUtils.test.js
Lines 73 to 90 in bfb5e17
The text was updated successfully, but these errors were encountered: