lib/runner/request-helpers-presend.js
function (context, run, done) {
        var request,
            pfxPath,
            keyPath,
            certPath,
            fileResolver,

            certificate;

        // A. Check if we have the file resolver
        fileResolver = run.options.fileResolver;

        if (!fileResolver) { return done(); } // No point going ahead

        // B. Ensure we have the request
        request = _.get(context.item, 'request');
        if (!request) { return done(new Error('No request to resolve certificates for.')); }

        // C. See if any cert should be sent, by performing a URL matching
        certificate = run.options.certificates && run.options.certificates.resolveOne(request.url);
        if (!certificate) { return done(); }

        // D. Fetch the paths
        // @todo: check why aren't we reading ca file (why are we not supporting ca file)
        pfxPath = _.get(certificate, 'pfx.src');
        keyPath = _.get(certificate, 'key.src');
        certPath = _.get(certificate, 'cert.src');

        // E. Read from the path, and add the values to the certificate, also associate
        // the certificate with the current request.
        async.mapValues({
            pfx: pfxPath,
            key: keyPath,
            cert: certPath
        }, function (value, key, next) {
            // bail out if value is not defined
            // @todo add test with server which only accepts cert file
            if (!value) { return next(); }

            // eslint-disable-next-line security/detect-non-literal-fs-filename
            fileResolver.readFile(value, function (err, data) {
                // Swallow the error after triggering a warning message for the user.
                err && run.triggers.console(context.coords, 'warn',
                    `certificate "${key}" load error:  ${(err.message || err)}`);
                next(null, data);
            });
        }, function (err, fileContents) {
            if (err) {
                // Swallow the error after triggering a warning message for the user.
                run.triggers.console(context.coords, 'warn', 'certificate load error: ' + (err.message || err));

                return done();
            }

            if (fileContents) {
                !_.isNil(fileContents.pfx) && _.set(certificate, 'pfx.value', fileContents.pfx);
                !_.isNil(fileContents.key) && _.set(certificate, 'key.value', fileContents.key);
                !_.isNil(fileContents.cert) && _.set(certificate, 'cert.value', fileContents.cert);

                (fileContents.cert || fileContents.key || fileContents.pfx) && (request.certificate = certificate);
            }
            done();
        });
    }
function (context, run, done) {
        var request,
            pfxPath,
            keyPath,
            certPath,
            fileResolver,

            certificate;

        // A. Check if we have the file resolver
        fileResolver = run.options.fileResolver;

        if (!fileResolver) { return done(); } // No point going ahead

        // B. Ensure we have the request
        request = _.get(context.item, 'request');
        if (!request) { return done(new Error('No request to resolve certificates for.')); }

        // C. See if any cert should be sent, by performing a URL matching
        certificate = run.options.certificates && run.options.certificates.resolveOne(request.url);
        if (!certificate) { return done(); }

        // D. Fetch the paths
        // @todo: check why aren't we reading ca file (why are we not supporting ca file)
        pfxPath = _.get(certificate, 'pfx.src');
        keyPath = _.get(certificate, 'key.src');
        certPath = _.get(certificate, 'cert.src');

        // E. Read from the path, and add the values to the certificate, also associate
        // the certificate with the current request.
        async.mapValues({
            pfx: pfxPath,
            key: keyPath,
            cert: certPath
        }, function (value, key, next) {
            // bail out if value is not defined
            // @todo add test with server which only accepts cert file
            if (!value) { return next(); }

            // eslint-disable-next-line security/detect-non-literal-fs-filename
            fileResolver.readFile(value, function (err, data) {
                // Swallow the error after triggering a warning message for the user.
                err && run.triggers.console(context.coords, 'warn',
                    `certificate "${key}" load error:  ${(err.message || err)}`);
                next(null, data);
            });
        }, function (err, fileContents) {
            if (err) {
                // Swallow the error after triggering a warning message for the user.
                run.triggers.console(context.coords, 'warn', 'certificate load error: ' + (err.message || err));

                return done();
            }

            if (fileContents) {
                !_.isNil(fileContents.pfx) && _.set(certificate, 'pfx.value', fileContents.pfx);
                !_.isNil(fileContents.key) && _.set(certificate, 'key.value', fileContents.key);
                !_.isNil(fileContents.cert) && _.set(certificate, 'cert.value', fileContents.cert);

                (fileContents.cert || fileContents.key || fileContents.pfx) && (request.certificate = certificate);
            }
            done();
        });
    }
function ( context , run , done ) { var request , pfxPath , keyPath , certPath , fileResolver , certificate ; // A. Check if we have the file resolver fileResolver = run . options . fileResolver ; if ( ! fileResolver ) { return done ( ) ; } // No point going ahead // B. Ensure we have the request request = _ . get ( context . item , 'request' ) ; if ( ! request ) { return done ( new Error ( 'No request to resolve certificates for.' ) ) ; } // C. See if any cert should be sent, by performing a URL matching certificate = run . options . certificates && run . options . certificates . resolveOne ( request . url ) ; if ( ! certificate ) { return done ( ) ; } // D. Fetch the paths // @todo: check why aren't we reading ca file (why are we not supporting ca file) pfxPath = _ . get ( certificate , 'pfx.src' ) ; keyPath = _ . get ( certificate , 'key.src' ) ; certPath = _ . get ( certificate , 'cert.src' ) ; // E. Read from the path, and add the values to the certificate, also associate // the certificate with the current request. async . mapValues ( { pfx : pfxPath , key : keyPath , cert : certPath } , function ( value , key , next ) { // bail out if value is not defined // @todo add test with server which only accepts cert file if ( ! value ) { return next ( ) ; } // eslint-disable-next-line security/detect-non-literal-fs-filename fileResolver . readFile ( value , function ( err , data ) { // Swallow the error after triggering a warning message for the user. err && run . triggers . console ( context . coords , 'warn' , ` ${ key } ${ ( err . message || err ) } ` ) ; next ( null , data ) ; } ) ; } , function ( err , fileContents ) { if ( err ) { // Swallow the error after triggering a warning message for the user. run . triggers . console ( context . coords , 'warn' , 'certificate load error: ' + ( err . message || err ) ) ; return done ( ) ; } if ( fileContents ) { ! _ . isNil ( fileContents . pfx ) && _ . set ( certificate , 'pfx.value' , fileContents . pfx ) ; ! _ . isNil ( fileContents . key ) && _ . set ( certificate , 'key.value' , fileContents . key ) ; ! _ . isNil ( fileContents . cert ) && _ . set ( certificate , 'cert.value' , fileContents . cert ) ; ( fileContents . cert || fileContents . key || fileContents . pfx ) && ( request . certificate = certificate ) ; } done ( ) ; } ) ; }
Certificate lookup + reading from whichever file resolver is provided
Certificate lookup + reading from whichever file resolver is provided