-
Notifications
You must be signed in to change notification settings - Fork 121
Fix initialization of authenticator #15953
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
Changes from all commits
a5b8de1
73aa96f
c05fed8
6ba0f92
3c9be27
a605753
e2c525a
40282f6
b4f38e6
4ab5712
061fe4f
10afd4c
e3f7b31
df0a0df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,6 @@ final class JetpackSetupCoordinator { | |
| private let stores: StoresManager | ||
| private let analytics: Analytics | ||
| private let featureFlagService: FeatureFlagService | ||
| private let dotcomAuthScheme: String | ||
|
|
||
| private var loginNavigationController: LoginNavigationController? | ||
| private var setupStepsNavigationController: UINavigationController? | ||
|
|
@@ -43,24 +42,18 @@ final class JetpackSetupCoordinator { | |
| } | ||
|
|
||
| init(site: Site, | ||
| dotcomAuthScheme: String = ApiCredentials.dotcomAuthScheme, | ||
| rootViewController: UIViewController, | ||
| accountService: WordPressComAccountServiceProtocol = WordPressComAccountService(), | ||
| stores: StoresManager = ServiceLocator.stores, | ||
| analytics: Analytics = ServiceLocator.analytics, | ||
| featureFlagService: FeatureFlagService = ServiceLocator.featureFlagService) { | ||
| self.site = site | ||
| self.dotcomAuthScheme = dotcomAuthScheme | ||
| self.requiresConnectionOnly = false // to be updated later after fetching Jetpack status | ||
| self.rootViewController = rootViewController | ||
| self.accountService = accountService | ||
| self.stores = stores | ||
| self.analytics = analytics | ||
| self.featureFlagService = featureFlagService | ||
|
|
||
| /// the authenticator needs to be initialized with configs | ||
| /// to be used for requesting authentication link and handle login later. | ||
| WordPressAuthenticator.initializeWithCustomConfigs(dotcomAuthScheme: dotcomAuthScheme) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed in 40282f6. |
||
| } | ||
|
|
||
| func showBenefitModal() { | ||
|
|
@@ -72,7 +65,7 @@ final class JetpackSetupCoordinator { | |
| rootViewController.present(benefitsController, animated: true, completion: nil) | ||
| } | ||
|
|
||
| func handleAuthenticationUrl(_ url: URL) -> Bool { | ||
| func handleAuthenticationUrl(_ url: URL, dotcomAuthScheme: String = ApiCredentials.dotcomAuthScheme) -> Bool { | ||
| let expectedPrefix = dotcomAuthScheme + "://" + Constants.magicLinkUrlHostname | ||
| guard url.absoluteString.hasPrefix(expectedPrefix) else { | ||
| return false | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ import WordPressAuthenticator | |
| final class JetpackSetupCoordinatorTests: XCTestCase { | ||
|
|
||
| private var navigationController: UINavigationController! | ||
| private let dotcomAuthScheme = "scheme" | ||
|
|
||
| override func setUp() { | ||
| navigationController = UINavigationController() | ||
|
|
@@ -14,6 +15,9 @@ final class JetpackSetupCoordinatorTests: XCTestCase { | |
| window.rootViewController = UIViewController() | ||
| window.makeKeyAndVisible() | ||
| window.rootViewController = navigationController | ||
|
|
||
| AuthenticationManager().initialize() | ||
|
|
||
| super.setUp() | ||
| } | ||
|
|
||
|
|
@@ -40,12 +44,11 @@ final class JetpackSetupCoordinatorTests: XCTestCase { | |
| func test_handleAuthenticationUrl_returns_false_for_unsupported_url_scheme() throws { | ||
| // Given | ||
| let testSite = Site.fake().copy(siteID: WooConstants.placeholderStoreID) | ||
| let expectedScheme = "scheme" | ||
| let coordinator = JetpackSetupCoordinator(site: testSite, dotcomAuthScheme: expectedScheme, rootViewController: navigationController) | ||
| let coordinator = JetpackSetupCoordinator(site: testSite, rootViewController: navigationController) | ||
| let url = try XCTUnwrap(URL(string: "example://handle-authentication")) | ||
|
|
||
| // When | ||
| let result = coordinator.handleAuthenticationUrl(url) | ||
| let result = coordinator.handleAuthenticationUrl(url, dotcomAuthScheme: dotcomAuthScheme) | ||
|
|
||
| // Then | ||
| XCTAssertFalse(result) | ||
|
|
@@ -54,12 +57,11 @@ final class JetpackSetupCoordinatorTests: XCTestCase { | |
| func test_handleAuthenticationUrl_returns_false_for_missing_queries() throws { | ||
| // Given | ||
| let testSite = Site.fake().copy(siteID: -1) | ||
| let expectedScheme = "scheme" | ||
| let coordinator = JetpackSetupCoordinator(site: testSite, dotcomAuthScheme: expectedScheme, rootViewController: navigationController) | ||
| let url = try XCTUnwrap(URL(string: "scheme://magic-login")) | ||
| let coordinator = JetpackSetupCoordinator(site: testSite, rootViewController: navigationController) | ||
| let url = try XCTUnwrap(URL(string: "\(dotcomAuthScheme)://magic-login")) | ||
|
|
||
| // When | ||
| let result = coordinator.handleAuthenticationUrl(url) | ||
| let result = coordinator.handleAuthenticationUrl(url, dotcomAuthScheme: dotcomAuthScheme) | ||
|
|
||
| // Then | ||
| XCTAssertFalse(result) | ||
|
|
@@ -68,12 +70,11 @@ final class JetpackSetupCoordinatorTests: XCTestCase { | |
| func test_handleAuthenticationUrl_returns_false_for_incorrect_host_name() throws { | ||
| // Given | ||
| let testSite = Site.fake().copy(siteID: WooConstants.placeholderStoreID) | ||
| let expectedScheme = "scheme" | ||
| let coordinator = JetpackSetupCoordinator(site: testSite, dotcomAuthScheme: expectedScheme, rootViewController: navigationController) | ||
| let url = try XCTUnwrap(URL(string: "scheme://handle-authentication?token=test")) | ||
| let coordinator = JetpackSetupCoordinator(site: testSite, rootViewController: navigationController) | ||
| let url = try XCTUnwrap(URL(string: "\(dotcomAuthScheme)://handle-authentication?token=test")) | ||
|
|
||
| // When | ||
| let result = coordinator.handleAuthenticationUrl(url) | ||
| let result = coordinator.handleAuthenticationUrl(url, dotcomAuthScheme: dotcomAuthScheme) | ||
|
|
||
| // Then | ||
| XCTAssertFalse(result) | ||
|
|
@@ -82,12 +83,11 @@ final class JetpackSetupCoordinatorTests: XCTestCase { | |
| func test_handleAuthenticationUrl_returns_true_for_correct_url_and_sufficient_queries() throws { | ||
| // Given | ||
| let testSite = Site.fake().copy(siteID: WooConstants.placeholderStoreID) | ||
| let expectedScheme = "scheme" | ||
| let coordinator = JetpackSetupCoordinator(site: testSite, dotcomAuthScheme: expectedScheme, rootViewController: navigationController) | ||
| let url = try XCTUnwrap(URL(string: "scheme://magic-login?token=test")) | ||
| let coordinator = JetpackSetupCoordinator(site: testSite, rootViewController: navigationController) | ||
| let url = try XCTUnwrap(URL(string: "\(dotcomAuthScheme)://magic-login?token=test")) | ||
|
|
||
| // When | ||
| let result = coordinator.handleAuthenticationUrl(url) | ||
| let result = coordinator.handleAuthenticationUrl(url, dotcomAuthScheme: dotcomAuthScheme) | ||
|
|
||
| // Then | ||
| XCTAssertTrue(result) | ||
|
|
@@ -97,9 +97,8 @@ final class JetpackSetupCoordinatorTests: XCTestCase { | |
| // Given | ||
| let stores = MockStoresManager(sessionManager: .makeForTesting(authenticated: true, isWPCom: false, defaultRoles: [.shopManager])) | ||
| let testSite = Site.fake().copy(siteID: WooConstants.placeholderStoreID) | ||
| let expectedScheme = "scheme" | ||
| let coordinator = JetpackSetupCoordinator(site: testSite, dotcomAuthScheme: expectedScheme, rootViewController: navigationController, stores: stores) | ||
| let url = try XCTUnwrap(URL(string: "scheme://magic-login?token=test")) | ||
| let coordinator = JetpackSetupCoordinator(site: testSite, rootViewController: navigationController, stores: stores) | ||
| let url = try XCTUnwrap(URL(string: "\(dotcomAuthScheme)://magic-login?token=test")) | ||
|
|
||
| let expectedAccount = Account(userID: 123, displayName: "Test", email: "[email protected]", username: "test", gravatarUrl: nil) | ||
| stores.whenReceivingAction(ofType: JetpackConnectionAction.self) { action in | ||
|
|
@@ -115,9 +114,10 @@ final class JetpackSetupCoordinatorTests: XCTestCase { | |
| stores.mockJetpackCheck() | ||
|
|
||
| // When | ||
| _ = coordinator.handleAuthenticationUrl(url) | ||
| let result = coordinator.handleAuthenticationUrl(url, dotcomAuthScheme: dotcomAuthScheme) | ||
|
|
||
| // Then | ||
| XCTAssertTrue(result) | ||
| waitUntil { | ||
| (self.navigationController.presentedViewController as? UINavigationController)?.topViewController is AdminRoleRequiredHostingController | ||
| } | ||
|
|
@@ -127,9 +127,9 @@ final class JetpackSetupCoordinatorTests: XCTestCase { | |
| // Given | ||
| let stores = MockStoresManager(sessionManager: .makeForTesting(authenticated: true, isWPCom: false)) | ||
| let testSite = Site.fake().copy(siteID: WooConstants.placeholderStoreID) | ||
| let coordinator = JetpackSetupCoordinator(site: testSite, rootViewController: navigationController, stores: stores) | ||
| let expectedScheme = "scheme" | ||
| let coordinator = JetpackSetupCoordinator(site: testSite, dotcomAuthScheme: expectedScheme, rootViewController: navigationController, stores: stores) | ||
| let url = try XCTUnwrap(URL(string: "scheme://magic-login?token=test")) | ||
| let url = try XCTUnwrap(URL(string: "\(dotcomAuthScheme)://magic-login?token=test")) | ||
|
|
||
| let expectedAccount = Account(userID: 123, displayName: "Test", email: "[email protected]", username: "test", gravatarUrl: nil) | ||
| stores.whenReceivingAction(ofType: JetpackConnectionAction.self) { action in | ||
|
|
@@ -145,9 +145,10 @@ final class JetpackSetupCoordinatorTests: XCTestCase { | |
| stores.mockJetpackCheck() | ||
|
|
||
| // When | ||
| _ = coordinator.handleAuthenticationUrl(url) | ||
| let result = coordinator.handleAuthenticationUrl(url, dotcomAuthScheme: dotcomAuthScheme) | ||
|
|
||
| // Then | ||
| XCTAssertTrue(result) | ||
| waitUntil { | ||
| (self.navigationController.presentedViewController as? UINavigationController)?.topViewController is JetpackSetupHostingController | ||
| } | ||
|
|
@@ -158,9 +159,8 @@ final class JetpackSetupCoordinatorTests: XCTestCase { | |
| let stores = MockStoresManager(sessionManager: .makeForTesting(authenticated: true, isWPCom: false)) | ||
| let siteURL = "https://example.com" | ||
| let testSite = Site.fake().copy(siteID: WooConstants.placeholderStoreID, url: siteURL) | ||
| let expectedScheme = "scheme" | ||
| let coordinator = JetpackSetupCoordinator(site: testSite, dotcomAuthScheme: expectedScheme, rootViewController: navigationController, stores: stores) | ||
| let url = try XCTUnwrap(URL(string: "scheme://magic-login?token=test")) | ||
| let coordinator = JetpackSetupCoordinator(site: testSite, rootViewController: navigationController, stores: stores) | ||
| let url = try XCTUnwrap(URL(string: "\(dotcomAuthScheme)://magic-login?token=test")) | ||
|
|
||
| let expectedAccount = Account(userID: 123, displayName: "Test", email: "[email protected]", username: "test", gravatarUrl: nil) | ||
| stores.whenReceivingAction(ofType: JetpackConnectionAction.self) { action in | ||
|
|
@@ -200,9 +200,10 @@ final class JetpackSetupCoordinatorTests: XCTestCase { | |
| stores.mockJetpackCheck() | ||
|
|
||
| // When | ||
| _ = coordinator.handleAuthenticationUrl(url) | ||
| let result = coordinator.handleAuthenticationUrl(url, dotcomAuthScheme: dotcomAuthScheme) | ||
|
|
||
| // Then | ||
| XCTAssertTrue(result) | ||
| waitUntil { | ||
| stores.sessionManager.defaultSite == expectedSite | ||
| } | ||
|
|
||
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.
There is another
configureAuthenticatorcall on line 292. Should it removed as well?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.
Thanks for catching this! Removed in b4f38e6.