moosicbox_music_api 0.2.0

MoosicBox music API package
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
//! Authentication types and handlers for music APIs.
//!
//! This module provides authentication configurations for different auth methods:
//! * Poll-based authentication (requires `auth-poll` feature)
//! * Username/password authentication (requires `auth-username-password` feature)
//!
//! The [`ApiAuth`] type manages authentication state and credentials validation.

use std::{
    future::Future,
    ops::{Deref, DerefMut},
    pin::Pin,
    sync::{Arc, atomic::AtomicBool},
};

use crate::Error;

/// Poll-based authentication implementation.
#[cfg(feature = "auth-poll")]
pub mod poll;

/// Username and password authentication implementation.
#[cfg(feature = "auth-username-password")]
pub mod username_password;

/// Authentication configuration for a music API.
#[derive(Debug, Clone)]
pub enum Auth {
    /// Poll-based authentication.
    #[cfg(feature = "auth-poll")]
    Poll(poll::PollAuth),
    /// Username and password authentication.
    #[cfg(feature = "auth-username-password")]
    UsernamePassword(username_password::UsernamePasswordAuth),
    /// No authentication.
    None,
}

impl<T> From<Option<T>> for Auth
where
    T: Into<Self>,
{
    /// Converts an `Option<T>` into `Auth`, using `Auth::None` if the option is `None`.
    fn from(value: Option<T>) -> Self {
        value.map_or(Self::None, Into::into)
    }
}

/// Extension trait for accessing specific authentication types.
pub trait AuthExt {
    /// Returns a reference to poll authentication if applicable.
    #[cfg(feature = "auth-poll")]
    fn as_poll(&self) -> Option<&poll::PollAuth>;
    /// Consumes self and returns poll authentication if applicable.
    #[cfg(feature = "auth-poll")]
    fn into_poll(self) -> Option<poll::PollAuth>;
    /// Returns a reference to username/password authentication if applicable.
    #[cfg(feature = "auth-username-password")]
    fn as_username_password(&self) -> Option<&username_password::UsernamePasswordAuth>;
    /// Consumes self and returns username/password authentication if applicable.
    #[cfg(feature = "auth-username-password")]
    fn into_username_password(self) -> Option<username_password::UsernamePasswordAuth>;
}

impl Auth {
    /// Returns a reference to poll authentication if applicable.
    #[cfg(feature = "auth-poll")]
    #[must_use]
    pub fn as_poll(&self) -> Option<&poll::PollAuth> {
        <Self as AuthExt>::as_poll(self)
    }

    /// Consumes self and returns poll authentication if applicable.
    #[cfg(feature = "auth-poll")]
    #[must_use]
    pub fn into_poll(self) -> Option<poll::PollAuth> {
        <Self as AuthExt>::into_poll(self)
    }

    /// Returns a reference to username/password authentication if applicable.
    #[cfg(feature = "auth-username-password")]
    #[must_use]
    pub fn as_username_password(&self) -> Option<&username_password::UsernamePasswordAuth> {
        <Self as AuthExt>::as_username_password(self)
    }

    /// Consumes self and returns username/password authentication if applicable.
    #[cfg(feature = "auth-username-password")]
    #[must_use]
    pub fn into_username_password(self) -> Option<username_password::UsernamePasswordAuth> {
        <Self as AuthExt>::into_username_password(self)
    }
}

impl AuthExt for Auth {
    #[cfg(feature = "auth-poll")]
    fn as_poll(&self) -> Option<&poll::PollAuth> {
        let Self::Poll(x) = self else {
            return None;
        };

        Some(x)
    }

    #[cfg(feature = "auth-poll")]
    fn into_poll(self) -> Option<poll::PollAuth> {
        let Self::Poll(x) = self else {
            return None;
        };

        Some(x)
    }

    #[cfg(feature = "auth-username-password")]
    fn as_username_password(&self) -> Option<&username_password::UsernamePasswordAuth> {
        let Self::UsernamePassword(x) = self else {
            return None;
        };

        Some(x)
    }

    #[cfg(feature = "auth-username-password")]
    fn into_username_password(self) -> Option<username_password::UsernamePasswordAuth> {
        let Self::UsernamePassword(x) = self else {
            return None;
        };

        Some(x)
    }
}

