style: apply cargo fmt across the crate (A20)
The repo never enforced rustfmt, so formatting had drifted broadly. This is a single mechanical `cargo fmt` pass over the whole crate (no behavioral change; lib suite green, 493 passed). Going forward fmt should be enforced (planned CI fmt --check step). Part of the 0.6.1 hygiene pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+67
-19
@@ -36,8 +36,11 @@ pub enum PresenceMode {
|
||||
|
||||
impl PresenceMode {
|
||||
/// All postures, default first — the option list for the Settings/home picker.
|
||||
pub const ALL: [PresenceMode; 3] =
|
||||
[PresenceMode::Normal, PresenceMode::Invisible, PresenceMode::Discoverable];
|
||||
pub const ALL: [PresenceMode; 3] = [
|
||||
PresenceMode::Normal,
|
||||
PresenceMode::Invisible,
|
||||
PresenceMode::Discoverable,
|
||||
];
|
||||
|
||||
/// Whether this posture publishes to discovery (the only mode that does).
|
||||
pub fn publishes_to_discovery(self) -> bool {
|
||||
@@ -193,7 +196,11 @@ mod tests {
|
||||
assert!(!should_answer(&friend, &friends, PresenceMode::Invisible));
|
||||
// Stranger is NEVER answered, in any mode.
|
||||
assert!(!should_answer(&stranger, &friends, PresenceMode::Normal));
|
||||
assert!(!should_answer(&stranger, &friends, PresenceMode::Discoverable));
|
||||
assert!(!should_answer(
|
||||
&stranger,
|
||||
&friends,
|
||||
PresenceMode::Discoverable
|
||||
));
|
||||
assert!(!should_answer(&stranger, &friends, PresenceMode::Invisible));
|
||||
}
|
||||
|
||||
@@ -214,7 +221,10 @@ mod tests {
|
||||
ControlMsg::Ping,
|
||||
ControlMsg::Pong { room: None },
|
||||
ControlMsg::Pong {
|
||||
room: Some(RoomPresence { name: "HangOut".into(), ticket: "abc".into() }),
|
||||
room: Some(RoomPresence {
|
||||
name: "HangOut".into(),
|
||||
ticket: "abc".into(),
|
||||
}),
|
||||
},
|
||||
];
|
||||
for msg in cases {
|
||||
@@ -245,19 +255,37 @@ mod tests {
|
||||
);
|
||||
// Valid ticket -> InRoom with a sanitized name.
|
||||
let t = valid_ticket(friend);
|
||||
let got = interpret_pong(&ControlMsg::Pong {
|
||||
room: Some(RoomPresence { name: "HangOut".into(), ticket: t.clone() }),
|
||||
}, friend);
|
||||
assert_eq!(got, Some(FriendPresence::InRoom { name: "HangOut".into(), ticket: t }));
|
||||
let got = interpret_pong(
|
||||
&ControlMsg::Pong {
|
||||
room: Some(RoomPresence {
|
||||
name: "HangOut".into(),
|
||||
ticket: t.clone(),
|
||||
}),
|
||||
},
|
||||
friend,
|
||||
);
|
||||
assert_eq!(
|
||||
got,
|
||||
Some(FriendPresence::InRoom {
|
||||
name: "HangOut".into(),
|
||||
ticket: t
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn interpret_pong_downgrades_a_garbage_ticket_to_online() {
|
||||
// A friend reporting a room with an unparseable ticket is treated as just
|
||||
// Online — no dead/hostile Join button is surfaced.
|
||||
let got = interpret_pong(&ControlMsg::Pong {
|
||||
room: Some(RoomPresence { name: "Trap".into(), ticket: "not-a-ticket".into() }),
|
||||
}, id());
|
||||
let got = interpret_pong(
|
||||
&ControlMsg::Pong {
|
||||
room: Some(RoomPresence {
|
||||
name: "Trap".into(),
|
||||
ticket: "not-a-ticket".into(),
|
||||
}),
|
||||
},
|
||||
id(),
|
||||
);
|
||||
assert_eq!(got, Some(FriendPresence::Online));
|
||||
}
|
||||
|
||||
@@ -266,9 +294,15 @@ mod tests {
|
||||
let friend = id();
|
||||
let attacker = id();
|
||||
let t = valid_ticket(attacker);
|
||||
let got = interpret_pong(&ControlMsg::Pong {
|
||||
room: Some(RoomPresence { name: "Redirect".into(), ticket: t }),
|
||||
}, friend);
|
||||
let got = interpret_pong(
|
||||
&ControlMsg::Pong {
|
||||
room: Some(RoomPresence {
|
||||
name: "Redirect".into(),
|
||||
ticket: t,
|
||||
}),
|
||||
},
|
||||
friend,
|
||||
);
|
||||
assert_eq!(got, Some(FriendPresence::Online));
|
||||
}
|
||||
|
||||
@@ -287,10 +321,18 @@ mod tests {
|
||||
let t = valid_ticket(friend);
|
||||
assert_eq!(
|
||||
presence_from_probe(Some((
|
||||
&ControlMsg::Pong { room: Some(RoomPresence { name: "Den".into(), ticket: t.clone() }) },
|
||||
&ControlMsg::Pong {
|
||||
room: Some(RoomPresence {
|
||||
name: "Den".into(),
|
||||
ticket: t.clone()
|
||||
})
|
||||
},
|
||||
friend,
|
||||
))),
|
||||
FriendPresence::InRoom { name: "Den".into(), ticket: t }
|
||||
FriendPresence::InRoom {
|
||||
name: "Den".into(),
|
||||
ticket: t
|
||||
}
|
||||
);
|
||||
// A non-reply (a stray Ping) is not a presence -> Offline, never a false Online.
|
||||
assert_eq!(
|
||||
@@ -304,9 +346,15 @@ mod tests {
|
||||
// Control/bidi characters in a peer-supplied name are stripped.
|
||||
let friend = id();
|
||||
let t = valid_ticket(friend);
|
||||
let got = interpret_pong(&ControlMsg::Pong {
|
||||
room: Some(RoomPresence { name: "Hang\u{202e}Out\u{0007}".into(), ticket: t.clone() }),
|
||||
}, friend);
|
||||
let got = interpret_pong(
|
||||
&ControlMsg::Pong {
|
||||
room: Some(RoomPresence {
|
||||
name: "Hang\u{202e}Out\u{0007}".into(),
|
||||
ticket: t.clone(),
|
||||
}),
|
||||
},
|
||||
friend,
|
||||
);
|
||||
match got {
|
||||
Some(FriendPresence::InRoom { name, .. }) => {
|
||||
assert!(!name.contains('\u{202e}'), "bidi override must be stripped");
|
||||
|
||||
Reference in New Issue
Block a user