Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Malicious site protection - extract special error page navigation logic #3624

Conversation

alessandroboron
Copy link
Contributor

Task/Issue URL: https://app.asana.com/0/1206329551987282/1208836682251611/f
Tech Design URL: https://app.asana.com/0/1206329551987282/1207273224076495/f

Description:

This PR extracts the navigation logic for special error pages in its own class.

This PR focuses on creating the the entites used to encapsulate the logic for SSL and Malicious site protection

The implementation of the logic for Malicious site protection will follow in an upcoming PR.

Steps to test this PR:

  1. Ensure all the SpecialErrorPage tests pass

Manual tests
SSL Tests from SSL PR

Steps to test this PR:

  1. Go to badssl.com
  2. Select expired certificate
  3. Our custom special error page should open.
  • at this point you should be able to go back, and once you go back you should be able to go forward
  • please validate if design looks fine, and if it doesn't break in landscape
  • please validate if design supports light/dark modes
  • please validate if design supports translations (in order to test it you will most likely have to re-enter the page)
  • please validate the privacy shield icon in navigation bar is invisible.
  1. Tap on leave site.
  • you should be taken back (if it was possible) or the tab should be closed if this was first page in navigation
  1. Tap on advanced and accept the risk.
  • please validate that expired.badssl.com has loaded (red background)
  • please validate that privacy shield icon reappeared but has red dot on top of it
  • once you go to privacy dashboard you should see information about incorrect certificate
  • please validate you can go back to badssl.com site

Definition of Done (Internal Only):

Copy Testing:

  • Use of correct apostrophes in new copy, ie rather than '

Orientation Testing:

  • Portrait
  • Landscape

Device Testing:

  • iPhone SE (1st Gen)
  • iPhone 8
  • iPhone X
  • iPhone 14 Pro
  • iPad

OS Testing:

  • iOS 15
  • iOS 16
  • iOS 17

Theme Testing:

  • Light theme
  • Dark theme

Internal references:

Software Engineering Expectations
Technical Design Template

Copy link

github-actions bot commented Nov 26, 2024

Warnings
⚠️ PR has more than 500 lines of code changing. Consider splitting into smaller PRs if possible.

Generated by 🚫 dangerJS against b77eb5a

@alessandroboron alessandroboron force-pushed the alessandro/malicious-site-protection-navigation branch 3 times, most recently from b1ff305 to 2a77dee Compare November 26, 2024 20:31
@alessandroboron alessandroboron force-pushed the alessandro/malicious-site-protection-navigation branch from 2a77dee to c3815f5 Compare November 27, 2024 09:06

import Foundation