/// Builder for constructing `ApiAuth` instances.
#[derive(Clone)]
pub struct ApiAuthBuilder {
    auth: Option<Auth>,
    logged_in: Option<bool>,
    validate_credentials: Option<
        Arc<
            dyn Fn() -> Pin<
                    Box<
                        dyn Future<Output = Result<bool, Box<dyn std::error::Error + Send>>> + Send,
                    >,
                > + Send
                + Sync,
        >,
    >,
}

impl std::fmt::Debug for ApiAuthBuilder {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("ApiAuthBuilder")
            .field("auth", &self.auth)
            .field("logged_in", &self.logged_in)
            .finish_non_exhaustive()
    }
}

impl Default for ApiAuthBuilder {
    fn default() -> Self {
        Self::new()
    }
}

impl ApiAuthBuilder {
    /// Creates a new builder.
    #[must_use]
    pub const fn new() -> Self {
        Self {
            auth: None,
            logged_in: None,
            validate_credentials: None,
        }
    }

    /// Configures the builder to use no authentication.
    #[must_use]
    #[allow(clippy::missing_const_for_fn)]
    pub fn without_auth(mut self) -> Self {
        self.auth = Some(Auth::None);
        self
    }

    /// Sets the authentication configuration.
    #[must_use]
    pub fn with_auth(mut self, auth: impl Into<Auth>) -> Self {
        self.auth = Some(auth.into());
        self
    }

    /// Sets the authentication configuration (mutable version).
    pub fn auth(&mut self, auth: impl Into<Auth>) -> &mut Self {
        self.auth = Some(auth.into());
        self
    }

    /// Sets the initial logged-in state.
    #[must_use]
    pub const fn with_logged_in(mut self, logged_in: bool) -> Self {
        self.logged_in = Some(logged_in);
        self
    }

    /// Sets a function to validate credentials.
    #[must_use]
    pub fn with_validate_credentials<
        Fut: Future<Output = Result<bool, Box<dyn std::error::Error + Send>>> + Send + 'static,
        Func: Fn() -> Fut + Send + Sync + 'static,
    >(
        mut self,
        validate_credentials: Func,
    ) -> Self {
        self.validate_credentials = Some(Arc::new(move || Box::pin(validate_credentials())));
        self
    }

    /// Builds the `ApiAuth` instance.
    ///
    /// # Panics
    ///
    /// * If `auth` was not configured
    #[must_use]
    pub fn build(self) -> ApiAuth {
        let auth = self.auth.unwrap();
        let logged_in = Arc::new(AtomicBool::new(self.logged_in.unwrap_or(false)));

        ApiAuth {
            logged_in,
            auth,
            validate_credentials: self.validate_credentials,
        }
    }
}

/// Authentication handler for a music API.
#[derive(Clone)]
pub struct ApiAuth {
    logged_in: Arc<AtomicBool>,
    auth: Auth,
    validate_credentials: Option<
        Arc<
            dyn Fn() -> Pin<
                    Box<
                        dyn Future<Output = Result<bool, Box<dyn std::error::Error + Send>>> + Send,
                    >,
                > + Send
                + Sync,
        >,
    >,
}

impl std::fmt::Debug for ApiAuth {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("ApiAuth")
            .field("logged_in", &self.logged_in)
            .field("auth", &self.auth)
            .finish_non_exhaustive()
    }
}

impl ApiAuth {
    /// Creates a new builder for `ApiAuth`.
    #[must_use]
    pub const fn builder() -> ApiAuthBuilder {
        ApiAuthBuilder::new()
    }

    /// Returns whether the user is currently logged in.
    ///
    /// # Errors
    ///
    /// * If the authentication status check fails
    #[allow(clippy::unused_async)]
    pub async fn is_logged_in(&self) -> Result<bool, Error> {
        Ok(self.logged_in.load(std::sync::atomic::Ordering::SeqCst))
    }

    /// Sets the logged-in state.
    pub fn set_logged_in(&self, logged_in: bool) {
        self.logged_in
            .store(logged_in, std::sync::atomic::Ordering::SeqCst);
    }

    /// Validates the configured credentials.
    ///
    /// # Errors
    ///
    /// * If credential validation fails
    pub async fn validate_credentials(&self) -> Result<bool, Box<dyn std::error::Error + Send>> {
        if let Some(validate_credentials) = &self.validate_credentials {
            match validate_credentials().await {
                Ok(valid) => self.set_logged_in(valid),
                Err(e) => {
                    self.set_logged_in(false);
                    return Err(e);
                }
            }
        }

        Ok(false)
    }

