Skip to content

Commit

Permalink
Removes VPN waitlist and beta code (#801)
Browse files Browse the repository at this point in the history
iOS: duckduckgo/iOS#2795
macOS: duckduckgo/macos-browser#2776
What kind of version bump will this require?: Minor

Description

Let's remove the VPN waitlist code.
  • Loading branch information
diegoreymendez authored May 24, 2024
1 parent 610a58a commit 7c235d2
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}
}

}
10 changes: 0 additions & 10 deletions Sources/NetworkProtection/Networking/NetworkProtectionClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import Foundation

protocol NetworkProtectionClient {
func redeem(inviteCode: String) async -> Result<String, NetworkProtectionClientError>
func getLocations(authToken: String) async -> Result<[NetworkProtectionLocation], NetworkProtectionClientError>
func getServers(authToken: String) async -> Result<[NetworkProtectionServer], NetworkProtectionClientError>
func register(authToken: String,
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -381,11 +376,6 @@ final class NetworkProtectionBackendClient: NetworkProtectionClient {
}
}

public func redeem(inviteCode: String) async -> Result<String, NetworkProtectionClientError> {
let requestBody = RedeemInviteCodeRequestBody(code: inviteCode)
return await retrieveAuthToken(requestBody: requestBody, endpoint: redeemURL)
}

private func retrieveAuthToken<RequestBody: Encodable>(
requestBody: RequestBody,
endpoint: URL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
71 changes: 4 additions & 67 deletions Tests/NetworkProtectionTests/NetworkProtectionClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 7c235d2

Please sign in to comment.