use std::fs; use std::ffi::OsStr; use es_public_proxy::parse::{ScrollBody, SearchBody}; use es_public_proxy::{ProxyConfig, filter_request}; mod common; #[test] fn basic_load() { let parts = common::load_parts_by_name("GET_search"); assert_eq!(parts.method, "GET"); assert_eq!(parts.path_and_query, "/some-index/_search"); } #[test] fn basic_parse() { let parts = common::load_parts_by_name("GET_search"); assert_eq!(parts.method, "GET"); assert_eq!(parts.path_and_query, "/some-index/_search"); let _parsed: SearchBody = serde_json::from_str(&parts.body.unwrap()).unwrap(); } #[test] fn parse_search_bodies() { let file_paths = fs::read_dir("tests/files").unwrap(); for path in file_paths { let path = path.unwrap().path(); if path.extension() != Some(OsStr::new("txt")) { continue } let parts = common::load_parts(&path); if let Some(body) = parts.body { println!("parsing: {}", path.display()); println!("BODY: {}", body); let _parsed: SearchBody = serde_json::from_str(&body).unwrap(); } } } #[test] fn parse_scroll_bodies() { let file_paths = fs::read_dir("tests/files/scroll").unwrap(); for path in file_paths { let path = path.unwrap().path(); if path.extension() != Some(OsStr::new("txt")) { continue } let parts = common::load_parts(&path); if let Some(body) = parts.body { println!(" parsing: {}", path.display()); //println!("BODY: {}", body); let _parsed: ScrollBody = serde_json::from_str(&body).unwrap(); } } } #[test] fn filter_search_requests() { let file_paths = fs::read_dir("tests/files").unwrap(); let mut config = ProxyConfig::default(); config.allow_all_indices = Some(true); let mut rt = tokio::runtime::Runtime::new().unwrap(); for path in file_paths { let path = path.unwrap().path(); if path.extension() != Some(OsStr::new("txt")) { continue } println!(" filtering: {}", path.display()); let req = common::load_request(&path); rt.block_on(filter_request(req, &config)).unwrap(); } } #[test] fn filter_scroll_requests() { let file_paths = fs::read_dir("tests/files/scroll").unwrap(); let mut config = ProxyConfig::default(); config.allow_all_indices = Some(true); let mut rt = tokio::runtime::Runtime::new().unwrap(); for path in file_paths { let path = path.unwrap().path(); if path.extension() != Some(OsStr::new("txt")) { continue } println!(" filtering: {}", path.display()); let req = common::load_request(&path); rt.block_on(filter_request(req, &config)).unwrap(); } }