From e1b82dc78cc0ba463a21694e52cfbbe1cd8e4df7 Mon Sep 17 00:00:00 2001 From: Tres Finocchiaro Date: Mon, 4 Sep 2023 15:00:16 -0400 Subject: [PATCH] Make callCert() rejectable (#1172) * Make callCert() rejectable (not working) Co-authored-by: Berenz <5912715+akberenz@users.noreply.github.com> --- js/qz-tray.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/js/qz-tray.js b/js/qz-tray.js index 694fcfa5e..25ac3d698 100644 --- a/js/qz-tray.js +++ b/js/qz-tray.js @@ -363,7 +363,12 @@ var qz = (function() { _qz.security.callCert().then(sendCert).catch(function(error) { _qz.log.warn("Failed to get certificate:", error); - sendCert(null); + + if (_qz.security.rejectOnCertFailure) { + openPromise.reject(error); + } else { + sendCert(null); + } }); }, @@ -579,6 +584,8 @@ var qz = (function() { /** Signing algorithm used on signatures */ signAlgorithm: "SHA1", + rejectOnCertFailure: false, + needsSigned: function(callName) { const undialoged = [ "printers.getStatus", @@ -2595,11 +2602,13 @@ var qz = (function() { * * @param {Function|AsyncFunction|Promise} promiseHandler Either a function that will be used as a promise resolver (of format Function({function} resolve, {function}reject)), * an async function, or a promise. Any of which should return the public certificate via their respective resolve call. - * + * @param {Object} [options] Configuration options for the certificate resolver + * @param {boolean} [options.rejectOnFailure=[false]] Overrides default behavior to call resolve with a blank certificate on failure. * @memberof qz.security */ - setCertificatePromise: function(promiseHandler) { + setCertificatePromise: function(promiseHandler, options) { _qz.security.certHandler = promiseHandler; + _qz.security.rejectOnCertFailure = !!(options && options.rejectOnFailure); }, /**