-
Notifications
You must be signed in to change notification settings - Fork 426
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
Malicious site protection - extract special error page navigation logic #3624
Conversation
b1ff305
to
2a77dee
Compare
2a77dee
to
c3815f5
Compare
|
||
import Foundation | ||
|
||
final class MaliciousSiteProtectionManager: MaliciousSiteDetecting { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 | ||
|
There was a problem hiding this comment.
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 | ||
|
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be great :)
There was a problem hiding this comment.
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
There was a problem hiding this 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
|
||
func makeNewRequestURLAndSpecialErrorDataIfEnabled(error: NSError) -> SSLSpecialError? | ||
|
||
func errorPageVisited(errorType: SSLErrorType) |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏
update: tested and it works well |
Thanks @jaceklyp, I will address the comments! I will re-request a review soon :) |
02670bc
into
alessandro/malicious-site-protection
…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
…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
…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
…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
…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
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:
Manual tests
SSL Tests from SSL PR
Steps to test this PR:
Definition of Done (Internal Only):
Copy Testing:
’
rather than'
Orientation Testing:
Device Testing:
OS Testing:
Theme Testing:
Internal references:
Software Engineering Expectations
Technical Design Template