Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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)
121 changes: 121 additions & 0 deletions testharness/build.gradle.kts
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"
Copy link
Collaborator

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 x8bit here?

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" },
Copy link
Collaborator

@david-livefront david-livefront Nov 13, 2025

Choose a reason for hiding this comment

The 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()
}
}
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.x8bit.bitwarden.testharness.**$$serializer { *; }
-keepclassmembers class com.x8bit.bitwarden.testharness.** {
*** Companion;
}
-keepclasseswithmembers class com.x8bit.bitwarden.testharness.** {
kotlinx.serialization.KSerializer serializer(...);
}
29 changes: 29 additions & 0 deletions testharness/src/main/AndroidManifest.xml
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"
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should be observing the uiMode configChanges

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.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 }
}
}
}
}
}
Loading
Loading