Expand description
§Bitwarden Test
This crate should only be used in tests and should not be included in production builds.
Contains test utilities for Bitwarden.
§Play Framework
The Play framework provides scene-based E2E testing with automatic test isolation and cleanup. Using
the server side SeederApi to generate data.
§How It Works
- Each
Playinstance generates a uniqueplay_id(UUID) - All HTTP requests include an
x-play-idheader for server-side test isolation - Any db entry created through a request associated with an
x-play-id(users, etc.) are saved as associated with thatplay_id - When the test closure completes, associated data is automatically cleaned up
§Usage
Use the #[play_test] macro for the most ergonomic experience:
use bitwarden_test::play::{play_test, Play, SingleUserArgs, SingleUserScene};
#[play_test]
async fn test_example(play: Play) {
// Create a test user via the seeder API
let args = SingleUserArgs {
email: "[email protected]".to_string(),
verified: true,
..Default::default()
};
let scene = play.scene::<SingleUserScene>(&args).await.unwrap();
// Access user data from the scene result
let user_id = &scene.result().user_id;
let api_key = &scene.result().api_key;
// Use mangled values for test isolation
let email = scene.get_mangled("[email protected]");
// Use credentials for testing...
// Cleanup happens automatically when the test completes
}Or use the builder pattern directly for more control:
use bitwarden_test::play::{Play, PlayConfig, SingleUserArgs, SingleUserScene};
#[tokio::test]
async fn test_example() {
Play::builder()
.config(PlayConfig::new("https://api", "https://identity", "http://seeder"))
.run(|play| async move {
let args = SingleUserArgs {
email: "[email protected]".to_string(),
verified: true,
..Default::default()
};
let scene = play.scene::<SingleUserScene>(&args).await.unwrap();
// Use credentials for testing...
})
.await;
}§Environment Variables
| Variable | Default | Description |
|---|---|---|
BITWARDEN_API_URL | https://localhost:8080/api | Base API URL |
BITWARDEN_IDENTITY_URL | https://localhost:8080/identity | Identity server URL |
BITWARDEN_SEEDER_URL | http://localhost:5047 | Seeder API URL |
§Running E2E Tests
E2E tests require a running Bitwarden server with the seeder API enabled:
cargo test -p bw --features integrationModules§
- api 🔒
- play
- Play test framework for E2E testing
- repository 🔒
Structs§
- Memory
Repository - A simple in-memory repository implementation. The data is only stored in memory and will not persist beyond the lifetime of the repository instance.
Functions§
- start_
api_ mock - Helper for testing the Bitwarden API using wiremock.