Skip to content

Commit a6b5c8f

Browse files
committed
SDKS-4759 - Implement end-to-end instrumented tests for the MFA authentication migration module.
The new test suite verifies the full migration pipeline from legacy ForgeRock Authenticator SDK storage (encrypted SharedPreferences and AndroidKeyStore) to the modern Ping SDK SQLite storage. Key changes: - Added `MigrationTest.kt` containing comprehensive instrumented tests for TOTP, HOTP, Push credentials, Push notifications, and device token migration. - Integrated `MockWebServer` to simulate PingAM registration endpoints for authenticating legacy Push mechanisms during tests. - Implemented robust cleanup logic to ensure test isolation by removing SharedPreferences, KeyStore entries, and SQLite databases before and after each test. - Verified migration idempotency, progress event emission order, and automatic cleanup of legacy data upon successful migration. - Updated `build.gradle.kts` with necessary `androidTest` dependencies including `mockwebserver`, `nimbus-jose-jwt`, and the legacy `forgerock-authenticator` SDK. - Configured JNI library packaging options in `build.gradle.kts` to resolve duplicate `.so` file conflicts during instrumentation tests.
1 parent 8ab10dc commit a6b5c8f

10 files changed

Lines changed: 1421 additions & 9 deletions

File tree

mfa/auth-migration/build.gradle.kts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/*
2+
* Copyright (c) 2026 Ping Identity Corporation. All rights reserved.
3+
*
4+
* This software may be modified and distributed under the terms
5+
* of the MIT license. See the LICENSE file for details.
6+
*/
7+
18
description = "Legacy Authentication Migration"
29

310
plugins {
@@ -41,5 +48,10 @@ dependencies {
4148
testImplementation(libs.mockk)
4249
testImplementation(libs.robolectric)
4350
testImplementation(project(":foundation:android"))
44-
testImplementation(libs.forgerock.authenticator)
51+
52+
androidTestImplementation(libs.mockwebserver)
53+
androidTestImplementation(libs.kotlinx.coroutines.test)
54+
androidTestImplementation(libs.kotlin.test)
55+
androidTestImplementation(libs.androidx.junit)
56+
androidTestImplementation(libs.androidx.test.runner)
4557
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright (c) 2019 - 2026 Ping Identity Corporation. All rights reserved.
4+
~
5+
~ This software may be modified and distributed under the terms
6+
~ of the MIT license. See the LICENSE file for details.
7+
-->
8+
9+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
10+
11+
<application
12+
android:allowBackup="false"
13+
android:label="Test"
14+
android:supportsRtl="true"
15+
android:usesCleartextTraffic="true">
16+
17+
</application>
18+
19+
</manifest>

mfa/auth-migration/src/androidTest/kotlin/com/pingidentity/auth/migration/MigrationTest.kt

Lines changed: 1085 additions & 0 deletions
Large diffs are not rendered by default.

mfa/auth-migration/src/main/kotlin/com/pingidentity/auth/migration/AuthMigration.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
/*
22
* Copyright (c) 2026 Ping Identity Corporation. All rights reserved.
3+
*
34
* This software may be modified and distributed under the terms
45
* of the MIT license. See the LICENSE file for details.
56
*/
67

78
package com.pingidentity.auth.migration
89

910
import android.content.Context
11+
import com.pingidentity.auth.migration.AuthMigration.logger
12+
import com.pingidentity.auth.migration.AuthMigration.start
1013
import com.pingidentity.logger.Logger
1114
import com.pingidentity.logger.STANDARD
1215
import com.pingidentity.migration.Migration
1316
import com.pingidentity.migration.MigrationProgress
17+
import kotlinx.coroutines.flow.FlowCollector
1418
import kotlinx.coroutines.sync.Mutex
1519
import kotlinx.coroutines.sync.withLock
1620

@@ -112,7 +116,7 @@ object AuthMigration {
112116
step(cleanupLegacyDataStep(config.legacyStorageProvider, config.backup))
113117
}
114118

115-
migration.migrate(context).collect { progress ->
119+
val collector = config.progress ?: FlowCollector { progress ->
116120
when (progress) {
117121
is MigrationProgress.Started -> {
118122
logger.i("Migration started")
@@ -134,6 +138,8 @@ object AuthMigration {
134138
}
135139
}
136140
}
141+
142+
migration.migrate(context).collect(collector)
137143
}
138144
}
139145
}

mfa/auth-migration/src/main/kotlin/com/pingidentity/auth/migration/LegacyAuthenticationConfig.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) 2026 Ping Identity Corporation. All rights reserved.
3+
*
34
* This software may be modified and distributed under the terms
45
* of the MIT license. See the LICENSE file for details.
56
*/
@@ -9,6 +10,8 @@ package com.pingidentity.auth.migration
910
import android.content.Context
1011
import com.pingidentity.logger.Logger
1112
import com.pingidentity.logger.STANDARD
13+
import com.pingidentity.migration.MigrationProgress
14+
import kotlinx.coroutines.flow.FlowCollector
1215
import org.forgerock.android.auth.StorageClient
1316

1417
/**
@@ -29,6 +32,7 @@ import org.forgerock.android.auth.StorageClient
2932
* invoked by [StorageClientProvider.cleanUp] unconditionally — pass a no-op (the default) to
3033
* skip backup. For custom [LegacyStorageProvider] implementations, the callback is forwarded
3134
* via [LegacyStorageProvider.cleanUp] and it is the implementation's responsibility to invoke it.
35+
* @property progress An optional [FlowCollector] that receives migration pipeline events.
3236
*
3337
* ## Example — default migration (no block needed)
3438
* ```kotlin
@@ -72,4 +76,5 @@ class LegacyAuthenticationConfig(context: Context) {
7276
var legacyStorageProvider: LegacyStorageProvider = StorageClientProvider(context)
7377
var logger: Logger = Logger.STANDARD
7478
var backup: (context: Context) -> Unit = {}
79+
var progress: FlowCollector<MigrationProgress>? = null
7580
}

mfa/binding-migration/build.gradle.kts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2025 Ping Identity Corporation. All rights reserved.
2+
* Copyright (c) 2025 - 2026 Ping Identity Corporation. All rights reserved.
33
*
44
* This software may be modified and distributed under the terms
55
* of the MIT license. See the LICENSE file for details.
@@ -18,6 +18,13 @@ plugins {
1818

1919
android {
2020
namespace = "com.pingidentity.device.binding.migration"
21+
22+
packaging {
23+
resources.excludes += setOf(
24+
"META-INF/LICENSE.md",
25+
"META-INF/LICENSE-notice.md",
26+
)
27+
}
2128
}
2229

2330
dependencies {
@@ -37,4 +44,13 @@ dependencies {
3744
testImplementation(libs.mockk)
3845
testImplementation(libs.robolectric)
3946

47+
androidTestImplementation(project(":foundation:journey-plugin"))
48+
androidTestImplementation(libs.mockk)
49+
androidTestImplementation(libs.mockk.android)
50+
androidTestImplementation(libs.kotlinx.coroutines.test)
51+
androidTestImplementation(libs.forgerock.auth)
52+
androidTestImplementation(libs.kotlin.test)
53+
androidTestImplementation(libs.androidx.junit)
54+
androidTestImplementation(libs.androidx.test.runner)
55+
4056
}

0 commit comments

Comments
 (0)