-
Notifications
You must be signed in to change notification settings - Fork 910
[PM-28086] Add testharness for Credential Manager and Autofill testing #6159
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
634aa91
89f4090
d70615b
2f970ee
646c2ac
53d0f44
a5db63e
0e5fc1a
39f8529
e840bec
20c24ff
e65bc69
89c236f
8b4eba7
e5469e2
5178504
061da02
fe3bec0
620d0a3
0ef026f
e9670c6
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 |
|---|---|---|
|
|
@@ -56,5 +56,6 @@ include( | |
| ":cxf", | ||
| ":data", | ||
| ":network", | ||
| ":testharness", | ||
| ":ui", | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| /build | ||
| *.iml | ||
| .gradle | ||
| /local.properties | ||
| .idea/ | ||
| .DS_Store | ||
| /captures | ||
| .externalNativeBuild | ||
| .cxx |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| # Credential Manager Test Harness | ||
|
|
||
| ## Purpose | ||
|
|
||
| This standalone application serves as a test client for validating the Bitwarden Android credential provider implementation. It uses the Android CredentialManager APIs to request credential operations and verify that the `:app` module responds correctly as a credential provider. | ||
|
|
||
| Future iterations will introduce validation for the Android Autofill Framework. | ||
|
|
||
| ## Features | ||
|
|
||
| - **Password Creation**: Test `CreatePasswordRequest` flow through CredentialManager | ||
| - **Password Retrieval**: Test `GetPasswordOption` flow through CredentialManager | ||
| - **Passkey Creation**: Test `CreatePublicKeyCredentialRequest` flow through CredentialManager | ||
|
|
||
| ## Requirements | ||
|
|
||
| - Android device or emulator running API 28+ | ||
| - Bitwarden app (`:app`) installed and configured as a credential provider | ||
| - Google Play Services (for API 28-33 compatibility) | ||
|
|
||
| ## Usage | ||
|
|
||
| ### Setup | ||
|
|
||
| 1. Build and install the main Bitwarden app (`:app`) | ||
| 2. Configure Bitwarden as a credential provider in system settings: | ||
| - Settings โ Passwords & accounts โ Credential Manager | ||
| - Enable Bitwarden as a provider | ||
| 3. Build and install the test harness: | ||
| ```bash | ||
| ./gradlew :testharness:installDebug | ||
| ``` | ||
|
|
||
| ### Running Tests | ||
|
|
||
| 1. Launch "Credential Manager Test Harness" app | ||
| 2. Select a credential operation type (Password Create, Password Get, or Passkey Create) | ||
| 3. Fill in required fields: | ||
| - **Password Create**: Username, Password, Origin (optional) | ||
| - **Password Get**: No inputs required | ||
| - **Passkey Create**: Username, Relying Party ID, Origin | ||
| - **Passkey Get**: Relying Party ID, Origin | ||
| 4. Tap "Execute" button | ||
| 5. System credential picker should appear with Bitwarden as an option | ||
| 6. Select Bitwarden and follow the flow | ||
| 7. Result will be displayed in the app | ||
|
|
||
| ## Known Limitations | ||
|
|
||
| 1. **API 28-33 compatibility**: Requires Google Play Services for CredentialManager APIs on older Android versions. | ||
| 2. Passkey operations must be performed as a Privileged App due to security measures built in `:app`. | ||
|
|
||
| ## Architecture | ||
|
|
||
| This module follows the same architectural patterns as the main Bitwarden app: | ||
| - **MVVM + UDF**: `BaseViewModel` with State/Action/Event pattern | ||
| - **Hilt DI**: Dependency injection throughout | ||
| - **Compose UI**: Modern declarative UI with Material 3 | ||
| - **Result handling**: No exceptions, sealed result classes | ||
|
|
||
| ## Testing | ||
|
|
||
| Run unit tests: | ||
| ```bash | ||
| ./gradlew :testharness:test | ||
| ``` | ||
|
|
||
| ### Debugging | ||
|
|
||
| Check Logcat for detailed error messages: | ||
| ```bash | ||
| adb logcat | grep -E "CredentialManager|Bitwarden|TestHarness" | ||
| ``` | ||
|
|
||
| ## References | ||
|
|
||
| - [Android Credential Manager Documentation](https://developer.android.com/identity/credential-manager) | ||
| - [Bitwarden Android Architecture](../docs/ARCHITECTURE.md) | ||
| - [Passkey Registration Research](../PASSKEY_REGISTRATION_RESEARCH_REPORT.md) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| import org.jetbrains.kotlin.gradle.dsl.JvmTarget | ||
|
|
||
| plugins { | ||
| alias(libs.plugins.android.application) | ||
| alias(libs.plugins.hilt) | ||
| alias(libs.plugins.kotlin.android) | ||
| alias(libs.plugins.kotlin.compose.compiler) | ||
| alias(libs.plugins.kotlin.parcelize) | ||
| alias(libs.plugins.kotlin.serialization) | ||
| alias(libs.plugins.ksp) | ||
| } | ||
|
|
||
| android { | ||
| namespace = "com.bitwarden.testharness" | ||
| compileSdk = libs.versions.compileSdk.get().toInt() | ||
|
|
||
| defaultConfig { | ||
| applicationId = "com.bitwarden.testharness" | ||
| // API 28 - CredentialManager with Play Services support | ||
| minSdk = libs.versions.minSdkBwa.get().toInt() | ||
| targetSdk = libs.versions.targetSdk.get().toInt() | ||
| versionCode = 1 | ||
| versionName = "1.0.0" | ||
|
|
||
| testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
| } | ||
|
|
||
| buildTypes { | ||
| debug { | ||
| applicationIdSuffix = ".dev" | ||
| isDebuggable = true | ||
| } | ||
| release { | ||
| isMinifyEnabled = true | ||
| proguardFiles( | ||
| getDefaultProguardFile("proguard-android-optimize.txt"), | ||
| "proguard-rules.pro", | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| buildFeatures { | ||
| compose = true | ||
| buildConfig = true | ||
| } | ||
|
|
||
| testOptions { | ||
| // Required for Android framework classes in unit tests | ||
| unitTests.isIncludeAndroidResources = true | ||
| unitTests.isReturnDefaultValues = true | ||
| } | ||
|
|
||
| compileOptions { | ||
| sourceCompatibility(libs.versions.jvmTarget.get()) | ||
| targetCompatibility(libs.versions.jvmTarget.get()) | ||
| } | ||
|
|
||
| kotlin { | ||
| compilerOptions { | ||
| jvmTarget = JvmTarget.fromTarget(libs.versions.jvmTarget.get()) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| dependencies { | ||
| // Internal modules | ||
| implementation(project(":annotation")) | ||
| implementation(project(":core")) | ||
| implementation(project(":ui")) | ||
|
|
||
| // AndroidX Credentials - PRIMARY DEPENDENCY | ||
| implementation(libs.androidx.credentials) | ||
|
|
||
| // Hilt DI | ||
| implementation(libs.google.hilt.android) | ||
| ksp(libs.google.hilt.compiler) | ||
| implementation(libs.androidx.hilt.navigation.compose) | ||
|
|
||
| // Compose UI | ||
| implementation(platform(libs.androidx.compose.bom)) | ||
| implementation(libs.androidx.compose.material3) | ||
| implementation(libs.androidx.compose.runtime) | ||
| implementation(libs.androidx.compose.ui) | ||
| implementation(libs.androidx.compose.ui.tooling.preview) | ||
| implementation(libs.androidx.activity.compose) | ||
| implementation(libs.androidx.lifecycle.runtime.compose) | ||
| implementation(libs.androidx.splashscreen) | ||
|
|
||
| // Kotlin essentials | ||
| implementation(libs.androidx.core.ktx) | ||
| implementation(libs.kotlinx.coroutines.android) | ||
| implementation(libs.kotlinx.serialization) | ||
| implementation(libs.kotlinx.collections.immutable) | ||
|
|
||
| // Testing | ||
| testImplementation(libs.androidx.compose.ui.test) | ||
| testImplementation(libs.google.hilt.android.testing) | ||
| testImplementation(platform(libs.junit.bom)) | ||
| testRuntimeOnly(libs.junit.platform.launcher) | ||
| testImplementation(libs.junit.jupiter) | ||
| testImplementation(libs.junit.vintage) | ||
| testImplementation(libs.kotlinx.coroutines.test) | ||
| testImplementation(libs.mockk.mockk) | ||
| // Robolectric reserved for future Android framework tests if needed | ||
| testImplementation(libs.robolectric.robolectric) | ||
| testImplementation(libs.square.turbine) | ||
|
|
||
| testImplementation(testFixtures(project(":ui"))) | ||
| } | ||
|
|
||
| tasks { | ||
| withType<Test> { | ||
| useJUnitPlatform() | ||
| maxHeapSize = "2g" | ||
| maxParallelForks = Runtime.getRuntime().availableProcessors() | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # CredentialManager classes | ||
| -keep class androidx.credentials.** { *; } | ||
| -keep interface androidx.credentials.** { *; } | ||
|
|
||
| # Hilt | ||
| -dontwarn com.google.errorprone.annotations.** | ||
|
|
||
| # Kotlinx Serialization | ||
| -keepattributes *Annotation*, InnerClasses | ||
| -dontnote kotlinx.serialization.AnnotationsKt | ||
| -keepclassmembers class kotlinx.serialization.json.** { | ||
| *** Companion; | ||
| } | ||
| -keepclasseswithmembers class kotlinx.serialization.json.** { | ||
| kotlinx.serialization.KSerializer serializer(...); | ||
| } | ||
| -keep,includedescriptorclasses class com.bitwarden.testharness.**$$serializer { *; } | ||
| -keepclassmembers class com.bitwarden.testharness.** { | ||
| *** Companion; | ||
| } | ||
| -keepclasseswithmembers class com.bitwarden.testharness.** { | ||
| kotlinx.serialization.KSerializer serializer(...); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
|
||
| <uses-permission android:name="android.permission.CREDENTIAL_MANAGER_SET_ORIGIN" /> | ||
|
|
||
| <application | ||
| android:name=".TestHarnessApplication" | ||
| android:allowBackup="false" | ||
| android:icon="@mipmap/ic_launcher" | ||
| android:label="@string/app_name" | ||
| android:theme="@style/Theme.AppCompat.DayNight.NoActionBar"> | ||
|
|
||
| <!-- Digital Asset Links for Credential Manager (empty for test consumer) --> | ||
| <meta-data | ||
| android:name="asset_statements" | ||
| android:resource="@string/asset_statements" /> | ||
|
|
||
| <activity | ||
| android:name=".MainActivity" | ||
| android:configChanges="uiMode" | ||
SaintPatrck marked this conversation as resolved.
Show resolved
Hide resolved
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. โ Missing critical configuration changes The
Required fixandroid:configChanges="orientation|screenSize|uiMode"Why this matters:
The main
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. This is intentional. We are only concerned with |
||
| android:exported="true" | ||
SaintPatrck marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| android:windowSoftInputMode="adjustResize"> | ||
| <intent-filter> | ||
| <action android:name="android.intent.action.MAIN" /> | ||
| <category android:name="android.intent.category.LAUNCHER" /> | ||
| </intent-filter> | ||
| </activity> | ||
| </application> | ||
|
|
||
| </manifest> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package com.bitwarden.testharness | ||
|
|
||
| import android.os.Bundle | ||
| import androidx.activity.ComponentActivity | ||
| import androidx.activity.compose.setContent | ||
| import androidx.activity.viewModels | ||
| import androidx.compose.runtime.getValue | ||
| import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen | ||
| import androidx.lifecycle.compose.collectAsStateWithLifecycle | ||
| import androidx.navigation.compose.NavHost | ||
| import androidx.navigation.compose.rememberNavController | ||
| import com.bitwarden.testharness.ui.platform.feature.rootnav.RootNavScreen | ||
| import com.bitwarden.testharness.ui.platform.feature.rootnav.RootNavigationRoute | ||
| import com.bitwarden.testharness.ui.platform.feature.rootnav.rootNavDestination | ||
| import com.bitwarden.ui.platform.theme.BitwardenTheme | ||
| import com.bitwarden.ui.platform.util.setupEdgeToEdge | ||
| import dagger.hilt.android.AndroidEntryPoint | ||
| import kotlinx.coroutines.flow.map | ||
|
|
||
| /** | ||
| * Primary entry point for the Credential Manager test harness application. | ||
| * | ||
| * Delegates navigation to [RootNavScreen] following the same pattern as @app and @authenticator | ||
| * modules. Handles Activity-level concerns like theme and splash screen. | ||
| * | ||
| * The root navigation is managed by [RootNavScreen] which orchestrates all test screen flows: | ||
| * - Landing screen with test category selection (Autofill, Credential Manager) | ||
| * - Individual test screens for each Credential Manager API operation | ||
| */ | ||
| @AndroidEntryPoint | ||
| class MainActivity : ComponentActivity() { | ||
|
|
||
| private val mainViewModel: MainViewModel by viewModels() | ||
|
|
||
| override fun onCreate(savedInstanceState: Bundle?) { | ||
| var shouldShowSplashScreen = true | ||
| installSplashScreen().setKeepOnScreenCondition { shouldShowSplashScreen } | ||
| super.onCreate(savedInstanceState) | ||
|
|
||
| setupEdgeToEdge(appThemeFlow = mainViewModel.stateFlow.map { it.theme }) | ||
|
|
||
| setContent { | ||
| val navController = rememberNavController() | ||
| val state by mainViewModel.stateFlow.collectAsStateWithLifecycle() | ||
|
|
||
| BitwardenTheme( | ||
| theme = state.theme, | ||
| ) { | ||
| NavHost( | ||
| navController = navController, | ||
| startDestination = RootNavigationRoute, | ||
| ) { | ||
| rootNavDestination { shouldShowSplashScreen = false } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.