47 lines
5.8 KiB
JavaScript
47 lines
5.8 KiB
JavaScript
"use strict";
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const os_1 = __importDefault(require("os"));
|
|
const debug_1 = __importDefault(require("debug"));
|
|
const base_1 = __importDefault(require("./base"));
|
|
const runtime_1 = require("../../errors/runtime");
|
|
const promisified_functions_1 = require("../promisified-functions");
|
|
const render_template_1 = __importDefault(require("../../utils/render-template"));
|
|
const types_1 = require("../../errors/types");
|
|
const warning_message_1 = __importDefault(require("../../notifications/warning-message"));
|
|
const DEBUG_LOGGER = (0, debug_1.default)('testcafe:utils:get-options:ssl');
|
|
const MAX_PATH_LENGTH = {
|
|
'Linux': 4096,
|
|
'Windows_NT': 260,
|
|
'Darwin': 1024,
|
|
};
|
|
const OS_MAX_PATH_LENGTH = MAX_PATH_LENGTH[os_1.default.type()];
|
|
const OPTIONS_SEPARATOR = ';';
|
|
const FILE_OPTION_NAMES = ['cert', 'key', 'pfx'];
|
|
async function default_1(optionString) {
|
|
return (0, base_1.default)(optionString, {
|
|
optionsSeparator: OPTIONS_SEPARATOR,
|
|
async onOptionParsed(key, value) {
|
|
if (!FILE_OPTION_NAMES.includes(key) || value.length > OS_MAX_PATH_LENGTH)
|
|
return value;
|
|
try {
|
|
await (0, promisified_functions_1.stat)(value);
|
|
}
|
|
catch (error) {
|
|
DEBUG_LOGGER((0, render_template_1.default)(warning_message_1.default.cannotFindSSLCertFile, value, key, error.stack));
|
|
return value;
|
|
}
|
|
try {
|
|
return await (0, promisified_functions_1.readFile)(value);
|
|
}
|
|
catch (error) {
|
|
throw new runtime_1.GeneralError(types_1.RUNTIME_ERRORS.cannotReadSSLCertFile, key, value, error.stack);
|
|
}
|
|
},
|
|
});
|
|
}
|
|
exports.default = default_1;
|
|
module.exports = exports.default;
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJza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ge1xuICAgICAgICAgICAgICAgIGF3YWl0IHN0YXQodmFsdWUpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgY2F0Y2ggKGVycm9yOiBhbnkpIHtcbiAgICAgICAgICAgICAgICBERUJVR19MT0dHRVIocmVuZGVyVGVtcGxhdGUoV0FSTklOR19NRVNTQUdFUy5jYW5ub3RGaW5kU1NMQ2VydEZpbGUsIHZhbHVlLCBrZXksIGVycm9yLnN0YWNrKSk7XG5cbiAgICAgICAgICAgICAgICByZXR1cm4gdmFsdWU7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIHRyeSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuIGF3YWl0IHJlYWRGaWxlKHZhbHVlKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGNhdGNoIChlcnJvcjogYW55KSB7XG4gICAgICAgICAgICAgICAgdGhyb3cgbmV3IEdlbmVyYWxFcnJvcihSVU5USU1FX0VSUk9SUy5jYW5ub3RSZWFkU1NMQ2VydEZpbGUsIGtleSwgdmFsdWUsIGVycm9yLnN0YWNrKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSxcbiAgICB9KTtcbn1cblxuIl19
|