-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Task/Issue URL: https://app.asana.com/0/0/1206919998699658/f iOS PR: duckduckgo/iOS#2636 macOS PR: duckduckgo/macos-browser#2498 What kind of version bump will this require?: Minor ## Description Adds some new errors to improve tracking of pixel errors.
- Loading branch information
1 parent
24da852
commit c2ae796
Showing
6 changed files
with
251 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
Tests/NetworkProtectionTests/NetworkProtectionErrorTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// | ||
// NetworkProtectionErrorTests.swift | ||
// | ||
// Copyright © 2024 DuckDuckGo. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import Foundation | ||
import XCTest | ||
@testable import NetworkProtection | ||
|
||
final class NetworkProtectionErrorTests: XCTestCase { | ||
|
||
/// Tests that `TunnelError`implements `CustomNSError`. | ||
/// | ||
func testThatNetworkProtectionErrorImplementsCustomNSError() { | ||
let genericError: Error = NetworkProtectionError.noServerRegistrationInfo | ||
|
||
XCTAssertNotNil(genericError as? CustomNSError) | ||
} | ||
|
||
/// Test that some `NetworkProtectionError` have no underlying errors. | ||
/// | ||
func testThatSomeErrorsHaveNoUnderlyingError() { | ||
let errorsWithoutUnderlyingError: [NetworkProtectionError] = [ | ||
.noServerRegistrationInfo, | ||
.couldNotSelectClosestServer, | ||
.couldNotGetPeerPublicKey, | ||
.couldNotGetPeerHostName, | ||
.couldNotGetInterfaceAddressRange, | ||
.failedToEncodeRegisterKeyRequest, | ||
.failedToEncodeRedeemRequest, | ||
.invalidInviteCode, | ||
.invalidAuthToken, | ||
.serverListInconsistency, | ||
.noServerListFound, | ||
.wireGuardCannotLocateTunnelFileDescriptor, | ||
.wireGuardDnsResolution, | ||
.noAuthTokenFound, | ||
.vpnAccessRevoked, | ||
.failedToCastKeychainValueToData(field: "test"), | ||
.keychainReadError(field: "test", status: 1), | ||
.keychainWriteError(field: "test", status: 1), | ||
.keychainUpdateError(field: "test", status: 1), | ||
.keychainDeleteError(status: 1), | ||
.wireGuardInvalidState(reason: "test"), | ||
.startWireGuardBackend(1), | ||
|
||
] | ||
|
||
for error in errorsWithoutUnderlyingError { | ||
let nsError = error as NSError | ||
XCTAssertEqual(nsError.userInfo[NSUnderlyingErrorKey] as? NSError, nil) | ||
} | ||
} | ||
|
||
func testThatSomeErrorsHaveUnderlyingErrors() { | ||
let underlyingError = NSError(domain: "test", code: 1) | ||
|
||
let errorsWithUnderlyingError: [NetworkProtectionError] = [ | ||
.failedToFetchServerList(underlyingError), | ||
.failedToParseServerListResponse(underlyingError), | ||
.failedToFetchLocationList(underlyingError), | ||
.failedToParseLocationListResponse(underlyingError), | ||
.failedToFetchRegisteredServers(underlyingError), | ||
.failedToParseRegisteredServersResponse(underlyingError), | ||
.failedToRedeemInviteCode(underlyingError), | ||
.failedToParseRedeemResponse(underlyingError), | ||
.failedToEncodeServerList(underlyingError), | ||
.failedToDecodeServerList(underlyingError), | ||
.failedToWriteServerList(underlyingError), | ||
.couldNotCreateServerListDirectory(underlyingError), | ||
.failedToReadServerList(underlyingError), | ||
.wireGuardSetNetworkSettings(underlyingError), | ||
.unhandledError(function: #function, line: #line, error: underlyingError), | ||
] | ||
|
||
for error in errorsWithUnderlyingError { | ||
let nsError = error as NSError | ||
XCTAssertEqual(nsError.userInfo[NSUnderlyingErrorKey] as? NSError, underlyingError) | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
Tests/NetworkProtectionTests/PacketTunnelProviderTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// | ||
// PacketTunnelProviderTests.swift | ||
// | ||
// Copyright © 2024 DuckDuckGo. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import Foundation | ||
import XCTest | ||
@testable import NetworkProtection | ||
|
||
final class PacketTunnelProviderTests: XCTestCase { | ||
|
||
typealias TunnelError = PacketTunnelProvider.TunnelError | ||
|
||
/// Tests that `TunnelError`implements `CustomNSError`. | ||
/// | ||
func testThatTunnelErrorImplementsCustomNSError() { | ||
let genericError: Error = TunnelError.startingTunnelWithoutAuthToken | ||
|
||
XCTAssertNotNil(genericError as? CustomNSError) | ||
} | ||
|
||
/// Tests that `TunnelError` has the expected underlying error information. | ||
/// | ||
func testThatTunnelErrorHasTheExpectedUnderlyingErrorInformation() { | ||
XCTAssertEqual(TunnelError.startingTunnelWithoutAuthToken.errorUserInfo[NSUnderlyingErrorKey] as? NSError, nil) | ||
XCTAssertEqual(TunnelError.simulateTunnelFailureError.errorUserInfo[NSUnderlyingErrorKey] as? NSError, nil) | ||
XCTAssertEqual(TunnelError.vpnAccessRevoked.errorUserInfo[NSUnderlyingErrorKey] as? NSError, nil) | ||
|
||
let underlyingError = NSError(domain: "test", code: 1) | ||
XCTAssertEqual(TunnelError.couldNotGenerateTunnelConfiguration(internalError: underlyingError).errorUserInfo[NSUnderlyingErrorKey] as? NSError, underlyingError) | ||
} | ||
} |
Oops, something went wrong.