Watch
0
0
Fork
You've already forked hyperhive
0

swarm-controller: stop minting the per-hive matrix sender account and token nothing reads

This commit is contained in:
damocles 2026-11-12 15:38:34 +01:00
commit c66832febf

View file

@ -480,37 +480,6 @@ fn whoami_session_verdict(
}
}
/// The ids of the rooms `token`'s user has joined.
///
/// # Errors
/// When the request cannot be sent, the response will not decode, the
/// homeserver refuses, or the answer carries no `joined_rooms`.
pub async fn joined_rooms(
client: &reqwest::Client,
base: &str,
token: &str,
) -> Result<Vec<String>> {
let (status, json) = get(
client,
&format!("{base}/_matrix/client/v3/joined_rooms"),
token,
)
.await
.context("GET /joined_rooms")?;
if !status.is_success() {
bail!(
"the homeserver refused to list joined rooms: {}",
why(status, &json)
);
}
Ok(json["joined_rooms"]
.as_array()
.context("the homeserver's answer carried no `joined_rooms`")?
.iter()
.filter_map(|room| room.as_str().map(str::to_owned))
.collect())
}
/// The content of `room_id`'s `event_type` state event under `state_key`
/// (empty for most), or `None` when the room has none.
///
@ -546,37 +515,6 @@ pub async fn room_state(
)
}
/// Set `room_id`'s `event_type` state event under `state_key` to `content`.
///
/// # Errors
/// When the request cannot be sent, the response will not decode, or the
/// homeserver refuses.
pub async fn put_state(
client: &reqwest::Client,
base: &str,
token: &str,
room_id: &str,
event_type: &str,
state_key: &str,
content: &serde_json::Value,
) -> Result<()> {
let (status, json) = exchange(
client
.put(state_url(base, room_id, event_type, state_key))
.bearer_auth(token)
.json(content),
)
.await
.with_context(|| format!("PUT {event_type} state into {room_id}"))?;
if !status.is_success() {
bail!(
"the homeserver refused to set {event_type} in {room_id}: {}",
why(status, &json)
);
}
Ok(())
}
/// The state-event URL for `room_id`, `event_type` and `state_key`.
fn state_url(base: &str, room_id: &str, event_type: &str, state_key: &str) -> String {
format!(
@ -586,37 +524,6 @@ fn state_url(base: &str, room_id: &str, event_type: &str, state_key: &str) -> St
)
}
/// Create a room from the `createRoom` request `body` and return its id.
///
/// # Errors
/// When the request cannot be sent, the response will not decode, the
/// homeserver refuses, or the answer carries no `room_id`.
pub async fn create_room(
client: &reqwest::Client,
base: &str,
token: &str,
body: &serde_json::Value,
) -> Result<String> {
let (status, json) = post(
client,
&format!("{base}/_matrix/client/v3/createRoom"),
token,
body,
)
.await
.context("POST /createRoom")?;
if !status.is_success() {
bail!(
"the homeserver refused to create the room: {}",
why(status, &json)
);
}
json["room_id"]
.as_str()
.map(str::to_owned)
.context("the homeserver's createRoom answer carried no `room_id`")
}
/// What the homeserver did with an invite.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Invited {
@ -1153,23 +1060,11 @@ mod tests {
async fn every_room_call_refuses_without_quoting_the_body() {
let base = any_stub(500, LEAKY).await;
let c = client().expect("a client");
let body = serde_json::json!({});
assert_refusal_hides_body(&joined_rooms(&c, &base, "t").await.expect_err("refused"));
assert_refusal_hides_body(
&room_state(&c, &base, "t", "!r:x", "m.room.name", "")
.await
.expect_err("refused"),
);
assert_refusal_hides_body(
&put_state(&c, &base, "t", "!r:x", "m.room.name", "", &body)
.await
.expect_err("refused"),
);
assert_refusal_hides_body(
&create_room(&c, &base, "t", &body)
.await
.expect_err("refused"),
);
assert_refusal_hides_body(
&invite(&c, &base, "t", "!r:x", "@a:x")
.await
@ -1204,29 +1099,6 @@ mod tests {
);
}
#[tokio::test]
async fn joined_rooms_and_create_room_read_their_fields() {
let c = client().expect("a client");
let base = any_stub(200, r#"{"joined_rooms":["!a:x","!b:x"]}"#).await;
assert_eq!(
joined_rooms(&c, &base, "t").await.expect("rooms"),
["!a:x", "!b:x"]
);
assert!(
create_room(&c, &base, "t", &serde_json::json!({}))
.await
.is_err()
);
let base = any_stub(200, r#"{"room_id":"!new:x"}"#).await;
assert_eq!(
create_room(&c, &base, "t", &serde_json::json!({}))
.await
.expect("room"),
"!new:x"
);
assert!(joined_rooms(&c, &base, "t").await.is_err());
}
#[test]
fn a_state_url_encodes_room_and_key_and_keeps_an_empty_key_slash() {
assert_eq!(