Skip to content

Commit

Permalink
update to match macOS codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
mallexxx committed Nov 28, 2024
1 parent f7b0998 commit aa8ddaa
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 36 deletions.
2 changes: 1 addition & 1 deletion DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11054,7 +11054,7 @@
repositoryURL = "https://github.com/DuckDuckGo/BrowserServicesKit";
requirement = {
kind = revision;
revision = b2bdcc7fedf176fbf167d17bd76e25e488e71b86;
revision = b65fd02ab1ca29a73286f79f9da4678bc4af1789;
};
};
9F8FE9472BAE50E50071E372 /* XCRemoteSwiftPackageReference "lottie-spm" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/DuckDuckGo/BrowserServicesKit",
"state" : {
"revision" : "b2bdcc7fedf176fbf167d17bd76e25e488e71b86"
"revision" : "b65fd02ab1ca29a73286f79f9da4678bc4af1789"
}
},
{
Expand Down
21 changes: 8 additions & 13 deletions DuckDuckGo/TabViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1705,20 +1705,15 @@ extension TabViewController: WKNavigationDelegate {

private func loadSpecialErrorPageIfNeeded(error: NSError) {
guard featureFlagger.isFeatureOn(.sslCertificatesBypass),
error.code == NSURLErrorServerCertificateUntrusted,
let errorCode = error.userInfo["_kCFStreamErrorCodeKey"] as? Int32,
let failedURL = error.failedUrl else {
return
}
error.isServerCertificateUntrusted,
let errorType = error.sslErrorType,
let failedURL = error.failedUrl else { return }

let tld = storageCache.tld
let errorType = SSLErrorType.forErrorCode(Int(errorCode))
self.failedURL = failedURL
errorData = SpecialErrorData(kind: .ssl,
errorType: errorType.rawValue,
domain: failedURL.host,
eTldPlus1: tld.eTLDplus1(failedURL.host))
errorData = SpecialErrorData.ssl(type: errorType, domain: failedURL.host!, eTldPlus1: tld.eTLDplus1(failedURL.host))
loadSpecialErrorPage(url: failedURL)
Pixel.fire(pixel: .certificateWarningDisplayed(errorType.rawParameter))
Pixel.fire(pixel: .certificateWarningDisplayed(errorType.pixelParameter))
}

private func loadSpecialErrorPage(url: URL) {
Expand Down Expand Up @@ -3138,7 +3133,7 @@ extension UserContentController {

extension TabViewController: SpecialErrorPageUserScriptDelegate {

func leaveSite() {
func leaveSiteAction() {
Pixel.fire(pixel: .certificateWarningLeaveClicked)
guard webView?.canGoBack == true else {
delegate?.tabDidRequestClose(self)
Expand All @@ -3147,7 +3142,7 @@ extension TabViewController: SpecialErrorPageUserScriptDelegate {
_ = webView?.goBack()
}

func visitSite() {
func visitSiteAction() {
Pixel.fire(pixel: .certificateWarningProceedClicked)
isSpecialErrorPageVisible = false
shouldBypassSSLError = true
Expand Down
30 changes: 9 additions & 21 deletions DuckDuckGoTests/SpecialErrorPageTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ final class SpecialErrorPageTests: XCTestCase {

func testWhenCertificateExpiredThenExpectedErrorPageIsShown() {
// GIVEN
let error = NSError(domain: "test",
let error = NSError(domain: NSURLErrorDomain,
code: NSURLErrorServerCertificateUntrusted,
userInfo: ["_kCFStreamErrorCodeKey": errSSLCertExpired,
NSURLErrorFailingURLErrorKey: URL(string: "https://expired.badssl.com")!])
Expand All @@ -89,18 +89,15 @@ final class SpecialErrorPageTests: XCTestCase {

// THEN
XCTAssertEqual(sut.failedURL, URL(string: "https://expired.badssl.com")!)
XCTAssertEqual(sut.errorData, SpecialErrorData(kind: .ssl,
errorType: "expired",
domain: "expired.badssl.com",
eTldPlus1: "badssl.com"))
XCTAssertEqual(sut.errorData, SpecialErrorData.ssl(type: .expired, domain: "expired.badssl.com", eTldPlus1: "badssl.com"))
waitForExpectations(timeout: 1) { error in
XCTAssertNil(error, "Expectation was not fulfilled in time")
}
}

func testWhenCertificateWrongHostThenExpectedErrorPageIsShown() {
// GIVEN
let error = NSError(domain: "test",
let error = NSError(domain: NSURLErrorDomain,
code: NSURLErrorServerCertificateUntrusted,
userInfo: ["_kCFStreamErrorCodeKey": errSSLHostNameMismatch,
NSURLErrorFailingURLErrorKey: URL(string: "https://wrong.host.badssl.com")!])
Expand All @@ -121,18 +118,15 @@ final class SpecialErrorPageTests: XCTestCase {

// THEN
XCTAssertEqual(sut.failedURL, URL(string: "https://wrong.host.badssl.com")!)
XCTAssertEqual(sut.errorData, SpecialErrorData(kind: .ssl,
errorType: "wrongHost",
domain: "wrong.host.badssl.com",
eTldPlus1: "badssl.com"))
XCTAssertEqual(sut.errorData, SpecialErrorData.ssl(type: .wrongHost, domain: "wrong.host.badssl.com", eTldPlus1: "badssl.com"))
waitForExpectations(timeout: 1) { error in
XCTAssertNil(error, "Expectation was not fulfilled in time")
}
}

func testWhenCertificateSelfSignedThenExpectedErrorPageIsShown() {
// GIVEN
let error = NSError(domain: "test",
let error = NSError(domain: NSURLErrorDomain,
code: NSURLErrorServerCertificateUntrusted,
userInfo: ["_kCFStreamErrorCodeKey": errSSLXCertChainInvalid,
NSURLErrorFailingURLErrorKey: URL(string: "https://self-signed.badssl.com")!])
Expand All @@ -153,18 +147,15 @@ final class SpecialErrorPageTests: XCTestCase {

// THEN
XCTAssertEqual(sut.failedURL, URL(string: "https://self-signed.badssl.com")!)
XCTAssertEqual(sut.errorData, SpecialErrorData(kind: .ssl,
errorType: "selfSigned",
domain: "self-signed.badssl.com",
eTldPlus1: "badssl.com"))
XCTAssertEqual(sut.errorData, SpecialErrorData.ssl(type: .selfSigned, domain: "self-signed.badssl.com", eTldPlus1: "badssl.com"))
waitForExpectations(timeout: 1) { error in
XCTAssertNil(error, "Expectation was not fulfilled in time")
}
}

func testWhenOtherCertificateIssueThenExpectedErrorPageIsShown() {
// GIVEN
let error = NSError(domain: "test",
let error = NSError(domain: NSURLErrorDomain,
code: NSURLErrorServerCertificateUntrusted,
userInfo: ["_kCFStreamErrorCodeKey": errSSLUnknownRootCert,
NSURLErrorFailingURLErrorKey: URL(string: "https://untrusted-root.badssl.com")!])
Expand All @@ -185,10 +176,7 @@ final class SpecialErrorPageTests: XCTestCase {

// THEN
XCTAssertEqual(sut.failedURL, URL(string: "https://untrusted-root.badssl.com")!)
XCTAssertEqual(sut.errorData, SpecialErrorData(kind: .ssl,
errorType: "invalid",
domain: "untrusted-root.badssl.com",
eTldPlus1: "badssl.com"))
XCTAssertEqual(sut.errorData, SpecialErrorData.ssl(type: .invalid, domain: "untrusted-root.badssl.com", eTldPlus1: "badssl.com"))
waitForExpectations(timeout: 1) { error in
XCTAssertNil(error, "Expectation was not fulfilled in time")
}
Expand Down Expand Up @@ -246,7 +234,7 @@ final class SpecialErrorPageTests: XCTestCase {
func testWhenDidReceiveChallengeIfChallengeForCertificateValidationAndUserRequestBypassThenReturnsCredentials() async {
let protectionSpace = URLProtectionSpace(host: "", port: 4, protocol: nil, realm: nil, authenticationMethod: NSURLAuthenticationMethodServerTrust)
let challenge = URLAuthenticationChallenge(protectionSpace: protectionSpace, proposedCredential: nil, previousFailureCount: 0, failureResponse: nil, error: nil, sender: ChallengeSender())
await sut.visitSite()
await sut.visitSiteAction()
await sut.webView(webView, didReceive: challenge) { _, credential in
XCTAssertNotNil(credential)
}
Expand Down

0 comments on commit aa8ddaa

Please sign in to comment.