Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add system path check to start command #4

Merged
merged 5 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
Loading