mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-12-06 14:56:23 +01:00
Put Yaak Proxy's search on the shared query engine (#826)
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
7453869ac6
commit
77226dbedb
58 files changed
+4754
-1594
No files matched your search
@@ -267,17 +267,13 @@ fn search_reaches_inside_the_encrypted_database() {
|
||||
let db = ctx.db().unwrap();
|
||||
|
||||
// Query strings are searchable, being inside the encrypted file.
|
||||
let q = |q: &str| FlowFilter { q: Some(q.into()), limit: Some(50), ..Default::default() };
|
||||
let q = |q: &str| FlowFilter { limit: Some(50), ..FlowFilter::search(q) };
|
||||
let (page, total, matching) = flows::page(&db, &q(QUERY_SECRET)).unwrap();
|
||||
assert_eq!((page.len(), total, matching), (50, FLOWS, Some(FLOWS)));
|
||||
let (page, _, matching) = flows::page(&db, &q("items/2999")).unwrap();
|
||||
assert_eq!((page[0].id.as_str(), matching), ("fl_02999", Some(1)));
|
||||
let posts_not_found = FlowFilter {
|
||||
method: Some("post".into()),
|
||||
status: Some("4xx".into()),
|
||||
limit: Some(1),
|
||||
..Default::default()
|
||||
};
|
||||
let posts_not_found =
|
||||
FlowFilter { limit: Some(1), ..FlowFilter::search("@method:post @status:4xx") };
|
||||
let (_, _, matching) = flows::page(&db, &posts_not_found).unwrap();
|
||||
assert_eq!(matching, Some((0..FLOWS).filter(|i| i % 3 == 0 && i % 10 == 0).count()));
|
||||
|
||||
@@ -295,11 +291,11 @@ fn search_reaches_inside_the_encrypted_database() {
|
||||
}
|
||||
assert_eq!(seen, FLOWS);
|
||||
|
||||
// The sidebar's site and path filters, which run the database's own functions.
|
||||
let under = |u: &str| FlowFilter { under: Some(vec![u.into()]), ..Default::default() };
|
||||
assert_eq!(flows::list(&db, &under("api.example.com")).unwrap().len(), FLOWS);
|
||||
assert_eq!(flows::list(&db, &under("*.example.com")).unwrap().len(), FLOWS);
|
||||
assert_eq!(flows::list(&db, &under("api.example.com/v1/items/42")).unwrap().len(), 1);
|
||||
// The sidebar's host, site and path terms, which run the database's own functions.
|
||||
let found = |q: &str| flows::list(&db, &FlowFilter::search(q)).unwrap().len();
|
||||
assert_eq!(found("@host:api.example.com"), FLOWS);
|
||||
assert_eq!(found("@host:*.example.com"), FLOWS);
|
||||
assert_eq!(found("@host:api.example.com @path:/v1/items/42/*"), 1);
|
||||
|
||||
// A full-text table, as body search will want, made and searched in the encrypted file.
|
||||
let hits: i64 = db
|
||||
|
||||
@@ -144,14 +144,18 @@ async fn round_trip() {
|
||||
assert_eq!(flows.iter().map(|f| &f.id).collect::<Vec<_>>(), vec![&flow.id]);
|
||||
let following = FlowFilter { after: Some(flow.id.clone()), ..Default::default() };
|
||||
assert!(client.flows(&following).await.unwrap().is_empty());
|
||||
let filter = FlowFilter { status: Some("4xx".into()), ..Default::default() };
|
||||
let filter = FlowFilter::search("@status:4xx");
|
||||
assert!(client.flows(&filter).await.unwrap().is_empty());
|
||||
let search = FlowFilter { q: Some("CHARGES post 2xx".into()), ..Default::default() };
|
||||
let search = FlowFilter::search("CHARGES post @status:2xx");
|
||||
assert_eq!(client.flows(&search).await.unwrap().len(), 1);
|
||||
let search = FlowFilter { q: Some("charges get".into()), ..Default::default() };
|
||||
let search = FlowFilter::search("charges @method:get");
|
||||
assert!(client.flows(&search).await.unwrap().is_empty());
|
||||
// Listing is not reading; an agent reading the flow marks it.
|
||||
let read = FlowFilter::search("@is:read");
|
||||
assert!(client.flows(&read).await.unwrap().is_empty());
|
||||
|
||||
let detail = client.flow(&flow.id, 8).await.unwrap();
|
||||
assert_eq!(client.flows(&read).await.unwrap().len(), 1);
|
||||
assert_eq!(detail.flow.method, "POST");
|
||||
let request_body = detail.request_body.unwrap();
|
||||
assert_eq!((request_body.data.as_str(), request_body.truncated), (r#"{"amount"#, true));
|
||||
@@ -283,7 +287,7 @@ async fn offline_reads_proxy_db() {
|
||||
assert_eq!(detail.response_body.unwrap().data, r#"{"id":"ch_1","amount":42}"#);
|
||||
let body = connection.body(&flow.id, FlowBody::Request).await.unwrap();
|
||||
assert_eq!(body.data, br#"{"amount":42}"#);
|
||||
let posts = FlowFilter { method: Some("post".into()), ..Default::default() };
|
||||
let posts = FlowFilter::search("@method:post");
|
||||
assert_eq!(connection.har(&posts).await.unwrap().log.entries.len(), 1);
|
||||
|
||||
let empty = tempfile::tempdir().unwrap();
|
||||
@@ -602,7 +606,7 @@ async fn export_har_writes_the_flows_asked_for() {
|
||||
assert_eq!(read(&selected)["log"]["entries"].as_array().unwrap().len(), 1);
|
||||
|
||||
let searched = dir.path().join("searched.har");
|
||||
let filter = json!({ "q": "charges", "limit": 1 });
|
||||
let filter = json!({ "query": "charges", "limit": 1 });
|
||||
let written =
|
||||
rpc(&ctx, "export_har", json!({ "path": searched, "filter": filter })).await.unwrap();
|
||||
// The whole search, not the page the list had loaded.
|
||||
@@ -613,7 +617,7 @@ async fn export_har_writes_the_flows_asked_for() {
|
||||
|
||||
let none = dir.path().join("none.har");
|
||||
let written =
|
||||
rpc(&ctx, "export_har", json!({ "path": none, "filter": { "q": "nothing-matches" } }))
|
||||
rpc(&ctx, "export_har", json!({ "path": none, "filter": { "query": "nothing-matches" } }))
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(written, 0);
|
||||
@@ -657,7 +661,7 @@ async fn flows_name_the_app_that_sent_them() {
|
||||
assert_eq!(flow.client_path.as_deref(), Some("/usr/bin/curl"));
|
||||
|
||||
// The search and the sidebar's Apps group find it by its path.
|
||||
let filter = FlowFilter { app: Some(vec!["/usr/bin/curl".into()]), ..Default::default() };
|
||||
let filter = FlowFilter::search("@app:/usr/bin/curl");
|
||||
assert_eq!(yaak_proxy_lib::flows::list(&ctx.db().unwrap(), &filter).unwrap().len(), 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -502,10 +502,10 @@ async fn a_tunnelled_connect_is_recorded_with_its_sizes() {
|
||||
assert_eq!(done.error, None);
|
||||
assert!(done.request_headers.is_empty() && done.response_headers.is_empty());
|
||||
|
||||
let tunnelled = rpc(&ctx, "list_flows", json!({"tunnelled": true})).await.unwrap();
|
||||
let tunnelled = rpc(&ctx, "list_flows", json!({"query": "@is:tunnelled"})).await.unwrap();
|
||||
assert_eq!(tunnelled["flows"].as_array().unwrap().len(), 1);
|
||||
assert_eq!(tunnelled["flows"][0]["tunnelled"], true);
|
||||
let decrypted = rpc(&ctx, "list_flows", json!({"tunnelled": false})).await.unwrap();
|
||||
let decrypted = rpc(&ctx, "list_flows", json!({"query": "-@is:tunnelled"})).await.unwrap();
|
||||
assert_eq!(decrypted["flows"].as_array().unwrap().len(), 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -370,7 +370,7 @@ async fn grpc_web_calls_are_stored_and_decoded() {
|
||||
(failed.grpc_status, failed.grpc_message.as_deref()),
|
||||
(Some(12), Some("not here"))
|
||||
);
|
||||
let errors = rpc(&ctx, "list_flows", json!({ "status": "error" })).await.unwrap();
|
||||
let errors = rpc(&ctx, "list_flows", json!({ "query": "@is:error" })).await.unwrap();
|
||||
let ids: Vec<_> =
|
||||
errors["flows"].as_array().unwrap().iter().map(|f| f["id"].clone()).collect();
|
||||
assert_eq!(ids, vec![json!(failed.id)], "a non-zero status is a failed call");
|
||||
|
||||
Reference in new issue
Block a user