Skip to content

Commit

Permalink
Merge pull request #4 from browserup/sys32
Browse files Browse the repository at this point in the history
Add system path check to start command
  • Loading branch information
zoujas authored Sep 28, 2023
2 parents 6732084 + 22d5ebb commit 2bc922e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 39 deletions.
39 changes: 0 additions & 39 deletions files/browserup.load.yaml

This file was deleted.

13 changes: 13 additions & 0 deletions lib/commands/init.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ import fs from 'fs';
import path from 'path';
import ejs from 'ejs';
import {getAbsolutePathFromRelativeToRoot} from "../utils/path_utils.mjs";
import {isSystemDirectory} from "../commands/path_detect.mjs";
import { fileURLToPath } from 'url';
import { dirname } from 'path';
const filename = fileURLToPath(import.meta.url);
const directoryName = dirname(filename);

let isSDirectory = isSystemDirectory(directoryName);
if(isSDirectory == true){
console.log("WARNING. You are currently in a system directory(ex: /bin,sys32), please switch to a subdirectory before proceeding.");
process.exit(1);
}


// const TEST_TYPES = ['postman', 'curl', 'java', 'ruby', 'python', 'playwright-js', 'playwright-python', 'selenium-ruby', 'selenium-java', 'selenium-python', 'custom']; // Replace with your actual TEST_TYPES values

Expand Down Expand Up @@ -78,6 +90,7 @@ export function init(options, _programOpts) {
total_users: 10,
exampleArr: exampleArr}


let renderedConfig = ejs.render(template, templateVars );
let outputPath = path.join(process.cwd(), "browserup.load.yaml");
let exampleStr = Array.from(examples).join(',');
Expand Down
47 changes: 47 additions & 0 deletions lib/commands/path_detect.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
export function isSystemDirectory(dirPath) {
// Normalize the directory path to lower case and ensure it ends with a slash
dirPath = dirPath.toLowerCase().replace(/\\+/g, '/');
if (!dirPath.endsWith('/')) {
dirPath += '/';
}

// Known system directories for Windows and Linux
const windowsSystemDirs = [
'c:/',
'c:/windows/',
'c:/program files/',
'c:/program files (x86)/',
'c:/programdata/',
'c:/users/',
'c:/windows/system32/',
'c:/windows/syswow64/'
];

const linuxSystemDirs = [
'/',
'/bin/',
'/sbin/',
'/usr/',
'/usr/bin/',
'/usr/sbin/',
'/etc/',
'/var/',
'/var/lib/',
'/opt/',
'/lib/',
'/lib64/',
'/tmp/',
'/boot/',
'/home/',
'/root/',
'/mnt/',
'/media/',
'/srv/'
];

// Combine both lists
const systemDirs = windowsSystemDirs.concat(linuxSystemDirs);

// Check if the directory path is an exact match to any known system directory
return systemDirs.includes(dirPath);
}

0 comments on commit 2bc922e

Please sign in to comment.