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

Implement packet capture client and models #6317

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

niklasberglund
Copy link
Collaborator

@niklasberglund niklasberglund commented Jun 4, 2024

This PR adds support for packet capture in end to end tests. In BaseUITestCase there are the functions startPacketCapture() and stopPacketCapture() for tests to use for starting and stopping packet capture sessions. The PCAP file for a packet capture session will be attached to the test run in teardown.

Created testLeaks in LeakTests as an example of how to do packet capture. The test is just there as an example right now and is not analysing the captured traffic yet.

To test the changes in this PR out you will need to copy the latest UITests.xcconfig.template file or add this to your UITests.xcconfig file:

// Base URL for the packet capture API. Note that // will be treated as a comment, therefor you need to insert a ${} between the slashes for example http:/${}/8.8.8.8
PACKET_CAPTURE_BASE_URL = http:/${}/8.8.8.8

Also note that tests are now running on staging environment, so you need to connfigure staging accounts for NO_TIME_ACCOUNT_NUMBER and HAS_TIME_ACCOUNT_NUMBER in your UITests.xcconfig.

Try out the changes by running testLeaks. You must be on the app-team-ios-tests WiFi. After running the test you should find a PCAP file for the test run in the test report under tear down.
image


This change is Reviewable

Copy link

linear bot commented Jun 4, 2024

@niklasberglund niklasberglund force-pushed the write-a-test-class-that-will-automatically-capture-traffic-ios-534 branch 2 times, most recently from c49e7a7 to 96952e6 Compare June 4, 2024 09:13
@buggmagnet buggmagnet added the iOS Issues related to iOS label Jun 4, 2024
@niklasberglund niklasberglund force-pushed the write-a-test-class-that-will-automatically-capture-traffic-ios-534 branch from 96952e6 to cf113e0 Compare June 5, 2024 08:19
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.

Added a second attachment to test runs - JSON data. Maybe not something that should be kept later but it's very useful during development to inspect the data tests can see, rather than only inspecting the PCAP file which shows all traffic.

Reviewable status: 0 of 10 files reviewed, all discussions resolved

@niklasberglund niklasberglund force-pushed the write-a-test-class-that-will-automatically-capture-traffic-ios-534 branch 4 times, most recently from 2c2b408 to 233fbfb Compare June 12, 2024 08:28
Copy link
Contributor

@acb-mv acb-mv left a comment

Choose a reason for hiding this comment

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

Reviewed 10 of 10 files at r1.
Reviewable status: 8 of 10 files reviewed, all discussions resolved

@niklasberglund niklasberglund force-pushed the write-a-test-class-that-will-automatically-capture-traffic-ios-534 branch from 233fbfb to 01f98a5 Compare June 12, 2024 11:45
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 10 files reviewed, 1 unresolved discussion (waiting on @acb-mv)


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

                // Check if interface is en0 which is the WiFi connection on the iPhone
                let name = String(cString: interfacePointer.pointee.ifa_name)
                if name.hasPrefix("en") {

Fix for one of the Mullvad iPhones using network interface en2 instead of en0. I was under the impression all iPhones and iOS versions use en0 for the wifi network interface, but turned out other en interfaces can be used.

mojganii
mojganii previously approved these changes Jun 13, 2024
Copy link
Collaborator

@mojganii mojganii left a comment

Choose a reason for hiding this comment

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

it sometimes fails to retrieve file, perhaps there is some problem with IO which needs to be tested more.

Reviewable status: 7 of 10 files reviewed, 1 unresolved discussion (waiting on @acb-mv)

Copy link
Collaborator

@mojganii mojganii 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 10 files reviewed, 1 unresolved discussion (waiting on @acb-mv)

@niklasberglund niklasberglund force-pushed the write-a-test-class-that-will-automatically-capture-traffic-ios-534 branch from 01f98a5 to 557635d Compare June 20, 2024 08:59
acb-mv
acb-mv previously approved these changes Jul 3, 2024
Copy link
Contributor

@acb-mv acb-mv 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 2 files at r2, 1 of 1 files at r3, 2 of 2 files at r4, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion

@niklasberglund niklasberglund force-pushed the write-a-test-class-that-will-automatically-capture-traffic-ios-534 branch 3 times, most recently from 927294b to 89ea598 Compare July 5, 2024 09:08
@buggmagnet buggmagnet force-pushed the write-a-test-class-that-will-automatically-capture-traffic-ios-534 branch from 89ea598 to 89e9074 Compare August 12, 2024 11:31
@niklasberglund niklasberglund dismissed stale reviews from acb-mv and mojganii via 89e9074 August 22, 2024 07:30
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.

4 participants