    /// Attempts to log in using the provided function.
    ///
    /// # Errors
    ///
    /// * If the login attempt fails
    pub async fn attempt_login<
        Fut: Future<Output = Result<bool, Box<dyn std::error::Error + Send>>> + Send + 'static,
        Func: Fn(&Auth) -> Fut + Send + Sync + 'static,
    >(
        &self,
        func: Func,
    ) -> Result<bool, Box<dyn std::error::Error + Send>> {
        let logged_in = func(&self.auth).await?;

        self.logged_in
            .store(logged_in, std::sync::atomic::Ordering::SeqCst);

        Ok(logged_in)
    }

    /// Returns a reference to poll authentication if applicable.
    #[cfg(feature = "auth-poll")]
    #[must_use]
    pub fn as_poll(&self) -> Option<&poll::PollAuth> {
        <Self as AuthExt>::as_poll(self)
    }

    /// Consumes self and returns poll authentication if applicable.
    #[cfg(feature = "auth-poll")]
    #[must_use]
    pub fn into_poll(self) -> Option<poll::PollAuth> {
        <Self as AuthExt>::into_poll(self)
    }

    /// Returns a reference to username/password authentication if applicable.
    #[cfg(feature = "auth-username-password")]
    #[must_use]
    pub fn as_username_password(&self) -> Option<&username_password::UsernamePasswordAuth> {
        <Self as AuthExt>::as_username_password(self)
    }

    /// Consumes self and returns username/password authentication if applicable.
    #[cfg(feature = "auth-username-password")]
    #[must_use]
    pub fn into_username_password(self) -> Option<username_password::UsernamePasswordAuth> {
        <Self as AuthExt>::into_username_password(self)
    }
}

impl AuthExt for ApiAuth {
    #[cfg(feature = "auth-poll")]
    fn as_poll(&self) -> Option<&poll::PollAuth> {
        self.auth.as_poll()
    }

    #[cfg(feature = "auth-poll")]
    fn into_poll(self) -> Option<poll::PollAuth> {
        self.auth.into_poll()
    }

    #[cfg(feature = "auth-username-password")]
    fn as_username_password(&self) -> Option<&username_password::UsernamePasswordAuth> {
        self.auth.as_username_password()
    }

    #[cfg(feature = "auth-username-password")]
    fn into_username_password(self) -> Option<username_password::UsernamePasswordAuth> {
        self.auth.into_username_password()
    }
}

impl Deref for ApiAuth {
    type Target = Auth;

    /// Returns a reference to the inner `Auth`.
    fn deref(&self) -> &Self::Target {
        &self.auth
    }
}

impl DerefMut for ApiAuth {
    /// Returns a mutable reference to the inner `Auth`.
    fn deref_mut(&mut self) -> &mut Self::Target {
        &mut self.auth
    }
}

#[cfg(test)]
mod test {
    use super::{ApiAuth, Auth};

    #[test_log::test(switchy_async::test)]
    async fn api_auth_builder_builds_with_no_auth() {
        let auth = ApiAuth::builder().without_auth().build();

        assert!(matches!(*auth, Auth::None));
    }

    #[test_log::test(switchy_async::test)]
    async fn api_auth_builder_sets_logged_in_state() {
        let auth = ApiAuth::builder()
            .without_auth()
            .with_logged_in(true)
            .build();

        let is_logged_in = auth.is_logged_in().await.unwrap();
        assert!(is_logged_in);
    }

    #[test_log::test(switchy_async::test)]
    async fn api_auth_set_logged_in_updates_state() {
        let auth = ApiAuth::builder()
            .without_auth()
            .with_logged_in(false)
            .build();

        assert!(!auth.is_logged_in().await.unwrap());

        auth.set_logged_in(true);
        assert!(auth.is_logged_in().await.unwrap());

        auth.set_logged_in(false);
        assert!(!auth.is_logged_in().await.unwrap());
    }

    #[test_log::test(switchy_async::test)]
    async fn api_auth_validate_credentials_returns_false_when_no_validator() {
        let auth = ApiAuth::builder().without_auth().build();

        let result = auth.validate_credentials().await.unwrap();
        assert!(!result);
    }

    #[test_log::test(switchy_async::test)]
    async fn api_auth_validate_credentials_calls_validator_and_updates_state() {
        let auth = ApiAuth::builder()
            .without_auth()
            .with_validate_credentials(|| async { Ok(true) })
            .build();

        assert!(!auth.is_logged_in().await.unwrap());

        auth.validate_credentials().await.unwrap();

        assert!(auth.is_logged_in().await.unwrap());
    }

