-
Notifications
You must be signed in to change notification settings - Fork 905
[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
Open
SaintPatrck
wants to merge
7
commits into
main
Choose a base branch
from
testharness-app
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
634aa91
Add testharness module for Credential Manager and Autofill e2e testing
SaintPatrck 89f4090
Fix testharness screen layouts on small displays
SaintPatrck d70615b
Refactor and expand CredentialTestManager tests
SaintPatrck 2f970ee
Add @OmitFromCoverage to testharness navigation files
SaintPatrck 646c2ac
Extract WebAuthn JSON building logic into dedicated builder
SaintPatrck 53d0f44
Suppress unused exception variable warnings
SaintPatrck a5db63e
Add @OmitFromCoverage to WebAuthnJsonBuilder
SaintPatrck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,5 +56,6 @@ include( | |
| ":cxf", | ||
| ":data", | ||
| ":network", | ||
| ":testharness", | ||
| ":ui", | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| 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.x8bit.bitwarden.testharness" | ||
| compileSdk = libs.versions.compileSdk.get().toInt() | ||
|
|
||
| defaultConfig { | ||
| applicationId = "com.x8bit.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 = JavaVersion.valueOf( | ||
| libs.versions.jvmTarget.get().replace(".", "_").let { "VERSION_$it" }, | ||
|
Collaborator
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. Why does this need to modify the value? |
||
| ) | ||
| targetCompatibility = JavaVersion.valueOf( | ||
| libs.versions.jvmTarget.get().replace(".", "_").let { "VERSION_$it" }, | ||
| ) | ||
| } | ||
|
|
||
| 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() | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.x8bit.bitwarden.testharness.**$$serializer { *; } | ||
| -keepclassmembers class com.x8bit.bitwarden.testharness.** { | ||
| *** Companion; | ||
| } | ||
| -keepclasseswithmembers class com.x8bit.bitwarden.testharness.** { | ||
| kotlinx.serialization.KSerializer serializer(...); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| <?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:exported="true" | ||
|
Collaborator
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. We should be observing the |
||
| android:windowSoftInputMode="adjustResize"> | ||
| <intent-filter> | ||
| <action android:name="android.intent.action.MAIN" /> | ||
| <category android:name="android.intent.category.LAUNCHER" /> | ||
| </intent-filter> | ||
| </activity> | ||
| </application> | ||
|
|
||
| </manifest> | ||
58 changes: 58 additions & 0 deletions
58
testharness/src/main/kotlin/com/x8bit/bitwarden/testharness/MainActivity.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package com.x8bit.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.ui.platform.theme.BitwardenTheme | ||
| import com.bitwarden.ui.platform.util.setupEdgeToEdge | ||
| import com.x8bit.bitwarden.testharness.ui.platform.feature.rootnav.RootNavScreen | ||
| import com.x8bit.bitwarden.testharness.ui.platform.feature.rootnav.RootNavigationRoute | ||
| import com.x8bit.bitwarden.testharness.ui.platform.feature.rootnav.rootNavDestination | ||
| 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 } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
More of a curiosity than anything else, but why did we go with the
x8bithere?