Skip to content

Commit 323b5e6

Browse files
committed
During restart in some login tests
Adding rollbacks in several migration tests
1 parent 7dc8c11 commit 323b5e6

File tree

6 files changed

+108
-68
lines changed

6 files changed

+108
-68
lines changed

native/SampleApps/AuthFlowTester/AuthFlowTesterUITests/Tests/BaseAuthFlowTesterTest.swift

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class BaseAuthFlowTesterTest: XCTestCase {
6767
app.launch()
6868

6969
// Start logged out
70-
if (!loginPage.isShowing()) {
70+
if (mainPage.isShowing()) {
7171
logout()
7272
}
7373
}
@@ -323,17 +323,13 @@ class BaseAuthFlowTesterTest: XCTestCase {
323323
/// with the expected credentials. Use this to test session persistence.
324324
///
325325
/// - Parameters:
326-
/// - user: The user that should still be logged in after restart.
327-
/// - staticAppConfigName: The static app configuration name.
328-
/// - staticScopeSelection: The scope selection for static configuration. Defaults to `.empty`.
326+
/// - user: The user that should still be logged in after restart. Defaults to `.first`.
329327
/// - userAppConfigName: The app configuration the user was logged in with.
330328
/// - userScopeSelection: The scope selection the user was logged in with. Defaults to `.empty`.
331329
/// - useWebServerFlow: Whether web server OAuth flow was used. Defaults to `true`.
332330
/// - useHybridFlow: Whether hybrid authentication flow was used. Defaults to `true`.
333331
func restartAndValidate(
334-
user: KnownUserConfig,
335-
staticAppConfigName: KnownAppConfig,
336-
staticScopeSelection: ScopeSelection = .empty,
332+
user: KnownUserConfig = .first,
337333
userAppConfigName: KnownAppConfig,
338334
userScopeSelection: ScopeSelection = .empty,
339335
useWebServerFlow: Bool = true,
@@ -343,11 +339,10 @@ class BaseAuthFlowTesterTest: XCTestCase {
343339
app.terminate()
344340
app.launch()
345341

346-
// Validate
347-
validate(
342+
// Validate user
343+
// Not checking static app config since it will depend on the bootconfig of the target app
344+
validateUser(
348345
user: user,
349-
staticAppConfigName: staticAppConfigName,
350-
staticScopeSelection: staticScopeSelection,
351346
userAppConfigName: userAppConfigName,
352347
userScopeSelection: userScopeSelection,
353348
useWebServerFlow: useWebServerFlow,
@@ -410,25 +405,24 @@ class BaseAuthFlowTesterTest: XCTestCase {
410405
// MARK: - Private Helpers
411406

412407
@discardableResult
413-
private func validate(
408+
private func validateUser(
414409
user: KnownUserConfig,
415-
staticAppConfigName: KnownAppConfig,
416-
staticScopeSelection: ScopeSelection,
417410
userAppConfigName: KnownAppConfig,
418411
userScopeSelection: ScopeSelection,
419412
useWebServerFlow: Bool,
420-
useHybridFlow: Bool
413+
useHybridFlow: Bool,
421414
) -> UserCredentialsData {
422-
415+
423416
let userConfig = getUser(user)
424-
let staticAppConfig = getAppConfig(named: staticAppConfigName)
425417
let userAppConfig = getAppConfig(named: userAppConfigName)
426418
let expectedGrantedScopes = testConfig.getExpectedScopesGranted(for: userAppConfig, userScopeSelection)
427419
let issuesJwt = userAppConfig.issuesJwt
428420

429421
// Check that app loads and shows the expected user credentials etc
430422
assertMainPageLoaded()
431423

424+
425+
432426
// Check the user credentials (consumer key should match the app config used)
433427
let userCredentials = checkUserCredentials(
434428
username: userConfig.username,
@@ -438,13 +432,6 @@ class BaseAuthFlowTesterTest: XCTestCase {
438432
issuesJwt: issuesJwt
439433
)
440434

441-
// Check the oauth configuration
442-
_ = checkOauthConfiguration(
443-
staticConsumerKey: staticAppConfig.consumerKey,
444-
staticCallbackUrl: staticAppConfig.redirectUri,
445-
staticScopes: testConfig.getScopesToRequest(for: staticAppConfig, staticScopeSelection)
446-
)
447-
448435
// Check JWT if applicable
449436
checkJwtDetailsIfApplicable(
450437
appConfig: userAppConfig,
@@ -462,6 +449,39 @@ class BaseAuthFlowTesterTest: XCTestCase {
462449
return userCredentials
463450
}
464451

452+
@discardableResult
453+
private func validate(
454+
user: KnownUserConfig,
455+
staticAppConfigName: KnownAppConfig,
456+
staticScopeSelection: ScopeSelection,
457+
userAppConfigName: KnownAppConfig,
458+
userScopeSelection: ScopeSelection,
459+
useWebServerFlow: Bool,
460+
useHybridFlow: Bool,
461+
) -> UserCredentialsData {
462+
463+
let staticAppConfig = getAppConfig(named: staticAppConfigName)
464+
465+
// Check that app loads and shows the expected user credentials etc
466+
assertMainPageLoaded()
467+
468+
let userCredentials = validateUser(
469+
user: user,
470+
userAppConfigName: userAppConfigName,
471+
userScopeSelection: userScopeSelection,
472+
useWebServerFlow: useWebServerFlow,
473+
useHybridFlow: useHybridFlow
474+
)
475+
476+
// Check the oauth configuration
477+
_ = checkOauthConfiguration(
478+
staticConsumerKey: staticAppConfig.consumerKey,
479+
staticCallbackUrl: staticAppConfig.redirectUri,
480+
staticScopes: testConfig.getScopesToRequest(for: staticAppConfig, staticScopeSelection)
481+
)
482+
483+
return userCredentials
484+
}
465485

466486
private func migrateRefreshToken(
467487
appConfigName: KnownAppConfig,

native/SampleApps/AuthFlowTester/AuthFlowTesterUITests/Tests/BeaconLoginTests.swift

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,28 @@ class BeaconLoginTests: BaseAuthFlowTesterTest {
7171
// MARK: - Using dynamic config
7272

7373
/// Login with Beacon advanced JWT using default scopes and web server flow provided as dynamic configuration.
74-
func testBeaconAdvancedJwt_DefaultScopes_DynamicConfiguration() throws {
74+
/// Restart the application and validate it still works afterwards
75+
func testBeaconAdvancedJwt_DefaultScopes_DynamicConfiguration_WithRestart() throws {
7576
launchLoginAndValidate(
7677
staticAppConfigName: .beaconAdvancedOpaque,
7778
dynamicAppConfigName: .beaconAdvancedJwt
7879
)
80+
restartAndValidate(
81+
userAppConfigName: .beaconAdvancedJwt
82+
)
7983
}
8084

8185
/// Login with Beacon advanced JWT using subset of scopes and web server flow provided as dynamic configuration.
82-
func testBeaconAdvancedJwt_SubsetScopes_DynamicConfiguration() throws {
86+
/// Restart the application and validate it still works afterwards
87+
func testBeaconAdvancedJwt_SubsetScopes_DynamicConfiguration_WithRestart() throws {
8388
launchLoginAndValidate(
8489
staticAppConfigName: .beaconAdvancedOpaque,
8590
dynamicAppConfigName: .beaconAdvancedJwt,
86-
dynamicScopeSelection: .subset)
91+
dynamicScopeSelection: .subset
92+
)
93+
restartAndValidate(
94+
userAppConfigName: .beaconAdvancedJwt,
95+
userScopeSelection: .subset
96+
)
8797
}
8898
}

native/SampleApps/AuthFlowTester/AuthFlowTesterUITests/Tests/ECALoginTests.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,27 @@ class ECALoginTests: BaseAuthFlowTesterTest {
7171
// MARK: - Using dynamic config
7272

7373
/// Login with ECA advanced JWT using default scopes and web server flow provided as dynamic configuration.
74-
func testECAAdvancedJwt_DefaultScopes_DynamicConfiguration() throws {
74+
/// Restart the application and validate it still works afterwards
75+
func testECAAdvancedJwt_DefaultScopes_DynamicConfiguration_WithRestart() throws {
7576
launchLoginAndValidate(
7677
staticAppConfigName: .ecaAdvancedOpaque,
7778
dynamicAppConfigName: .ecaAdvancedJwt
7879
)
80+
restartAndValidate(
81+
userAppConfigName: .ecaAdvancedJwt
82+
)
7983
}
8084

8185
/// Login with ECA advanced JWT using subset of scopes and web server flow provided as dynamic configuration.
82-
func testECAAdvancedJwt_SubsetScopes_DynamicConfiguration() throws {
86+
/// Restart the application and validate it still works afterwards
87+
func testECAAdvancedJwt_SubsetScopes_DynamicConfiguration_WithRestart() throws {
8388
launchLoginAndValidate(
8489
staticAppConfigName: .ecaAdvancedOpaque,
8590
dynamicAppConfigName: .ecaAdvancedJwt,
8691
dynamicScopeSelection: .subset)
92+
restartAndValidate(
93+
userAppConfigName: .ecaAdvancedJwt,
94+
userScopeSelection: .subset
95+
)
8796
}
8897
}

native/SampleApps/AuthFlowTester/AuthFlowTesterUITests/Tests/LegacyLoginTests.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,19 +107,28 @@ class LegacyLoginTests: BaseAuthFlowTesterTest {
107107
// MARK: - Using dynamic config
108108

109109
/// Login with CA advanced JWT using default scopes and web server flow provided as dynamic configuration.
110-
func testCAAdvancedJwt_DefaultScopes_DynamicConfiguration() throws {
110+
/// Restart the application and validate it still works afterwards
111+
func testCAAdvancedJwt_DefaultScopes_DynamicConfiguration_WithRestart() throws {
111112
launchLoginAndValidate(
112113
staticAppConfigName: .caAdvancedOpaque,
113114
dynamicAppConfigName: .caAdvancedJwt
114115
)
116+
restartAndValidate(
117+
userAppConfigName: .caAdvancedJwt
118+
)
115119
}
116120

117121
/// Login with CA advanced JWT using subset of scopes and web server flow provided as dynamic configuration.
118-
func testCAAdvancedJwt_SubsetScopes_DynamicConfiguration() throws {
122+
/// Restart the application and validate it still works afterwards
123+
func testCAAdvancedJwt_SubsetScopes_DynamicConfiguration_WithRestart() throws {
119124
launchLoginAndValidate(
120125
staticAppConfigName: .caAdvancedOpaque,
121126
dynamicAppConfigName: .caAdvancedJwt,
122127
dynamicScopeSelection: .subset)
128+
restartAndValidate(
129+
userAppConfigName: .caAdvancedJwt,
130+
userScopeSelection: .subset
131+
)
123132
}
124133

125134
}

native/SampleApps/AuthFlowTester/AuthFlowTesterUITests/Tests/MigrationTests.swift

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,21 @@ import XCTest
3636
class MigrationTests: BaseAuthFlowTesterTest {
3737

3838
// MARK: - Migration within same app (scope upgrade)
39+
40+
/// Migrate within same CA (scope upgrade).
41+
func testMigrateCA_AddMoreScopes() throws {
42+
launchAndLogin(
43+
user:.second,
44+
staticAppConfigName: .caAdvancedJwt,
45+
staticScopeSelection: .subset
46+
)
47+
migrateAndValidate(
48+
staticAppConfigName: .caAdvancedJwt,
49+
staticScopeSelection: .subset,
50+
migrationAppConfigName: .caAdvancedJwt,
51+
migrationScopeSelection: .all
52+
)
53+
}
3954

4055
/// Migrate within same ECA (scope upgrade).
4156
func testMigrateECA_AddMoreScopes() throws {
@@ -67,9 +82,9 @@ class MigrationTests: BaseAuthFlowTesterTest {
6782
)
6883
}
6984

70-
// MARK: - Cross-App Migrations
85+
// MARK: - Cross-App Migrations with rollbacks
7186

72-
/// Migrate from CA to ECA
87+
/// Migrate from CA to ECA and back to CA
7388
func testMigrateCAToECA() throws {
7489
launchAndLogin(
7590
user:.second,
@@ -79,34 +94,12 @@ class MigrationTests: BaseAuthFlowTesterTest {
7994
staticAppConfigName: .caAdvancedOpaque,
8095
migrationAppConfigName: .ecaAdvancedOpaque
8196
)
82-
}
83-
84-
/// Migrate from CA to Beacon
85-
func testMigrateCAToBeacon() throws {
86-
launchAndLogin(
87-
user:.second,
88-
staticAppConfigName: .caAdvancedOpaque
89-
)
9097
migrateAndValidate(
91-
staticAppConfigName: .caAdvancedOpaque,
92-
migrationAppConfigName: .beaconAdvancedOpaque
93-
)
94-
}
95-
96-
/// Migrate from Beacon opaque to Beacon JWT
97-
func testMigrateBeaconOpaqueToJWT() throws {
98-
launchAndLogin(
99-
user:.second,
100-
staticAppConfigName: .beaconAdvancedOpaque
101-
)
102-
migrateAndValidate(
103-
staticAppConfigName: .beaconAdvancedOpaque,
104-
migrationAppConfigName: .beaconAdvancedJwt
98+
staticAppConfigName: .caAdvancedOpaque, // should not have changed
99+
migrationAppConfigName: .caAdvancedOpaque
105100
)
106101
}
107102

108-
// MARK: - Migration followed by rollback
109-
110103
// Migrate from CA to Beacon and back to CA
111104
func testMigrateCAToBeaconAndBack() throws {
112105
launchAndLogin(

native/SampleApps/AuthFlowTester/AuthFlowTesterUITests/overview.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ Tests for Connected App (CA) configurations including user agent flow and non-hy
3434
| `testCAAdvancedOpaque_DefaultScopes_UserAgentFlow_NotHybrid` | CA Advanced Opaque | Default | User Agent | No | No |
3535
| `testCAAdvancedOpaque_SubsetScopes_UserAgentFlow_NotHybrid` | CA Advanced Opaque | Subset | User Agent | No | No |
3636
| `testCAAdvancedOpaque_AllScopes_UserAgentFlow_NotHybrid` | CA Advanced Opaque | All | User Agent | No | No |
37-
| `testCAAdvancedJwt_DefaultScopes_DynamicConfiguration` | CA Advanced JWT | Default | Web Server | Yes | Yes |
38-
| `testCAAdvancedJwt_SubsetScopes_DynamicConfiguration` | CA Advanced JWT | Subset | Web Server | Yes | Yes |
37+
| `testCAAdvancedJwt_DefaultScopes_DynamicConfiguration_WithRestart` | CA Advanced JWT | Default | Web Server | Yes | Yes |
38+
| `testCAAdvancedJwt_SubsetScopes_DynamicConfiguration_WithRestart` | CA Advanced JWT | Subset | Web Server | Yes | Yes |
3939

4040
### ECALoginTests (8 tests)
4141

@@ -49,8 +49,8 @@ Tests for External Client App (ECA) configurations using web server flow with hy
4949
| `testECAAdvancedJwt_DefaultScopes` | ECA Advanced JWT | Default | No |
5050
| `testECAAdvancedJwt_SubsetScopes_NotHybrid` | ECA Advanced JWT | Subset | No |
5151
| `testECAAdvancedJwt_AllScopes` | ECA Advanced JWT | All | No |
52-
| `testECAAdvancedJwt_DefaultScopes_DynamicConfiguration` | ECA Advanced JWT | Default | Yes |
53-
| `testECAAdvancedJwt_SubsetScopes_DynamicConfiguration` | ECA Advanced JWT | Subset | Yes |
52+
| `testECAAdvancedJwt_DefaultScopes_DynamicConfiguration_WithRestart` | ECA Advanced JWT | Default | Yes |
53+
| `testECAAdvancedJwt_SubsetScopes_DynamicConfiguration_WithRestart` | ECA Advanced JWT | Subset | Yes |
5454

5555
### BeaconLoginTests (8 tests)
5656

@@ -64,26 +64,25 @@ Tests for Beacon app configurations using web server flow with hybrid auth.
6464
| `testBeaconAdvancedJwt_DefaultScopes` | Beacon Advanced JWT | Default | No |
6565
| `testBeaconAdvancedJwt_SubsetScopes` | Beacon Advanced JWT | Subset | No |
6666
| `testBeaconAdvancedJwt_AllScopes` | Beacon Advanced JWT | All | No |
67-
| `testBeaconAdvancedJwt_DefaultScopes_DynamicConfiguration` | Beacon Advanced JWT | Default | Yes |
68-
| `testBeaconAdvancedJwt_SubsetScopes_DynamicConfiguration` | Beacon Advanced JWT | Subset | Yes |
67+
| `testBeaconAdvancedJwt_DefaultScopes_DynamicConfiguration_WithRestart` | Beacon Advanced JWT | Default | Yes |
68+
| `testBeaconAdvancedJwt_SubsetScopes_DynamicConfiguration_WithRestart` | Beacon Advanced JWT | Subset | Yes |
6969

7070
---
7171

7272
## Migration Tests
7373

74-
### MigrationTests (7 tests)
74+
### MigrationTests (6 tests)
7575

7676
Tests for migrating refresh tokens between different app configurations without re-authentication.
7777

7878
| Test Name | Original App | Migration App | Scope Change |
7979
|-----------|--------------|---------------|--------------|
80+
| `testMigrateCA_AddMoreScopes` | CA Advanced JWT (subset) | CA Advanced JWT (all) | Yes (add more scopes) |
8081
| `testMigrateECA_AddMoreScopes` | ECA Advanced JWT (subset) | ECA Advanced JWT (all) | Yes (add more scopes) |
8182
| `testMigrateBeacon_AddMoreScopes` | Beacon Advanced JWT (subset) | Beacon Advanced JWT (all) | Yes (add more scopes) |
82-
| `testMigrateCAToECA` | CA Advanced Opaque | ECA Advanced Opaque | No |
83-
| `testMigrateCAToBeacon` | CA Advanced Opaque | Beacon Advanced Opaque | No |
84-
| `testMigrateBeaconOpaqueToJWT` | Beacon Advanced Opaque | Beacon Advanced JWT | No |
83+
| `testMigrateCAToECA` | CA Advanced Opaque → ECA Advanced Opaque → CA Advanced Opaque | Migration with rollback | No |
8584
| `testMigrateCAToBeaconAndBack` | CA Advanced Opaque → Beacon Advanced Opaque → CA Advanced Opaque | Migration with rollback | No |
86-
| `testMigrateBeaconOpaqueToJWTAndBack` | Beacon Advanced Opaque → Beacon Advanced JWT | Migration with rollback | No |
85+
| `testMigrateBeaconOpaqueToJWTAndBack` | Beacon Advanced Opaque → Beacon Advanced JWT → Beacon Advanced Opaque | Migration with rollback | No |
8786

8887
---
8988

0 commit comments

Comments
 (0)