    #[test_log::test(switchy_async::test)]
    async fn api_auth_validate_credentials_sets_logged_out_on_error() {
        let auth = ApiAuth::builder()
            .without_auth()
            .with_logged_in(true)
            .with_validate_credentials(|| async {
                Err(Box::new(std::io::Error::other("validation failed"))
                    as Box<dyn std::error::Error + Send>)
            })
            .build();

        assert!(auth.is_logged_in().await.unwrap());

        let result = auth.validate_credentials().await;
        assert!(result.is_err());
        assert!(!auth.is_logged_in().await.unwrap());
    }

    #[test_log::test(switchy_async::test)]
    async fn api_auth_attempt_login_updates_logged_in_state_on_success() {
        let auth = ApiAuth::builder().without_auth().build();

        let result = auth.attempt_login(|_| async { Ok(true) }).await.unwrap();

        assert!(result);
        assert!(auth.is_logged_in().await.unwrap());
    }

    #[test_log::test(switchy_async::test)]
    async fn api_auth_attempt_login_sets_logged_out_on_failure() {
        let auth = ApiAuth::builder()
            .without_auth()
            .with_logged_in(true)
            .build();

        let result = auth.attempt_login(|_| async { Ok(false) }).await.unwrap();

        assert!(!result);
        assert!(!auth.is_logged_in().await.unwrap());
    }

    #[test_log::test(switchy_async::test)]
    async fn api_auth_attempt_login_propagates_error() {
        let auth = ApiAuth::builder().without_auth().build();

        let result = auth
            .attempt_login(|_| async {
                Err(Box::new(std::io::Error::other("login failed"))
                    as Box<dyn std::error::Error + Send>)
            })
            .await;

        assert!(result.is_err());
    }

    #[test_log::test]
    fn auth_from_option_none_converts_to_auth_none() {
        let auth: Auth = None::<Auth>.into();
        assert!(matches!(auth, Auth::None));
    }

    #[test_log::test]
    fn api_auth_builder_auth_mutable_method_sets_auth() {
        let mut builder = super::ApiAuthBuilder::new();
        builder.auth(Auth::None);
        let api_auth = builder.build();

        assert!(matches!(*api_auth, Auth::None));
    }

    #[cfg(feature = "auth-poll")]
    #[test_log::test]
    fn auth_as_poll_returns_some_for_poll_variant() {
        use super::poll::PollAuth;

        let poll = PollAuth::new();
        let auth = Auth::Poll(poll);

        assert!(auth.as_poll().is_some());
    }

    #[cfg(feature = "auth-poll")]
    #[test_log::test]
    fn auth_as_poll_returns_none_for_other_variants() {
        let auth = Auth::None;
        assert!(auth.as_poll().is_none());
    }

    #[cfg(feature = "auth-username-password")]
    #[test_log::test]
    fn auth_as_username_password_returns_some_for_username_password_variant() {
        use super::username_password::UsernamePasswordAuth;

        let up_auth = UsernamePasswordAuth::builder()
            .with_handler(|_u, _p| async { Ok(true) })
            .build()
            .unwrap();
        let auth = Auth::UsernamePassword(up_auth);

        assert!(auth.as_username_password().is_some());
    }

    #[cfg(feature = "auth-username-password")]
    #[test_log::test]
    fn auth_as_username_password_returns_none_for_other_variants() {
        let auth = Auth::None;
        assert!(auth.as_username_password().is_none());
    }

    #[cfg(feature = "auth-poll")]
    #[test_log::test]
    fn auth_into_poll_returns_some_for_poll_variant() {
        use super::poll::PollAuth;

        let poll = PollAuth::new();
        let auth = Auth::Poll(poll);

        assert!(auth.into_poll().is_some());
    }

    #[cfg(feature = "auth-poll")]
    #[test_log::test]
    fn auth_into_poll_returns_none_for_other_variants() {
        let auth = Auth::None;
        assert!(auth.into_poll().is_none());
    }

    #[cfg(feature = "auth-username-password")]
    #[test_log::test]
    fn auth_into_username_password_returns_some_for_username_password_variant() {
        use super::username_password::UsernamePasswordAuth;

        let up_auth = UsernamePasswordAuth::builder()
            .with_handler(|_u, _p| async { Ok(true) })
            .build()
            .unwrap();
        let auth = Auth::UsernamePassword(up_auth);

        assert!(auth.into_username_password().is_some());
    }

