forked from DevExpress/testcafe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement a possibility to run TestCafe over https (close DevExpress#…
…1985) (DevExpress#2540) * implement a possibility to run TestCafe over https * update text * update option description * fix review issues
- Loading branch information
1 parent
e6aa20e
commit 4ddb6cc
Showing
8 changed files
with
158 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import fs from 'fs'; | ||
import os from 'os'; | ||
|
||
const MAX_PATH_LENGTH = { | ||
'Linux': 4096, | ||
'Windows_NT': 260, | ||
'Darwin': 1024 | ||
}; | ||
|
||
const OS_MAX_PATH_LENGTH = MAX_PATH_LENGTH[os.type()]; | ||
|
||
const OPTIONS_SEPARATOR = ';'; | ||
const OPTION_KEY_VALUE_SEPARATOR = '='; | ||
const FILE_OPTION_NAMES = ['cert', 'key', 'pfx']; | ||
const NUMBER_REG_EX = /^[0-9-.,]+$/; | ||
const BOOLEAN_STRING_VALUES = ['true', 'false']; | ||
|
||
export default function (optionsStr = '') { | ||
const splittedOptions = optionsStr.split(OPTIONS_SEPARATOR); | ||
|
||
if (!splittedOptions.length) | ||
return null; | ||
|
||
const parsedOptions = {}; | ||
|
||
splittedOptions.forEach(item => { | ||
const keyValuePair = item.split(OPTION_KEY_VALUE_SEPARATOR); | ||
const key = keyValuePair[0]; | ||
let value = keyValuePair[1]; | ||
|
||
if (!key || !value) | ||
return; | ||
|
||
value = convertToBestFitType(value); | ||
|
||
if (FILE_OPTION_NAMES.includes(key) && value.length < OS_MAX_PATH_LENGTH && fs.existsSync(value)) | ||
value = fs.readFileSync(value); | ||
|
||
parsedOptions[key] = value; | ||
}); | ||
|
||
return parsedOptions; | ||
} | ||
|
||
function convertToBestFitType (valueStr) { | ||
if (typeof valueStr !== 'string') | ||
return void 0; | ||
|
||
else if (NUMBER_REG_EX.test(valueStr)) | ||
return parseFloat(valueStr); | ||
|
||
else if (BOOLEAN_STRING_VALUES.includes(valueStr)) | ||
return valueStr === 'true'; | ||
|
||
else if (!valueStr.length) | ||
return void 0; | ||
|
||
return valueStr; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters