Skip to content

Commit

Permalink
Network Protection debug menu (duckduckgo#1910)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/0/1205084446087078/f
Description:

Until now, the option to clear the auth token (thus resetting the invite flow) was in the status view. Now that we’re moving to an actual MVP, it makes sense to move this functionality to a debug menu item.

I give you: the NetworkProtectionDebugViewController
  • Loading branch information
graeme authored Aug 11, 2023
1 parent a6a1463 commit 1e2b85e
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 5 deletions.
4 changes: 4 additions & 0 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,7 @@
EE4FB1882A28D11900E5CBA7 /* NetworkProtectionStatusViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE4FB1872A28D11900E5CBA7 /* NetworkProtectionStatusViewModel.swift */; };
EE50052E29C369D300AE0773 /* FeatureFlag.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE50052D29C369D300AE0773 /* FeatureFlag.swift */; };
EE50053029C3BA0800AE0773 /* InternalUserStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE50052F29C3BA0800AE0773 /* InternalUserStore.swift */; };
EE72CA852A862D000043B5B3 /* NetworkProtectionDebugViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE72CA842A862D000043B5B3 /* NetworkProtectionDebugViewController.swift */; };
EE7917912A83DE93008DFF28 /* CombineTestUtilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE7917902A83DE93008DFF28 /* CombineTestUtilities.swift */; };
EE8594992A44791C008A6D06 /* NetworkProtectionTunnelController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE8594982A44791C008A6D06 /* NetworkProtectionTunnelController.swift */; };
EE8E568A2A56BCE400F11DCA /* NetworkProtection in Frameworks */ = {isa = PBXBuildFile; productRef = EE8E56892A56BCE400F11DCA /* NetworkProtection */; };
Expand Down Expand Up @@ -2307,6 +2308,7 @@
EE4FB1872A28D11900E5CBA7 /* NetworkProtectionStatusViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkProtectionStatusViewModel.swift; sourceTree = "<group>"; };
EE50052D29C369D300AE0773 /* FeatureFlag.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeatureFlag.swift; sourceTree = "<group>"; };
EE50052F29C3BA0800AE0773 /* InternalUserStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InternalUserStore.swift; sourceTree = "<group>"; };
EE72CA842A862D000043B5B3 /* NetworkProtectionDebugViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkProtectionDebugViewController.swift; sourceTree = "<group>"; };
EE7917902A83DE93008DFF28 /* CombineTestUtilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CombineTestUtilities.swift; sourceTree = "<group>"; };
EE8594982A44791C008A6D06 /* NetworkProtectionTunnelController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkProtectionTunnelController.swift; sourceTree = "<group>"; };
EEEB80A22A421CE600386378 /* NetworkProtectionPacketTunnelProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkProtectionPacketTunnelProvider.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3674,6 +3676,7 @@
1EDE39D12705D4A100C99C72 /* FileSizeDebugViewController.swift */,
F46FEC5627987A5F0061D9DF /* KeychainItemsDebugViewController.swift */,
983D71B02A286E810072E26D /* SyncDebugViewController.swift */,
EE72CA842A862D000043B5B3 /* NetworkProtectionDebugViewController.swift */,
);
name = Debug;
sourceTree = "<group>";
Expand Down Expand Up @@ -6249,6 +6252,7 @@
31EF52E1281B3BDC0034796E /* AutofillLoginListItemViewModel.swift in Sources */,
1E4FAA6627D8DFC800ADC5B3 /* CompleteDownloadRowViewModel.swift in Sources */,
83004E862193E5ED00DA013C /* TabViewControllerBrowsingMenuExtension.swift in Sources */,
EE72CA852A862D000043B5B3 /* NetworkProtectionDebugViewController.swift in Sources */,
CB84C7BD29A3EF530088A5B8 /* AppConfigurationURLProvider.swift in Sources */,
AA3D854723D9E88E00788410 /* AppIconSettingsCell.swift in Sources */,
316931D927BD22A80095F5ED /* DownloadActionMessageViewHelper.swift in Sources */,
Expand Down
59 changes: 54 additions & 5 deletions DuckDuckGo/Debug.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,28 @@
<segue destination="ThP-iv-zau" kind="show" destinationCreationSelector="onCreateSyncDebugScreen:sender:segueIdentifier:" id="1wD-Fd-sw9"/>
</connections>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" textLabel="3I9-TA-KKr" style="IBUITableViewCellStyleDefault" id="0tb-2l-dsc">
<rect key="frame" x="0.0" y="354.5" width="414" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="0tb-2l-dsc" id="poM-jf-dYy">
<rect key="frame" x="0.0" y="0.0" width="383.5" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Network Protection" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="3I9-TA-KKr">
<rect key="frame" x="20" y="0.0" width="355.5" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
<connections>
<segue destination="TDP-d3-gtB" kind="show" destinationCreationSelector="onCreateNetPDebugScreen:sender:segueIdentifier:" id="bS9-Ic-OhH"/>
</connections>
</tableViewCell>
<tableViewCell clipsSubviews="YES" tag="665" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" id="iau-ES-Bnx">
<rect key="frame" x="0.0" y="354.5" width="414" height="44.5"/>
<rect key="frame" x="0.0" y="398" width="414" height="44.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="iau-ES-Bnx" id="DHw-no-bUr">
<rect key="frame" x="0.0" y="0.0" width="414" height="44.5"/>
Expand All @@ -169,7 +189,7 @@
<listContentConfiguration key="contentConfiguration" text="Reset Autoconsent Settings"/>
</tableViewCell>
<tableViewCell clipsSubviews="YES" tag="668" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" accessoryType="checkmark" indentationWidth="10" id="f8n-C1-CnF">
<rect key="frame" x="0.0" y="399" width="414" height="44.5"/>
<rect key="frame" x="0.0" y="442.5" width="414" height="44.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="f8n-C1-CnF" id="Gna-nE-FtW">
<rect key="frame" x="0.0" y="0.0" width="370" height="44.5"/>
Expand All @@ -178,7 +198,7 @@
<listContentConfiguration key="contentConfiguration" text="Enable Inspectable WebViews" secondaryText=""/>
</tableViewCell>
<tableViewCell clipsSubviews="YES" tag="669" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" accessoryType="checkmark" indentationWidth="10" id="AgK-xW-xB6">
<rect key="frame" x="0.0" y="443.5" width="414" height="44.5"/>
<rect key="frame" x="0.0" y="487" width="414" height="44.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="AgK-xW-xB6" id="onY-PV-AQp">
<rect key="frame" x="0.0" y="0.0" width="370" height="44.5"/>
Expand All @@ -187,7 +207,7 @@
<listContentConfiguration key="contentConfiguration" text="Internal User State" secondaryText=""/>
</tableViewCell>
<tableViewCell clipsSubviews="YES" tag="666" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" id="Lqc-aq-UoJ">
<rect key="frame" x="0.0" y="488" width="414" height="44.5"/>
<rect key="frame" x="0.0" y="531.5" width="414" height="44.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="Lqc-aq-UoJ" id="SOZ-8q-BYe">
<rect key="frame" x="0.0" y="0.0" width="414" height="44.5"/>
Expand All @@ -196,7 +216,7 @@
<listContentConfiguration key="contentConfiguration" text="Crash (fatal error)"/>
</tableViewCell>
<tableViewCell clipsSubviews="YES" tag="667" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" id="roW-Eb-6hF">
<rect key="frame" x="0.0" y="532.5" width="414" height="44.5"/>
<rect key="frame" x="0.0" y="576" width="414" height="44.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="roW-Eb-6hF" id="1IO-6X-jOv">
<rect key="frame" x="0.0" y="0.0" width="414" height="44.5"/>
Expand Down Expand Up @@ -545,6 +565,35 @@
</objects>
<point key="canvasLocation" x="3296" y="968"/>
</scene>
<!--Network Protection Debug View Controller-->
<scene sceneID="ml3-iJ-UAe">
<objects>
<tableViewController id="TDP-d3-gtB" customClass="NetworkProtectionDebugViewController" customModule="DuckDuckGo" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="-1" estimatedSectionHeaderHeight="-1" sectionFooterHeight="-1" estimatedSectionFooterHeight="-1" id="USF-eU-XuP">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="Cell" id="N0S-pX-hY3">
<rect key="frame" x="0.0" y="50" width="414" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="N0S-pX-hY3" id="rHS-8N-Oav">
<rect key="frame" x="0.0" y="0.0" width="414" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
</tableViewCellContentView>
</tableViewCell>
</prototypes>
<connections>
<outlet property="dataSource" destination="TDP-d3-gtB" id="v2Z-JS-2xa"/>
<outlet property="delegate" destination="TDP-d3-gtB" id="SBR-Ki-hep"/>
</connections>
</tableView>
<navigationItem key="navigationItem" id="kFw-XD-90y"/>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Vw1-aJ-BgA" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="4042" y="989"/>
</scene>
<!--Sync Info-->
<scene sceneID="A1E-XU-w8R">
<objects>
Expand Down
105 changes: 105 additions & 0 deletions DuckDuckGo/NetworkProtectionDebugViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
//
// NetworkProtectionDebugViewController.swift
// DuckDuckGo
//
// Copyright © 2023 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 UIKit
import NetworkProtection

