From a0820a49095271072f81cc3335cfccd1ef622766 Mon Sep 17 00:00:00 2001 From: Jason Zou Date: Tue, 26 Sep 2023 20:14:11 -0400 Subject: [PATCH 1/5] Add system path check to start command --- browserup.load.yaml | 27 ++++++++++++++++++++ lib/commands/init.mjs | 14 +++++++++++ lib/commands/pathdetect.mjs | 48 ++++++++++++++++++++++++++++++++++++ postman/postman-example.json | 37 +++++++++++++++++++++++++++ 4 files changed, 126 insertions(+) create mode 100644 browserup.load.yaml create mode 100644 lib/commands/pathdetect.mjs create mode 100644 postman/postman-example.json diff --git a/browserup.load.yaml b/browserup.load.yaml new file mode 100644 index 00000000..ec95a9cb --- /dev/null +++ b/browserup.load.yaml @@ -0,0 +1,27 @@ +scenario: + name: GiveMeABetterName + total_users: 10 + profiles: + - name: "PostManExample" + command: "newman run --delay-request $THINK_TIME ./postman/postman-example.json" + think_time: "30s" + artifact_dir: "." + iteration_delay: "10s" + allocation: "100%" + stop_after: 15m + ramp: + - ramp_to: 100% + over: 5m + +reports: + - name: 'UrlResponseTime' + title: 'URL 90th Response Time (SLA)' + cards: + - type: 'line' + metrics: + - metric: 'urls.response_ms.avg' + check: + '<': 2000 + +settings: + cluster_type: local diff --git a/lib/commands/init.mjs b/lib/commands/init.mjs index 6fec1360..3a45e4c7 100644 --- a/lib/commands/init.mjs +++ b/lib/commands/init.mjs @@ -3,6 +3,19 @@ import fs from 'fs'; import path from 'path'; import ejs from 'ejs'; import {getAbsolutePathFromRelativeToRoot} from "../utils/path_utils.mjs"; +import {isSystemDirectory} from "../commands/pathdetect.mjs"; +import { fileURLToPath } from 'url'; +import { dirname } from 'path'; +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); + +let isSDirectory = isSystemDirectory(__dirname); +console.log(isSDirectory); +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 @@ -78,6 +91,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(','); diff --git a/lib/commands/pathdetect.mjs b/lib/commands/pathdetect.mjs new file mode 100644 index 00000000..a0c2d4b0 --- /dev/null +++ b/lib/commands/pathdetect.mjs @@ -0,0 +1,48 @@ +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 += '/'; + console.log(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); + } diff --git a/postman/postman-example.json b/postman/postman-example.json new file mode 100644 index 00000000..3c9281de --- /dev/null +++ b/postman/postman-example.json @@ -0,0 +1,37 @@ +{ + "info": { + "_postman_id": "04a340dd-30ed-4067-8757-b2b0a1a6d777", + "name": "Collection for Toy REST API", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", + "_exporter_id": "80898" + }, + "item": [ + { + "name": "http://playground.browserup.com/api/toys", + "request": { + "method": "GET", + "header": [ + { + "key": "Accept", + "value": "application/json", + "type": "text" + } + ], + "url": { + "raw": "http://playground.browserup.com/api/toys", + "protocol": "http", + "host": [ + "playground", + "browserup", + "com" + ], + "path": [ + "api", + "toys" + ] + } + }, + "response": [] + } + ] +} \ No newline at end of file From f5b263d3bedf63fa3e03ed8097b91b9928ca099c Mon Sep 17 00:00:00 2001 From: Jason Zou Date: Thu, 28 Sep 2023 12:10:26 -0400 Subject: [PATCH 2/5] Cleaned up init and path_detect.mjs, removed print lines, changed file names to snake case --- lib/commands/init.mjs | 7 +++--- lib/commands/path_detect.mjs | 47 ++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 lib/commands/path_detect.mjs diff --git a/lib/commands/init.mjs b/lib/commands/init.mjs index 3a45e4c7..716f9787 100644 --- a/lib/commands/init.mjs +++ b/lib/commands/init.mjs @@ -3,14 +3,13 @@ import fs from 'fs'; import path from 'path'; import ejs from 'ejs'; import {getAbsolutePathFromRelativeToRoot} from "../utils/path_utils.mjs"; -import {isSystemDirectory} from "../commands/pathdetect.mjs"; +import {isSystemDirectory} from "../commands/path_detect.mjs"; import { fileURLToPath } from 'url'; import { dirname } from 'path'; -const __filename = fileURLToPath(import.meta.url); -const __dirname = dirname(__filename); +const filename = fileURLToPath(import.meta.url); +const __dirname = dirname(filename); let isSDirectory = isSystemDirectory(__dirname); -console.log(isSDirectory); 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); diff --git a/lib/commands/path_detect.mjs b/lib/commands/path_detect.mjs new file mode 100644 index 00000000..98db1ddf --- /dev/null +++ b/lib/commands/path_detect.mjs @@ -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); + } From 614439396801afd351345d6ae542bdc8d85c8658 Mon Sep 17 00:00:00 2001 From: Jason Zou Date: Thu, 28 Sep 2023 12:23:47 -0400 Subject: [PATCH 3/5] updated variable name for the current directory --- lib/commands/init.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/commands/init.mjs b/lib/commands/init.mjs index 716f9787..430da590 100644 --- a/lib/commands/init.mjs +++ b/lib/commands/init.mjs @@ -7,9 +7,9 @@ import {isSystemDirectory} from "../commands/path_detect.mjs"; import { fileURLToPath } from 'url'; import { dirname } from 'path'; const filename = fileURLToPath(import.meta.url); -const __dirname = dirname(filename); +const directoryName = dirname(filename); -let isSDirectory = isSystemDirectory(__dirname); +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); From b9c6b5d49f765c1fa416f368b6aa46a4ed509578 Mon Sep 17 00:00:00 2001 From: Jason Zou Date: Thu, 28 Sep 2023 12:37:47 -0400 Subject: [PATCH 4/5] removed testing files --- files/browserup.load.yaml | 39 ----------------------------- lib/commands/pathdetect.mjs | 48 ------------------------------------ postman/postman-example.json | 37 --------------------------- 3 files changed, 124 deletions(-) delete mode 100644 files/browserup.load.yaml delete mode 100644 lib/commands/pathdetect.mjs delete mode 100644 postman/postman-example.json diff --git a/files/browserup.load.yaml b/files/browserup.load.yaml deleted file mode 100644 index ef1b86aa..00000000 --- a/files/browserup.load.yaml +++ /dev/null @@ -1,39 +0,0 @@ -scenario: - name: GiveMeABetterName - total_users: 50 - profiles: - - name: "PostManExample" - command: "newman run --delay-request $THINK_TIME postman-example.json" - think_time: "30s" - artifact_dir: "." - iteration_delay: "10s" - allocation: "34%" - - name: "PlayWrightJSExample" - command: "node playwright-js-example.js" - think_time: "30s" - artifact_dir: "." - iteration_delay: "10s" - allocation: "33%" - - name: "SeleniumPyExample" - command: "python3 selenium-js-example.cjs" - think_time: "30s" - artifact_dir: "." - iteration_delay: "10s" - allocation: "33%" - stop_after: 15m - ramp: - - ramp_to: 100% - over: 5m - -reports: - - name: "UrlResponseTime" - title: "URL 90th Response Time (SLA)" - type: "line" - cards: - - metrics: - - metric: "urls.response_ms.avg" - check: - "<": 2000 - -settings: - cluster_type: local diff --git a/lib/commands/pathdetect.mjs b/lib/commands/pathdetect.mjs deleted file mode 100644 index a0c2d4b0..00000000 --- a/lib/commands/pathdetect.mjs +++ /dev/null @@ -1,48 +0,0 @@ -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 += '/'; - console.log(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); - } diff --git a/postman/postman-example.json b/postman/postman-example.json deleted file mode 100644 index 3c9281de..00000000 --- a/postman/postman-example.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "info": { - "_postman_id": "04a340dd-30ed-4067-8757-b2b0a1a6d777", - "name": "Collection for Toy REST API", - "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", - "_exporter_id": "80898" - }, - "item": [ - { - "name": "http://playground.browserup.com/api/toys", - "request": { - "method": "GET", - "header": [ - { - "key": "Accept", - "value": "application/json", - "type": "text" - } - ], - "url": { - "raw": "http://playground.browserup.com/api/toys", - "protocol": "http", - "host": [ - "playground", - "browserup", - "com" - ], - "path": [ - "api", - "toys" - ] - } - }, - "response": [] - } - ] -} \ No newline at end of file From 22d5ebba1488a49811c41976654596ff7e23e1f0 Mon Sep 17 00:00:00 2001 From: Jason Zou Date: Thu, 28 Sep 2023 12:42:16 -0400 Subject: [PATCH 5/5] removed more testing files --- browserup.load.yaml | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 browserup.load.yaml diff --git a/browserup.load.yaml b/browserup.load.yaml deleted file mode 100644 index ec95a9cb..00000000 --- a/browserup.load.yaml +++ /dev/null @@ -1,27 +0,0 @@ -scenario: - name: GiveMeABetterName - total_users: 10 - profiles: - - name: "PostManExample" - command: "newman run --delay-request $THINK_TIME ./postman/postman-example.json" - think_time: "30s" - artifact_dir: "." - iteration_delay: "10s" - allocation: "100%" - stop_after: 15m - ramp: - - ramp_to: 100% - over: 5m - -reports: - - name: 'UrlResponseTime' - title: 'URL 90th Response Time (SLA)' - cards: - - type: 'line' - metrics: - - metric: 'urls.response_ms.avg' - check: - '<': 2000 - -settings: - cluster_type: local