[GH-ISSUE #274] Block List #4: Unit Test #274

Open
opened 2026-03-03 19:49:33 +03:00 by kerem · 1 comment
Owner

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

Originally assigned to: @kics223w1 on GitHub.

Description

It's time to write Unit Test to verify the Block Tool is working

Acceptance Criteria

1. Block & Hide

Please reference the macOS Unit Test:

    func testBlackListWithSSLProxying_BlockAndHide() throws {

        // create a server with a given pool
        let pool = FlowPool()
        core = PMProxyServer.allwaysInterceptCore(pool)

        // start
        runProxyCore { (expectation) in
            let group = DispatchGroup()

            //
            let url = "https://httpbin.proxyman.app/get?action=block_list"
            let entry = try! BlacklistEntry(url: url, isIncludingPaths: true, isEnabled: true, method: .any, regex: .useWildcard, blockAction: .blockAndHide)
            BlacklistService.shared.add(entry)

            group.enter()
            self.manager.request(url, method: .get).responseJSON { response in
                defer {
                    group.leave()
                }

                XCTAssertNil(response.data)
            }

            group.enter()
            let passURL = "https://www.google.com/"
            self.manager.request(passURL, method: .get).responseJSON { response in
                defer {
                    group.leave()
                }

                XCTAssertEqual(200, response.response?.statusCode)
            }


            // done
            _ = group.wait(timeout: .now() + .seconds(15))

            // make sure only 1 blocklist is passed
            XCTAssertEqual(1, pool.allFlows.count)
            XCTAssertEqual(passURL, pool.allFlows.first?.request.fullPath)
            expectation.fulfill()
        }
    }
  1. It creates a Proxy Server and inject the pool
  2. Start the server -> Create a block rule -> Make 2 requests to different domains (1 is matched with the block list)
  3. Wait until two async requests are completed
  4. Verify the Pool
  5. Verify the request in the pool
  6. Also verify the blocked Request is closed!

=> Implement similar Unit Test for the Block & Hide

2. Block, but not hide

  1. Implement a similar logic.
  • Verify Pool length = 2
  • Verify google.com is a success
  • Verify the block request is closed!
  • verify the URL of two requests in the Pool

3. Hide, not block

  1. Implement a similar logic.
  • Verify Pool length = 1
  • Verify google.com is a success
  • verify httpbin.proxyman.app is a success.
  • verify the URL of two requests in the Pool
Originally created by @NghiaTranUIT on GitHub (Jul 20, 2023). Original GitHub issue: https://github.com/ProxymanApp/proxyman-windows-linux/issues/274 Originally assigned to: @kics223w1 on GitHub. ## Description It's time to write Unit Test to verify the Block Tool is working ## Acceptance Criteria ### 1. Block & Hide Please reference the macOS Unit Test: ```swift func testBlackListWithSSLProxying_BlockAndHide() throws { // create a server with a given pool let pool = FlowPool() core = PMProxyServer.allwaysInterceptCore(pool) // start runProxyCore { (expectation) in let group = DispatchGroup() // let url = "https://httpbin.proxyman.app/get?action=block_list" let entry = try! BlacklistEntry(url: url, isIncludingPaths: true, isEnabled: true, method: .any, regex: .useWildcard, blockAction: .blockAndHide) BlacklistService.shared.add(entry) group.enter() self.manager.request(url, method: .get).responseJSON { response in defer { group.leave() } XCTAssertNil(response.data) } group.enter() let passURL = "https://www.google.com/" self.manager.request(passURL, method: .get).responseJSON { response in defer { group.leave() } XCTAssertEqual(200, response.response?.statusCode) } // done _ = group.wait(timeout: .now() + .seconds(15)) // make sure only 1 blocklist is passed XCTAssertEqual(1, pool.allFlows.count) XCTAssertEqual(passURL, pool.allFlows.first?.request.fullPath) expectation.fulfill() } } ``` 1. It creates a Proxy Server and inject the pool 2. Start the server -> Create a block rule -> Make 2 requests to different domains (1 is matched with the block list) 3. Wait until two async requests are completed 4. Verify the Pool 5. Verify the request in the pool 6. Also verify the blocked Request is closed! ✅ => Implement similar Unit Test for the Block & Hide ### 2. Block, but not hide 1. Implement a similar logic. - Verify Pool length = 2 - Verify google.com is a success - Verify the block request is closed! - verify the URL of two requests in the Pool ### 3. Hide, not block 1. Implement a similar logic. - Verify Pool length = 1 - Verify google.com is a success - verify httpbin.proxyman.app is a success. - verify the URL of two requests in the Pool
Author
Owner

@NghiaTranUIT commented on GitHub (Jul 20, 2023):

  • Write some Unit Tests that you think it's important.
<!-- gh-comment-id:1643963033 --> @NghiaTranUIT commented on GitHub (Jul 20, 2023): - Write some Unit Tests that you think it's important.
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#274
No description provided.