From f63422219c116b0d6876b91cb1804eebfa75eec3 Mon Sep 17 00:00:00 2001 From: thirug010 <30732819+thirug010@users.noreply.github.com> Date: Fri, 7 Apr 2023 14:31:44 -0500 Subject: [PATCH] Array.prototype methods cause validation error in the expected transports[] to be 'string' added condition to skip Array.prototype method irritated as item/object in the array --- dist/main.cjs | 22 ++++++++++++++-------- dist/main.js | 10 ++++++++++ lib/parser.js | 3 +++ lib/validator.js | 3 +++ 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/dist/main.cjs b/dist/main.cjs index fc5ddf4e..c06f1b38 100644 --- a/dist/main.cjs +++ b/dist/main.cjs @@ -1980,22 +1980,22 @@ async function validateExpectations() { if (!Array.isArray(allowCredentials)) { throw new Error("expected allowCredentials to be null or array"); } else { - for (const index in allowCredentials) { - if (typeof allowCredentials[index].id === "string") { - allowCredentials[index].id = coerceToArrayBuffer$1(allowCredentials[index].id, "allowCredentials[" + index + "].id"); + allowCredentials.forEach((allowCredential, index) => { + if (typeof allowCredential.id === "string") { + allowCredential.id = coerceToArrayBuffer$1(allowCredential.id, "allowCredentials[" + index + "].id"); } - if (allowCredentials[index].id == null || !(allowCredentials[index].id instanceof ArrayBuffer)) { + if (allowCredential.id == null || !(allowCredential.id instanceof ArrayBuffer)) { throw new Error("expected id of allowCredentials[" + index + "] to be ArrayBuffer"); } - if (allowCredentials[index].type == null || allowCredentials[index].type !== "public-key") { + if (allowCredential.type == null || allowCredential.type !== "public-key") { throw new Error("expected type of allowCredentials[" + index + "] to be string with value 'public-key'"); } - if (allowCredentials[index].transports != null && !Array.isArray(allowCredentials[index].transports)) { + if (allowCredential.transports != null && !Array.isArray(allowCredential.transports)) { throw new Error("expected transports of allowCredentials[" + index + "] to be array or null"); - } else if (allowCredentials[index].transports != null && !allowCredentials[index].transports.every(el => ["usb", "nfc", "ble", "cable", "internal"].includes(el))) { + } else if (allowCredential.transports != null && !allowCredential.transports.every(el => ["usb", "nfc", "ble", "cable", "internal"].includes(el))) { throw new Error("expected transports of allowCredentials[" + index + "] to be string with value 'usb', 'nfc', 'ble', 'cable', 'internal' or null"); } - } + }); } } @@ -2100,6 +2100,9 @@ async function validateTransports() { } for (const index in transports) { + if (typeof transports[index] == "function") { + continue; //expected transports[] are skipped; + } if (typeof transports[index] !== "string") { throw new Error("expected transports[" + index + "] to be 'string'"); } @@ -2704,6 +2707,9 @@ function parseExpectations(exp) { } for (const index in allowCredentials) { + if (typeof allowCredentials[index] == "function") { + continue; //expected allowCredentials[] are skipped; + } if (allowCredentials[index].id != null) { allowCredentials[index].id = coerceToArrayBuffer$1( allowCredentials[index].id, diff --git a/dist/main.js b/dist/main.js index f524f6f0..79cf7607 100644 --- a/dist/main.js +++ b/dist/main.js @@ -42933,6 +42933,10 @@ async function validateExpectations() { throw new Error("expected allowCredentials to be null or array"); } else { for(const index in allowCredentials){ + if (typeof allowCredentials[index] == "function") + { + continue; //expected allowCredentials[] are skipped; + } if (typeof allowCredentials[index].id === "string") { allowCredentials[index].id = coerceToArrayBuffer(allowCredentials[index].id, "allowCredentials[" + index + "].id"); } @@ -43020,6 +43024,9 @@ function parseExpectations(exp) { throw new TypeError("expected 'allowCredentials' to be null or array, got " + typeof allowCredentials); } for(const index in allowCredentials){ + if (typeof allowCredentials[index] == "function") { + continue; //expected allowCredentials[] are skipped; + } if (allowCredentials[index].id != null) { allowCredentials[index].id = coerceToArrayBuffer(allowCredentials[index].id, "allowCredentials[" + index + "].id"); } @@ -43763,6 +43770,9 @@ async function validateTransports() { throw new Error("expected transports to be 'null' or 'array'"); } for(const index in transports){ + if (typeof transports[index] == "function") { + continue; //expected transports[] are skipped; + } if (typeof transports[index] !== "string") { throw new Error("expected transports[" + index + "] to be 'string'"); } diff --git a/lib/parser.js b/lib/parser.js index a401b6bc..b128a8c4 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -108,6 +108,9 @@ function parseExpectations(exp) { } for (const index in allowCredentials) { + if (typeof allowCredentials[index] == "function") { + continue; //expected allowCredentials[] are skipped; + } if (allowCredentials[index].id != null) { allowCredentials[index].id = coerceToArrayBuffer( allowCredentials[index].id, diff --git a/lib/validator.js b/lib/validator.js index de1a8c56..33308393 100644 --- a/lib/validator.js +++ b/lib/validator.js @@ -250,6 +250,9 @@ async function validateTransports() { } for (const index in transports) { + if (typeof transports[index] == "function") { + continue; //expected transports[] are skipped; + } if (typeof transports[index] !== "string") { throw new Error("expected transports[" + index + "] to be 'string'"); }