bitwarden_test/play/
config.rs

1//! Configuration for the Play test framework
2//!
3//! Environment variables:
4//! - `BITWARDEN_API_URL`: Base API URL (default: `https://localhost:8080/api`)
5//! - `BITWARDEN_IDENTITY_URL`: Identity URL (default: `https://localhost:8080/identity`)
6//! - `BITWARDEN_SEEDER_URL`: Seeder API URL (defaults to `http://localhost:5047`)
7
8use std::env;
9
10/// Configuration for connecting to Bitwarden services during E2E tests
11#[derive(Debug, Clone)]
12pub struct PlayConfig {
13    /// Base API URL
14    pub api_url: String,
15    /// Identity URL for authentication
16    pub identity_url: String,
17    /// Seeder API URL for test data management
18    pub seeder_url: String,
19}
20
21impl PlayConfig {
22    /// Load configuration from environment variables
23    pub fn from_env() -> Self {
24        let api_url = env::var("BITWARDEN_API_URL")
25            .unwrap_or_else(|_| "https://localhost:8080/api".to_string());
26
27        let identity_url = env::var("BITWARDEN_IDENTITY_URL")
28            .unwrap_or_else(|_| "https://localhost:8080/identity".to_string());
29
30        // TODO: Should use the web proxy once available
31        let seeder_url = env::var("BITWARDEN_SEEDER_URL")
32            .unwrap_or_else(|_| "http://localhost:5047".to_string());
33
34        Self {
35            api_url,
36            identity_url,
37            seeder_url,
38        }
39    }
40
41    /// Create a new configuration with custom URLs
42    pub fn new(
43        api_url: impl Into<String>,
44        identity_url: impl Into<String>,
45        seeder_url: impl Into<String>,
46    ) -> Self {
47        Self {
48            api_url: api_url.into(),
49            identity_url: identity_url.into(),
50            seeder_url: seeder_url.into(),
51        }
52    }
53}
54
55impl Default for PlayConfig {
56    fn default() -> Self {
57        Self::from_env()
58    }
59}
60
61#[cfg(test)]
62mod tests {
63    use super::*;
64
65    #[test]
66    fn test_new_creates_config_with_custom_urls() {
67        let config = PlayConfig::new(
68            String::from("https://api.example.com"),
69            "https://identity.example.com",
70            "http://seeder.example.com",
71        );
72
73        assert_eq!(config.api_url, "https://api.example.com");
74        assert_eq!(config.identity_url, "https://identity.example.com");
75        assert_eq!(config.seeder_url, "http://seeder.example.com");
76    }
77}