Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: browserstack/requests-debugger
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.0.0
Choose a base ref
...
head repository: browserstack/requests-debugger
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref

Commits on Oct 8, 2020

  1. Copy the full SHA
    bdafb4d View commit details

Commits on Oct 9, 2020

  1. fix for proxy host

    neerajshukla1911 committed Oct 9, 2020
    Copy the full SHA
    3af63ab View commit details
  2. refactor

    neerajshukla1911 committed Oct 9, 2020
    Copy the full SHA
    b5582c4 View commit details

Commits on Oct 12, 2020

  1. mremoved

    neerajshukla1911 committed Oct 12, 2020
    Copy the full SHA
    d93a2e0 View commit details
  2. reverse proxy tests

    neerajshukla1911 committed Oct 12, 2020
    Copy the full SHA
    853c140 View commit details

Commits on Oct 14, 2020

  1. https support

    neerajshukla1911 committed Oct 14, 2020
    Copy the full SHA
    e02d3ab View commit details
  2. refactor

    neerajshukla1911 committed Oct 14, 2020
    Copy the full SHA
    d58a203 View commit details
  3. refactor and tests

    neerajshukla1911 committed Oct 14, 2020
    Copy the full SHA
    00327ba View commit details
  4. Copy the full SHA
    678e456 View commit details
  5. Copy the full SHA
    94ce40c View commit details
  6. refactored code

    neerajshukla1911 committed Oct 14, 2020
    Copy the full SHA
    b77557d View commit details
  7. bug fix

    neerajshukla1911 committed Oct 14, 2020
    Copy the full SHA
    8fe5b23 View commit details

Commits on Oct 15, 2020

  1. Copy the full SHA
    a1e8281 View commit details
  2. version bump

    neerajshukla1911 committed Oct 15, 2020
    Copy the full SHA
    c8fa1f9 View commit details

Commits on Oct 16, 2020

  1. Copy the full SHA
    d62fd57 View commit details
  2. request log change

    neerajshukla1911 committed Oct 16, 2020
    Copy the full SHA
    b44e248 View commit details
  3. log url fix

    neerajshukla1911 committed Oct 16, 2020
    Copy the full SHA
    949c0c3 View commit details

Commits on Oct 19, 2020

  1. refactored code

    neerajshukla1911 committed Oct 19, 2020
    Copy the full SHA
    3eb7827 View commit details
  2. bug fix

    neerajshukla1911 committed Oct 19, 2020
    Copy the full SHA
    50744b3 View commit details
  3. Copy the full SHA
    b81b4eb View commit details
  4. refactored code

    neerajshukla1911 committed Oct 19, 2020
    Copy the full SHA
    99412f5 View commit details
  5. refactor

    neerajshukla1911 committed Oct 19, 2020
    Copy the full SHA
    8c62005 View commit details
  6. more refactore

    neerajshukla1911 committed Oct 19, 2020
    Copy the full SHA
    1deee5a View commit details
  7. Copy the full SHA
    2305517 View commit details

Commits on Oct 20, 2020

  1. tests

    neerajshukla1911 committed Oct 20, 2020
    Copy the full SHA
    0f31476 View commit details
  2. lint fix and test

    neerajshukla1911 committed Oct 20, 2020
    Copy the full SHA
    7b9b8c6 View commit details
  3. readme and refactor

    neerajshukla1911 committed Oct 20, 2020
    Copy the full SHA
    2c70cbf View commit details
  4. bug fix

    neerajshukla1911 committed Oct 20, 2020
    Copy the full SHA
    d799697 View commit details
  5. unit tests

    neerajshukla1911 committed Oct 20, 2020
    Copy the full SHA
    939d4b7 View commit details
  6. lint fix

    neerajshukla1911 committed Oct 20, 2020
    Copy the full SHA
    269f7eb View commit details
  7. refactor

    neerajshukla1911 committed Oct 20, 2020
    Copy the full SHA
    1d0b707 View commit details
  8. Copy the full SHA
    cef8c1e View commit details
  9. more refactor

    neerajshukla1911 committed Oct 20, 2020
    Copy the full SHA
    9e382d1 View commit details

Commits on Oct 21, 2020

  1. Copy the full SHA
    b6af389 View commit details
  2. Copy the full SHA
    3ee7f44 View commit details
  3. Copy the full SHA
    d0464c2 View commit details
  4. added tests

    neerajshukla1911 committed Oct 21, 2020
    Copy the full SHA
    59987ea View commit details
  5. bug fix

    neerajshukla1911 committed Oct 21, 2020
    Copy the full SHA
    406abf6 View commit details
  6. refactor

    neerajshukla1911 committed Oct 21, 2020
    Copy the full SHA
    4930ed1 View commit details

