Skip to main content

ibridge_auth/
lib.rs

1// SPDX-License-Identifier: Apache-2.0
2
3//! Credentials, credential sources and the iCloud host allowlist.
4
5mod call;
6mod credentials;
7mod hosts;
8mod platform;
9mod source;
10
11pub use call::{LoginLog, LoginVerdict, call_credentials, report_login, with_call_credentials};
12pub use credentials::{
13    AuthError, AuthMethod, Credentials, ServiceCheck, ValidationReport, Validator,
14};
15pub use hosts::is_allowed_host;
16pub use source::{CredentialSource, EnvSource, FileSource, KeyringSource};
17
18#[cfg(test)]
19mod tests {
20    use super::{AuthError, ServiceCheck, ValidationReport, Validator};
21
22    fn require_send<T: Send>(value: T) -> T {
23        value
24    }
25
26    struct NullValidator;
27
28    #[expect(
29        clippy::unused_async_trait_impl,
30        reason = "null validator returns immediately"
31    )]
32    impl Validator for NullValidator {
33        async fn validate(&self) -> Result<ValidationReport, AuthError> {
34            Err(AuthError::Validation)
35        }
36    }
37
38    fn assert_validator_send<V: Validator + ?Sized>(validator: &V) {
39        let _future = require_send(validator.validate());
40    }
41
42    #[test]
43    fn provider_futures_are_send() {
44        assert_validator_send(&NullValidator);
45    }
46
47    #[test]
48    fn validation_report_any_service_ok() {
49        let calendar_only = ValidationReport {
50            mail: ServiceCheck::Failed {
51                reason: "mail is off".to_owned(),
52            },
53            calendar: ServiceCheck::Ok,
54            contacts: ServiceCheck::Failed {
55                reason: "contacts are off".to_owned(),
56            },
57        };
58        assert!(
59            calendar_only.any_service_ok(),
60            "sign-in succeeds if any service validates"
61        );
62
63        let none = ValidationReport {
64            mail: ServiceCheck::Failed {
65                reason: "no".to_owned(),
66            },
67            calendar: ServiceCheck::Failed {
68                reason: "no".to_owned(),
69            },
70            contacts: ServiceCheck::Failed {
71                reason: "no".to_owned(),
72            },
73        };
74        assert!(
75            !none.any_service_ok(),
76            "sign-in fails when every service fails"
77        );
78    }
79}