Open NghiaTranUIT opened 1 year ago
exec()
to run a command line. Ref: https://stackabuse.com/executing-shell-commands-with-node-js/let script = "cd \(path) && pwd && npm run start_ws"
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()
}
}
}
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
Acceptance Criteria