summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormojganii <mojgan.jelodar@codic.se>2025-03-27 09:55:53 +0100
committermojganii <mojgan.jelodar@codic.se>2025-04-15 15:38:45 +0200
commitd7dcd81cc2c9238cb21d5036ee3dc4baadd2d02b (patch)
tree994fc004e873851c392bfaeacd8faaf82d9babf4
parent4f52ef7f5f4072ff53d1ddc1f358cbf3e35a6d14 (diff)
downloadmullvadvpn-d7dcd81cc2c9238cb21d5036ee3dc4baadd2d02b.tar.xz
mullvadvpn-d7dcd81cc2c9238cb21d5036ee3dc4baadd2d02b.zip
Add test for validating string for meta data
-rw-r--r--ios/MullvadREST/Rust/RustProblemReportRequest.swift2
-rw-r--r--ios/MullvadRustRuntime/MullvadApiCancellable.swift5
-rw-r--r--ios/MullvadVPN.xcodeproj/project.pbxproj12
-rw-r--r--ios/MullvadVPNTests/MullvadREST/MullvadApi/RustProblemReportRequestTests.swift71
4 files changed, 85 insertions, 5 deletions
diff --git a/ios/MullvadREST/Rust/RustProblemReportRequest.swift b/ios/MullvadREST/Rust/RustProblemReportRequest.swift
index 8bd8a4490f..8ac4fd1339 100644
--- a/ios/MullvadREST/Rust/RustProblemReportRequest.swift
+++ b/ios/MullvadREST/Rust/RustProblemReportRequest.swift
@@ -48,7 +48,7 @@ final public class RustProblemReportRequest {
)
}
- public func release() {
+ deinit {
swift_problem_report_meta_data_free(problemReportMetaData)
addressPointer?.pointer?.deallocate()
messagePointer?.pointer?.deallocate()
diff --git a/ios/MullvadRustRuntime/MullvadApiCancellable.swift b/ios/MullvadRustRuntime/MullvadApiCancellable.swift
index 3c7c184096..6c76bc3c14 100644
--- a/ios/MullvadRustRuntime/MullvadApiCancellable.swift
+++ b/ios/MullvadRustRuntime/MullvadApiCancellable.swift
@@ -10,15 +10,12 @@ import MullvadTypes
public class MullvadApiCancellable: Cancellable {
private let handle: SwiftCancelHandle
- private let deinitializer: (() -> Void)?
- public init(handle: consuming SwiftCancelHandle, deinitializer: (() -> Void)? = nil) {
+ public init(handle: consuming SwiftCancelHandle) {
self.handle = handle
- self.deinitializer = deinitializer
}
deinit {
- deinitializer?()
mullvad_api_cancel_task_drop(handle)
}
diff --git a/ios/MullvadVPN.xcodeproj/project.pbxproj b/ios/MullvadVPN.xcodeproj/project.pbxproj
index 7adfaf5e2d..7d5e8377bf 100644
--- a/ios/MullvadVPN.xcodeproj/project.pbxproj
+++ b/ios/MullvadVPN.xcodeproj/project.pbxproj
@@ -1083,6 +1083,7 @@
F0E8E4C92A604E7400ED26A3 /* AccountDeletionInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0E8E4C82A604E7400ED26A3 /* AccountDeletionInteractor.swift */; };
F0EEFBA22D8D61A9007FE4B3 /* RustProblemReportRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0EEFB9E2D8D60E1007FE4B3 /* RustProblemReportRequest.swift */; };
F0EF50D52A949F8E0031E8DF /* ChangeLogViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0EF50D42A949F8E0031E8DF /* ChangeLogViewModel.swift */; };
+ F0F146942D9462E100BF78E7 /* RustProblemReportRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0F146912D94491200BF78E7 /* RustProblemReportRequestTests.swift */; };
F0F316192BF3572B0078DBCF /* RelaySelectorResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0F316182BF3572B0078DBCF /* RelaySelectorResult.swift */; };
F0F3161B2BF358590078DBCF /* NoRelaysSatisfyingConstraintsError.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0F3161A2BF358590078DBCF /* NoRelaysSatisfyingConstraintsError.swift */; };
F0F56B092C0E058A009D676B /* ObserverList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58CC40EE24A601900019D96E /* ObserverList.swift */; };
@@ -2484,6 +2485,7 @@
F0E8E4C82A604E7400ED26A3 /* AccountDeletionInteractor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountDeletionInteractor.swift; sourceTree = "<group>"; };
F0EEFB9E2D8D60E1007FE4B3 /* RustProblemReportRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RustProblemReportRequest.swift; sourceTree = "<group>"; };
F0EF50D42A949F8E0031E8DF /* ChangeLogViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChangeLogViewModel.swift; sourceTree = "<group>"; };
+ F0F146912D94491200BF78E7 /* RustProblemReportRequestTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RustProblemReportRequestTests.swift; sourceTree = "<group>"; };
F0F1EF8C2BE8FF0A00CED01D /* LaunchArguments.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LaunchArguments.swift; sourceTree = "<group>"; };
F0F316182BF3572B0078DBCF /* RelaySelectorResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelaySelectorResult.swift; sourceTree = "<group>"; };
F0F3161A2BF358590078DBCF /* NoRelaysSatisfyingConstraintsError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NoRelaysSatisfyingConstraintsError.swift; sourceTree = "<group>"; };
@@ -2745,6 +2747,7 @@
440E9EF32BDA942E00B1FD11 /* MullvadREST */ = {
isa = PBXGroup;
children = (
+ F0F146932D9462BA00BF78E7 /* MullvadApi */,
7AD63A452CDA665200445268 /* Extensions */,
F072D3D02C071A9100906F64 /* Shadowsocks */,
440E9EF42BDA943B00B1FD11 /* ApiHandlers */,
@@ -4821,6 +4824,14 @@
path = ChangeLog;
sourceTree = "<group>";
};
+ F0F146932D9462BA00BF78E7 /* MullvadApi */ = {
+ isa = PBXGroup;
+ children = (
+ F0F146912D94491200BF78E7 /* RustProblemReportRequestTests.swift */,
+ );
+ path = MullvadApi;
+ sourceTree = "<group>";
+ };
F0FA16072D7F03F8007E2546 /* Filter */ = {
isa = PBXGroup;
children = (
@@ -6007,6 +6018,7 @@
F0D5591F2D38051C0072B63F /* LatestChangesNotificationProvider.swift in Sources */,
7A9F28FC2CA69D0C005F2089 /* DAITASettingsTests.swift in Sources */,
A9A5FA2F2ACB05160083449F /* FixedWidthIntegerArithmeticsTests.swift in Sources */,
+ F0F146942D9462E100BF78E7 /* RustProblemReportRequestTests.swift in Sources */,
7AA513862BC91C6B00D081A4 /* LogRotationTests.swift in Sources */,
F04413622BA45CE30018A6EE /* CustomListLocationNodeBuilder.swift in Sources */,
A9A5FA302ACB05160083449F /* InputTextFormatterTests.swift in Sources */,
diff --git a/ios/MullvadVPNTests/MullvadREST/MullvadApi/RustProblemReportRequestTests.swift b/ios/MullvadVPNTests/MullvadREST/MullvadApi/RustProblemReportRequestTests.swift
new file mode 100644
index 0000000000..44e800fab4
--- /dev/null
+++ b/ios/MullvadVPNTests/MullvadREST/MullvadApi/RustProblemReportRequestTests.swift
@@ -0,0 +1,71 @@
+//
+// RustProblemReportRequestTests.swift
+// MullvadVPN
+//
+// Created by Mojgan on 2025-03-26.
+// Copyright © 2025 Mullvad VPN AB. All rights reserved.
+//
+
+import Testing
+
+@testable import MullvadREST
+@testable import MullvadRustRuntime
+
+struct RustProblemReportRequestTests {
+ @Test(
+ "Test vaild metadata insertion for SendProblemReport",
+ arguments: [
+ ["key1": "value1"],
+ ["key2": "value2"],
+ ["long_key_abcdefghijklmnopqrstuvwxyz": "long_value_1234567890"],
+ ["special_chars_!@#$%": "special_value_(*&^%)"],
+ ["": ""],
+ ]
+ )
+ func testMetadataInsertion(metadata: [String: String]) {
+ let request = REST.ProblemReportRequest(
+ address: "127.0.0.1",
+ message: "Test message",
+ log: "Log data",
+ metadata: metadata
+ )
+ let rustRequest = RustProblemReportRequest(from: request)
+ let rustStruct = rustRequest.toRust()
+ #expect(rustStruct.meta_data != nil, "Metadata should not be for \(metadata)")
+ }
+
+ @Test(
+ "Test invalid metadata insertion for SendProblemReport"
+ )
+ func testInvalidMetadataHandling() {
+ let invalidMetadata: [[UInt8]] = [
+ [0xC0, 0x80], // Incomplete UTF-8 byte sequence
+ [0x80], // Invalid start byte in UTF-8
+ [0xE0, 0x80], // Malformed UTF-8 multibyte sequence
+ ]
+
+ let metadata = swift_problem_report_meta_data_new()
+
+ for byteArray in invalidMetadata {
+ byteArray.withUnsafeBytes { (keyPtr: UnsafeRawBufferPointer) in
+ byteArray.withUnsafeBytes { (valuePtr: UnsafeRawBufferPointer) in
+
+ guard let keyBaseAddress = keyPtr.baseAddress?.assumingMemoryBound(to: UInt8.self),
+ let valueBaseAddress = valuePtr.baseAddress?.assumingMemoryBound(to: UInt8.self) else {
+ return
+ }
+ let result = swift_problem_report_meta_data_add(
+ metadata,
+ keyBaseAddress,
+ valueBaseAddress
+ )
+
+ #expect(
+ result == false,
+ "Metadata with invalid UTF-8 should not be added. Key/Value: \(byteArray)"
+ )
+ }
+ }
+ }
+ }
+}