Commits on Oct 23, 2020

  1. bug fix for logging

    neerajshukla1911 committed Oct 23, 2020
    Copy the full SHA
    95f96f2 View commit details
  2. Copy the full SHA
    4f25a94 View commit details

Commits on Oct 26, 2020

  1. doc changes

    neerajshukla1911 committed Oct 26, 2020
    Copy the full SHA
    8828e6d View commit details
  2. Copy the full SHA
    a9ff653 View commit details
  3. Copy the full SHA
    2970e3c View commit details
  4. Merge pull request #1 from rchougule/reverse-proxy-with-https

    Github Actions setup for unit tests. Logo and badge addition in README
    neerajshukla1911 authored Oct 26, 2020
    Copy the full SHA
    37e90bb View commit details

Commits on Oct 27, 2020

  1. Merge pull request #7 from neerajshukla1911/reverse-proxy-with-https

    Reverse proxy with https support
    francisf authored Oct 27, 2020
    Copy the full SHA
    c9dbc80 View commit details

Commits on Jan 7, 2021

  1. Copy the full SHA
    1683c10 View commit details
  2. Copy the full SHA
    1ab8c3a View commit details
  3. Copy the full SHA
    5e39341 View commit details
  4. Copy the full SHA
    f6dfd11 View commit details
