Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add negative leak test for iOS #6449

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

niklasberglund
Copy link
Collaborator

@niklasberglund niklasberglund commented Jul 5, 2024

Adds basic leak tests which makes sure that traffic to a specific host goes through tunnel. There's a lot of room for improvement in how the window for packet capture is determined. Since local APIs cannot be accessed once connected to a relay the packet capture is started before connecting to relay, and stopped after disconnecting. Then a few seconds is trimmed from the beginning and end of the packet capture in order to not get any packet capture from when the tunnel connection was not up.

The changes in this PR can be tested by running the end to end tests testNoLeak and testShouldLeak.

Note: there's a known issue with the traffic generation. After setting up a tunnel connection all the connections for dummy traffic are blocked.


This change is Reviewable

@niklasberglund niklasberglund added the iOS Issues related to iOS label Jul 5, 2024
@niklasberglund niklasberglund force-pushed the iOS-negative-leak-tests branch from 45b5c0e to dc55447 Compare July 5, 2024 16:10
Copy link
Collaborator Author

@niklasberglund niklasberglund left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 13 files reviewed, 1 unresolved discussion (waiting on @pinkisemils)


ios/MullvadVPNUITests/Networking/StreamCollection.swift line 160 at r1 (raw file):

        }

        return DateInterval(start: startDate!, end: endDate!)

Left some illegal force unwrapping in this function which should probably be fixed 👮

Copy link
Collaborator Author

@niklasberglund niklasberglund left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 13 files reviewed, 2 unresolved discussions (waiting on @pinkisemils)


ios/MullvadVPNUITests/Base/BaseUITestCase.swift line 110 at r1 (raw file):

        let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")

        if springboard.buttons["Allowi"].waitForExistence(timeout: Self.shortTimeout) {

Typo "Allowi"

Copy link
Collaborator Author

@niklasberglund niklasberglund left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 13 files reviewed, 3 unresolved discussions (waiting on @pinkisemils)


ios/MullvadVPN.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved line 0 at r1 (raw file):
Restore 😄

@niklasberglund niklasberglund force-pushed the iOS-negative-leak-tests branch 2 times, most recently from e91216d to 811e8f4 Compare December 17, 2024 14:26
Copy link
Collaborator

@pinkisemils pinkisemils left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 3 of 13 files at r1, 7 of 11 files at r2, 3 of 5 files at r3, all commit messages.
Reviewable status: 11 of 15 files reviewed, 5 unresolved discussions (waiting on @niklasberglund)


ios/MullvadVPNUITests/LeakTests.swift line 87 at r3 (raw file):

        let capturedStreams = stopPacketCapture()
        LeakCheck.assertNoLeaks(streams: capturedStreams, rules: [NoTrafficToHostLeakRule(host: targetIPAddress)])

assertNoLeaks implies that it shouldn't leak, no? Or am I reading this wrong? :)


ios/MullvadVPNUITests/Base/BaseUITestCase.swift line 225 at r3 (raw file):

            // If there's a an active session due to cancelled/failed test run make sure to end it
            if packetCaptureSessionIsActive {

S

Copy link
Collaborator

@pinkisemils pinkisemils left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 13 files at r1, 1 of 5 files at r3.
Reviewable status: 13 of 15 files reviewed, 5 unresolved discussions (waiting on @niklasberglund)


ios/MullvadVPNUITests/Networking/Networking.swift line 32 at r3 (raw file):

class Networking {
    static func getIPAddress() throws -> String {
        var ipAddress: String

We actually have an API now to get the correct IP address here, there are devices in the office where en0 is not the WiFi interface. A simple GET on /own-ip will return the IP of the device.

@pinkisemils pinkisemils marked this pull request as ready for review December 19, 2024 09:12
@niklasberglund niklasberglund force-pushed the iOS-negative-leak-tests branch 3 times, most recently from 9b49b22 to 5cdb5b8 Compare December 19, 2024 10:29
Copy link
Collaborator Author

@niklasberglund niklasberglund left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 7 of 18 files reviewed, 3 unresolved discussions (waiting on @pinkisemils)


ios/MullvadVPNUITests/LeakTests.swift line 87 at r3 (raw file):

Previously, pinkisemils (Emīls Piņķis) wrote…

assertNoLeaks implies that it shouldn't leak, no? Or am I reading this wrong? :)

Haha yes you're right. Fixed


ios/MullvadVPNUITests/Base/BaseUITestCase.swift line 225 at r3 (raw file):

Previously, pinkisemils (Emīls Piņķis) wrote…

S

Did you mean to write something more? 😊


ios/MullvadVPNUITests/Networking/Networking.swift line 32 at r3 (raw file):

Previously, pinkisemils (Emīls Piņķis) wrote…

We actually have an API now to get the correct IP address here, there are devices in the office where en0 is not the WiFi interface. A simple GET on /own-ip will return the IP of the device.

Nice, using it instead now. There was a function to get IP address using the API in FirewallClient but I created a super class TestRouterAPIClient which all other "clients" inherit from. Moved the get IP address function to there because it's not firewall specific.

@niklasberglund niklasberglund force-pushed the iOS-negative-leak-tests branch 3 times, most recently from bd454de to bb8614c Compare December 19, 2024 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
iOS Issues related to iOS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants