porta-rs 0.1.1

Zero-trust CGNAT bypass via WireGuard tunnel
#[cfg(test)]
mod tests {
    use crate::control::protocol::{Command, Response, PortEntry};
    use crate::control::auth::ClientRegistry;

    #[test]
    fn test_command_serialization() {
        let cmd = Command::RegisterPorts {
            client_id: "test-client".to_string(),
            ports: vec![
                PortEntry {
                    remote_port: 80,
                    local_port: 8080,
                    protocol: "tcp".to_string(),
                    description: "HTTP".to_string(),
                },
            ],
        };

        let bytes = cmd.to_bytes().unwrap();
        let deserialized = Command::from_bytes(&bytes).unwrap();

        if let Command::RegisterPorts { client_id, ports } = deserialized {
            assert_eq!(client_id, "test-client");
            assert_eq!(ports.len(), 1);
            assert_eq!(ports[0].remote_port, 80);
        } else {
            panic!("Expected RegisterPorts command");
        }
    }

    #[test]
    fn test_response_serialization() {
        let resp = Response::Ok {
            message: "test".to_string(),
        };

        let bytes = resp.to_bytes().unwrap();
        let deserialized = Response::from_bytes(&bytes).unwrap();

        if let Response::Ok { message } = deserialized {
            assert_eq!(message, "test");
        } else {
            panic!("Expected Ok response");
        }
    }

    #[test]
    fn test_heartbeat_command() {
        let cmd = crate::control::protocol::heartbeat_command("client-1");

        if let Command::Heartbeat { client_id, .. } = cmd {
            assert_eq!(client_id, "client-1");
        } else {
            panic!("Expected Heartbeat command");
        }
    }

    #[test]
    fn test_client_registry() {
        let registry = ClientRegistry::new();

        assert!(!registry.is_registered("client-1"));

        registry.register("client-1");
        assert!(registry.is_registered("client-1"));

        let clients = registry.get_all();
        assert_eq!(clients.len(), 1);
        assert_eq!(clients[0].client_id, "client-1");

        registry.unregister("client-1");
        assert!(!registry.is_registered("client-1"));
    }
}