4 changes: 3 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -16,7 +16,9 @@ module.exports = {
"indent": ["error", 2],
"linebreak-style": [ "error", "unix"],
"semi": ["error", "always"],
"eol-last": ["error", "always"]
"eol-last": ["error", "always"],
"keyword-spacing": [1],
"no-trailing-spaces": ["error", { "skipBlankLines": true }]
},
"overrides": [{
"files": ["src/requestsDebugger.js", "src/commandLine.js", "test/**/*.test.js"],
48 changes: 48 additions & 0 deletions .github/workflows/Semgrep.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Name of this GitHub Actions workflow.
name: Semgrep

on:
# Scan changed files in PRs (diff-aware scanning):
# The branches below must be a subset of the branches above
pull_request:
branches: ["master", "main"]
push:
branches: ["master", "main"]
schedule:
- cron: '0 6 * * *'


permissions:
contents: read

jobs:
semgrep:
# User definable name of this GitHub Actions job.
permissions:
contents: read # for actions/checkout to fetch code
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
name: semgrep/ci
# If you are self-hosting, change the following `runs-on` value:
runs-on: ubuntu-latest

container:
# A Docker image with Semgrep installed. Do not change this.
image: returntocorp/semgrep

# Skip any PR created by dependabot to avoid permission issues:
if: (github.actor != 'dependabot[bot]')

steps:
# Fetch project source with GitHub Actions Checkout.
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
# Run the "semgrep ci" command on the command line of the docker image.
- run: semgrep ci --sarif --output=semgrep.sarif
env:
# Add the rules that Semgrep uses by setting the SEMGREP_RULES environment variable.
SEMGREP_RULES: p/default # more at semgrep.dev/explore

- name: Upload SARIF file for GitHub Advanced Security Dashboard
uses: github/codeql-action/upload-sarif@6c089f53dd51dc3fc7e599c3cb5356453a52ca9e # v2.20.0
with:
sarif_file: semgrep.sarif
if: always()
32 changes: 32 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: 'unit-tests'
on:
pull_request:
paths:
- './**'
- '.github/workflows/unit-tests*'
push:
paths:
- './**'
- '.github/workflows/unit-tests*'

jobs:
unit-tests:
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v2

- name: Set Node.js 4.9.1
uses: actions/setup-node@master
with:
node-version: 4.9.1

- name: npm install
working-directory: ./
run: npm install

- name: Lint and Unit tests
working-directory: ./
run: npm run test
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -108,3 +108,9 @@ dist
RequestsDebugger-Mac
RequestsDebugger.exe
RequestsDebugger-Linux*

# VS code settings
.vscode/

# Others
.DS_Store
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @browserstack/default_owner
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
## Requests Debugger

<p align="center">
<a href="https://browserstack.com"><img alt="BrowserStack Logo" src="https://d98b8t1nnulk5.cloudfront.net/production/images/layout/logo-invoice.svg"></a>
</p>

<p align="center">
<a href="https://github.com/browserstack/requests-debugger/actions?query=workflow%3Aunit-tests"><img alt="unit-tests build status" src="https://github.com/browserstack/requests-debugger/workflows/unit-tests/badge.svg"></a>
</p>

### Tool for debugging client side failure of requests, leading to requests getting dropped or not reaching BrowserStack.

## Features
- Proxy Server to intercept requests fired by client bindings to keep track of their flow.
- Server to intercept requests fired by client bindings to keep track of their flow.
- Connectivity Checker : To check for the reachability of BrowserStack components, i.e. Rails & Hub.
- Multi-Platform Stats Compatibility : Ability to collect stats of CPU, Network & Memory Stats.
- Retry Mechanism in case a request fails at the client side

## How to run
- Code
- Install all the required packages: `npm install`
- Start Requests Debugger with the required arguments: `npm run start -- <args>`.
- Start Requests Debugger with the required arguments: `npm run start -- <args>`. On windows, use `node src\requestsDebugger.js` if npm run start fails.
- Supported `args`:
- `--port <port>`: Port on which the Requests Debugger Tool's Proxy will run. Default: 9687
- `--reverse-proxy-port <port>`: Port on which the Requests Debugger Tool's Reverse Proxy will run. Default: 9688
- `--scheme <https/http>`: Scheme for requests to browserstack. Default: https
- `--proxy-host <hostname>`: Hostname of the Upstream Proxy
- `--proxy-port <port>`: Port of the Upstream Proxy. Default: 3128 (if hostname is provided)
- `--proxy-user <username>`: Username for auth of the Upstream Proxy
@@ -30,7 +41,8 @@
- Windows: `RequestsDebugger.exe <args>`

## How to use
- Since the tool acts like a proxy, you will have to set the proxy to be used by your client binding to `localhost:9687`. i.e.
- To use tool as reverse proxy, you will have to replace `hub-cloud.browserstack.com` in hub url with `localhost:9688`.
- To use tool as a proxy, you will have to set the proxy to be used by your client binding to `localhost:9687`. i.e.
- For Java:
- ```
System.getProperties().put("http.proxyHost", "localhost");
@@ -40,7 +52,7 @@
- Set your system's env variable `http_proxy=localhost:9687` and Ruby's Selenium Client Binding will pick the value. Or,
- Run you test by giving the environment variable to your command itself, i.e. `http_proxy=localhost:9687 ruby <your_script.rb>`
- Similarly, you can also set proxy for other client bindings.
## Steps to build the executables
- Linux
- `npm run build:linux`
32 changes: 22 additions & 10 deletions config/constants.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
module.exports.VERSION = '1.0.0';
module.exports.HUB_STATUS_URL = 'http://hub-cloud.browserstack.com/wd/hub/status';
module.exports.RAILS_AUTOMATE = 'http://automate.browserstack.com';
module.exports.VERSION = '1.1.0';
module.exports.BS_DOMAIN = 'browserstack.com';
module.exports.HUB_HOST = 'hub-cloud.' + this.BS_DOMAIN;
module.exports.RAILS_HOST = 'automate.' + this.BS_DOMAIN;
module.exports.HUB_STATUS_PATH = '/wd/hub/status';
module.exports.HUB_STATUS_URL = 'http://' + this.HUB_HOST + this.HUB_STATUS_PATH;
module.exports.HUB_STATUS_URL_HTTPS = 'https://' + this.HUB_HOST + this.HUB_STATUS_PATH;
module.exports.RAILS_AUTOMATE = 'http://' + this.RAILS_HOST;
module.exports.RAILS_AUTOMATE_HTTPS = 'https://' + this.RAILS_HOST;
module.exports.CONNECTIVITY_REQ_TIMEOUT = 30000;
module.exports.DEFAULT_PROXY_PORT = 3128;
module.exports.CUSTOM_ERROR_RESPONSE_CODE = 502;
@@ -10,6 +16,8 @@ module.exports.PORTS = {
MAX: 65535,
MIN: 1
};

module.exports.LINE_LENGTH = 70;
module.exports.PROTOCOL_REGEX = /(^\w+:|^)\/\//;

module.exports.LOGS = Object.freeze({
@@ -23,13 +31,15 @@ module.exports.LOGS = Object.freeze({

module.exports.RdGlobalConfig = {
RETRY_DELAY: 1000, // in ms
RD_HANDLER_PORT: process.env.NODE_ENV === 'test' ? 8787 : 9687,
RD_HANDLER_PROXY_PORT: process.env.NODE_ENV === 'test' ? 8787 : 9687,
RD_HANDLER_REVERSE_PROXY_PORT: process.env.NODE_ENV === 'test' ? 8788 : 9688,
CLIENT_REQ_TIMEOUT: 260000, // in ms
SCHEME: 'https'
};

module.exports.COMMON = Object.freeze({
PING_HUB: 'ping -c 5 hub-cloud.browserstack.com',
PING_AUTOMATE: 'ping -c 5 automate.browserstack.com'
PING_HUB: 'ping -c 5 ' + this.HUB_HOST,
PING_AUTOMATE: 'ping -c 5 ' + this.RAILS_HOST
});

module.exports.MAC = Object.freeze({
@@ -49,8 +59,8 @@ module.exports.WIN = Object.freeze({
NETSTAT_ROUTING_TABLE: 'netstat -r',
IPCONFIG_ALL: 'ipconfig /all',
SWAP_USAGE: 'pagefile get AllocatedBaseSize, CurrentUsage', // this is a WMIC command. Prefix with WMIC Path
PING_HUB: 'ping -n 5 hub-cloud.browserstack.com',
PING_AUTOMATE: 'ping -n 5 automate.browserstack.com',
PING_HUB: 'ping -n 5 ' + this.HUB_HOST,
PING_AUTOMATE: 'ping -n 5 ' + this.RAILS_HOST,
LOAD_PERCENTAGE: 'cpu get loadpercentage', // prefix wmic path
});

@@ -78,8 +88,10 @@ module.exports.STATIC_MESSAGES = Object.freeze({
CHECK_NETWORK_STATS: 'Stats : Checking Network Stats',
CHECK_MEMORY_STATS: 'Stats : Checking Memory Stats',
CHECK_CONNECTIVITY: 'Checks : Checking Connectivity With BrowserStack',
ERR_STARTING_TOOL: 'Error in starting Requests Debugger Tool Proxy: ',
TOOL_STARTED_ON_PORT: 'Requests Debugger Tool Proxy Started on Port: ',
ERR_STARTING_TOOL_PROXY: 'Error in starting Requests Debugger Tool Proxy: ',
ERR_STARTING_TOOL_REVERSE_PROXY: 'Error in starting Requests Debugger Tool Reverse Proxy: ',
TOOL_PROXY_STARTED_ON_PORT: 'Requests Debugger Tool Proxy Server Started on Port: ',
TOOL_REVESE_PROXY_STARTED_ON_PORT: 'Requests Debugger Tool Reverse Proxy Server Started on Port: ',
CPU_STATS_COLLECTED: 'Stats : Initial CPU Stats Collected',
NETWORK_STATS_COLLECTED: 'Stats : Initial Network Stats Collected',
MEMORY_STATS_COLLECTED: 'Stats : Initial Memory Stats Collected',
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -6,13 +6,13 @@
"scripts": {
"start": "NODE_ENV=prod node src/requestsDebugger.js",
"lint": "./node_modules/.bin/eslint 'src/*' 'test/*' 'config/*.js'",
"test": "npm run lint; NODE_ENV=test nyc --reporter=html ./node_modules/mocha/bin/mocha 'test/**/*.test.js'",
"test": "npm run lint; NODE_ENV=test ./node_modules/nyc/bin/nyc.js --reporter=html ./node_modules/mocha/bin/mocha 'test/**/*.test.js'",
"build:mac": "npm install; ./node_modules/pkg/lib-es5/bin.js -t node4-macos-x64 src/requestsDebugger.js; mv requestsDebugger RequestsDebugger-Mac",
"build:linux-x86": "npm install; ./node_modules/pkg/lib-es5/bin.js -t node4-linux-x86 src/requestsDebugger.js; mv requestsDebugger RequestsDebugger-Linux-x86",
"build:linux-x64": "npm install; ./node_modules/pkg/lib-es5/bin.js -t node4-linux-x64 src/requestsDebugger.js; mv requestsDebugger RequestsDebugger-Linux-x64",
"build:linux": "npm run build:linux-x86; npm run build:linux-x64",
"build:win": "npm install; ./node_modules/pkg/lib-es5/bin.js -t node4-win-x86 src/requestsDebugger.js; mv requestsDebugger.exe RequestsDebugger.exe",
"copyhooks": "cp hooks/* .git/hooks/; chmod +x .git/hooks/*",
"copyhooks": "node ./scripts/copyhooks.js",
"postinstall": "npm run copyhooks"
},
"bin": {
@@ -34,6 +34,8 @@
"sinon": "7.5.0"
},
"dependencies": {
"http-proxy-agent": "^2.1.0",
"https-proxy-agent": "^2.1.0",
"uuid": "3.4.0",
"winston": "2.4.4"
},
12 changes: 12 additions & 0 deletions scripts/copyhooks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const fs = require('fs');
const path = require('path');

const srcDir = './hooks/';
const dstDir = './.git/hooks/'

fs.readdirSync(srcDir).forEach(file => {
const srcFile = path.join(srcDir, file);
const dstFile = path.join(dstDir, file);
fs.createReadStream(srcFile).pipe(fs.createWriteStream(dstFile));
fs.chmodSync(dstFile , '755');
});
Loading