Skip to content

Commit

Permalink
Add a “clear all VPN data” option to the debug menu.
Browse files Browse the repository at this point in the history
  • Loading branch information
samsymons committed Dec 13, 2023
1 parent 2351ab0 commit 369ce97
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions DuckDuckGo/NetworkProtectionDebugViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import NetworkProtection
// swiftlint:disable:next type_body_length
final class NetworkProtectionDebugViewController: UITableViewController {
private let titles = [
Sections.keychain: "Keychain",
Sections.clearData: "Clear Data",
Sections.debugFeature: "Debug Features",
Sections.simulateFailure: "Simulate Failure",
Sections.registrationKey: "Registration Key",
Expand All @@ -49,7 +49,7 @@ final class NetworkProtectionDebugViewController: UITableViewController {
]

enum Sections: Int, CaseIterable {
case keychain
case clearData
case debugFeature
case simulateFailure
case registrationKey
Expand All @@ -59,9 +59,10 @@ final class NetworkProtectionDebugViewController: UITableViewController {
case vpnConfiguration
}

enum KeychainRows: Int, CaseIterable {
enum ClearDataRows: Int, CaseIterable {

case clearAuthToken
case clearAllVPNData

}

Expand Down Expand Up @@ -162,10 +163,12 @@ final class NetworkProtectionDebugViewController: UITableViewController {

switch Sections(rawValue: indexPath.section) {

case .keychain:
switch KeychainRows(rawValue: indexPath.row) {
case .clearData:
switch ClearDataRows(rawValue: indexPath.row) {
case .clearAuthToken:
cell.textLabel?.text = "Clear auth token"
cell.textLabel?.text = "Clear Auth Token"
case .clearAllVPNData:
cell.textLabel?.text = "Reset VPN State Completely"
case .none:
break
}
Expand Down Expand Up @@ -200,7 +203,7 @@ final class NetworkProtectionDebugViewController: UITableViewController {

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
switch Sections(rawValue: section) {
case .keychain: return KeychainRows.allCases.count
case .clearData: return ClearDataRows.allCases.count
case .debugFeature: return DebugFeatureRows.allCases.count
case .simulateFailure: return SimulateFailureRows.allCases.count
case .registrationKey: return RegistrationKeyRows.allCases.count
Expand All @@ -216,9 +219,10 @@ final class NetworkProtectionDebugViewController: UITableViewController {
// swiftlint:disable:next cyclomatic_complexity
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
switch Sections(rawValue: indexPath.section) {
case .keychain:
switch KeychainRows(rawValue: indexPath.row) {
case .clearData:
switch ClearDataRows(rawValue: indexPath.row) {
case .clearAuthToken: clearAuthToken()
case .clearAllVPNData: clearAllVPNData()
default: break
}
case .debugFeature:
Expand Down Expand Up @@ -542,6 +546,12 @@ final class NetworkProtectionDebugViewController: UITableViewController {
private func clearAuthToken() {
try? tokenStore.deleteToken()
}

private func clearAllVPNData() {
let accessController = NetworkProtectionAccessController()
accessController.revokeNetworkProtectionAccess()
}

}


Expand Down

0 comments on commit 369ce97

Please sign in to comment.