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
use crate::access_control::IncomingAccessControl;
use crate::compat::boxed::Box;
use crate::{async_trait, OutgoingAccessControl, RelayMessage, Result};

/// An Access Control type that allows all messages to pass through.
#[derive(Debug)]
pub struct AllowAll;

#[async_trait]
impl IncomingAccessControl for AllowAll {
    async fn is_authorized(&self, _relay_msg: &RelayMessage) -> Result<bool> {
        crate::allow()
    }
}

#[async_trait]
impl OutgoingAccessControl for AllowAll {
    async fn is_authorized(&self, _relay_msg: &RelayMessage) -> Result<bool> {
        crate::allow()
    }
}

#[cfg(feature = "alloc")]
#[cfg(test)]
mod tests {
    use crate::compat::future::poll_once;
    use crate::{Address, LocalMessage, RelayMessage};

    use super::{AllowAll, IncomingAccessControl};

    #[test]
    fn test_allow_all() {
        let is_authorized = poll_once(async {
            let local_message = LocalMessage::new();
            let relay_message = RelayMessage::new(
                Address::random_local(),
                Address::random_local(),
                local_message,
            );
            AllowAll.is_authorized(&relay_message).await
        });
        assert!(
            is_authorized.is_ok(),
            "this implementation should never return Err"
        );
        let is_authorized = is_authorized.ok();
        assert_eq!(is_authorized, crate::allow().ok());
        assert_ne!(is_authorized, crate::deny().ok());
    }
}