From 1928bdc80e3770b4bd7d966054372f8e9d408e3a Mon Sep 17 00:00:00 2001 From: scannillo <35243507+scannillo@users.noreply.github.com> Date: Fri, 3 Nov 2023 16:46:35 -0500 Subject: [PATCH] Use hardcoded ClientToken in UITests (#431) Co-authored-by: Jax DesMarais-Leder --- Demo/Application/DemoAppDelegate.swift | 17 ++++--- .../DemoContainerViewController.swift | 48 ++++++++++--------- .../DemoDropInViewController.swift | 2 +- Demo/Application/Settings/DemoSettings.swift | 17 ++++--- .../Settings/Settings.bundle/Root.plist | 18 +++++-- Demo/UITests/BraintreeDropIn_UITests.swift | 19 ++++---- 6 files changed, 69 insertions(+), 52 deletions(-) diff --git a/Demo/Application/DemoAppDelegate.swift b/Demo/Application/DemoAppDelegate.swift index aba7efd7..033aa7e1 100644 --- a/Demo/Application/DemoAppDelegate.swift +++ b/Demo/Application/DemoAppDelegate.swift @@ -56,13 +56,16 @@ class DemoAppDelegate: UIResponder, UIApplicationDelegate { UserDefaults.standard.set(BTThreeDSecureVersion.version1.rawValue, forKey:DemoSettings.ThreeDSecureVersionDefaultsKey) } - if testArguments.contains("-TokenizationKey") { - UserDefaults.standard.set(true, forKey:"BraintreeDemoUseTokenizationKey") - } else if testArguments.contains("-ClientToken") { - UserDefaults.standard.set(false, forKey:"BraintreeDemoUseTokenizationKey") - // Use random users for testing with Client Tokens - UserDefaults.standard.set(true, forKey:"BraintreeDemoCustomerPresent") - UserDefaults.standard.set("", forKey:"BraintreeDemoCustomerIdentifier") + if testArguments.contains("-ClientToken") { + UserDefaults.standard.set(DemoAuthType.clientToken.rawValue, forKey: DemoSettings.AuthorizationTypeDefaultsKey) + } else if testArguments.contains("-TokenizationKey") { + UserDefaults.standard.setValue(DemoAuthType.tokenizationKey.rawValue, forKey: DemoSettings.AuthorizationTypeDefaultsKey) + } else if testArguments.contains("-MockedPayPalTokenizationKey") { + UserDefaults.standard.setValue(DemoAuthType.mockedPayPalTokenizationKey.rawValue, forKey: DemoSettings.AuthorizationTypeDefaultsKey) + } else if testArguments.contains("-UITestHardcodedClientTokenWithoutCustomerID") { + UserDefaults.standard.setValue(DemoAuthType.uiTestHardcodedClientTokenWithoutCustomerID.rawValue, forKey: DemoSettings.AuthorizationTypeDefaultsKey) + } else if testArguments.contains("-UITestHardcodedClientTokenWithCVVValidationEnabled") { + UserDefaults.standard.setValue(DemoAuthType.uiTestHardcodedClientTokenwithCVVValidationEnabled.rawValue, forKey: DemoSettings.AuthorizationTypeDefaultsKey) } if testArguments.contains("-CreateVaultedPaymentMethod") { diff --git a/Demo/Application/DemoContainerViewController.swift b/Demo/Application/DemoContainerViewController.swift index 9ada5ab0..1c9caf9e 100644 --- a/Demo/Application/DemoContainerViewController.swift +++ b/Demo/Application/DemoContainerViewController.swift @@ -90,17 +90,19 @@ class DemoContainerViewController: UIViewController { title = NSLocalizedString("Braintree", comment: "") - if let auth = DemoSettings.authorizationOverride { - currentViewController = instantiateCurrentViewController(with: auth) - } else if DemoSettings.useMockedPayPalFlow { - updateStatusItem("Using Tokenization Key") - - let tokenizationKey: String - - tokenizationKey = "sandbox_q7v35n9n_555d2htrfsnnmfb3" - currentViewController = instantiateCurrentViewController(with: tokenizationKey) - } - else if DemoSettings.useTokenizationKey { + switch DemoSettings.demoAuthType { + case .clientToken: + updateStatusItem("Fetching Client Token...") + + DemoMerchantAPIClient.shared.createCustomerAndFetchClientToken { clientToken, error in + guard let clientToken else { + self.updateStatusItem(error?.localizedDescription ?? "An unknown error occurred.") + return + } + + self.currentViewController = self.instantiateCurrentViewController(with: clientToken) + } + case .tokenizationKey: let tokenizationKey: String switch DemoSettings.currentEnvironment { @@ -113,17 +115,19 @@ class DemoContainerViewController: UIViewController { } currentViewController = instantiateCurrentViewController(with: tokenizationKey) - } else { - updateStatusItem("Fetching Client Token...") - - DemoMerchantAPIClient.shared.createCustomerAndFetchClientToken { (clientToken, error) in - guard let token = clientToken else { - self.updateStatusItem(error?.localizedDescription ?? "An unknown error occurred.") - return - } - - self.currentViewController = self.instantiateCurrentViewController(with: token) - } + case .mockedPayPalTokenizationKey: + updateStatusItem("Using Tokenization Key") + + let tokenizationKey: String + + tokenizationKey = "sandbox_q7v35n9n_555d2htrfsnnmfb3" + currentViewController = instantiateCurrentViewController(with: tokenizationKey) + case .uiTestHardcodedClientTokenWithoutCustomerID: + let uiTestClientTokenWithoutCustomerID = "eyJ2ZXJzaW9uIjozLCJhdXRob3JpemF0aW9uRmluZ2VycHJpbnQiOiIxYzM5N2E5OGZmZGRkNDQwM2VjNzEzYWRjZTI3NTNiMzJlODc2MzBiY2YyN2M3NmM2OWVmZjlkMTE5MjljOTVkfGNyZWF0ZWRfYXQ9MjAxNy0wNC0wNVQwNjowNzowOC44MTUwOTkzMjUrMDAwMFx1MDAyNm1lcmNoYW50X2lkPWRjcHNweTJicndkanIzcW5cdTAwMjZwdWJsaWNfa2V5PTl3d3J6cWszdnIzdDRuYzgiLCJjb25maWdVcmwiOiJodHRwczovL2FwaS5zYW5kYm94LmJyYWludHJlZWdhdGV3YXkuY29tOjQ0My9tZXJjaGFudHMvZGNwc3B5MmJyd2RqcjNxbi9jbGllbnRfYXBpL3YxL2NvbmZpZ3VyYXRpb24ifQ==" + currentViewController = instantiateCurrentViewController(with: uiTestClientTokenWithoutCustomerID) + case .uiTestHardcodedClientTokenwithCVVValidationEnabled: + let uiTestClientTokenWithCVV = "eyJ2ZXJzaW9uIjoyLCJhdXRob3JpemF0aW9uRmluZ2VycHJpbnQiOiI2ZGE5Y2VhMzVkNGNlMjkxNGI3YzBiOGRiN2M5OWU4MjVmYTQ5ZTY5OTNiYWM4YmE3MTQwYjdiZjI0ODc4NGQ0fGNyZWF0ZWRfYXQ9MjAxOC0wMy0xMlQyMTo0MzoxMS4wOTI1MzAxNDcrMDAwMCZjdXN0b21lcl9pZD01ODA3NDE3NzEmbWVyY2hhbnRfaWQ9aGg0Y3BjMzl6cTRyZ2pjZyZwdWJsaWNfa2V5PXEzanRzcTNkM3Aycmg1dnQiLCJjb25maWdVcmwiOiJ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5jb20iLCJhc3NldHNVcmwiOiJodHRwczovL2NoZWNrb3V0LnBheXBhbC5jb20iLCJkaXJlY3RCYXNlVXJsIjpudWxsLCJhbGxvd0h0dHAiOnRydWUsImVudmlyb25tZW50Tm9OZXR3b3JrIjpmYWxzZSwiZW52aXJvbm1lbnQiOiJvZmZsaW5lIiwidW52ZXR0ZWRNZXJjaGFudCI6ZmFsc2UsImJyYWludHJlZUNsaWVudElkIjoibWFzdGVyY2xpZW50MyIsImJpbGxpbmdBZ3JlZW1lbnRzRW5hYmxlZCI6dHJ1ZSwibWVyY2hhbnRBY2NvdW50SWQiOiJjNXljdzJzdnlrbnp3anR6IiwiY3VycmVuY3lJc29Db2RlIjoiVVNEIn0sIm1lcmNoYW50SWQiOiJoaDRjcGMzOXpxNHJnamNnIiwidmVubW8iOiJvZmYiLCJicmFpbnRyZWVfYXBpIjp7InVybCI6Imh0dHBzOi8vcGF5bWVudHMuc2FuZGJveC5icmFpbnRyZWUtYXBpLmNvbSIsImFjY2Vzc190b2tlbiI6InNhbmRib3hfNmRkdG13X3B6YjZ3cF93ZHdoY3lfOWhnNm5iX2N5NiJ9fQ==" + currentViewController = instantiateCurrentViewController(with: uiTestClientTokenWithCVV) } } diff --git a/Demo/Application/DemoDropInViewController.swift b/Demo/Application/DemoDropInViewController.swift index 8ffcccee..6ebd7cc6 100644 --- a/Demo/Application/DemoDropInViewController.swift +++ b/Demo/Application/DemoDropInViewController.swift @@ -27,7 +27,7 @@ class DemoDropInViewController: DemoBaseViewController, DemoDropInViewDelegate { override func viewDidLoad() { super.viewDidLoad() - if !DemoSettings.useTokenizationKey { + if DemoSettings.demoAuthType != .tokenizationKey { fetchPaymentMethods() } } diff --git a/Demo/Application/Settings/DemoSettings.swift b/Demo/Application/Settings/DemoSettings.swift index 13ed8808..ef8740e1 100644 --- a/Demo/Application/Settings/DemoSettings.swift +++ b/Demo/Application/Settings/DemoSettings.swift @@ -17,6 +17,14 @@ enum DemoThreeDSecureRequiredSetting: Int { case optional } +enum DemoAuthType: Int { + case clientToken + case tokenizationKey + case mockedPayPalTokenizationKey + case uiTestHardcodedClientTokenWithoutCustomerID + case uiTestHardcodedClientTokenwithCVVValidationEnabled +} + class DemoSettings { static let UIFrameworkDefaultsKey = "BraintreeDemoSettingsUIFrameworkDefaultsKey" @@ -24,10 +32,7 @@ class DemoSettings { static let CustomEnvironmentURLDefaultsKey = "BraintreeDemoSettingsCustomEnvironmentURLDefaultsKey" static let ThreeDSecureRequiredDefaultsKey = "BraintreeDemoSettingsThreeDSecureRequiredDefaultsKey" static let ThreeDSecureVersionDefaultsKey = "BraintreeDemoSettingsThreeDSecureVersionDefaultsKey" - - static var useMockedPayPalFlow: Bool { - ProcessInfo.processInfo.arguments.contains("-UseMockedPayPalFlow") - } + static let AuthorizationTypeDefaultsKey = "BraintreeDemoSettingsAuthorizationTypeKey" static var currentUIFramework: DemoUIFramework { return DemoUIFramework(rawValue: UserDefaults.standard.integer(forKey: UIFrameworkDefaultsKey)) ?? DemoUIFramework.uikit @@ -68,8 +73,8 @@ class DemoSettings { return UserDefaults.standard.string(forKey: "BraintreeDemoSettingsAuthorizationOverride") } - static var useTokenizationKey: Bool { - return UserDefaults.standard.bool(forKey: "BraintreeDemoUseTokenizationKey") + static var demoAuthType: DemoAuthType { + return DemoAuthType(rawValue: UserDefaults.standard.integer(forKey: AuthorizationTypeDefaultsKey))! } static var threeDSecureRequiredStatus: DemoThreeDSecureRequiredSetting { diff --git a/Demo/Application/Settings/Settings.bundle/Root.plist b/Demo/Application/Settings/Settings.bundle/Root.plist index 19ca68b5..09f2b4d4 100644 --- a/Demo/Application/Settings/Settings.bundle/Root.plist +++ b/Demo/Application/Settings/Settings.bundle/Root.plist @@ -64,13 +64,21 @@ Type - PSToggleSwitchSpecifier + PSMultiValueSpecifier Title - Use Tokenization Key + Authorization Type Key - BraintreeDemoUseTokenizationKey - DefaultValue - + BraintreeDemoSettingsAuthorizationTypeKey + Titles + + Client Token + Tokenization Key + + Values + + 0 + 1 + Type diff --git a/Demo/UITests/BraintreeDropIn_UITests.swift b/Demo/UITests/BraintreeDropIn_UITests.swift index e4342dea..965805e0 100644 --- a/Demo/UITests/BraintreeDropIn_UITests.swift +++ b/Demo/UITests/BraintreeDropIn_UITests.swift @@ -108,9 +108,8 @@ class BraintreeDropIn_securityCodeValidation_CardForm_UITests: XCTestCase { continueAfterFailure = false app = XCUIApplication() app.launchArguments.append("-EnvironmentSandbox") + app.launchArguments.append("-UITestHardcodedClientTokenWithCVVValidationEnabled") app.launchArguments.append("-ThreeDSecureDefault") - // NOTE: This sandbox client token has CVV validation enabled. - app.launchArguments.append("-Authorization:eyJ2ZXJzaW9uIjoyLCJhdXRob3JpemF0aW9uRmluZ2VycHJpbnQiOiI2ZGE5Y2VhMzVkNGNlMjkxNGI3YzBiOGRiN2M5OWU4MjVmYTQ5ZTY5OTNiYWM4YmE3MTQwYjdiZjI0ODc4NGQ0fGNyZWF0ZWRfYXQ9MjAxOC0wMy0xMlQyMTo0MzoxMS4wOTI1MzAxNDcrMDAwMCZjdXN0b21lcl9pZD01ODA3NDE3NzEmbWVyY2hhbnRfaWQ9aGg0Y3BjMzl6cTRyZ2pjZyZwdWJsaWNfa2V5PXEzanRzcTNkM3Aycmg1dnQiLCJjb25maWdVcmwiOiJodHRwczovL2FwaS5zYW5kYm94LmJyYWludHJlZWdhdGV3YXkuY29tOjQ0My9tZXJjaGFudHMvaGg0Y3BjMzl6cTRyZ2pjZy9jbGllbnRfYXBpL3YxL2NvbmZpZ3VyYXRpb24iLCJncmFwaFFMVXJsIjoiaHR0cHM6Ly9wYXltZW50cy5zYW5kYm94LmJyYWludHJlZS1hcGkuY29tL2dyYXBocWwiLCJjaGFsbGVuZ2VzIjpbImN2diJdLCJlbnZpcm9ubWVudCI6InNhbmRib3giLCJjbGllbnRBcGlVcmwiOiJodHRwczovL2FwaS5zYW5kYm94LmJyYWludHJlZWdhdGV3YXkuY29tOjQ0My9tZXJjaGFudHMvaGg0Y3BjMzl6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VVNEIn0sIm1lcmNoYW50SWQiOiJoaDRjcGMzOXpxNHJnamNnIiwidmVubW8iOiJvZmYiLCJicmFpbnRyZWVfYXBpIjp7InVybCI6Imh0dHBzOi8vcGF5bWVudHMuc2FuZGJveC5icmFpbnRyZWUtYXBpLmNvbSIsImFjY2Vzc190b2tlbiI6InNhbmRib3hfNmRkdG13X3B6YjZ3cF93ZHdoY3lfOWhnNm5iX2N5NiJ9fQ==") app.launch() sleep(1) let button = app.buttons.containing(NSPredicate(format: "label LIKE '* Payment Method'")).element @@ -482,7 +481,7 @@ class BraintreeDropIn_ClientToken_CardForm_UITests: XCTestCase { continueAfterFailure = false app = XCUIApplication() app.launchArguments.append("-EnvironmentSandbox") - app.launchArguments.append("-ClientToken") + app.launchArguments.append("-UITestHardcodedClientTokenWithoutCustomerID") app.launchArguments.append("-ThreeDSecureDefault") app.launch() sleep(1) @@ -617,8 +616,7 @@ class BraintreeDropIn_PayPal_UITests: XCTestCase { continueAfterFailure = false app = XCUIApplication() app.launchArguments.append("-EnvironmentSandbox") - app.launchArguments.append("-TokenizationKey") - app.launchArguments.append("-UseMockedPayPalFlow") + app.launchArguments.append("-MockedPayPalTokenizationKey") app.launch() sleep(1) waitForElementToBeHittable(app.buttons["Add Payment Method"]) @@ -697,8 +695,7 @@ class BraintreeDropIn_PayPal_OneTime_UITests: XCTestCase { app = XCUIApplication() app.launchArguments.append("-EnvironmentSandbox") app.launchArguments.append("-PayPalOneTime") - app.launchArguments.append("-TokenizationKey") - app.launchArguments.append("-UseMockedPayPalFlow") + app.launchArguments.append("-MockedPayPalTokenizationKey") app.launch() sleep(1) waitForElementToBeHittable(app.buttons["Add Payment Method"]) @@ -769,7 +766,7 @@ class BraintreeDropIn_ThreeDSecure_2_UITests: XCTestCase { continueAfterFailure = false app = XCUIApplication() app.launchArguments.append("-EnvironmentSandbox") - app.launchArguments.append("-ClientToken") + app.launchArguments.append("-UITestHardcodedClientTokenWithoutCustomerID") app.launchArguments.append("-ThreeDSecureRequired") app.launchArguments.append("-ThreeDSecureVersion2") app.launch() @@ -960,7 +957,7 @@ class BraintreeDropIn_SaveCardToggleVisibleAndOn_UITests: XCTestCase { continueAfterFailure = false app = XCUIApplication() app.launchArguments.append("-EnvironmentSandbox") - app.launchArguments.append("-ClientToken") + app.launchArguments.append("-UITestHardcodedClientTokenWithoutCustomerID") app.launchArguments.append("-ThreeDSecureDefault") app.launchArguments.append("-SaveCardToggleVisible") app.launch() @@ -997,7 +994,7 @@ class BraintreeDropIn_SaveCardToggleVisibleAndOff_UITests: XCTestCase { continueAfterFailure = false app = XCUIApplication() app.launchArguments.append("-EnvironmentSandbox") - app.launchArguments.append("-ClientToken") + app.launchArguments.append("-UITestHardcodedClientTokenWithoutCustomerID") app.launchArguments.append("-ThreeDSecureDefault") app.launchArguments.append("-SaveCardToggleVisible") app.launchArguments.append("-VaultCardIsFalse") @@ -1034,7 +1031,7 @@ class BraintreeDropIn_SaveCardToggleHidden_UITests: XCTestCase { continueAfterFailure = false app = XCUIApplication() app.launchArguments.append("-EnvironmentSandbox") - app.launchArguments.append("-ClientToken") + app.launchArguments.append("-UITestHardcodedClientTokenWithoutCustomerID") app.launchArguments.append("-ThreeDSecureDefault") app.launch() sleep(1)