Skip to content

Commit 43b08ad

Browse files
authored
Merge pull request #5 from BrowserStackCE/semgrep-fix
added filename sanitization
2 parents 9929bbf + 0057f59 commit 43b08ad

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules/
2-
package-lock.json
2+
package-lock.json
3+
semgrep.sarif

index.mjs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,28 @@ import commander from 'commander';
1010
import logger from 'cli-logger';
1111
import glob from 'glob';
1212
import spawn from 'cross-spawn';
13-
import * as dotenv from 'dotenv';
13+
import * as dotenv from 'dotenv';
1414
import { exit } from 'process';
15+
import sanitize from 'sanitize-filename';
16+
1517
dotenv.config();
1618
commander
1719
.usage('[options] project.side [project.side] [*.side]')
1820
.option('-d, --debug', 'output extra debugging')
1921
.option('-f, --filter <grep regex>', 'Run tests matching name')
2022
.option('--base-url <url>', 'Override the base URL that was set in the IDE')
2123
.option('--test-timeout <ms>', 'Timeout value for each tests (default: 30000)')
22-
.option('--browserstack.config <path>','path to browserstack config file, default to browserstack.yml')
24+
.option('--browserstack.config <path>', 'path to browserstack config file, default to browserstack.yml')
2325
.option('--output-format <json|xunit>', 'Format for the output file.')
24-
.option('--output-file <path>','path for the report file. required if --output-format provided')
26+
.option('--output-file <path>', 'path for the report file. required if --output-format provided')
2527

2628
commander.parse(process.argv);
2729
const options = commander.opts();
2830
options.testTimeout = options.testTimeout ? options.testTimeout : 30000
2931
options.filter = options.filter ? options.filter : ''
3032
options.browserstackConfig = options['browserstack.config'] ? options['browserstack.config'] : 'browserstack.yml'
3133
options.buildFolderPath = '_generated'
32-
var conf = {level: options.debug ? logger.DEBUG :logger.INFO};
34+
var conf = { level: options.debug ? logger.DEBUG : logger.INFO };
3335
var log = logger(conf);
3436

3537
const sideFiles = [
@@ -49,7 +51,7 @@ function readFile(filename) {
4951
fs.readFileSync(
5052
path.join(
5153
'.',
52-
filename
54+
sanitize(filename)
5355
)
5456
)
5557
)
@@ -64,21 +66,18 @@ function normalizeProject(project) {
6466
return _project
6567
}
6668

67-
for(const sideFileName of sideFiles)
68-
{
69+
for (const sideFileName of sideFiles) {
6970
const project = normalizeProject(readFile(sideFileName))
70-
for(const aSuite of project.suites)
71-
{
72-
for(const aTestCase of aSuite.tests)
73-
{
71+
for (const aSuite of project.suites) {
72+
for (const aTestCase of aSuite.tests) {
7473
const test = project.tests.find(test => test.name === aTestCase);
7574
var results = await codeExport.default.emit.test({
7675
baseUrl: options.baseUrl ? options.baseUrl : project.url,
7776
test: test,
7877
tests: project.tests,
7978
project: project
8079
})
81-
fs.writeFileSync( path.join(
80+
fs.writeFileSync(path.join(
8281
options.buildFolderPath,
8382
results.filename
8483
), results.body);
@@ -88,13 +87,12 @@ for(const sideFileName of sideFiles)
8887
}
8988

9089
var reporter = []
91-
if(options.outputFormat && options.outputFile)
92-
reporter = [ '--reporter', options.outputFormat, '--reporter-options', 'output=' + options.outputFile]
90+
if (options.outputFormat && options.outputFile)
91+
reporter = ['--reporter', options.outputFormat, '--reporter-options', 'output=' + options.outputFile]
9392

9493
const testSuiteProcess = spawn.sync('npx', ['browserstack-node-sdk', 'mocha', '_generated', '--timeouts', options.testTimeout, '-g', options.filter, '--browserstack.config', options.browserstackConfig, ...reporter], { stdio: 'inherit', env: { ...process.env, testTimeout: options.testTimeout } });
9594

96-
if(!options.debug)
97-
{
95+
if (!options.debug) {
9896
rimraf.sync(options.buildFolderPath)
9997
}
10098
exit(testSuiteProcess.status)

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"type": "git",
55
"url": "git+https://github.com/BrowserStackCE/browserstack-side-runner.git"
66
},
7-
"version": "2.2.1",
7+
"version": "2.2.2",
88
"main": "index.mjs",
99
"homepage": "https://github.com/BrowserStackCE/browserstack-side-runner#readme",
1010
"scripts": {
@@ -32,6 +32,7 @@
3232
"mocha-multi-reporters": "^1.5.1",
3333
"rfdc": "^1.3.0",
3434
"rimraf": "^6.0.1",
35+
"sanitize-filename": "^1.6.3",
3536
"selenium-webdriver": "^4.1.1"
3637
}
37-
}
38+
}

0 commit comments

Comments
 (0)