final class MaliciousSiteProtectionManager: MaliciousSiteDetecting {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementation of this class will come in a subsequent PR.
This was used to mock the BSK library and assert that the special error page was rendered.

import SpecialErrorPages
import WebKit

enum MaliciousSiteProtectionNavigationResult: Equatable {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class will encapsulate MaliciousSiteProtection logic to evaluate if a site is malicious and will handle its internal state to bypass URLs.

}

func errorPageVisited(errorType: SSLErrorType) {
Pixel.fire(pixel: .certificateWarningDisplayed(errorType.rawParameter))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could inject the fire function and add tests to ensure Pixels are fired.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh I don't mind leaving it as it is for now

import BrowserServicesKit
import SpecialErrorPages
import Core

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class encapsulate the SSL logic

import WebKit
import SpecialErrorPages
import Core

Copy link
Contributor Author

@alessandroboron alessandroboron Nov 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class will orchestrate the navigation logic of features that require a Special Error Page

@testable import SpecialErrorPages
@testable import DuckDuckGo

final class SSLSpecialErrorPageTests: XCTestCase {
Copy link
Contributor Author

@alessandroboron alessandroboron Nov 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests were initially using the TabViewController. I split them in two test classes, SSLSpecialErrorPageTests and SpecialErrorPageNavigationHandlerIntegrationTests.

We could also convert this class using SwiftTesting so we have all test suites related to Special Error Pages. I can make a follow up task at the end of the project.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be great :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I update the existing tests to use Swift Testing

Copy link
Contributor

@jaceklyp jaceklyp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what a nice piece of code, you're definitely leaving it in much better shape than it was, the other comments are just minor;
note: haven't tested it yet

Comment on lines 28 to 31

func makeNewRequestURLAndSpecialErrorDataIfEnabled(error: NSError) -> SSLSpecialError?

func errorPageVisited(errorType: SSLErrorType)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's remove empty lines

}

func errorPageVisited(errorType: SSLErrorType) {
Pixel.fire(pixel: .certificateWarningDisplayed(errorType.rawParameter))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh I don't mind leaving it as it is for now

// MARK: - SpecialErrorPageNavigationDelegate

/// A delegate for handling navigation actions related to special error pages.
protocol SpecialErrorPageNavigationDelegate: AnyObject {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we move this protocol above BaseSpecialError protocol where it is already used?

@@ -0,0 +1,131 @@
//
// SpecialErrorPageInterfaces.swift
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should put all these protocols under this umbrella file - for me personally it makes things confusing - I'm fine with putting separate files into group though named like this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me!

func setUserScript(_ userScript: SpecialErrorPageUserScript?)
}

typealias SpecialErrorPageNavigationHandling = BaseSpecialErrorPageNavigationHandling & WebViewNavigationHandling & SpecialErrorPageUserScriptDelegate
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps we can rename these to:
SpecialErrorPageNavigationHandling -> SpecialErrorPageManaging
BaseSpecialErrorPageNavigationHandling -> SpecialErrorPageContextHandling/SpecialErrorPageFlowHandling (as it is mostly responsible for state handling and setup)? Base prefix doesn't tell much

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I wasn’t fan of “Base” as well but couldn’t find a better name. :)

@testable import SpecialErrorPages
@testable import DuckDuckGo

final class SSLSpecialErrorPageTests: XCTestCase {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be great :)

import SpecialErrorPages
@testable import DuckDuckGo

@Suite("Special Error Pages - SSL Integration Tests", .serialized)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

@jaceklyp
Copy link
Contributor

what a nice piece of code, you're definitely leaving it in much better shape than it was, the other comments are just minor; note: haven't tested it yet

update: tested and it works well

@alessandroboron
Copy link
Contributor Author

what a nice piece of code, you're definitely leaving it in much better shape than it was, the other comments are just minor; note: haven't tested it yet

Thanks @jaceklyp, I will address the comments! I will re-request a review soon :)

@alessandroboron alessandroboron merged commit 02670bc into alessandro/malicious-site-protection Dec 2, 2024
16 checks passed
@alessandroboron alessandroboron deleted the alessandro/malicious-site-protection-navigation branch December 2, 2024 10:11
alessandroboron added a commit that referenced this pull request Dec 2, 2024
…ic (#3624)

Task/Issue URL: https://app.asana.com/0/1206329551987282/1208836682251611/f
Tech Design URL: https://app.asana.com/0/1206329551987282/1207273224076495/f

**Description**:
This PR extracts the navigation logic for special error pages in its own class.
This PR focuses on creating the the entites used to encapsulate the logic for SSL and Malicious site protection
alessandroboron added a commit that referenced this pull request Dec 9, 2024
…ic (#3624)

Task/Issue URL: https://app.asana.com/0/1206329551987282/1208836682251611/f
Tech Design URL: https://app.asana.com/0/1206329551987282/1207273224076495/f

**Description**:
This PR extracts the navigation logic for special error pages in its own class.
This PR focuses on creating the the entites used to encapsulate the logic for SSL and Malicious site protection
alessandroboron added a commit that referenced this pull request Dec 10, 2024
…ic (#3624)

Task/Issue URL: https://app.asana.com/0/1206329551987282/1208836682251611/f
Tech Design URL: https://app.asana.com/0/1206329551987282/1207273224076495/f

**Description**:
This PR extracts the navigation logic for special error pages in its own class.
This PR focuses on creating the the entites used to encapsulate the logic for SSL and Malicious site protection
alessandroboron added a commit that referenced this pull request Dec 19, 2024
…ic (#3624)

Task/Issue URL: https://app.asana.com/0/1206329551987282/1208836682251611/f
Tech Design URL: https://app.asana.com/0/1206329551987282/1207273224076495/f

**Description**:
This PR extracts the navigation logic for special error pages in its own class.
This PR focuses on creating the the entites used to encapsulate the logic for SSL and Malicious site protection
alessandroboron added a commit that referenced this pull request Jan 9, 2025
…ic (#3624)

Task/Issue URL: https://app.asana.com/0/1206329551987282/1208836682251611/f
Tech Design URL: https://app.asana.com/0/1206329551987282/1207273224076495/f

**Description**:
This PR extracts the navigation logic for special error pages in its own class.
This PR focuses on creating the the entites used to encapsulate the logic for SSL and Malicious site protection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants