use securitydept_utils::observability::DiagnosedResult;
use super::{contracts::FrontendOidcModeConfigProjection, runtime::FrontendOidcModeRuntime};
#[derive(Debug, Clone)]
pub struct FrontendOidcModeService {
runtime: FrontendOidcModeRuntime,
}
impl FrontendOidcModeService {
pub fn new(runtime: FrontendOidcModeRuntime) -> Self {
Self { runtime }
}
pub fn runtime(&self) -> &FrontendOidcModeRuntime {
&self.runtime
}
pub async fn config_projection(&self) -> std::io::Result<FrontendOidcModeConfigProjection> {
self.runtime.config_projection().await
}
pub async fn config_projection_with_diagnosis(
&self,
) -> DiagnosedResult<FrontendOidcModeConfigProjection, std::io::Error> {
self.runtime.config_projection_with_diagnosis().await
}
}
#[cfg(test)]
mod tests {
use securitydept_oauth_provider::{OAuthProviderRemoteConfig, OidcSharedConfig};
use super::*;
use crate::frontend_oidc_mode::config::{FrontendOidcModeConfig, FrontendOidcModeConfigSource};
fn test_service() -> FrontendOidcModeService {
let shared = OidcSharedConfig {
remote: OAuthProviderRemoteConfig {
well_known_url: Some(
"https://auth.example.com/.well-known/openid-configuration".to_string(),
),
..Default::default()
},
client_id: Some("spa-client".to_string()),
..Default::default()
};
let config = FrontendOidcModeConfig::default()
.resolve_all(&shared)
.expect("should resolve");
let runtime = FrontendOidcModeRuntime::new(config);
FrontendOidcModeService::new(runtime)
}
#[tokio::test]
async fn service_delegates_to_runtime() {
let service = test_service();
let projection = service
.config_projection()
.await
.expect("projection should succeed");
assert_eq!(projection.client_id, "spa-client");
}
}