    #[cfg(feature = "auth-username-password")]
    #[test_log::test]
    fn auth_into_username_password_returns_none_for_other_variants() {
        let auth = Auth::None;
        assert!(auth.into_username_password().is_none());
    }

    #[cfg(feature = "auth-poll")]
    #[test_log::test]
    fn api_auth_into_poll_returns_some_for_poll_variant() {
        use super::poll::PollAuth;

        let poll = PollAuth::new();
        let api_auth = ApiAuth::builder().with_auth(poll).build();

        assert!(api_auth.into_poll().is_some());
    }

    #[cfg(feature = "auth-poll")]
    #[test_log::test]
    fn api_auth_into_poll_returns_none_for_other_variants() {
        let api_auth = ApiAuth::builder().without_auth().build();
        assert!(api_auth.into_poll().is_none());
    }

    #[cfg(feature = "auth-username-password")]
    #[test_log::test]
    fn api_auth_into_username_password_returns_some_for_username_password_variant() {
        use super::username_password::UsernamePasswordAuth;

        let up_auth = UsernamePasswordAuth::builder()
            .with_handler(|_u, _p| async { Ok(true) })
            .build()
            .unwrap();
        let api_auth = ApiAuth::builder().with_auth(up_auth).build();

        assert!(api_auth.into_username_password().is_some());
    }

    #[cfg(feature = "auth-username-password")]
    #[test_log::test]
    fn api_auth_into_username_password_returns_none_for_other_variants() {
        let api_auth = ApiAuth::builder().without_auth().build();
        assert!(api_auth.into_username_password().is_none());
    }

    #[cfg(feature = "auth-poll")]
    #[test_log::test]
    fn api_auth_as_poll_returns_some_for_poll_variant() {
        use super::poll::PollAuth;

        let poll = PollAuth::new();
        let api_auth = ApiAuth::builder().with_auth(poll).build();

        assert!(api_auth.as_poll().is_some());
    }

    #[cfg(feature = "auth-poll")]
    #[test_log::test]
    fn api_auth_as_poll_returns_none_for_other_variants() {
        let api_auth = ApiAuth::builder().without_auth().build();
        assert!(api_auth.as_poll().is_none());
    }

    #[cfg(feature = "auth-username-password")]
    #[test_log::test]
    fn api_auth_as_username_password_returns_some_for_username_password_variant() {
        use super::username_password::UsernamePasswordAuth;

        let up_auth = UsernamePasswordAuth::builder()
            .with_handler(|_u, _p| async { Ok(true) })
            .build()
            .unwrap();
        let api_auth = ApiAuth::builder().with_auth(up_auth).build();

        assert!(api_auth.as_username_password().is_some());
    }

    #[cfg(feature = "auth-username-password")]
    #[test_log::test]
    fn api_auth_as_username_password_returns_none_for_other_variants() {
        let api_auth = ApiAuth::builder().without_auth().build();
        assert!(api_auth.as_username_password().is_none());
    }

    #[cfg(feature = "auth-poll")]
    #[test_log::test]
    fn auth_from_option_some_converts_to_wrapped_auth() {
        use super::poll::PollAuth;

        let poll = PollAuth::new();
        let auth: Auth = Some(Auth::Poll(poll)).into();

        assert!(matches!(auth, Auth::Poll(_)));
    }

    #[test_log::test]
    fn api_auth_deref_returns_inner_auth() {
        let api_auth = ApiAuth::builder().without_auth().build();

        let auth_ref: &Auth = &api_auth;
        assert!(matches!(auth_ref, Auth::None));
    }

    #[cfg(feature = "auth-poll")]
    #[test_log::test]
    fn api_auth_deref_mut_allows_modifying_inner_auth() {
        use super::poll::PollAuth;

        let mut api_auth = ApiAuth::builder().without_auth().build();

        // Verify starts as None
        assert!(matches!(*api_auth, Auth::None));

        // Modify through DerefMut
        *api_auth = Auth::Poll(PollAuth::new());

        // Verify changed to Poll
        assert!(matches!(*api_auth, Auth::Poll(_)));
    }

    #[test_log::test(switchy_async::test)]
    async fn api_auth_validate_credentials_sets_logged_in_to_false_when_validator_returns_false() {
        let auth = ApiAuth::builder()
            .without_auth()
            .with_logged_in(true)
            .with_validate_credentials(|| async { Ok(false) })
            .build();

        assert!(auth.is_logged_in().await.unwrap());

        auth.validate_credentials().await.unwrap();

        assert!(!auth.is_logged_in().await.unwrap());
    }
}