Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
634aa91
Add testharness module for Credential Manager and Autofill e2e testing
SaintPatrck Nov 11, 2025
89f4090
Fix testharness screen layouts on small displays
SaintPatrck Nov 12, 2025
d70615b
Refactor and expand CredentialTestManager tests
SaintPatrck Nov 12, 2025
2f970ee
Add @OmitFromCoverage to testharness navigation files
SaintPatrck Nov 12, 2025
646c2ac
Extract WebAuthn JSON building logic into dedicated builder
SaintPatrck Nov 12, 2025
53d0f44
Suppress unused exception variable warnings
SaintPatrck Nov 12, 2025
a5db63e
Add @OmitFromCoverage to WebAuthnJsonBuilder
SaintPatrck Nov 12, 2025
0e5fc1a
Refactor exception handling in CredentialTestManagerImpl to follow stโ€ฆ
SaintPatrck Nov 17, 2025
39f8529
Use localized string for Autofill back button description
SaintPatrck Nov 17, 2025
e840bec
Refactor testharness to separate presentation from data layer
SaintPatrck Nov 17, 2025
20c24ff
Add uiMode to configChanges for testharness MainActivity
SaintPatrck Nov 17, 2025
e65bc69
Replace Date/SimpleDateFormat with Clock injection in ViewModels
SaintPatrck Nov 17, 2025
89c236f
Connect TopAppBar scroll behavior with Scaffold nestedScroll
SaintPatrck Nov 17, 2025
8b4eba7
Add missing navigation bar padding to password screens
SaintPatrck Nov 17, 2025
e5469e2
Replace spacedBy arrangements with explicit Spacer components
SaintPatrck Nov 17, 2025
5178504
Refactor testharness UI screens for consistency
SaintPatrck Nov 18, 2025
061da02
Fix non-deterministic Credential-related view model tests
SaintPatrck Nov 18, 2025
fe3bec0
Refactor build.gradle.kts to simplify JVM target compatibility
SaintPatrck Nov 18, 2025
620d0a3
Update Credential Manager list navigation and padding
SaintPatrck Nov 18, 2025
0ef026f
Refactor testharness package to com.bitwarden.testharness
SaintPatrck Nov 18, 2025
e9670c6
Refactor testharness navigation patterns and string resources
SaintPatrck Nov 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ dependencies {
kover(project(":cxf"))
kover(project(":data"))
kover(project(":network"))
kover(project(":testharness"))
kover(project(":ui"))
}

Expand All @@ -42,6 +43,7 @@ detekt {
"cxf/src",
"data/src",
"network/src",
"testharness/src",
"ui/src",
)
}
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@ include(
":cxf",
":data",
":network",
":testharness",
":ui",
)
9 changes: 9 additions & 0 deletions testharness/.gitignore
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
79 changes: 79 additions & 0 deletions testharness/README.md
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)
117 changes: 117 additions & 0 deletions testharness/build.gradle.kts
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()
}
}
23 changes: 23 additions & 0 deletions testharness/proguard-rules.pro
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(...);
}
30 changes: 30 additions & 0 deletions testharness/src/main/AndroidManifest.xml
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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

โŒ Missing critical configuration changes

The configChanges attribute must include orientation|screenSize in addition to uiMode. Without these:

  • Device rotation will destroy and recreate the activity
  • Multi-window/foldable device changes will destroy and recreate the activity
  • SavedStateHandle usage alone doesn't prevent the performance cost and visual disruption
Required fix
android:configChanges="orientation|screenSize|uiMode"

Why this matters:

  • orientation: Handles device rotation without recreation
  • screenSize: Handles multi-window mode and foldable device configuration changes
  • uiMode: Handles dark/light theme changes (already present)

The main :app module follows this same pattern. See app/src/main/AndroidManifest.xml for reference.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is intentional. We are only concerned with uiMode changes.

android:exported="true"
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 }
}
}
}
}
}
Loading
Loading