From 2f827547ee4ff65a88d1684d398589b1dd91400c Mon Sep 17 00:00:00 2001 From: Stoyan Petrov Date: Thu, 11 Jul 2024 11:37:09 -0700 Subject: [PATCH 1/2] Uncomment browser login tests --- .../FRAuth/Browser/BrowserTests.swift | 91 +++++++++++-------- .../Model/User/FRUserBrowserTests.swift | 33 +++++-- 2 files changed, 80 insertions(+), 44 deletions(-) diff --git a/FRAuth/FRAuthTests/FRAuthSwiftTests/FRAuth/Browser/BrowserTests.swift b/FRAuth/FRAuthTests/FRAuthSwiftTests/FRAuth/Browser/BrowserTests.swift index 124ebbd0..f9b07894 100644 --- a/FRAuth/FRAuthTests/FRAuthSwiftTests/FRAuth/Browser/BrowserTests.swift +++ b/FRAuth/FRAuthTests/FRAuthSwiftTests/FRAuth/Browser/BrowserTests.swift @@ -85,8 +85,7 @@ class BrowserTests: FRAuthBaseTest { @available(iOS 13, *) func test_03_browser_login_already_in_progress_from_another_instance() throws { - try XCTSkipIf(true) // Skip this test - see SDKS-3304 - + // Start SDK self.startSDK() @@ -128,6 +127,8 @@ class BrowserTests: FRAuthBaseTest { ex.fulfill() } + // Sleep for 1 second + sleep(1) waitForExpectations(timeout: 60, handler: nil) } @@ -324,7 +325,6 @@ class BrowserTests: FRAuthBaseTest { @available(iOS 13, *) func test_08_login_auth_session_cancelled() throws { - try XCTSkipIf(true) // Skip this test - see SDKS-3304 // Start SDK self.startSDK() @@ -371,7 +371,11 @@ class BrowserTests: FRAuthBaseTest { ex.fulfill() } + // Sleep for 1 second + sleep(1) browser.cancel() + // Sleep for 1 second + sleep(1) waitForExpectations(timeout: 60, handler: nil) } @@ -379,41 +383,52 @@ class BrowserTests: FRAuthBaseTest { func test_09_login_native_browser_cancelled() { // TODO: - Temporarily disable this test due to UI issue -// // Start SDK -// self.startSDK() -// -// // Construct Browser -// guard let oAuth2Client = self.config.oAuth2Client, let sessionManager = self.config.sessionManager else { -// XCTFail("Failed to retrieve OAuth2Client, and/or SessionManager instance after SDK init") -// return -// } -// -// // Given with SFSafariViewController type of Browser object -// let browser = Browser(.nativeBrowserApp, oAuth2Client, sessionManager, UIViewController()) -// Browser.currentBrowser = browser -// -// let ex = self.expectation(description: "Browser Login") -// browser.login { (user, error) in -// XCTAssertNil(user) -// XCTAssertNotNil(error) -// -// if let browserError = error as? BrowserError { -// switch browserError { -// case .externalUserAgentCancelled: -// break -// default: -// XCTFail("While expecting BrowserError.externalUserAgentCancelled; failed with different error \(browserError.localizedDescription)") -// break -// } -// } -// else { -// XCTFail("While expecting BrowserError.externalUserAgentCancelled; failed with different error \(error?.localizedDescription ?? "")") -// } -// -// ex.fulfill() -// } -// browser.cancel() -// waitForExpectations(timeout: 60, handler: nil) + // Start SDK + self.startSDK() + + // Construct Browser + guard let oAuth2Client = self.config.oAuth2Client, let keychainManager = self.config.keychainManager else { + XCTFail("Failed to retrieve OAuth2Client, and/or KeychainManager instance after SDK init") + return + } + + let keyWindow = UIApplication.shared.windows.filter {$0.isKeyWindow}.first + var topVC = keyWindow?.rootViewController + while let presentedViewController = topVC?.presentedViewController { + topVC = presentedViewController + } + + guard let vc = topVC else { + XCTFail("Failed to retrieve top most ViewController") + return + } + + // Given with nativeBrowserApp type of Browser object + let browser = Browser(.nativeBrowserApp, oAuth2Client, keychainManager, vc) + Browser.currentBrowser = browser + + let ex = self.expectation(description: "Browser Login") + browser.login { (user, error) in + XCTAssertNil(user) + XCTAssertNotNil(error) + + if let browserError = error as? BrowserError { + switch browserError { + case .externalUserAgentCancelled: + break + default: + XCTFail("While expecting BrowserError.externalUserAgentCancelled; failed with different error \(browserError.localizedDescription)") + break + } + } + else { + XCTFail("While expecting BrowserError.externalUserAgentCancelled; failed with different error \(error?.localizedDescription ?? "")") + } + + ex.fulfill() + } + browser.cancel() + waitForExpectations(timeout: 60, handler: nil) } diff --git a/FRAuth/FRAuthTests/FRAuthSwiftTests/FRAuth/Model/User/FRUserBrowserTests.swift b/FRAuth/FRAuthTests/FRAuthSwiftTests/FRAuth/Model/User/FRUserBrowserTests.swift index d7211469..88033286 100644 --- a/FRAuth/FRAuthTests/FRAuthSwiftTests/FRAuth/Model/User/FRUserBrowserTests.swift +++ b/FRAuth/FRAuthTests/FRAuthSwiftTests/FRAuth/Model/User/FRUserBrowserTests.swift @@ -51,8 +51,6 @@ class FRUserBrowserTests: FRAuthBaseTest { @available(iOS 13, *) func test_02_fruser_browser_login_and_logout_success() throws { - try XCTSkipIf(true) // Skip this test - see SDKS-3304 - // SDK init self.startSDK() @@ -62,12 +60,25 @@ class FRUserBrowserTests: FRAuthBaseTest { "OAuth2_Token_Revoke_Success", "OAuth2_EndSession_Success"]) + // Get top VC + let keyWindow = UIApplication.shared.windows.filter {$0.isKeyWindow}.first + var topVC = keyWindow?.rootViewController + while let presentedViewController = topVC?.presentedViewController { + topVC = presentedViewController + } + guard let vc = topVC else { + XCTFail("Failed to retrieve top most ViewController") + return + } + let ex = self.expectation(description: "Browser Login") - let _ = FRUser.browser()?.set(browserType: .ephemeralAuthSession).build().login(completion: { (user, error) in + let _ = FRUser.browser()?.set(browserType: .ephemeralAuthSession).set(presentingViewController: vc).build().login(completion: { (user, error) in XCTAssertNil(error) XCTAssertNotNil(user) ex.fulfill() }) + // Sleep for 1 second + sleep(1) // Inject authorization_code to mimic browser authentication let _ = Browser.validateBrowserLogin(url: URL(string: "frauth://com.forgerock.ios/login?code=testcode")!) waitForExpectations(timeout: 60, handler: nil) @@ -87,8 +98,6 @@ class FRUserBrowserTests: FRAuthBaseTest { @available(iOS 13, *) func test_03_fruser_browser_login_and_logout_end_session_failure() throws { - try XCTSkipIf(true) // Skip this test - see SDKS-3304 - // SDK init self.startSDK() @@ -96,13 +105,25 @@ class FRUserBrowserTests: FRAuthBaseTest { self.loadMockResponses(["OAuth2_Token_Success", "OAuth2_Token_Revoke_Success", "OAuth2_EndSession_Failure"]) + + // Get top VC + let keyWindow = UIApplication.shared.windows.filter {$0.isKeyWindow}.first + var topVC = keyWindow?.rootViewController + while let presentedViewController = topVC?.presentedViewController { + topVC = presentedViewController + } + guard let vc = topVC else { + XCTFail("Failed to retrieve top most ViewController") + return + } let ex = self.expectation(description: "Browser Login") - let _ = FRUser.browser()?.set(browserType: .ephemeralAuthSession).build().login(completion: { (user, error) in + let _ = FRUser.browser()?.set(browserType: .ephemeralAuthSession).set(presentingViewController: vc).build().login(completion: { (user, error) in XCTAssertNotNil(user) XCTAssertNil(error) ex.fulfill() }) + // Inject authorization_code to mimic browser authentication let _ = Browser.validateBrowserLogin(url: URL(string: "frauth://com.forgerock.ios/login?code=testcode")!) waitForExpectations(timeout: 60, handler: nil) From 6652adda05dffe99feeac8eceab76fceb02f4992 Mon Sep 17 00:00:00 2001 From: Stoyan Petrov Date: Mon, 15 Jul 2024 08:48:00 -0700 Subject: [PATCH 2/2] Run only FRUserBrowserTests --- .../Model/User/FRUserBrowserTests.swift | 30 +- .../xcschemes/FRTestHost.xcscheme | 308 +++++++++++++++++- 2 files changed, 305 insertions(+), 33 deletions(-) diff --git a/FRAuth/FRAuthTests/FRAuthSwiftTests/FRAuth/Model/User/FRUserBrowserTests.swift b/FRAuth/FRAuthTests/FRAuthSwiftTests/FRAuth/Model/User/FRUserBrowserTests.swift index 88033286..4497d5a9 100644 --- a/FRAuth/FRAuthTests/FRAuthSwiftTests/FRAuth/Model/User/FRUserBrowserTests.swift +++ b/FRAuth/FRAuthTests/FRAuthSwiftTests/FRAuth/Model/User/FRUserBrowserTests.swift @@ -51,6 +51,7 @@ class FRUserBrowserTests: FRAuthBaseTest { @available(iOS 13, *) func test_02_fruser_browser_login_and_logout_success() throws { + // SDK init self.startSDK() @@ -60,25 +61,12 @@ class FRUserBrowserTests: FRAuthBaseTest { "OAuth2_Token_Revoke_Success", "OAuth2_EndSession_Success"]) - // Get top VC - let keyWindow = UIApplication.shared.windows.filter {$0.isKeyWindow}.first - var topVC = keyWindow?.rootViewController - while let presentedViewController = topVC?.presentedViewController { - topVC = presentedViewController - } - guard let vc = topVC else { - XCTFail("Failed to retrieve top most ViewController") - return - } - let ex = self.expectation(description: "Browser Login") - let _ = FRUser.browser()?.set(browserType: .ephemeralAuthSession).set(presentingViewController: vc).build().login(completion: { (user, error) in + let _ = FRUser.browser()?.set(browserType: .ephemeralAuthSession).build().login(completion: { (user, error) in XCTAssertNil(error) XCTAssertNotNil(user) ex.fulfill() }) - // Sleep for 1 second - sleep(1) // Inject authorization_code to mimic browser authentication let _ = Browser.validateBrowserLogin(url: URL(string: "frauth://com.forgerock.ios/login?code=testcode")!) waitForExpectations(timeout: 60, handler: nil) @@ -105,25 +93,13 @@ class FRUserBrowserTests: FRAuthBaseTest { self.loadMockResponses(["OAuth2_Token_Success", "OAuth2_Token_Revoke_Success", "OAuth2_EndSession_Failure"]) - - // Get top VC - let keyWindow = UIApplication.shared.windows.filter {$0.isKeyWindow}.first - var topVC = keyWindow?.rootViewController - while let presentedViewController = topVC?.presentedViewController { - topVC = presentedViewController - } - guard let vc = topVC else { - XCTFail("Failed to retrieve top most ViewController") - return - } let ex = self.expectation(description: "Browser Login") - let _ = FRUser.browser()?.set(browserType: .ephemeralAuthSession).set(presentingViewController: vc).build().login(completion: { (user, error) in + let _ = FRUser.browser()?.set(browserType: .ephemeralAuthSession).build().login(completion: { (user, error) in XCTAssertNotNil(user) XCTAssertNil(error) ex.fulfill() }) - // Inject authorization_code to mimic browser authentication let _ = Browser.validateBrowserLogin(url: URL(string: "frauth://com.forgerock.ios/login?code=testcode")!) waitForExpectations(timeout: 60, handler: nil) diff --git a/FRTestHost/FRTestHost.xcodeproj/xcshareddata/xcschemes/FRTestHost.xcscheme b/FRTestHost/FRTestHost.xcodeproj/xcshareddata/xcschemes/FRTestHost.xcscheme index 46f82f13..6f02557e 100644 --- a/FRTestHost/FRTestHost.xcodeproj/xcshareddata/xcschemes/FRTestHost.xcscheme +++ b/FRTestHost/FRTestHost.xcodeproj/xcshareddata/xcschemes/FRTestHost.xcscheme @@ -173,7 +173,7 @@ + skipped = "YES"> + skipped = "YES"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + skipped = "YES"> + skipped = "YES"> + skipped = "YES"> + skipped = "YES">