|
| 1 | +use colink::extensions::instant_server::{InstantRegistry, InstantServer}; |
| 2 | +use colink::extensions::policy_module::{Action, Rule, TaskFilter}; |
| 3 | + |
| 4 | +#[tokio::test] |
| 5 | +async fn test_policy_module() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> { |
| 6 | + let _ir = InstantRegistry::new(); |
| 7 | + let is = InstantServer::new(); |
| 8 | + let cl = is.get_colink().switch_to_generated_user().await?; |
| 9 | + //default policy |
| 10 | + let res = cl.policy_module_get_rules().await?; |
| 11 | + assert!(res.len() == 1); |
| 12 | + //test remove |
| 13 | + cl.policy_module_remove_rule(&res[0].rule_id).await?; |
| 14 | + let res = cl.policy_module_get_rules().await?; |
| 15 | + assert!(res.is_empty()); |
| 16 | + //test add |
| 17 | + let task_filter = Some(TaskFilter { |
| 18 | + protocol_name: "greetings".to_string(), |
| 19 | + ..Default::default() |
| 20 | + }); |
| 21 | + let action = Some(Action { |
| 22 | + r#type: "approve".to_string(), |
| 23 | + ..Default::default() |
| 24 | + }); |
| 25 | + let priority = 1; |
| 26 | + let rule_id = cl |
| 27 | + .policy_module_add_rule(&Rule { |
| 28 | + task_filter: task_filter.clone(), |
| 29 | + action: action.clone(), |
| 30 | + priority: priority, |
| 31 | + ..Default::default() |
| 32 | + }) |
| 33 | + .await?; |
| 34 | + let res = cl.policy_module_get_rules().await?; |
| 35 | + assert!(res.len() == 1); |
| 36 | + assert!(res[0].rule_id == rule_id); |
| 37 | + assert!(res[0].task_filter.eq(&task_filter)); |
| 38 | + assert!(res[0].action.eq(&action)); |
| 39 | + assert!(res[0].priority == priority); |
| 40 | + |
| 41 | + Ok(()) |
| 42 | +} |
0 commit comments