Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

test(desktop): strengthen notification and OAuth guards (#1172)

Gener3b82fc4827de
diff --git a/src/desktop/src-tauri/src/native_oauth.rs b/src/desktop/src-tauri/src/native_oauth.rs
index 8fd58c256..306dbf1bd 100644
--- a/src/desktop/src-tauri/src/native_oauth.rs
+++ b/src/desktop/src-tauri/src/native_oauth.rs
@@ -502,6 +502,7 @@ mod tests {
good.clone(),
good.replace("/native/", "/x/../native/"),
good.replace("/native/", "/%2e/native/"),
+ good.replace("/native/", &format!("/{}../native/", "x".repeat(600) + "/")),
];
for raw in &aliases {
let url = url::Url::parse(raw).unwrap();
@@ -536,6 +537,7 @@ mod tests {
.intake(&url::Url::parse(&good).unwrap(), NOW)
.unwrap());
let before = serde_json::to_value(&record).unwrap();
+ let good = callback(&record, &"d".repeat(32));
let id = &record.attempt.as_ref().unwrap().id;
for raw in [
good.replace("ai.alook.desktop:", "ai.alook:"),
@@ -549,41 +551,25 @@ mod tests {
format!("{good}#"),
format!("{good}&extra=1"),
format!("{good}&attempt={id}"),
- format!("{good}&code={}", "d".repeat(32)),
+ format!("{good}&code={}", "e".repeat(32)),
format!("{good}&status=access_denied"),
good.replace("attempt=", "att%65mpt="),
good.replace("code=", "c%6fde="),
- good.replace(&"c".repeat(32), "%63"),
- good.replace(&"c".repeat(32), &"c".repeat(129)),
- good.replace(&format!("&code={}", "c".repeat(32)), ""),
- good.replace(&format!("code={}", "c".repeat(32)), "status=unknown"),
+ good.replace(&"d".repeat(32), &"%64".repeat(32)),
+ good.replace(&"d".repeat(32), &"d".repeat(129)),
+ good.replace(&format!("&code={}", "d".repeat(32)), ""),
+ good.replace(&format!("code={}", "d".repeat(32)), "status=unknown"),
good.replace(id, &"x".repeat(43)),
] {
let url = url::Url::parse(&raw).unwrap();
assert!(!record.intake(&url, NOW).unwrap());
assert_eq!(serde_json::to_value(&record).unwrap(), before);
}
- let next = url::Url::parse(&good.replace(&"c".repeat(32), &"d".repeat(32))).unwrap();
+ let next = url::Url::parse(&good.replace(&"d".repeat(32), &"e".repeat(32))).unwrap();
assert!(!record.intake(&next, NOW + ATTEMPT_TTL).unwrap());
assert_eq!(serde_json::to_value(&record).unwrap(), before);
}
- #[test]
- fn callback_length_bound_applies_to_serialized_url() {
- let mut record = waiting();
- let good = callback(&record, &"c".repeat(32));
- let raw = good.replace("/native/", &format!("/{}../native/", "x".repeat(600) + "/"));
- assert!(raw.len() > 512);
- let url = url::Url::parse(&raw).unwrap();
- assert_eq!(url.as_str(), good);
- assert!(record.intake(&url, NOW).unwrap());
- let before = serde_json::to_value(&record).unwrap();
- let oversized = url::Url::parse(&format!("{good}&extra={}", "x".repeat(512))).unwrap();
- assert!(oversized.as_str().len() > 512);
- assert!(!record.intake(&oversized, NOW).unwrap());
- assert_eq!(serde_json::to_value(&record).unwrap(), before);
- }
-
#[test]
fn queue_is_bounded_deduplicated_and_wrong_candidate_cannot_delete_attempt() {
let mut r = waiting();
diff --git a/src/desktop/src-tauri/src/system_notifications.rs b/src/desktop/src-tauri/src/system_notifications.rs
index b22916c9b..deaaeff61 100644
--- a/src/desktop/src-tauri/src/system_notifications.rs
+++ b/src/desktop/src-tauri/src/system_notifications.rs
@@ -1574,12 +1574,14 @@ mod tests {
#[cfg(target_os = "macos")]
#[test]
fn presentation_deadline_shows_normally_and_late_true_cannot_consume_it() {
+ use objc2_user_notifications::UNNotificationPresentationOptions as Options;
+
let (decision, receiver) = presentation_test_completion();
assert_eq!(
receiver
.recv_timeout(std::time::Duration::from_secs(2))
.unwrap(),
- macos_presentation_options(false).bits() as u64
+ (Options::Banner | Options::List | Options::Sound).bits() as u64
);
assert!(!decision.finish(true));
assert!(receiver.try_recv().is_err());
@@ -1588,6 +1590,8 @@ mod tests {
#[cfg(target_os = "macos")]
#[test]
fn presentation_racing_outcomes_take_the_completion_once() {
+ use objc2_user_notifications::UNNotificationPresentationOptions as Options;
+
let (decision, receiver) = presentation_test_completion();
let fallback = decision.clone();
let thread = std::thread::spawn(move || fallback.finish(false));
@@ -1596,7 +1600,11 @@ mod tests {
assert_ne!(authorized, normal);
assert_eq!(
receiver.recv().unwrap(),
- macos_presentation_options(authorized).bits() as u64
+ if authorized {
+ Options::empty().bits() as u64
+ } else {
+ (Options::Banner | Options::List | Options::Sound).bits() as u64
+ }
);
assert!(receiver.try_recv().is_err());
}
@@ -1692,11 +1700,23 @@ mod tests {
server_id: "server_1".to_string(),
channel_id: "channel_1".to_string(),
};
+ let other_conversation = NotificationConversation::Server {
+ server_id: "server_1".to_string(),
+ channel_id: "channel_2".to_string(),
+ };
assert_eq!(
record.notification_ids("viewer_1", &conversation),
vec![same_first.clone(), same_second.clone()],
);
+ assert_eq!(
+ record.notification_ids("viewer_1", &other_conversation),
+ vec![other_channel.clone()],
+ );
+ assert_eq!(
+ record.notification_ids("viewer_2", &conversation),
+ vec![other_viewer.clone()],
+ );
record.complete_dismissals(&[same_first.clone(), same_second.clone()]);
assert_eq!(
record.notification_ids("viewer_1", &conversation),
@@ -1710,20 +1730,28 @@ mod tests {
"message_1"
))
.is_none());
- assert!(record
- .recent
- .iter()
- .any(|item| item.notification_id == other_channel));
- assert!(record
- .recent
- .iter()
- .any(|item| item.notification_id == other_viewer));
+ assert_eq!(
+ record.notification_ids("viewer_1", &other_conversation),
+ vec![other_channel.clone()],
+ );
+ assert_eq!(
+ record.notification_ids("viewer_2", &conversation),
+ vec![other_viewer.clone()],
+ );
let restored = NotificationRecord::restore(serde_json::to_value(record).unwrap()).unwrap();
assert_eq!(
restored.notification_ids("viewer_1", &conversation),
Vec::<String>::new()
);
+ assert_eq!(
+ restored.notification_ids("viewer_1", &other_conversation),
+ vec![other_channel],
+ );
+ assert_eq!(
+ restored.notification_ids("viewer_2", &conversation),
+ vec![other_viewer],
+ );
assert!(restored
.recent
.iter()
@@ -1800,18 +1828,11 @@ mod tests {
}
#[test]
- fn macos_completion_results_fail_closed_before_rollback() {
+ fn macos_completion_results_fail_closed() {
assert_eq!(macos_authorization_result(true, false), Ok(()));
assert_eq!(macos_authorization_result(false, false), Err(()));
assert_eq!(macos_authorization_result(true, true), Err(()));
assert_eq!(macos_add_result(false), Ok(()));
assert_eq!(macos_add_result(true), Err(()));
-
- let mut record = NotificationRecord::new();
- let original = candidate("viewer_1", "message_1");
- let id = record.claim(&original).unwrap();
- assert!(macos_add_result(true).is_err());
- record.rollback(&id);
- assert_eq!(record.claim(&original), Some(id));
}
}