[GH-ISSUE #297] Websocket: Logic for WS #2 #296

Open
opened 2026-03-03 19:49:41 +03:00 by kerem · 2 comments
Owner

Originally created by @NghiaTranUIT on GitHub (Aug 23, 2023).
Original GitHub issue: https://github.com/ProxymanApp/proxyman-windows-linux/issues/297

Originally assigned to: @kics223w1 on GitHub.

Description

This ticket is for WebSocket (WS). It's similar to HTTP, which is an insecure connection.

This ticket should be implemented at the same time as #296

⚠️ Do not start the WSS ticket until this this ticket is reviewed and done.

How to start a Websocket

  1. Open Proxyman for macOS
  2. Clone this repo: https://github.com/NghiaTranUIT/websocket-usercases
  3. Start Proxyman for macOS on port 9090
  4. npm i
  5. npm run start_ws
  6. Observe the WebSocket flow on the app

Acceptance Criteria

  • Able to see WebSocket messages on the app
  • Because it's an Insecure web socket, no need to enable SSL Proxying -> I'm still able to see the WebSocket content
Originally created by @NghiaTranUIT on GitHub (Aug 23, 2023). Original GitHub issue: https://github.com/ProxymanApp/proxyman-windows-linux/issues/297 Originally assigned to: @kics223w1 on GitHub. ## Description This ticket is for WebSocket (WS). It's similar to HTTP, which is an insecure connection. This ticket should be implemented at the same time as #296 ⚠️ Do not start the WSS ticket until this this ticket is reviewed and done. ## How to start a Websocket 1. Open Proxyman for macOS 2. Clone this repo: https://github.com/NghiaTranUIT/websocket-usercases 3. Start Proxyman for macOS on port 9090 4. npm i 5. npm run start_ws 6. Observe the WebSocket flow on the app ## Acceptance Criteria - Able to see WebSocket messages on the app - Because it's an Insecure web socket, no need to enable SSL Proxying -> I'm still able to see the WebSocket content
Author
Owner

@NghiaTranUIT commented on GitHub (Aug 23, 2023):

Unit Tests

How to Setup the Unit Test + Websocket

  1. Add the WebSocket Repo to the Testing Folder -> Make sure we don't include it in the main app
  2. use exec() to run a command line. Ref: https://stackabuse.com/executing-shell-commands-with-node-js/
  3. Depending on what Unit Test cases, the script can be different. For example:
let script = "cd \(path) && pwd && npm run start_ws"
  1. Wait until the shell is finished
  2. Verify the command shell runs fine
  3. Get the FlowPool -> Get the first websocket message -> Assert the storage (Message total, data, ...)
  • Sample Unit Test:
    /// Typical WS Websocket, which is made from Web Browser,
    /// It uses CONNECT -> Go to SSL Handler -> Websocket Handler
    func testNonSecureWebsocketClientFromNodeJS() {
        let pool = FlowPool()
        core = PMProxyServer.allwaysInterceptCore(pool)
        let path = getWebsocketClientPath()
        runProxyCore { (expectation) in

            // call the nodejs client
            let script = "cd \(path) && pwd && npm run start_ws"

            do {
                // Run it
                // Run it
                guard let _ = try runCommandLineWithCurrentShell(cmd: script) else {
                    XCTFail("Could not command line")
                    return
                }

                // Test
                XCTAssertEqual(1, pool.count)
                let flow = pool.allFlows.first
                let message = flow!.websocketMessageStorage!.receipts

                XCTAssertEqual(11, message.count)
                XCTAssertEqual(5, message.filter { $0.from == .client}.count )
                XCTAssertEqual(6, message.filter { $0.from == .server}.count )

                let json = #"""
{"name":"John","age":30,"city":"New York"}
"""#
                let isContainsJSON = message.contains { message in
                    return message.rawMessage == json
                }
                XCTAssertTrue(isContainsJSON)

                // Done
                expectation.fulfill()
            } catch let error {
                Log.error(error)
                XCTFail()
                expectation.fulfill()
            }
        }
    }

1. Unit Test: Test Websocket

  • Given: Start the WebSocket from the repo and proxy to Proxyman Test
  • Expected:
    => The WebSocket works fine, no errors
    => Assert all WebSocket message -> Verify it's correct.
<!-- gh-comment-id:1689188542 --> @NghiaTranUIT commented on GitHub (Aug 23, 2023): ## Unit Tests ### How to Setup the Unit Test + Websocket 1. Add the WebSocket Repo to the Testing Folder -> Make sure we don't include it in the main app 2. use `exec()` to run a command line. Ref: https://stackabuse.com/executing-shell-commands-with-node-js/ 3. Depending on what Unit Test cases, the script can be different. For example: ```swift let script = "cd \(path) && pwd && npm run start_ws" ``` 4. Wait until the shell is finished 5. ✅ Verify the command shell runs fine 6. ✅ Get the FlowPool -> Get the first websocket message -> Assert the storage (Message total, data, ...) - Sample Unit Test: ```swift /// Typical WS Websocket, which is made from Web Browser, /// It uses CONNECT -> Go to SSL Handler -> Websocket Handler func testNonSecureWebsocketClientFromNodeJS() { let pool = FlowPool() core = PMProxyServer.allwaysInterceptCore(pool) let path = getWebsocketClientPath() runProxyCore { (expectation) in // call the nodejs client let script = "cd \(path) && pwd && npm run start_ws" do { // Run it // Run it guard let _ = try runCommandLineWithCurrentShell(cmd: script) else { XCTFail("Could not command line") return } // Test XCTAssertEqual(1, pool.count) let flow = pool.allFlows.first let message = flow!.websocketMessageStorage!.receipts XCTAssertEqual(11, message.count) XCTAssertEqual(5, message.filter { $0.from == .client}.count ) XCTAssertEqual(6, message.filter { $0.from == .server}.count ) let json = #""" {"name":"John","age":30,"city":"New York"} """# let isContainsJSON = message.contains { message in return message.rawMessage == json } XCTAssertTrue(isContainsJSON) // Done expectation.fulfill() } catch let error { Log.error(error) XCTFail() expectation.fulfill() } } } ``` ------------------ ### 1. Unit Test: Test Websocket - Given: Start the WebSocket from the repo and proxy to Proxyman Test - Expected: => The WebSocket works fine, no errors => Assert all WebSocket message -> Verify it's correct.
Author
Owner

@NghiaTranUIT commented on GitHub (Aug 23, 2023):

How to test WS / WSS manually

  1. Open Proxyman
  2. Open Postman with Websocket
  • WSS: wss://ws.postman-echo.com/raw
  • WS: ws://echo.websocket.events
  1. Connect and type message
  2. For each message -> Observe the message on Proxyman app
<!-- gh-comment-id:1689212254 --> @NghiaTranUIT commented on GitHub (Aug 23, 2023): ### How to test WS / WSS manually 1. Open Proxyman 2. Open Postman with Websocket - WSS: wss://ws.postman-echo.com/raw - WS: ws://echo.websocket.events 3. Connect and type message 4. For each message -> Observe the message on Proxyman app
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/proxyman-windows-linux#296
No description provided.