final class NetworkProtectionDebugViewController: UITableViewController {
private let titles = [
Sections.keychain: "Keychain"
]

enum Sections: Int, CaseIterable {

case keychain

}

enum KeychainRows: Int, CaseIterable {

case clearAuthToken

}

private let tokenStore: NetworkProtectionTokenStore

init?(coder: NSCoder,
tokenStore: NetworkProtectionTokenStore) {

self.tokenStore = tokenStore

super.init(coder: coder)
}

required convenience init?(coder: NSCoder) {
self.init(coder: coder, tokenStore: NetworkProtectionKeychainTokenStore())
}

override func numberOfSections(in tableView: UITableView) -> Int {
return Sections.allCases.count
}

override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
guard let section = Sections(rawValue: section) else { return nil }
return titles[section]
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)

cell.detailTextLabel?.text = nil

switch Sections(rawValue: indexPath.section) {

case .keychain:
switch KeychainRows(rawValue: indexPath.row) {
case .clearAuthToken:
cell.textLabel?.text = "Clear auth token"
case .none:
break
}

default: break
}

return cell
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
switch Sections(rawValue: section) {
case .keychain: return KeychainRows.allCases.count
case .none: return 0
}
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
switch Sections(rawValue: indexPath.section) {
case .keychain:
switch KeychainRows(rawValue: indexPath.row) {
case .clearAuthToken:
try? tokenStore.deleteToken()
default: break
}
default: break
}

tableView.deselectRow(at: indexPath, animated: true)
}

}
8 changes: 8 additions & 0 deletions DuckDuckGo/RootDebugViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ class RootDebugViewController: UITableViewController {
return controller
}

@IBSegueAction func onCreateNetPDebugScreen(_ coder: NSCoder, sender: Any?, segueIdentifier: String?) -> NetworkProtectionDebugViewController {
guard let controller = NetworkProtectionDebugViewController(coder: coder) else {
fatalError("Failed to create controller")
}

return controller
}

override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
if cell.tag == Row.toggleInspectableWebViews.rawValue {
cell.accessoryType = AppUserDefaults().inspectableWebViewEnabled ? .checkmark : .none
Expand Down

0 comments on commit 1e2b85e

Please sign in to comment.