diff --git a/Sources/NetworkProtection/FeatureActivation/NetworkProtectionCodeRedemptionCoordinator.swift b/Sources/NetworkProtection/FeatureActivation/NetworkProtectionCodeRedemptionCoordinator.swift index 8c1d00fbf..ca5f77bce 100644 --- a/Sources/NetworkProtection/FeatureActivation/NetworkProtectionCodeRedemptionCoordinator.swift +++ b/Sources/NetworkProtection/FeatureActivation/NetworkProtectionCodeRedemptionCoordinator.swift @@ -19,15 +19,8 @@ import Foundation import Common -public protocol NetworkProtectionCodeRedeeming { - - /// Redeems an invite code with the Network Protection backend and stores the resulting auth token - func redeem(_ code: String) async throws - -} - /// Coordinates calls to the backend and oAuth token storage -public final class NetworkProtectionCodeRedemptionCoordinator: NetworkProtectionCodeRedeeming { +public final class NetworkProtectionCodeRedemptionCoordinator { private let networkClient: NetworkProtectionClient private let tokenStore: NetworkProtectionTokenStore private let isManualCodeRedemptionFlow: Bool @@ -54,21 +47,4 @@ public final class NetworkProtectionCodeRedemptionCoordinator: NetworkProtection self.errorEvents = errorEvents } - public func redeem(_ code: String) async throws { - let result = await networkClient.redeem(inviteCode: code) - switch result { - case .success(let token): - try tokenStore.store(token) - - case .failure(let error): - if case .invalidInviteCode = error, isManualCodeRedemptionFlow { - // Deliberately ignore cases where invalid invite codes are entered into the redemption form - throw error - } else { - errorEvents.fire(error.networkProtectionError) - throw error - } - } - } - } diff --git a/Sources/NetworkProtection/Networking/NetworkProtectionClient.swift b/Sources/NetworkProtection/Networking/NetworkProtectionClient.swift index 2a86436a2..26626238d 100644 --- a/Sources/NetworkProtection/Networking/NetworkProtectionClient.swift +++ b/Sources/NetworkProtection/Networking/NetworkProtectionClient.swift @@ -19,7 +19,6 @@ import Foundation protocol NetworkProtectionClient { - func redeem(inviteCode: String) async -> Result func getLocations(authToken: String) async -> Result<[NetworkProtectionLocation], NetworkProtectionClientError> func getServers(authToken: String) async -> Result<[NetworkProtectionServer], NetworkProtectionClientError> func register(authToken: String, @@ -189,10 +188,6 @@ final class NetworkProtectionBackendClient: NetworkProtectionClient { endpointURL.appending("/register") } - var redeemURL: URL { - endpointURL.appending("/redeem") - } - private let decoder: JSONDecoder = { let formatter = ISO8601DateFormatter() formatter.formatOptions = [.withFullDate, .withFullTime, .withFractionalSeconds] @@ -381,11 +376,6 @@ final class NetworkProtectionBackendClient: NetworkProtectionClient { } } - public func redeem(inviteCode: String) async -> Result { - let requestBody = RedeemInviteCodeRequestBody(code: inviteCode) - return await retrieveAuthToken(requestBody: requestBody, endpoint: redeemURL) - } - private func retrieveAuthToken( requestBody: RequestBody, endpoint: URL diff --git a/Sources/NetworkProtection/Settings/Extensions/UserDefaults+showMessaging.swift b/Sources/NetworkProtection/Settings/Extensions/UserDefaults+showMessaging.swift index d905ccde2..86efb8930 100644 --- a/Sources/NetworkProtection/Settings/Extensions/UserDefaults+showMessaging.swift +++ b/Sources/NetworkProtection/Settings/Extensions/UserDefaults+showMessaging.swift @@ -85,24 +85,3 @@ extension UserDefaults { public extension Notification.Name { static let vpnEntitlementMessagingDidChange = Notification.Name("com.duckduckgo.network-protection.entitlement-messaging-changed") } - -extension UserDefaults { - private var vpnEarlyAccessOverAlertAlreadyShownKey: String { - "vpnEarlyAccessOverAlertAlreadyShown" - } - - @objc - public dynamic var vpnEarlyAccessOverAlertAlreadyShown: Bool { - get { - value(forKey: vpnEarlyAccessOverAlertAlreadyShownKey) as? Bool ?? false - } - - set { - set(newValue, forKey: vpnEarlyAccessOverAlertAlreadyShownKey) - } - } - - public func resetThankYouMessaging() { - removeObject(forKey: vpnEarlyAccessOverAlertAlreadyShownKey) - } -} diff --git a/Tests/NetworkProtectionTests/NetworkProtectionClientTests.swift b/Tests/NetworkProtectionTests/NetworkProtectionClientTests.swift index ca87eee90..6b1011273 100644 --- a/Tests/NetworkProtectionTests/NetworkProtectionClientTests.swift +++ b/Tests/NetworkProtectionTests/NetworkProtectionClientTests.swift @@ -52,7 +52,7 @@ final class NetworkProtectionClientTests: XCTestCase { func testRegister401Response_ThrowsInvalidTokenError() async { let emptyData = "".data(using: .utf8)! - MockURLProtocol.stubs[client.redeemURL] = (response: HTTPURLResponse(url: client.registerKeyURL, statusCode: 401)!, + MockURLProtocol.stubs[client.registerKeyURL] = (response: HTTPURLResponse(url: client.registerKeyURL, statusCode: 401)!, .success(emptyData)) let body = RegisterKeyRequestBody(publicKey: .testData, serverSelection: .server(name: "MockServer")) @@ -68,7 +68,7 @@ final class NetworkProtectionClientTests: XCTestCase { func testGetServer401Response_ThrowsInvalidTokenError() async { let emptyData = "".data(using: .utf8)! - MockURLProtocol.stubs[client.redeemURL] = (response: HTTPURLResponse(url: client.serversURL, statusCode: 401)!, + MockURLProtocol.stubs[client.serversURL] = (response: HTTPURLResponse(url: client.serversURL, statusCode: 401)!, .success(emptyData)) let result = await client.getServers(authToken: "anAuthToken") @@ -79,74 +79,11 @@ final class NetworkProtectionClientTests: XCTestCase { } } - // MARK: redeem(inviteCode:) - - func testRedeemSuccess() async { - let token = "a6s7ad6ad76aasa7s6a" - let successData = redeemSuccessData(token: token) - MockURLProtocol.stubs[client.redeemURL] = (response: HTTPURLResponse(url: client.redeemURL, statusCode: 200)!, - .success(successData)) - - let result = await client.redeem(inviteCode: "DH76F8S") - - XCTAssertEqual(try? result.get(), token) - } - - func testRedeem400Response() async { - let emptyData = "".data(using: .utf8)! - MockURLProtocol.stubs[client.redeemURL] = (response: HTTPURLResponse(url: client.redeemURL, statusCode: 400)!, - .success(emptyData)) - - let result = await client.redeem(inviteCode: "DH76F8S") - - guard case .failure(let error) = result, case .invalidInviteCode = error else { - XCTFail("Expected an invalidInviteCode error to be thrown") - return - } - } - - func testRedeemNon200Or400Response() async { - let emptyData = "".data(using: .utf8)! - - for code in [401, 304, 500] { - MockURLProtocol.stubs[client.redeemURL] = (response: HTTPURLResponse(url: client.redeemURL, statusCode: code)!, - .success(emptyData)) - - let result = await client.redeem(inviteCode: "DH76F8S") - - guard case .failure(let error) = result, case .failedToRedeemInviteCode = error else { - XCTFail("Expected a failedToRedeemInviteCode error to be thrown") - return - } - } - } - - func testRedeemDecodeFailure() async { - let undecodableData = "sdfghj".data(using: .utf8)! - MockURLProtocol.stubs[client.redeemURL] = (response: HTTPURLResponse(url: client.redeemURL, statusCode: 200)!, - .success(undecodableData)) - - let result = await client.redeem(inviteCode: "DH76F8S") - - guard case .failure(let error) = result, case .failedToParseRedeemResponse = error else { - XCTFail("Expected a failedToRedeemInviteCode error to be thrown") - return - } - } - - private func redeemSuccessData(token: String) -> Data { - return """ - { - "token": "\(token)" - } - """.data(using: .utf8)! - } - // MARK: locations(authToken:) func testLocationsSuccess() async { let successData = TestData.mockLocations - MockURLProtocol.stubs[client.locationsURL] = (response: HTTPURLResponse(url: client.redeemURL, statusCode: 200)!, + MockURLProtocol.stubs[client.locationsURL] = (response: HTTPURLResponse(url: client.locationsURL, statusCode: 200)!, .success(successData)) let result = await client.getLocations(authToken: "DH76F8S") @@ -185,7 +122,7 @@ final class NetworkProtectionClientTests: XCTestCase { func testLocationsDecodeFailure() async { let undecodableData = "sdfghj".data(using: .utf8)! - MockURLProtocol.stubs[client.locationsURL] = (response: HTTPURLResponse(url: client.redeemURL, statusCode: 200)!, + MockURLProtocol.stubs[client.locationsURL] = (response: HTTPURLResponse(url: client.locationsURL, statusCode: 200)!, .success(undecodableData)) let result = await client.getLocations(authToken: "DH76F8S")