diff --git a/AGENTS.md b/AGENTS.md index f7e4e3986..d4aae725e 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -224,7 +224,7 @@ the same name in `include/`: `src/appservice/RegistrationYaml.cpp`, `src/databas │ ├── smoke/ # Smoke tests │ ├── password_cost/ # Proves the production Argon2id cost, in a binary without the tests' cheap hash │ ├── complement/ # Docker image that runs the release package under Complement -│ ├── fixtures/ # Test fixtures: complement/ (JSON flow fixtures) and upgrade/ (README only; the 1.0.x cross-release database fixture is not generated yet, the build VM has no PostgreSQL server) +│ ├── fixtures/ # Test fixtures: complement/ (JSON flow fixtures) and upgrade/ (the 1.0.3 release's SQLite database, PostgreSQL dump and manifest) │ ├── support/ # Test helpers (JsonTestSupport, MasterKey, RegistrationToken, TempDirectory, TlsMockServer) │ ├── sanitizer/ # Sanitizer suppression files (tsan.supp) │ └── tooling/ # Python tests for CI workflows, dependency wraps, example config, logger filter diff --git a/CHANGELOG.md b/CHANGELOG.md index 8fda24d24..1c5925ae0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,44 @@ Changes from 1.0.0, the first production release, onwards; the format is set out Changes before 1.0.0 are in [CHANGELOG-pre-release.md](CHANGELOG-pre-release.md), which is no longer added to ([ADR-0740](docs/adr/0740-the-changelog-starts-at-1-0-0-and-the-pre-release-entries-are-a-frozen-record.md)). +# Version 1.1.1 + +## Features + +* `GET /_matrix/client/v3/sync` honours `use_state_after` (Matrix v1.16): with it true each joined and left room + carries `state_after` and no `state` (ADR-0818, ADR-0819, ADR-0820). +* The cross-release upgrade fixture `tests/fixtures/upgrade/1.0.3/`, written by the 1.0.3 release, is opened, taken + through migration 002 and served on SQLite and PostgreSQL by the `[fixture]` scenarios (ADR-0216). +* MatrixRTC transport discovery (MSC4143): `server.rtc.livekit.service_url` is advertised as a `livekit` transport + on `/rtc/transports`, `/versions` and the well-known document (ADR-0822). +* `server.turn.uris` lists several TURN URIs for `GET /voip/turnServer`, in order; `server.turn.server` still works and + both together are refused (ADR-0821). +* The `use_state_after` scenarios asserting project choices, not spec rows, moved from the conformance suite to + `tests/integration/test_sync_state_after_flow.cpp`. + +## Security Fixes + +* None. + +## Bug fixes + +* `use_state_after`: the state anchor at `since` is a binary search of the room's index, so a client back after a long + absence no longer walks every row it missed under the runtime lock. +* `use_state_after`: a room joined and left inside one sync window now gets its whole readable state as of the leave in + `state_after`, not a delta that hid the create event, power levels and join rules (ADR-0820). +* The sync row of `docs/todos/capability-gaps.md` no longer says a limited sync gives no gap state, and tracks the + `state_after` limit after a state fork (ADR-0819). +* Tests: the upgrade fixture scenarios prove the 1.0.3 sync token stays incremental and its epoch survives + migration; scratch files are uniquely named; a missing JSON field fails one scenario, not the binary. + +## Release notes + +1.1.1 adds `use_state_after` to `/sync`, `server.turn.uris` and MatrixRTC transport discovery. The new keys +(`server.turn.uris`, `server.rtc.livekit.service_url`) are optional; no configuration change is needed. Group calls +still need your own LiveKit SFU and `lk-jwt-service`, and delayed events (MSC4140) are not implemented. Known limit +of `use_state_after`: after a state fork at the client's `since`, a key that state resolution later flips back to the +value recorded at `since` is not sent in `state_after`; a client repairs itself with `full_state=true` (ADR-0819). + # Version 1.1.0 ## Features diff --git a/config/merovingian.conf.bsd.example b/config/merovingian.conf.bsd.example index 072879541..c526135db 100644 --- a/config/merovingian.conf.bsd.example +++ b/config/merovingian.conf.bsd.example @@ -131,18 +131,30 @@ server.http.ipv6_client_prefix_length=64 # server.identity_server.total_timeout_seconds=30 # TURN server for VoIP relay (optional) -# When server.turn.server is empty, GET /_matrix/client/v3/voip/turnServer +# When server.turn.server and server.turn.uris are both empty, GET /_matrix/client/v3/voip/turnServer # returns an empty object so clients gracefully disable relay support. # Either static credentials, issued to every user (only supply credentials that # are acceptable for all users of this homeserver), or a coturn shared secret # (use-auth-secret): each user then gets time-limited credentials of their own. # Set one or the other; both is refused. # server.turn.server=turn:turn.example.org:3478?transport=udp +# Or several URIs, comma-separated, in the order clients should try them (instead of server.turn.server; both is +# refused). Each must be turn: or turns:, a host, an optional :port and an optional ?transport=udp or ?transport=tcp +# (RFC 7065), for example turn:[2001:db8::1]:3478. +# server.turn.uris=turn:turn.example.org:3478?transport=udp,turns:turn.example.org:5349?transport=tcp # server.turn.username=merovingian # server.turn.password=set-in-owner-only-secret-file # server.turn.shared_secret_file=@SYSCONFDIR@/merovingian/turn-secret # server.turn.ttl_seconds=86400 +# MatrixRTC group calls (optional) +# The HTTPS URL of an lk-jwt-service (Element's LiveKit authorisation service) that you run beside a LiveKit SFU. +# This server never contacts it: it only tells authenticated clients, and the /.well-known/matrix/client +# document, where it is. Empty means no group-call transport is advertised. Reloadable. +# Clients append /sfu/get or /get_token to it, so write it with no trailing slash and no query: a URL ending in / +# or holding ? is refused. https://host, https://host:8443 and https://host/jwt are fine. +# server.rtc.livekit.service_url=https://livekit-jwt.example.org/lk-jwt-service + # Listener exposure # Keep TLS disabled only on loopback binds behind a declared reverse proxy. # If binding to a public interface, set tls=true, reverse_proxy=false, and diff --git a/config/merovingian.conf.example b/config/merovingian.conf.example index 598867b3d..596edd463 100644 --- a/config/merovingian.conf.example +++ b/config/merovingian.conf.example @@ -104,18 +104,30 @@ server.http.ipv6_client_prefix_length=64 # server.identity_server.total_timeout_seconds=30 # TURN server for VoIP relay (optional) -# When server.turn.server is empty, GET /_matrix/client/v3/voip/turnServer +# When server.turn.server and server.turn.uris are both empty, GET /_matrix/client/v3/voip/turnServer # returns an empty object so clients gracefully disable relay support. # Either static credentials, issued to every user (only supply credentials that # are acceptable for all users of this homeserver), or a coturn shared secret # (use-auth-secret): each user then gets time-limited credentials of their own. # Set one or the other; both is refused. # server.turn.server=turn:turn.example.org:3478?transport=udp +# Or several URIs, comma-separated, in the order clients should try them (instead of server.turn.server; both is +# refused). Each must be turn: or turns:, a host, an optional :port and an optional ?transport=udp or ?transport=tcp +# (RFC 7065), for example turn:[2001:db8::1]:3478. +# server.turn.uris=turn:turn.example.org:3478?transport=udp,turns:turn.example.org:5349?transport=tcp # server.turn.username=merovingian # server.turn.password=set-in-owner-only-secret-file # server.turn.shared_secret_file=/etc/merovingian/turn-secret # server.turn.ttl_seconds=86400 +# MatrixRTC group calls (optional) +# The HTTPS URL of an lk-jwt-service (Element's LiveKit authorisation service) that you run beside a LiveKit SFU. +# This server never contacts it: it only tells authenticated clients, and the /.well-known/matrix/client +# document, where it is. Empty means no group-call transport is advertised. Reloadable. +# Clients append /sfu/get or /get_token to it, so write it with no trailing slash and no query: a URL ending in / +# or holding ? is refused. https://host, https://host:8443 and https://host/jwt are fine. +# server.rtc.livekit.service_url=https://livekit-jwt.example.org/lk-jwt-service + # Listener exposure # Keep TLS disabled only on loopback binds behind a declared reverse proxy. # If binding to a public interface, set tls=true, reverse_proxy=false, and diff --git a/docs/adr/0818-state-after-is-the-change-since-since-as-of-the-responses-position.md b/docs/adr/0818-state-after-is-the-change-since-since-as-of-the-responses-position.md new file mode 100644 index 000000000..fe8c5da4c --- /dev/null +++ b/docs/adr/0818-state-after-is-the-change-since-since-as-of-the-responses-position.md @@ -0,0 +1,41 @@ +# `state_after` is the change since `since`, as of the response's position + +* Status: accepted +* Date: 2026-11-16 + +## Context and Problem Statement + +`GET /sync` with `use_state_after=true` answers `state_after`: "Updates to the state, between the time indicated by the +`since` parameter, and the **end** of the `timeline`", and a client "MUST only update their local state with events in this +list, and MUST NOT update their local state with events in `timeline`". The spec leaves open which point is the end of the +timeline when the timeline filter hides events, and how much a `limited` sync sends. + +## Considered Options + +* The end is the state recorded for the last delivered timeline event (rejected, see below) +* The end is the response's own position, `sync_position`, the point `next_batch` names +* A `limited` sync sends the whole state at the end of the timeline, as `state` does at its start (rejected, see below) +* A `limited` sync sends the changes since `since`, like any other incremental sync + +## Decision Outcome + +Chosen options: the response's position, and the changes since `since`. + +The last delivered event is the wrong point because `next_batch` is past it. With `not_types: ["m.room.topic"]` on the +timeline, a topic change after the last delivered message lies before `next_batch`. The next sync starts after it, and the +client takes no state from the timeline, so a `state_after` as of that message would lose the change for good. Without a +filter the two points hold the same state, so this reading never contradicts the spec. + +`state` sends the whole state on a `limited` sync because a client cannot otherwise tell what the gap changed. `state_after` +has no such gap: the delta ([ADR-0819](0819-a-state-after-delta-compares-the-two-states.md)) covers `since` to the position +whatever the timeline's size, so whole state would only repeat what the client has, on the requests that are already +largest. Whole state remains for what the spec names (no `since`, `full_state=true`) and for a room joined in the window, +where the client holds nothing to apply a delta to. + +The parameter is parsed like `full_state`: `true` turns it on, anything else leaves it off. With it off, or absent, no +response changes. Sliding sync (MSC4186) has its own state model and is not changed. + +### Consequences + +* `state_after` can name an event after the last timeline event, when the timeline filter hid it. That event is not an + update a client could have got any other way. diff --git a/docs/adr/0819-a-state-after-delta-compares-the-two-states.md b/docs/adr/0819-a-state-after-delta-compares-the-two-states.md new file mode 100644 index 000000000..663bfac96 --- /dev/null +++ b/docs/adr/0819-a-state-after-delta-compares-the-two-states.md @@ -0,0 +1,59 @@ +# A `state_after` delta compares the two states, and every change it finds is sent under lazy-loading + +* Status: accepted +* Date: 2026-11-16 + +## Context and Problem Statement + +An incremental `state_after` holds the state that differs between `since` and the response's position. State resolution can +move a key back to an older event: no event of the window is about that key, and its current event is older than `since`. +This is the case `use_state_after` exists for, since a client reading `state` and `timeline` cannot see it. `/sync` runs under +`runtime.mutex` for every syncing user, so the cost matters as much as the answer +([ADR-0435](0435-the-event-table-keeps-a-per-room-index-in-stream-order.md), +[ADR-0436](0436-an-event-is-judged-for-ignored-senders-without-parsing-it-first.md)). + +## Considered Options + +* List the state events in the window and send each key's current value (rejected: misses a key moved back) +* Read both whole states for every room with a new event (rejected: a room's state, twice, per user, per message) +* Compare state groups: nothing when they are one group, the rows between them on an unforked delta chain, and both whole + states only when the chain does not connect them + +## Decision Outcome + +Chosen option: compare state groups (`joined_state_changes` in `ClientServerRuntime.cpp`, `state_changes_along_chain` in +`StateGroupLookup.cpp`). + +* A room with no event above `since` costs one look at its newest row and sends nothing. +* The state at `since` is the recorded state of the newest event at or below it (`state_anchor_event`, found by a binary + search of the room's stream-order index, so the rows a long absence missed cost nothing; a test reads + `state_anchor_rows_examined`). With one forward + extremity, at or below the position, the current state is that event's recorded state, so the two points are two groups: + the same group for a window of messages (no rows read), otherwise the rows between them + (`state_changes_along_chain`, which never reads a snapshot's rows). The extremity comes from the room's own tips + (`ForwardExtremityTable::tips_of_room`), never from a walk of every room's. +* A fork, a snapshot between the two points (at most `max_state_group_delta_depth` hops apart) or an unreadable chain falls + back to the state at the position minus the state at `since`, the room's own rows. An event is the value of one key, so + subtracting event IDs finds exactly the keys that differ. +* With no recorded state at `since`, all the state at the position is sent: an update the client holds is harmless. + +Lazy-loading: `state_after` carries, besides all non-member changes, every member event in the delta (never redundant, in +the timeline or not, about a sender or not, since the client takes no state from the timeline), and each timeline sender's +member event as of the position, by key and subject to redundancy (`member_event_at_position`, with the cost rule of +[ADR-0454](0454-a-senders-member-is-looked-up-by-key-never-by-scanning-the-room-state.md)). The user's own member event on +an initial sync, `full_state=true` or a join in the window is sent even when the timeline carries the join, which +[ADR-0452](0452-the-state-filter-selects-lazy-loaded-members-on-sync.md) allows only for `state`. + +The tracker's rules ([ADR-0450](0450-lazy-loaded-members-are-skipped-only-when-the-since-token-acknowledges-them.md)) are +unchanged, and it is shared with `state` responses under the same stream key. It compares event IDs: a client that switches +modes either holds the event named or is sent it again. What `state_after` sends is recorded as what `state` sends is. + +### Consequences + +* The state at `since` is what was recorded for one event, not what the response carrying that token said. If the graph was + forked at `since`, the resolved state the client was told can differ from that recorded state, and a key that resolution + later flipped to the recorded value is not sent. A backfilled event ordered at or below `since` can stand in the same way. + Storing each response's state per token would close this and was refused for its cost; `full_state=true` repairs a client. +* A window that crosses a snapshot reads both whole states, about once per `max_state_group_delta_depth` state changes. It + sends only what differs. +* A key that changed and changed back within the window may be sent, with the value the client already holds. diff --git a/docs/adr/0820-a-left-rooms-state-after-stops-at-what-the-user-may-read.md b/docs/adr/0820-a-left-rooms-state-after-stops-at-what-the-user-may-read.md new file mode 100644 index 000000000..1eb325a38 --- /dev/null +++ b/docs/adr/0820-a-left-rooms-state-after-stops-at-what-the-user-may-read.md @@ -0,0 +1,49 @@ +# A left room's `state_after` stops at what the user may read, and always holds their own membership + +* Status: accepted +* Date: 2026-11-16 + +## Context and Problem Statement + +A left room's `state_after` is "The state updates for the room up to the **end** of the timeline", and that timeline runs +"up to the point when the user left". A left room's incremental `state` holds only the leave, and only when the timeline does +not carry it ([ADR-0453](0453-sync-honours-full-state.md) kept that). A `state_after` client takes no state from the +timeline, and a user who left may not read the room after they left, whatever a later ban changes +([ADR-0357](0357-a-left-rooms-sync-state-is-gated-by-room-read-access.md)). + +## Considered Options + +* Reuse the joined room's delta, against current state (rejected: it tells a departed user what happened after they left) +* Keep `state`'s rule and send the leave alone on an incremental sync (rejected: "the state updates up to the end of the + timeline" hold what changed before the leave too) +* Read the state only as far as `room_read_access_for` allows, take away what the client held at `since`, and add the user's + own membership event + +## Decision Outcome + +Chosen option: the last (`build_left_room_state_after`). + +* The room's state comes from the state anchor of `room_read_access_for`, capped at the event that ended the join. +* The user's own key is always the current member event, sent even when the timeline carries it. For a user who left and + was banned since, the room is as of the leave and the membership is the ban, the one thing the room's state may say about + after the leave. +* A `since` at or past the end of what the user may read (they left before it, and were banned after it) leaves only that + membership event. +* A user who never joined (`none`) gets only their own event, as on `state` (ADR-0357). +* A client holds the room's state at `since` only if it was joined then. When the join this departure ended began after + `since` (`RoomReadAccess::join_ordering` above `since`: a join and leave inside one window, or a rejoin after an earlier + departure), nothing is taken away and the whole readable state as of the leave is sent, as an initial sync would, still + capped by `room_read_access_for`; lazy-loading then treats the room as new to the client (the tracker is not consulted). + The join's ordering comes from the walk of the user's member events that already finds the boundary, so no scan of the + room's rows decides it. It is the rule `joined_membership_changed_since` applies to a joined room, read from the join + event because a departed user's current member event is the leave. Subtracting what the client "held" would have hidden + the create event, power levels and join rules from a client that is never told them another way. +* `full_state=true` does not make a left room's `state_after` whole: `full_state` is about "all rooms the user is a member + of" and the Left Room `state_after` does not name it, as ADR-0453 has for `state`. +* With lazy-loading, a sender's member event is looked up as of the leave. When the state group chain cannot be read it is + omitted, while a joined room lets the current member event stand in: omitting a member is a smaller harm than telling a + departed user a later one. + +### Consequences + +* A left room's state always costs two whole reads, of that room's rows. Leaves are rare and once per room per client. diff --git a/docs/adr/0821-server-turn-uris-is-added-beside-server-turn-server-which-is-kept.md b/docs/adr/0821-server-turn-uris-is-added-beside-server-turn-server-which-is-kept.md new file mode 100644 index 000000000..e310d5d11 --- /dev/null +++ b/docs/adr/0821-server-turn-uris-is-added-beside-server-turn-server-which-is-kept.md @@ -0,0 +1,45 @@ +# server.turn.uris is added beside server.turn.server, which is kept + +* Status: accepted +* Date: 2026-11-16 + +## Context and Problem Statement + +`GET /voip/turnServer` answers `uris`, "a list of TURN URIs" (Matrix v1.19, Voice over IP), but the configuration held +one URI, `server.turn.server`. An operator normally runs a UDP and a TCP or TLS relay, and a client behind a firewall +that blocks UDP needs the second one. How does the configuration name several URIs without breaking a 1.0.x file? + +## Decision Outcome + +Chosen option: "a new list key beside the old one", because a 1.0.x configuration must still parse in 1.1 and the old +value keeps its meaning. + +* `server.turn.uris` uses the configuration's ordinary comma-separated list syntax (as + `server.identity_server.trusted_servers` does): whitespace around an entry and empty entries are ignored, by the shared + `parse_string_list`, which this change does not alter. The response's `uris` array carries the entries in the + configured order. `server.turn.server` stays, and still gives a one-element array. +* TURN is enabled when either key is set. Setting both is refused at parse time, like `shared_secret_file` with + `username` and `password`, so it is never unclear which one clients get. +* "Refused, never repaired" applies to the content of each entry. An entry is refused unless it follows the TURN URI + grammar of RFC 7065, strictly: `turn:` or `turns:` in lower case; a host, being a name or IPv4 address of ASCII + letters, digits, `.` and `-` that does not start or end with `.` or `-`, or a valid IPv6 address in square brackets (hex + digits, `:` and `.` only, so no zone identifier, and `inet_pton` must accept it); an optional `:port`, decimal, 1 to 65535, no sign, not empty; an optional `?transport=udp` or + `?transport=tcp`, exactly. No userinfo, path, fragment or other query. An entry with no host (`turn:?transport=udp`, + `turn::3478`) would be sent to every client, so it is refused. An entry is also at most 512 bytes of printable ASCII, + is not a repeat of an earlier entry, and the list holds at most 16 entries. `server.turn.server` has never been validated, and is not + tightened here: a value an existing configuration holds must not start to be refused by an upgrade. +* The key is reloadable and diffed by the reload plan like the other `server.turn.*` keys. + +## Pros and Cons of the Options + +### Replace server.turn.server with the list + +* Bad, because every 1.0.x configuration that sets it would stop working. + +### Make server.turn.server accept a list + +* Bad, because it changes the meaning of an existing value: a URI containing a comma would be split. + +## Links + +* Builds on [ADR-0480](0480-turn-credentials-come-from-a-coturn-shared-secret-file-through-an-openssl-hmac-sha1.md) diff --git a/docs/adr/0822-the-rtc-transport-is-advertised-as-type-livekit-with-livekit-service-url.md b/docs/adr/0822-the-rtc-transport-is-advertised-as-type-livekit-with-livekit-service-url.md new file mode 100644 index 000000000..dd7a1bfb2 --- /dev/null +++ b/docs/adr/0822-the-rtc-transport-is-advertised-as-type-livekit-with-livekit-service-url.md @@ -0,0 +1,54 @@ +# The RTC transport is advertised as type livekit with livekit_service_url + +* Status: accepted +* Date: 2026-11-16 + +## Context and Problem Statement + +MatrixRTC (MSC4143, with the LiveKit transport of MSC4195) is not in the Matrix v1.19 specification. Clients learn where +to get a LiveKit token from the homeserver, in three places: `GET /_matrix/client/v1/rtc/transports`, the older +`GET /_matrix/client/unstable/org.matrix.msc4143/rtc/transports`, and the `org.matrix.msc4143.rtc_foci` member of +`/.well-known/matrix/client`. This server has no token service of its own; the operator runs Element's +`lk-jwt-service` beside a LiveKit SFU. What does the server advertise, and how? + +## Decision Outcome + +Chosen option: "advertise the operator's service as type `livekit`", because released Element Web, Element X and +Element Call understand only that type. + +* `server.rtc.livekit.service_url` (an HTTPS URL, refused when not one; never fetched by this server) is advertised as + `{"type":"livekit","livekit_service_url":""}`. The entry has no `url` member. Clients build + `/sfu/get` and `/get_token` by appending to it, so a URL with a query, or whose path ends + in `/`, would give a broken request and is refused; a URL with no path (`https://host`, `https://host:8443`) is + accepted, as are an IPv6 literal host and a port. +* Both routes need an access token and are rate limited like any client route. The stable path answers + `{"transports":[...]}` and, with nothing configured, `{"transports":[]}`. The unstable path answers + `{"rtc_transports":[...]}` and, with nothing configured, `{}`. Both mirror the reference server. The transport + entry is identical on both, since one call can mix clients. +* `/versions` always carries `org.matrix.msc4143` and `org.matrix.msc4143.stable` as `true`: the routes exist + whether or not a service is configured. Released clients call the unstable path only when the first is present; + newer clients call the stable path when the second is. +* `/.well-known/matrix/client` carries `org.matrix.msc4143.rtc_foci` (the same entry in a list) only when a service + URL is configured, and is otherwise byte for byte what it was. Clients built on the Rust SDK fall back to it. + +A future reader must not "fix" the type to the MSC's stable name `m.livekit` without also adding the token +endpoints. + +## Pros and Cons of the Options + +### Type `m.livekit` + +* Bad, because released clients do not parse it. +* Bad, because it tells a client to fetch tokens from the homeserver, a `/rtc/livekit/*` endpoint that does not exist. + +### A different type on each path + +* Bad, because a call can mix clients that use different paths. + +### Drop the well-known member because MSC4143 rejected well-known discovery + +* Bad, because Rust SDK based clients still fall back to it. + +## Links + +* Related: [ADR-0821](0821-server-turn-uris-is-added-beside-server-turn-server-which-is-kept.md) diff --git a/docs/adr/index.md b/docs/adr/index.md index 005670d41..346534385 100644 --- a/docs/adr/index.md +++ b/docs/adr/index.md @@ -696,3 +696,8 @@ * [0815 - The authentication pages are built into the binary, without JavaScript](0815-the-authentication-pages-are-built-into-the-binary-without-javascript.md) * [0816 - `server.oauth.*` replaces `server.oidc.*`, and the old keys are refused](0816-server-oauth-replaces-server-oidc-and-the-old-keys-are-refused.md) * [0817 - A form body is read strictly and refused whole](0817-a-form-body-is-read-strictly-and-refused-whole.md) +* [0818 - state_after is the change since since, as of the response's position](0818-state-after-is-the-change-since-since-as-of-the-responses-position.md) +* [0819 - A state_after delta compares the two states, and every change it finds is sent under lazy-loading](0819-a-state-after-delta-compares-the-two-states.md) +* [0820 - A left room's state_after stops at what the user may read, and always holds their own membership](0820-a-left-rooms-state-after-stops-at-what-the-user-may-read.md) +* [0821 - server.turn.uris is added beside server.turn.server, which is kept](0821-server-turn-uris-is-added-beside-server-turn-server-which-is-kept.md) +* [0822 - The RTC transport is advertised as type livekit with livekit_service_url](0822-the-rtc-transport-is-advertised-as-type-livekit-with-livekit-service-url.md) diff --git a/docs/database-persistence.md b/docs/database-persistence.md index f80d85858..f404d2cf0 100644 --- a/docs/database-persistence.md +++ b/docs/database-persistence.md @@ -908,10 +908,16 @@ value. Test fixtures that do not exercise persistence select it through being refused (SQLite), a fresh database having every table's final columns and all six indexes, and a pre-1.0 ledger (rows 2 to 26) being refused on both backends. The "any older version opens at current" scenario is vacuous until a - v2 exists. There is no previous-release fixture: the 0.11.13 fixture was - removed when the migrations collapsed (0.12.47, ADR-0224). When the 1.1 series - starts, the last 1.0.x release writes the next fixture with - `scripts/generate_upgrade_fixture.py` (see `docs/release-process.md`). + v2 exists. The 1.1 series starts with a previous-release fixture, + `tests/fixtures/upgrade/1.0.3/`: the SQLite database, PostgreSQL dump and manifest the + 1.0.3 release wrote through its own HTTP API (`scripts/generate_upgrade_fixture.py`, ADR-0216; the 0.11.13 + fixture was removed when the migrations collapsed, 0.12.47, ADR-0224). Two scenarios + (`[fixture]`, one per backend) open it, run `migrate_*_schema_to`, start the runtime on it and read back the users, + access tokens, rooms, events, media, account data, pusher and device keys the manifest lists, then send a new + event signed with the old release's key. Opening the 1.0.3 database applies migration 002 (the OAuth 2.0 tables), so + the scenarios first assert the v1 to v2 step ran: the schema version is `current_schema_version()`, the ledger gained the + `oauth_tables` row, and `oauth_clients` and `oauth_sessions` exist and take a row. They then assert everything the manifest lists is still served. + The PostgreSQL scenario needs `MEROVINGIAN_TEST_POSTGRESQL_URI` and reports itself skipped without it. - Both stores read the migration ledger in numeric order (`ORDER BY CAST(version AS INTEGER)`): `schema_migrations.version` is `TEXT`, and ordering by it alone put `'10'` before `'9'`. diff --git a/docs/matrix-v1.19-client-server-api.md b/docs/matrix-v1.19-client-server-api.md index 5bb9cb03c..f54740812 100644 --- a/docs/matrix-v1.19-client-server-api.md +++ b/docs/matrix-v1.19-client-server-api.md @@ -514,7 +514,8 @@ In each case below the spec leaves the choice to the server; the owner decided t - **An identifier over 255 bytes is refused (ADR-0613).** `GET /profile/{userId}` and `GET /directory/room/{roomAlias}` answer `400 M_INVALID_PARAM` before any lookup. The spec limits a user ID and a room alias to 255 bytes. - **Unset profile fields are absent.** `GET /profile/{userId}`, the user directory and `/search` `profile_info` leave out a `displayname` or `avatar_url` that is not set, instead of sending an empty string. - **`GET /rooms/{roomId}/messages` with `lazy_load_members`.** `state` holds only the `m.room.member` events of the senders of the returned `chunk` (no other state). Redundant membership events are not tracked across calls, so a sender's membership is sent on every page (the spec's `include_redundant_members` default permits it). -- **Lazy-loading on `/context` and `/sync` (0.12.73).** `GET /context` with `lazy_load_members` returns as `state` only the member events of the senders of `events_before`, `event` and `events_after` (stateless, redundancy allowed). `GET /sync` with `room.state.lazy_load_members` (the `timeline` flag does nothing) sends, besides the non-member state the room would carry without lazy-loading (the state filter still applies, and an incremental sync is a delta), the member events of the delivered timeline's senders, every member change in the gap of a limited sync, and the user's own membership on joining or `full_state=true`. A member the client acknowledged through its `since` is skipped (best effort, in memory, per user, device and `filter`); `include_redundant_members=true` and `full_state=true` skip nothing. `full_state=true` is now honoured for joined rooms. Not implemented: `use_state_after`/`state_after`. +- **`use_state_after` on `/sync` (1.1.1, ADR-0818 to ADR-0820).** With `use_state_after=true`, joined and left rooms answer `state_after`, present even when empty, and omit `state`; with `false` or absent, the reverse. It is the state as of the response's position: all of it with no `since`, `full_state=true` or a join in the window, otherwise what differs from the state at `since`, including what the timeline carries, what the timeline filter hid and a key state resolution moved back, also on a `limited` sync. A left room's stops at the user's leave and always holds their own membership; `full_state` does not make it whole, but a room the user joined and left inside one window (or rejoined and left again) gets its whole readable state as of the leave, as the client held none of it. Invited and knocked rooms have no `state_after` in the spec and get none. With `lazy_load_members`, every member change is sent and each timeline sender's member is as of the end of the timeline. Sliding sync is unchanged. +- **Lazy-loading on `/context` and `/sync` (0.12.73).** `GET /context` with `lazy_load_members` returns as `state` only the member events of the senders of `events_before`, `event` and `events_after` (stateless, redundancy allowed). `GET /sync` with `room.state.lazy_load_members` (the `timeline` flag does nothing) sends, besides the non-member state the room would carry without lazy-loading (the state filter still applies, and an incremental sync is a delta), the member events of the delivered timeline's senders, every member change in the gap of a limited sync, and the user's own membership on joining or `full_state=true`. A member the client acknowledged through its `since` is skipped (best effort, in memory, per user, device and `filter`); `include_redundant_members=true` and `full_state=true` skip nothing. `full_state=true` is now honoured for joined rooms. `use_state_after` is implemented (1.1.0, below). - **Initial `/sync` carries `m.push_rules`.** An initial `/sync` (no usable `since`) always holds a global `m.push_rules` account-data event with the user's effective ruleset (the server defaults plus their changes), if the filter's `account_data` admits it. An incremental `/sync` carries it only after a change. - **A hole in the event graph makes a joined room's `/sync` timeline `limited` (ADR-0289).** The spec defines `limited` by the filter `limit` and leaves events the server never received over federation unspecified; an event in the window whose `prev_events` are not all held (no row, or an outlier with no state group; rejected, soft-failed and backfilled events count as held, ADR-0290) starts a limited timeline at that event, with `prev_batch` for `/messages` to reach what lies before. A limited incremental sync carries the state at the start of the timeline. Sliding sync is unchanged. - **`POST /user_directory/search` searches visible users only.** A search considers the users who share a joined room with the requester, and users joined to a room whose join rule is `public` or whose history visibility is `world_readable`. The requester is found only through a public or world-readable room. Before, every local profile matched. The result list is at most 100 users whatever `limit` asks for, and `limited` says when more matched (ADR-0334). @@ -538,6 +539,8 @@ In each case below the spec leaves the choice to the server; the owner decided t - **`POST /users/{userId}/report` (v1.14, ADR-0482).** Needs an access token and is rate-limited. The body is a JSON object whose `reason`, when present, is a string (`400 M_BAD_JSON` otherwise). A local user ID no account holds is `404 M_NOT_FOUND` and stores nothing; a user of another server is accepted without a lookup. It is stored as an audit row `trust_safety.account.accept_report` (reporter, reported user), one per pair, listed by `GET /admin/safety/reports`; a repeat answers `200` without a second row. The reporter need share no room with the reported user. - **Password reset by email (ADR-0481).** `POST /account/password/email/requestToken` (no token) answers `200` with `sid` and `submit_url` for every well-formed request, whether or not an account holds the address, and emails an 8-character code only to an active account's address; it never answers `M_THREEPID_NOT_FOUND` or `M_THREEPID_IN_USE`. A repeat with the same or a lower `send_attempt` returns the same `sid` and sends nothing. With no relay (`server.email.smtp_url`) it is `400 M_THREEPID_MEDIUM_NOT_SUPPORTED`. The client posts `{sid, client_secret, token}` to `submit_url` (`/_matrix/client/unstable/org.merovingian/account/password/email/submitToken`, this server's own path, the Identity Service `submitToken` shape): `{"success":true}`, or `400 M_TOKEN_INCORRECT`, `M_INVALID_PARAM` or `M_SESSION_EXPIRED` (five wrong codes end the session; sessions last 15 minutes). `POST /account/password` with no access token and `auth: {type: "m.login.email.identity", threepid_creds: {sid, client_secret}}` then sets the password of the account that holds the address (`401` with the flows for a missing or unvalidated stage, `400 M_WEAK_PASSWORD` for a weak password and the session is kept for a retry) and, with `logout_devices` (the default), revokes every token of the account. `POST /account/password/msisdn/requestToken` is `400 M_THREEPID_MEDIUM_NOT_SUPPORTED` (no SMS). +- **MatrixRTC transport discovery (MSC4143, not in v1.19; ADR-0822).** `GET /_matrix/client/v1/rtc/transports` answers `{"transports":[{"type":"livekit","livekit_service_url":""}]}` and `GET /_matrix/client/unstable/org.matrix.msc4143/rtc/transports` answers `{"rtc_transports":[...]}`, both needing an access token; with `server.rtc.livekit.service_url` empty they answer `{"transports":[]}` and `{}`. `/versions` always lists `org.matrix.msc4143` and `org.matrix.msc4143.stable`, and the well-known document gains `org.matrix.msc4143.rtc_foci` when a URL is set. There is no `m.livekit` transport and no `/rtc/livekit/*` route. +- **`GET /voip/turnServer` with `server.turn.uris` (ADR-0821)** answers one `uris` entry per configured URI, in the configured order; `server.turn.server` still gives one. - **`GET /voip/turnServer` with `server.turn.shared_secret_file` (ADR-0480)** answers per-user credentials in the coturn REST API format: `username` `:`, `password` the base64 HMAC-SHA1 of it under the secret, `ttl` `server.turn.ttl_seconds`. - **`GET /_merovingian/health` (ADR-0479)** is not a Matrix endpoint: an unauthenticated probe, `200 ok` or `503 unavailable`. diff --git a/docs/release-process.md b/docs/release-process.md index 1d052dbd8..9efcc8561 100644 --- a/docs/release-process.md +++ b/docs/release-process.md @@ -114,7 +114,8 @@ python scripts/generate_upgrade_fixture.py tests/fixtures/ ``` Then add scenarios to `tests/integration/test_database_upgrade_flow.cpp` that open that -fixture and serve it, and remove the previous fixture directory. Never regenerate a fixture from current code: it is +fixture and serve it, and remove the previous fixture directory. The 1.1 series did this +with `tests/fixtures/upgrade/1.0.3/`, generated from `5f458d57` (1.0.3). Never regenerate a fixture from current code: it is evidence only because the old release wrote it. A pre-1.0 series start added no fixture and no upgrade test, and no pre-1.0 database is @@ -125,8 +126,8 @@ this build no longer has (`schema_ledger_is_known` in `src/database/Migration.cp database from 0.12.47 onwards records the same v1 step and passes that check, but v1 changed seven times before it was frozen (0.12.59 to 0.12.86), and nothing compares a database's tables with this build's, so such a database may lack columns and indexes this build uses. -The 0.12.47 collapse also removed the 0.11.13 upgrade fixture and its scenarios; there is no -fixture until the 1.1 series starts. +The 0.12.47 collapse also removed the 0.11.13 upgrade fixture and its scenarios; the next +fixture is the 1.0.3 one that starts the 1.1 series. ### The v1 schema is frozen from 1.0.0 diff --git a/docs/testing-standards.md b/docs/testing-standards.md index 6f96dfeea..5fd179780 100644 --- a/docs/testing-standards.md +++ b/docs/testing-standards.md @@ -91,6 +91,16 @@ A scenario that reaches PostgreSQL carries the `[postgresql]` tag, because that checks for it, but it reads the scenario's own text, so it cannot see a helper that opens a connection for the scenario. Without `MEROVINGIAN_TEST_POSTGRESQL_URI` these scenarios skip, so an untagged one passes in CI having tested nothing. +### The upgrade fixture + +`tests/fixtures/upgrade//` is a database the previous series' last release wrote through its own +HTTP API (ADR-0216), and `test_database_upgrade_flow.cpp` opens, migrates and serves it on SQLite and on +PostgreSQL (the `[fixture]` scenarios). Those scenarios read every ID, token and key from `manifest.json`, never +name one, and never regenerate the fixture with current code. The scenarios assert what opening the database does: +when the schema has changed since that release (1.1.0 adds migration 002), they assert the step was applied, and while it has +not, the migration is a no-op and they must not claim to prove a step that does not exist. The PostgreSQL +scenario carries `[postgresql]` and skips without `MEROVINGIAN_TEST_POSTGRESQL_URI`. + ### Scenarios that need a quiet store The live PostgreSQL scenarios share one database (`MEROVINGIAN_TEST_POSTGRESQL_URI`), diff --git a/docs/threat-model.md b/docs/threat-model.md index 960c8e506..1d8e45e31 100644 --- a/docs/threat-model.md +++ b/docs/threat-model.md @@ -3324,3 +3324,16 @@ directly, so these are unverified: the browser's handling of the `__Host-` cooki Chromium's `form-action` lets the 303 after a form post through to the client, IPv6 loopback redirects, and a client's deep links to the account pages. Milestone A in [the OAuth 2.0 plan](todos/oauth-2-0-api.md) (Element X on iOS and Android against a server built from this branch) closes this item. + +### MatrixRTC transport discovery (1.1.1, ADR-0822) + +New surface: `server.rtc.livekit.service_url` is advertised in an unauthenticated document, the `org.matrix.msc4143.rtc_foci` +member of `/.well-known/matrix/client`, and by two routes, `GET /_matrix/client/v1/rtc/transports` and its MSC4143 +unstable path, which need an access token and are rate limited like any client route. Disclosed: an address the +operator chose for their MatrixRTC authorisation service, public by design because clients must be told where it is. +Threats: an attacker steering clients to a service of their choosing, or injecting into the document. Mitigations: the +value comes only from the operator's configuration file, never from a request; it is refused at parse time unless it +is an absolute `https` URL with a host, no userinfo, query or fragment, no whitespace and a path that does not end in `/`; +every body is built with the JSON serializer, never by concatenating the URL into a string; and the server never +fetches the URL, so it adds no outbound request and no SSRF path. Residual risk: an operator who points it at a service +they do not control hands that service the OpenID tokens clients send it. diff --git a/docs/todos/capability-gaps.md b/docs/todos/capability-gaps.md index 3f6dcd843..3d582cb33 100644 --- a/docs/todos/capability-gaps.md +++ b/docs/todos/capability-gaps.md @@ -48,7 +48,8 @@ When adding a capability, record what is *missing* as explicitly as what works. | Endpoint | Status | Needs | | --- | --- | --- | | `GET /_matrix/client/v1/auth_metadata` and the MSC2965 unstable path | `spec-covered` | The OAuth 2.0 server metadata, served while `server.oauth.enabled` is true (ADR-0773); `404 M_UNRECOGNIZED` while it is off. Registration, the authorisation pages, the token endpoint (code and refresh grants), revocation, the account pages at `/_merovingian/account` (all six account management actions), the `m.oauth` UIA stage, the `legacy_api_enabled=false` switch and the hand-off for OAuth 2.0 aware clients (`m.login.sso` with `oauth_aware_preferred`) are served (ADR-0779 to ADR-0802), and so is the device authorization grant with `server.oauth.device_grant_enabled=true` (ADR-0804 to ADR-0806). An OAuth session still cannot add an email address or mint a login token (no page; `403 M_FORBIDDEN`). Element X's QR-code login needs the MSC4108 rendezvous API, which is not in spec v1.19 and not part of 1.1.0 (owner decision), so it stays unavailable although the device authorization grant is served. Nothing here has yet been tried with Element X or in a real browser; see the open items in `docs/todos/oauth-2-0-api.md`. | -| `GET /_matrix/client/v3/voip/turnServer` | `spec-covered` | Static TURN credentials from `server.turn.*` configuration, or per-user time-limited coturn shared-secret credentials when `server.turn.shared_secret_file` is set (`src/homeserver/TurnCredentials.cpp`, ADR-0480). | +| `GET /_matrix/client/v1/rtc/transports` and the MSC4143 unstable path | `runtime-wired` | MatrixRTC transport discovery (MSC4143, not in the v1.19 spec): advertises the operator's `lk-jwt-service` (`server.rtc.livekit.service_url`) as type `livekit` (ADR-0822). Gaps: no delayed events (MSC4140), so a vanished participant can stay listed in a call; no built-in token service (`m.livekit`, `/rtc/livekit/*`). | +| `GET /_matrix/client/v3/voip/turnServer` | `spec-covered` | Static TURN credentials from `server.turn.*` configuration, or per-user time-limited coturn shared-secret credentials when `server.turn.shared_secret_file` is set (`src/homeserver/TurnCredentials.cpp`, ADR-0480). `server.turn.uris` advertises several URIs (ADR-0821). | | Unrouted v1.19 operations | `not-started` | These answer `404 M_UNRECOGNIZED` (most are asserted as `(implementation gap)` scenarios in `tests/conformance/test_client_server_conformance.cpp`): legacy `GET /v3/events`, `GET /v3/events/{eventId}`, `GET /v3/initialSync`; `GET /.well-known/matrix/policy_server` and `GET /.well-known/matrix/support`. `POST /v1/login/get_token` (off unless `security.login_token.enabled`; UIA password every call; single-use in-memory tokens, ADR-0548) and `GET /v3/admin/whois/{userId}` (devices only: the server records no IP, user agent or last-seen time, so `connections` is always empty) are implemented (CS8). The two `/account/password/*/requestToken` routes are routed (email: ADR-0481; msisdn answers `400 M_THREEPID_MEDIUM_NOT_SUPPORTED`). User reporting, redaction, the appservice ping and the appservice network directory have their own rows. | | Room summary over federation | `runtime-wired` | `GET /v1/room_summary/{roomIdOrAlias}?via=` asks up to 3 `via` servers over federation `GET /hierarchy/{roomId}` (the `room` chunk; v1.19 defines no federation summary route) for a room this server holds no state for (ADR-0556): one ADR-0079 slot (429 at once without one, also without a token), one deadline, unverified answer, shown only by its own `join_rule` / `world_readable` / `allowed_room_ids`. Local state always wins; a malformed `via` is `400 M_INVALID_PARAM`. Not implemented: resolving an alias that lives on another server (404 / 401), and `membership` for a room not held locally. | | `GET /_matrix/media/v3/thumbnail/*`, `GET /_matrix/client/v1/media/thumbnail/*` | `spec-covered` | Real image resampling (PNG/JPEG, `scale`/`crop`) via the sandboxed worker landed in 0.8.10. Remote thumbnails fetch via the authenticated federation media endpoint and resample locally instead of serving the full-size original (v0.11.5). Conformance coverage now verifies that a remote thumbnail request never returns 200 with the full-size original bytes when federation infrastructure is unavailable (v0.11.5). | @@ -67,7 +68,7 @@ When adding a capability, record what is *missing* as explicitly as what works. | `POST /_matrix/client/v3/rooms/{roomId}/receipt/{receiptType}/{eventId}` | `spec-covered` | 0.12.30: accepts `m.read`, `m.read.private`, and `m.fully_read`; rejects unknown types with 400 `M_INVALID_PARAM`, non-members with 403 `M_FORBIDDEN`, and malformed bodies with 400 `M_BAD_JSON`. `m.read` and `m.read.private` are durable receipt rows (ADR-0169), keyed by `(room, type, user, thread_id)`, so restarts preserve read positions. `thread_id` is optional for `m.read`/`m.read.private`, must be a non-empty string naming `main` or a thread root in this room, and is carried by `/sync` `m.receipt` events and federated `m.read` EDUs. `m.read` is public and federated; `m.read.private` is visible only to its sender and is not federated. `m.fully_read` is accepted without `thread_id`, rejected if `thread_id` is supplied, and stored as the owner's `m.fully_read` room account data rather than a receipt; it never appears in `m.receipt` or a federation EDU. Invalid `thread_id` values (including a non-root room event ID) return 400 `M_INVALID_PARAM`. 0.12.60: `/sync` delivers one `m.receipt` event per thread categorisation (unthreaded, `main`, each thread root), so a user's unthreaded and threaded `m.read` for one event both arrive; sliding sync's receipts extension still holds one event per room and keeps the latest receipt on such a clash. **Gap:** the optional 400 for "The event_id is not related to the thread_id" is not checked; the root's existence and main-timeline classification are checked, but the acknowledged event's relationship to it is not. | | `POST /_matrix/client/v3/user_directory/search` | `spec-covered` | 0.12.60: searches only the users visible to the requester (a shared joined room, or joined to a `public` or `world_readable` room), as Complement expects; the spec allows searching more. Remote users are still not queried (the spec says SHOULD). | | `POST /_matrix/client/v3/delete_devices` | `spec-covered` | | -| `GET /_matrix/client/v3/sync` | `spec-covered` | Unread-notification counts are relative to the user's read receipts, partitioned by thread (an unthreaded receipt covers every earlier event, a threaded one only its thread; 0.12.30), and bound to the response snapshot. 0.12.30: the `unread_thread_notifications` filter flag (on `room.timeline`) returns per-thread counts and limits `unread_notifications` to the main timeline, and a non-state event the user sends reads its own thread up to itself (ADR-0170). The `summary` object (`m.joined_member_count`, `m.invited_member_count`, `m.heroes`) is now emitted for every joined room and covered by conformance tests. `filter_id` parameter now wired and conformance-covered; sync-only stream tokens now bound to the response snapshot for to-device delivery so room keys queued during response construction remain pending for the next sync. 0.12.59: a joined room's `state` on an initial sync (or a newly joined room) is the state up to the start of the timeline, not current state. Not done: an incremental sync with a limited timeline gives no state updates for the gap between `since` and the timeline's start. 0.12.60: `rooms.leave` lists rooms the user left **or was banned from**; each holds the filtered timeline (types, senders, `contains_url` now apply to a `/sync` timeline, and a `limit` of 0 means none) up to the leave or ban, as the user may see it, and an initial sync's `state` as of the start of that timeline (as of the leave when it is empty). An incremental sync reports a leave once, after `since`; `include_leave` lists left rooms on an initial sync only. A forgotten room is never listed (the spec says so, although Complement `TestRoomForget` expects its leave in the next incremental sync). Timeline events carry `unsigned.membership` (the requesting user's membership at the event, `leave` before they had one) and, for the device that sent them, `unsigned.transaction_id`; the same two on `GET /rooms/{roomId}/event/{eventId}`. 0.12.71: sliding sync's timeline and `required_state` events carry the same two fields, and no read path serves a stored event's `unsigned` (a received PDU is stored without it; ADR-0402). **Not done:** both fields are absent from `/messages`, `/context`, `/relations` and `/search`, and transaction-ID idempotency is still scoped to the user, not the device (the spec scopes it to a device). 0.12.60: an initial `/sync` always carries a global `m.push_rules` event with the effective ruleset (defaults plus changes), as Complement expects; an incremental one only after a change. **Lazy-loading of room members (0.12.73, ADR-0450 to ADR-0454).** With `room.state.lazy_load_members`, `state` holds the non-member state as before and only these member events: the senders of the delivered timeline (as of its start, skipped when the client has acknowledged that very event through its `since`), every member change in the gap of a limited sync, and the user's own on joining or `full_state`. Redundancy is tracked in memory per (user, device, filter, room) and lost on restart; `include_redundant_members` and `full_state=true` bypass it. The same flag on `room.timeline` does nothing, and the state filter's `types`/`senders` apply to the members. `full_state=true` is now honoured for joined rooms. Not done: `use_state_after`/`state_after`, sliding sync. | +| `GET /_matrix/client/v3/sync` | `spec-covered` | Unread-notification counts are relative to the user's read receipts, partitioned by thread (an unthreaded receipt covers every earlier event, a threaded one only its thread; 0.12.30), and bound to the response snapshot. 0.12.30: the `unread_thread_notifications` filter flag (on `room.timeline`) returns per-thread counts and limits `unread_notifications` to the main timeline, and a non-state event the user sends reads its own thread up to itself (ADR-0170). The `summary` object (`m.joined_member_count`, `m.invited_member_count`, `m.heroes`) is now emitted for every joined room and covered by conformance tests. `filter_id` parameter now wired and conformance-covered; sync-only stream tokens now bound to the response snapshot for to-device delivery so room keys queued during response construction remain pending for the next sync. 0.12.59: a joined room's `state` on an initial sync (or a newly joined room) is the state up to the start of the timeline, not current state. An incremental sync with a limited timeline sends the whole state up to the start of the timeline as `state`, which covers the gap between `since` and the timeline's start (not as a delta), and `state_after` holds what changed in the gap. 0.12.60: `rooms.leave` lists rooms the user left **or was banned from**; each holds the filtered timeline (types, senders, `contains_url` now apply to a `/sync` timeline, and a `limit` of 0 means none) up to the leave or ban, as the user may see it, and an initial sync's `state` as of the start of that timeline (as of the leave when it is empty). An incremental sync reports a leave once, after `since`; `include_leave` lists left rooms on an initial sync only. A forgotten room is never listed (the spec says so, although Complement `TestRoomForget` expects its leave in the next incremental sync). Timeline events carry `unsigned.membership` (the requesting user's membership at the event, `leave` before they had one) and, for the device that sent them, `unsigned.transaction_id`; the same two on `GET /rooms/{roomId}/event/{eventId}`. 0.12.71: sliding sync's timeline and `required_state` events carry the same two fields, and no read path serves a stored event's `unsigned` (a received PDU is stored without it; ADR-0402). **Not done:** both fields are absent from `/messages`, `/context`, `/relations` and `/search`, and transaction-ID idempotency is still scoped to the user, not the device (the spec scopes it to a device). 0.12.60: an initial `/sync` always carries a global `m.push_rules` event with the effective ruleset (defaults plus changes), as Complement expects; an incremental one only after a change. **Lazy-loading of room members (0.12.73, ADR-0450 to ADR-0454).** With `room.state.lazy_load_members`, `state` holds the non-member state as before and only these member events: the senders of the delivered timeline (as of its start, skipped when the client has acknowledged that very event through its `since`), every member change in the gap of a limited sync, and the user's own on joining or `full_state`. Redundancy is tracked in memory per (user, device, filter, room) and lost on restart; `include_redundant_members` and `full_state=true` bypass it. The same flag on `room.timeline` does nothing, and the state filter's `types`/`senders` apply to the members. `full_state=true` is now honoured for joined rooms. Not done: sliding sync. 1.1.1: `use_state_after` answers `state_after` and omits `state` for joined and left rooms, on initial and incremental sync, with `full_state` and with `lazy_load_members` (ADR-0818 to ADR-0820); invited and knocked rooms have no such field. **Not done (accepted limit, ADR-0819):** after a state fork at `since`, a key that state resolution later flips back to the value recorded at `since` is not sent in `state_after`, because the delta compares against the state recorded for the event at `since`, not the state the client was told; `full_state=true` repairs the client. Storing each response's state per token would close it and was refused for its cost. | | `GET /_matrix/client/v3/keys/changes` | `spec-covered` | Requires and validates `from` and `to` sync tokens, decodes them to `sync_stream_id` boundaries, and filters `changed`/`left` device-list changes to that half-open range. Conformance coverage includes missing/invalid parameters and an upper-bound test proving `to` excludes later changes. | | Remote device-list cache | `spec-covered` | Server-Server API v1.19 "Device Management". 0.12.81 (G14, ADR-0560, ADR-0561): the list of a remote user who shares a joined room with a local user is filled from `GET /user/devices/{userId}` (its `stream_id` places later updates) and kept in memory, bounded per user and in all. `m.device_list_update` EDUs apply in `stream_id` order; a `prev_id` above the snapshot that was never applied, or an empty one, marks the list stale and the next `/keys/query` fetches it again; `m.signing_key_update` does the same. An update that changes nothing is no longer reported in `device_lists.changed`. Not persisted: a restart refills on demand. Complement `TestDeviceListsUpdateOverFederation` (three subtests) stays skip-listed until it is run against this change. | | `POST /_matrix/client/v4/sync` and `POST /_matrix/client/unstable/org.matrix.msc4186/sync` (MSC4186 Simplified Sliding Sync) | `spec-covered` | Advertised via `unstable_features["org.matrix.msc4186"] = true` and the compatibility alias `unstable_features["org.matrix.simplified_msc3575"] = true`; the stable `v4` endpoint is now also routed and accepts the same request shape. Implements named lists with windowed `ranges` or singular `range`, SYNC/INVALIDATE/INSERT/DELETE/UPDATE ops, per-room state/timeline, room subscriptions, and all five extensions (to_device, e2ee, account_data, receipts, typing). Long-poll parks in the notifier's registry and holds no sync-pool thread while it waits (ADR-0569); `pos` and `timeout` may be supplied in query parameters or in the JSON body. List + `room_subscriptions` merge: when a room is in both a list window and a `room_subscriptions` entry, `required_state` is the superset (dedup + wildcard-aware), `timeline_limit` is the max, and `include_heroes` is OR'd (previously the subscription overrode the list wholesale) — landed 0.11.9. Multi-list combination: a room in MORE THAN ONE list window now has ALL matching list windows combined (left-fold over `combine_room_configs`, associative+commutative) with each other and the `room_subscriptions` entry, not just the first matching list — landed 0.11.10. Access control (CSAZ-1): a `room_subscriptions` entry is served only for a room the caller has joined; an invited room yields `invite_state` only (no timeline or `required_state`); any other membership omits the room, and the receipts/typing extensions drop rooms the caller has not joined. `timeline_limit` is clamped to 100, and more than 256 subscriptions or 256 `required_state` pairs is a 400 `M_INVALID_PARAM` (`sync::room_access_for`, `sliding_sync_request_limit_violation`). Truncated timelines (0.12.45): a room carries `limited` when its timeline holds fewer events than it could, `prev_batch` (a `/messages` `from`) on every non-empty timeline, `num_live`, and on a grown `timeline_limit` resends its latest events with `expanded_timeline`, answering without long-polling once per request `pos` (ADR-0221). Remaining: broader MSC4186 conformance fixtures, subscription timeline pruning, and `bump_stamp`, which is never sent (Element X orders its room list by it). | diff --git a/docs/user-manual.md b/docs/user-manual.md index f9cf9dcb4..05fca380c 100644 --- a/docs/user-manual.md +++ b/docs/user-manual.md @@ -807,8 +807,9 @@ support. | Key | Default | When to change | |---|---|---| | `server.turn.server` | (empty) | TURN server URI advertised to clients, e.g. `turn:turn.example.org:3478?transport=udp`. Leave empty to keep the endpoint returning `{}`. | -| `server.turn.username` | (empty) | Static username issued to authenticated clients. Required when `server.turn.server` is set. | -| `server.turn.password` | (empty) | Static password issued alongside the username. Required when `server.turn.server` is set. | +| `server.turn.uris` | (empty) | Several TURN URIs advertised in the order listed, e.g. `turn:turn.example.org:3478?transport=udp,turns:turn.example.org:5349?transport=tcp`. An alternative to `server.turn.server`, which stays for existing files; setting both is refused. The list uses the configuration's ordinary comma-separated syntax: whitespace around an entry and empty entries are ignored. Each entry is then checked, and refused (never repaired) unless it follows RFC 7065: `turn:` or `turns:` in lower case, a host (a name or IPv4 address of ASCII letters, digits, `.` and `-` that does not start or end with `.` or `-`, or a valid IPv6 address in square brackets such as `[2001:db8::1]`, with no zone identifier), an optional `:port` from 1 to 65535, and an optional `?transport=udp` or `?transport=tcp`. No user name, path, fragment or other query. An entry is at most 512 bytes of printable ASCII, may appear once, and the list holds at most 16 entries. A bad entry refuses the configuration. `server.turn.server` is not checked this way, so an existing value keeps working. TURN is on when either key is set (ADR-0821). | +| `server.turn.username` | (empty) | Static username issued to authenticated clients. Required when `server.turn.server` or `server.turn.uris` is set (unless `shared_secret_file` is used). | +| `server.turn.password` | (empty) | Static password issued alongside the username. Required when `server.turn.server` or `server.turn.uris` is set (unless `shared_secret_file` is used). | | `server.turn.shared_secret_file` | (empty) | Path to an owner-read-only file (mode `0400`, as every secret file) holding the TURN server's `static-auth-secret`, for coturn run with `use-auth-secret`. Each client then gets its own credentials: username `:`, password the base64 HMAC-SHA1 of that username under the secret (the coturn REST API), valid for `ttl_seconds`. Cannot be combined with `username` and `password`: the configuration is refused if both are set. | | `server.turn.ttl_seconds` | `86400` | Credential lifetime advertised in the response, and with `shared_secret_file` the time until the username's expiry. | @@ -822,6 +823,34 @@ support. > Set the same value as coturn's `static-auth-secret`, and keep > `server.turn.ttl_seconds` at or below coturn's own limits. +#### Voice and video calls — `server.rtc.*` and `server.turn.*` + +Merovingian does not carry call media. A call needs a service you run beside it: + +- **1:1 calls** need a TURN server such as coturn. Configure it with `server.turn.*` (above). +- **Group calls (MatrixRTC)** need a LiveKit SFU plus Element's `lk-jwt-service`, the authorisation service that + hands a caller a LiveKit token. `lk-jwt-service` checks who is calling through this server's existing OpenID + endpoints (`/_matrix/client/v3/user/{userId}/openid/request_token` and the federation `openid/userinfo`), so it must + be able to reach this server over HTTPS. Merovingian only tells clients where it is. + +| Key | Default | When to change | +|---|---|---| +| `server.rtc.livekit.service_url` | (empty) | The HTTPS URL of your `lk-jwt-service`, for example `https://livekit-jwt.example.org/lk-jwt-service`. Empty means no group-call transport is advertised. Clients build `/sfu/get` and `/get_token` by appending to it, so give the address without a trailing `/` and without a query: `https://host`, `https://host:8443` and `https://host/jwt` are accepted, `https://host/` and `https://host/jwt?x=1` are refused. It must be an absolute `https` URL with a host, no user name or password, no `#fragment`, no whitespace and at most 2048 bytes; anything else refuses the configuration. The server never contacts this URL. | + +With the key set, an authenticated client reading `GET /_matrix/client/v1/rtc/transports` (or the older +`GET /_matrix/client/unstable/org.matrix.msc4143/rtc/transports`) learns a transport of type `livekit` with that +`livekit_service_url`, and `GET /.well-known/matrix/client` gains an `org.matrix.msc4143.rtc_foci` member with the same +entry, which clients built on the Rust SDK fall back to. `/_matrix/client/versions` always lists `org.matrix.msc4143` +and `org.matrix.msc4143.stable` (ADR-0822). The URL is shown to anyone who can read the well-known document, so give +it only an address you are happy to publish. + +Not implemented yet: + +- **Delayed events (MSC4140).** A participant whose client vanishes (a crash or lost network) is not removed from the + call's membership state automatically and can stay listed until they rejoin or someone removes them. +- **A built-in token service.** There is no `/_matrix/client/v1/rtc/livekit/*` endpoint and the transport type + `m.livekit` is not advertised; you must run `lk-jwt-service` yourself. + #### OAuth 2.0 API — `server.oauth.*` Merovingian has a built-in OAuth 2.0 API (Matrix v1.19 "OAuth 2.0 API"), which @@ -1943,6 +1972,7 @@ take effect. | `presence.*` | Restart required | | `database.pool_size` | Restart required | | `server.turn.*` | Reloadable | +| `server.rtc.*` | Reloadable | | `security.trust_safety.*` | Reloadable | | `security.access_token_lifetime_ms` / `security.refresh_token_lifetime_ms` / `security.audit_log_retention_days` | Reloadable | | `security.login_throttle.*` | Reloadable | @@ -2254,6 +2284,9 @@ server { default_type application/json; add_header Access-Control-Allow-Origin "*" always; return 200 '{"m.homeserver":{"base_url":"https://matrix.example.org"}}'; + # With server.rtc.livekit.service_url set, a document served here instead of by Merovingian must carry the + # "org.matrix.msc4143.rtc_foci" member itself: + # {"m.homeserver":{...},"org.matrix.msc4143.rtc_foci":[{"type":"livekit","livekit_service_url":"https://..."}]} } location = /.well-known/matrix/server { @@ -2344,6 +2377,10 @@ printf '{"m.server":"matrix.example.org:443"}' \ > /var/www/merovingian/.well-known/matrix/server ``` +A static `client` file is not produced by Merovingian: with `server.rtc.livekit.service_url` set, add the +`org.matrix.msc4143.rtc_foci` member to it yourself (see Voice and video calls above), or let Merovingian answer +`/.well-known/matrix/client`. + ### Apache httpd example This example assumes `mod_ssl`, `mod_headers`, `mod_proxy`, diff --git a/include/merovingian/config/RtcConfig.hpp b/include/merovingian/config/RtcConfig.hpp new file mode 100644 index 000000000..20acf4567 --- /dev/null +++ b/include/merovingian/config/RtcConfig.hpp @@ -0,0 +1,23 @@ +// SPDX-FileCopyrightText: 2026 James Chapman +// SPDX-License-Identifier: GPL-3.0-or-later +#pragma once + +#include + +namespace merovingian::config +{ + +// MatrixRTC transport discovery (MSC4143, MSC4195; ADR-0822). This server never fetches or proxies anything here: it +// only tells authenticated clients where the operator's own MatrixRTC authorisation service is. +struct RtcConfig final +{ + // The HTTPS URL of an external MatrixRTC authorisation service (Element's `lk-jwt-service`) that the operator + // runs beside a LiveKit SFU. Advertised as a `livekit` transport. Empty means no transport is configured. + // Clients build `/sfu/get` and `/get_token` by appending to it. validate() refuses a + // value that is not an absolute `https` URL with a host, no userinfo, no query, no fragment, no whitespace or + // control character and at most 2048 bytes, or whose path ends in `/`. A URL with no path (`https://host`, + // `https://host:8443`) is accepted. + std::string livekit_service_url{}; +}; + +} // namespace merovingian::config diff --git a/include/merovingian/config/ServerConfig.hpp b/include/merovingian/config/ServerConfig.hpp index 38f6b1176..84dc1455a 100644 --- a/include/merovingian/config/ServerConfig.hpp +++ b/include/merovingian/config/ServerConfig.hpp @@ -9,6 +9,7 @@ #include "merovingian/config/IdentityServerConfig.hpp" #include "merovingian/config/OAuthConfig.hpp" #include "merovingian/config/PushConfig.hpp" +#include "merovingian/config/RtcConfig.hpp" #include "merovingian/config/SsoConfig.hpp" #include "merovingian/config/TurnServerConfig.hpp" @@ -37,6 +38,8 @@ struct ServerConfig final // TURN relay configuration for GET /_matrix/client/v3/voip/turnServer. // Empty by default; when populated the endpoint returns real credentials. TurnServerConfig turn{}; + // MatrixRTC transport discovery (MSC4143). Empty by default: no transport is advertised (see RtcConfig). + RtcConfig rtc{}; // The built-in OAuth 2.0 API. Off by default (see OAuthConfig). OAuthConfig oauth{}; // Identity Service API client config for 3PID invites/bind/unbind/ diff --git a/include/merovingian/config/TurnServerConfig.hpp b/include/merovingian/config/TurnServerConfig.hpp index 3e1184be8..dd22bfd60 100644 --- a/include/merovingian/config/TurnServerConfig.hpp +++ b/include/merovingian/config/TurnServerConfig.hpp @@ -4,6 +4,7 @@ #include #include +#include namespace merovingian::config { @@ -14,6 +15,10 @@ struct TurnServerConfig final // When empty the TURN endpoint returns an empty object so VoIP clients // gracefully disable relay support. std::string server{}; + // Several TURN URIs advertised to clients in the configured order, e.g. a UDP and a TLS relay (ADR-0821). An + // alternative to `server`, which stays for 1.0.x config files: setting both is refused. Each entry is a `turn:` or + // `turns:` URI, validated by validate(). TURN is enabled when either `server` or `uris` is set. + std::vector uris{}; // Static credentials issued to every authenticated client, for a TURN server that takes one shared account // or none. Mutually exclusive with shared_secret_file. std::string username{}; diff --git a/include/merovingian/core/SyncRequest.hpp b/include/merovingian/core/SyncRequest.hpp index 4817785b2..e6e35fe6c 100644 --- a/include/merovingian/core/SyncRequest.hpp +++ b/include/merovingian/core/SyncRequest.hpp @@ -17,6 +17,8 @@ struct SyncRequest final std::optional filter{}; // GET /sync `set_presence`, as sent (validated by the caller: it is client input). std::optional set_presence{}; + // GET /sync `use_state_after`: whether a room reports `state_after` rather than `state`. + std::optional use_state_after{}; }; } // namespace merovingian::core diff --git a/include/merovingian/database/EventTable.hpp b/include/merovingian/database/EventTable.hpp index 27df7db11..06c03179b 100644 --- a/include/merovingian/database/EventTable.hpp +++ b/include/merovingian/database/EventTable.hpp @@ -134,6 +134,23 @@ class EventTable final }); } + // The rows room_in_stream_order() visits whose stream_ordering is at most `limit`, in the same order: the + // first row above `limit` is found by binary search, so the rows above it cost nothing however many there + // are (O(log n) to start). std::views::reverse gives newest first. Valid until the table is next changed. + [[nodiscard]] auto room_in_stream_order_up_to(std::string_view room_id, std::uint64_t limit) const + { + auto const room = by_room_stream_.find(room_id); + auto positions = + room == by_room_stream_.end() ? std::span{} : std::span{room->second}; + auto const above = std::ranges::upper_bound(positions, limit, {}, [this](std::size_t held) { + return rows_[held].stream_ordering; + }); + positions = positions.first(static_cast(above - positions.begin())); + return std::views::transform(positions, [this](std::size_t position) -> PersistentEvent const& { + return rows_[position]; + }); + } + // The greatest `origin_server_ts` among the rows of room `room_id`, of every status, counting only a positive // integer member of the event's own JSON; 0 when the room has none (ADR-0497). [[nodiscard]] auto room_latest_origin_server_ts(std::string_view room_id) const -> std::int64_t; diff --git a/include/merovingian/database/PersistentStore.hpp b/include/merovingian/database/PersistentStore.hpp index 506eb9f73..72fa88c9f 100644 --- a/include/merovingian/database/PersistentStore.hpp +++ b/include/merovingian/database/PersistentStore.hpp @@ -370,6 +370,10 @@ struct PersistentStore final // readers looked at, so a test proves cost by count, not time. std::unordered_map> membership_user_index{}; ExaminedRows membership_rows_examined{}; + // Event rows `sync::state_anchor_event` visited to find a room's newest accepted event at or below a stream + // ordering: the rows it stepped over to reach one, never the rows above the limit, which a seek skips. A test + // proves the cost by it, not by time. + ExaminedRows state_anchor_rows_examined{}; // Event rows the sliding-sync long-poll relevance check walked (ADR-0609). ExaminedRows sync_relevance_rows_examined{}; // (room, user) -> position in `memberships` (ADR-0603), same trust rule as `membership_room_index`. diff --git a/include/merovingian/sync/RoomReadAccess.hpp b/include/merovingian/sync/RoomReadAccess.hpp index 38d3ca2e4..6668819a3 100644 --- a/include/merovingian/sync/RoomReadAccess.hpp +++ b/include/merovingian/sync/RoomReadAccess.hpp @@ -22,6 +22,9 @@ struct RoomReadAccess final // stream ordering. std::string boundary_event_id{}; std::uint64_t boundary_ordering{0U}; + // `as_of` only: the stream ordering of the join that `boundary_event_id` ended, found by the walk that found the + // boundary (no extra read). A client whose `since` is below it held nothing of the room from this stay. + std::uint64_t join_ordering{0U}; }; // The one predicate behind `initialSync`, `/members`, `/state` and `/state/{type}/{key}`. diff --git a/include/merovingian/sync/StateGroupLookup.hpp b/include/merovingian/sync/StateGroupLookup.hpp index 2de037fce..b1f925706 100644 --- a/include/merovingian/sync/StateGroupLookup.hpp +++ b/include/merovingian/sync/StateGroupLookup.hpp @@ -5,7 +5,10 @@ #include "merovingian/database/PersistentStore.hpp" #include "merovingian/sync/GroupLookupResult.hpp" +#include +#include #include +#include namespace merovingian::sync { @@ -17,4 +20,12 @@ namespace merovingian::sync [[nodiscard]] auto lookup_state_in_group(database::PersistentStore const& store, std::string_view group_id, std::string_view event_type, std::string_view state_key) -> GroupLookupResult; +// The event IDs of the state `group_id` holds that differs from what its ancestor `ancestor_id` holds: the newest row +// of each key on the delta chain from `group_id` down to, not including, `ancestor_id`. Empty when the two are one +// group. Nullopt when `ancestor_id` is not on the chain (a snapshot, a missing group or a cycle comes first), and the +// caller compares the two states. It costs the rows of the groups between the two, not the room's state: a snapshot's +// rows are never read. A key that changed and changed back is reported, with the value it holds. +[[nodiscard]] auto state_changes_along_chain(database::PersistentStore const& store, std::string_view ancestor_id, + std::string_view group_id) -> std::optional>; + } // namespace merovingian::sync diff --git a/meson.build b/meson.build index 7dc278ba2..90070cb6a 100644 --- a/meson.build +++ b/meson.build @@ -2,7 +2,7 @@ project( 'merovingian', 'cpp', 'c', - version: '1.1.0', + version: '1.1.1', license: 'GPL-3.0-or-later', meson_version: '>=1.1.0', default_options: [ diff --git a/packaging/freebsd/+MANIFEST b/packaging/freebsd/+MANIFEST index 869abd079..2ba83013d 100644 --- a/packaging/freebsd/+MANIFEST +++ b/packaging/freebsd/+MANIFEST @@ -1,5 +1,5 @@ name: "merovingian" -version: "1.1.0" +version: "1.1.1" origin: net/merovingian comment: Secure Matrix Protocol homeserver desc: "Merovingian is a Matrix Protocol homeserver." diff --git a/packaging/netbsd/Makefile b/packaging/netbsd/Makefile index d981516b7..ccdfd53dc 100644 --- a/packaging/netbsd/Makefile +++ b/packaging/netbsd/Makefile @@ -1,4 +1,4 @@ -DISTNAME= merovingian-1.1.0 +DISTNAME= merovingian-1.1.1 CATEGORIES= net MASTER_SITES= ${MASTER_SITE_GITHUB:=OMG-Software/} GITHUB_PROJECT= Merovingian diff --git a/packaging/opensuse/merovingian.spec b/packaging/opensuse/merovingian.spec index 73cd3136b..9cbf6bb40 100644 --- a/packaging/opensuse/merovingian.spec +++ b/packaging/opensuse/merovingian.spec @@ -1,5 +1,5 @@ Name: merovingian -Version: 1.1.0 +Version: 1.1.1 Release: 1%{?dist} Summary: Secure Matrix Protocol homeserver @@ -115,6 +115,9 @@ fi %{_sysconfdir}/merovingian/merovingian.conf.example %changelog +* Mon Nov 16 2026 James Chapman - 1.1.1-1 +- Merovingian 1.1.1 + * Sun Nov 15 2026 James Chapman - 1.1.0-1 - Merovingian 1.1.0 diff --git a/packaging/rhel/merovingian.spec b/packaging/rhel/merovingian.spec index 00f68058b..dcad8c654 100644 --- a/packaging/rhel/merovingian.spec +++ b/packaging/rhel/merovingian.spec @@ -1,5 +1,5 @@ Name: merovingian -Version: 1.1.0 +Version: 1.1.1 Release: 1%{?dist} Summary: Secure Matrix Protocol homeserver @@ -100,6 +100,9 @@ fi %{_sysconfdir}/merovingian/merovingian.conf.example %changelog +* Mon Nov 16 2026 James Chapman - 1.1.1-1 +- Merovingian 1.1.1 + * Sun Nov 15 2026 James Chapman - 1.1.0-1 - Merovingian 1.1.0 diff --git a/packaging/rpm/merovingian.spec b/packaging/rpm/merovingian.spec index cf30b3889..861d50dfe 100644 --- a/packaging/rpm/merovingian.spec +++ b/packaging/rpm/merovingian.spec @@ -1,5 +1,5 @@ Name: merovingian -Version: 1.1.0 +Version: 1.1.1 Release: 1%{?dist} Summary: Secure Matrix Protocol homeserver @@ -104,6 +104,9 @@ fi %{_sysconfdir}/merovingian/merovingian.conf.example %changelog +* Mon Nov 16 2026 James Chapman - 1.1.1-1 +- Merovingian 1.1.1 + * Sun Nov 15 2026 James Chapman - 1.1.0-1 - Merovingian 1.1.0 diff --git a/scripts/build-deb.sh b/scripts/build-deb.sh index 2dfa97fb2..222b53984 100755 --- a/scripts/build-deb.sh +++ b/scripts/build-deb.sh @@ -1,9 +1,9 @@ #!/bin/sh # SPDX-License-Identifier: GPL-3.0-or-later -# Build for merovingian 1.1.0. +# Build for merovingian 1.1.1. set -e -VERSION="1.1.0" +VERSION="1.1.1" PKG_NAME="merovingian" STAGING="staging-deb" diff --git a/scripts/build-freebsd-pkg.sh b/scripts/build-freebsd-pkg.sh index 4dce63ce2..0c4e6fd97 100755 --- a/scripts/build-freebsd-pkg.sh +++ b/scripts/build-freebsd-pkg.sh @@ -1,9 +1,9 @@ #!/bin/sh # SPDX-License-Identifier: GPL-3.0-or-later -# Build for merovingian 1.1.0. +# Build for merovingian 1.1.1. set -e -VERSION="1.1.0" +VERSION="1.1.1" STAGING="staging-fbsd" # Clean any state (staged files, build dir) from cached FreeBSD VM runs. diff --git a/scripts/build-netbsd-pkg.sh b/scripts/build-netbsd-pkg.sh index 74a8fddc6..736a85ab9 100644 --- a/scripts/build-netbsd-pkg.sh +++ b/scripts/build-netbsd-pkg.sh @@ -1,6 +1,6 @@ #!/bin/sh # SPDX-License-Identifier: GPL-3.0-or-later -# Build for merovingian 1.1.0. +# Build for merovingian 1.1.1. # # The checked-in packaging/netbsd/Makefile is the pkgsrc recipe kept for # downstream porters. This script generates a framework-free package so CI @@ -11,7 +11,7 @@ # a staged tree using tar, which produces a package that pkg_add can install. set -e -VERSION="1.1.0" +VERSION="1.1.1" STAGE="staging-netbsd" PREFIX=/usr/pkg diff --git a/scripts/build-openbsd-pkg.sh b/scripts/build-openbsd-pkg.sh index 9a90fd6ba..4779ebb99 100644 --- a/scripts/build-openbsd-pkg.sh +++ b/scripts/build-openbsd-pkg.sh @@ -1,6 +1,6 @@ #!/bin/sh # SPDX-License-Identifier: GPL-3.0-or-later -# Build for merovingian 1.1.0. +# Build for merovingian 1.1.1. # # Standalone pkg_create(1), no ports tree. The checked-in packaging/openbsd/PLIST # is the ports-framework packing list kept for downstream porters; this script @@ -8,7 +8,7 @@ # produce and validate an installable package on every run. set -e -VERSION="1.1.0" +VERSION="1.1.1" STAGE="staging-openbsd" PREFIX=/usr/local diff --git a/scripts/build-opensuse-rpm.sh b/scripts/build-opensuse-rpm.sh index 2f31ed13a..c58981dbb 100644 --- a/scripts/build-opensuse-rpm.sh +++ b/scripts/build-opensuse-rpm.sh @@ -1,6 +1,6 @@ #!/bin/sh # SPDX-License-Identifier: GPL-3.0-or-later -# Build an RPM package for merovingian 1.1.0 on OpenSUSE Tumbleweed or Leap. +# Build an RPM package for merovingian 1.1.1 on OpenSUSE Tumbleweed or Leap. # # Uses packaging/opensuse/merovingian.spec which adapts BuildRequires to # OpenSUSE package names (libopenssl-devel, postgresql-devel, libpng16-devel, @@ -12,7 +12,7 @@ # (.leap16, ADR-0650). set -e -VERSION="1.1.0" +VERSION="1.1.1" DIST="${MEROVINGIAN_RPM_DIST:-.tumbleweed}" case "${DIST}" in .[a-z]*) ;; diff --git a/scripts/build-rhel-rpm.sh b/scripts/build-rhel-rpm.sh index 816e839cd..b9fac8782 100644 --- a/scripts/build-rhel-rpm.sh +++ b/scripts/build-rhel-rpm.sh @@ -1,13 +1,13 @@ #!/bin/sh # SPDX-License-Identifier: GPL-3.0-or-later -# Build an RPM package for merovingian 1.1.0 targeting RHEL 10 / AlmaLinux 10. +# Build an RPM package for merovingian 1.1.1 targeting RHEL 10 / AlmaLinux 10. # # Differs from build-rpm.sh only in the spec file used: packaging/rhel/merovingian.spec # omits catch-devel from BuildRequires (Catch2 is not reliably available in EPEL 10 # and is not needed when -Dbuild_tests=false). set -e -VERSION="1.1.0" +VERSION="1.1.1" mkdir -p "${HOME}/rpmbuild/BUILD" mkdir -p "${HOME}/rpmbuild/BUILDROOT" diff --git a/scripts/build-rpm.sh b/scripts/build-rpm.sh index 263ea16bb..5fd3f46ea 100755 --- a/scripts/build-rpm.sh +++ b/scripts/build-rpm.sh @@ -1,9 +1,9 @@ #!/bin/sh # SPDX-License-Identifier: GPL-3.0-or-later -# Build an RPM package for merovingian 1.1.0 using rpmbuild. +# Build an RPM package for merovingian 1.1.1 using rpmbuild. set -e -VERSION="1.1.0" +VERSION="1.1.1" # 1. Create rpmbuild directory tree mkdir -p "${HOME}/rpmbuild/BUILD" diff --git a/scripts/build-static-linux.sh b/scripts/build-static-linux.sh index 14141f61e..bacfb77c5 100755 --- a/scripts/build-static-linux.sh +++ b/scripts/build-static-linux.sh @@ -3,7 +3,7 @@ # Build a portable Linux fallback tarball with musl-linked static PIE binaries. set -eu -VERSION="${MEROVINGIAN_VERSION:-1.1.0}" +VERSION="${MEROVINGIAN_VERSION:-1.1.1}" BUILD_DIR="${BUILD_DIR:-build-static-linux}" STAGING="staging-static-linux" PACKAGE_ROOT="merovingian-${VERSION}-linux-static-x86_64" diff --git a/src/config/AGENTS.md b/src/config/AGENTS.md index 3f6eb3f18..566a37554 100644 --- a/src/config/AGENTS.md +++ b/src/config/AGENTS.md @@ -9,6 +9,7 @@ Parses and validates the server configuration and plans (but does not yet apply) | `Config.cpp` | `Config` class (its section structs, such as `ServerConfig`, `ListenersConfig`, `DatabaseConfig` and `SecurityConfig`, each have their own `.hpp`) — typed representation of every config option; `validate_config()`, `parse_size_limit()` | | `ConfigParser.cpp` | Parses the key-value `.conf` file into `Config`; validates ranges and required fields | | `RuntimeConfigSnapshot.cpp` | `RuntimeConfigSnapshot`: holds a `Config` and can swap it for a reload-only candidate. Only the unit tests construct it today; the server does not | +| `RtcConfig.hpp`; TURN and RTC rules in `Config.cpp` | The `server.turn.uris` list rules (`turn:`/`turns:` entries, 512 bytes, 16 entries, no repeats, never both with `server.turn.server`; ADR-0821) and the `server.rtc.livekit.service_url` rule (an `oauth::ParsedUri` with scheme `https` and a host; ADR-0822). `RtcConfig.hpp` is that section's struct. | | `ReloadPlan.cpp` | Diffs old vs new config and classifies each change; used by `--plan-config-reload`. No live reload path (SIGHUP/admin socket) exists yet | | `ReloadPolicy.cpp` | `reload_policy_for_key()`: which keys need a restart. Keys are reloadable by default. Restart is required for `server.name`, the `database.*` URI and role keys, listener TLS certificate/key and `reverse_proxy` keys, `security.registration.token_file`, `database.pool_size`, `security.media.thumbnail_cache_size`, `security.media.thumbnail_max_concurrent_per_user`, `security.secrets.master_key_file`, `security.federation.key_resolution_*`, `security.federation.join_response_max_size`, `client_rate_limits.*`, `log_modules.*`, `federation.worker.*`, `server.cors.*`, `server.http.*`, `server.identity_server.*`, `server.push.*`, `server.oauth.*`, `appservice.*` and `presence.*`. The rate-limit engine and per-module log map are built once at start-up, so they are not hot-reloadable. | diff --git a/src/config/Config.cpp b/src/config/Config.cpp index 73c2ec7e1..c7c8b1dc0 100644 --- a/src/config/Config.cpp +++ b/src/config/Config.cpp @@ -29,6 +29,7 @@ #include "merovingian/http/RateLimit.hpp" #include "merovingian/oauth/HandOffAllowlist.hpp" #include "merovingian/oauth/OAuthBaseUrl.hpp" +#include "merovingian/oauth/ParsedUri.hpp" #include #include @@ -36,7 +37,9 @@ #include #include +#include #include +#include #include #include #include @@ -339,6 +342,138 @@ auto is_valid_https_url(std::string_view url) noexcept -> bool return !remainder.empty() && remainder.find(' ') == std::string_view::npos; } +namespace +{ + + // The longest server.turn.uris entry and the most entries one list holds. + constexpr auto max_turn_uri_bytes = std::size_t{512U}; + constexpr auto max_turn_uris = std::size_t{16U}; + + // Whether `uri` is a TURN URI of RFC 7065, strictly: `turn:` or `turns:`, a host (a name or IPv4 address of ASCII + // letters, digits, `.` and `-`, not starting or ending with `.` or `-`, or a valid IPv6 address (checked with + // inet_pton) in square brackets, of hex digits, `:` and `.`, so no zone identifier), an optional `:port` of 1 to + // 65535, and an optional `?transport=udp` or `?transport=tcp`. No userinfo, path, fragment or other query. + auto is_turn_uri(std::string_view uri) -> bool + { + auto const rest = starts_with(uri, "turn:") ? uri.substr(5U) + : starts_with(uri, "turns:") ? uri.substr(6U) + : std::string_view{}; + auto const question = rest.find('?'); + if (question != std::string_view::npos) + { + auto const query = rest.substr(question + 1U); + if (query != "transport=udp" && query != "transport=tcp") + { + return false; + } + } + auto const authority = rest.substr(0U, question); + auto host = std::string_view{}; + auto port = std::optional{}; + if (!authority.empty() && authority.front() == '[') + { + auto const close = authority.find(']'); + if (close == std::string_view::npos) + { + return false; + } + host = authority.substr(1U, close - 1U); + auto const after = authority.substr(close + 1U); + if (!after.empty()) + { + if (after.front() != ':') + { + return false; + } + port = after.substr(1U); + } + if (host.empty() || host.size() >= INET6_ADDRSTRLEN || host.find(':') == std::string_view::npos || + !std::ranges::all_of(host, [](char c) { + return std::isxdigit(static_cast(c)) != 0 || c == ':' || c == '.'; + })) + { + return false; + } + // Only hex digits, `:` and `.` get here (so no zone identifier); the system parser then says whether they + // spell an IPv6 address. The copy is NUL-terminated because the view is not. + auto literal = std::array{}; + std::ranges::copy(host, literal.begin()); + auto v6 = in6_addr{}; + if (::inet_pton(AF_INET6, literal.data(), &v6) != 1) + { + return false; + } + } + else + { + auto const colon = authority.find(':'); + host = authority.substr(0U, colon); + if (colon != std::string_view::npos) + { + port = authority.substr(colon + 1U); + } + auto const is_host_byte = [](char c) { + return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '.' || + c == '-'; + }; + if (host.empty() || !std::ranges::all_of(host, is_host_byte) || host.front() == '.' || + host.front() == '-' || host.back() == '.' || host.back() == '-') + { + return false; + } + } + if (port.has_value()) + { + constexpr auto max_port_digits = std::size_t{5U}; + if (port->empty() || port->size() > max_port_digits || !std::ranges::all_of(*port, is_ascii_digit)) + { + return false; + } + auto const value = std::stoul(std::string{*port}); + if (value == 0U || value > 65535U) + { + return false; + } + } + return true; + } + + // Why `uris` is not an acceptable server.turn.uris list, or nullopt. Fixed text, never the input. + auto turn_uris_error(std::vector const& uris) -> std::optional + { + if (uris.size() > max_turn_uris) + { + return "at most 16 TURN URIs may be listed"; + } + for (auto index = std::size_t{0U}; index < uris.size(); ++index) + { + auto const& uri = uris[index]; + if (!is_turn_uri(uri)) + { + return "each TURN URI must be turn: or turns: and a host, an optional :port and an optional " + "?transport=udp or ?transport=tcp"; + } + if (uri.size() > max_turn_uri_bytes) + { + return "a TURN URI may be at most 512 bytes"; + } + if (!std::ranges::all_of(uri, [](char c) { + return static_cast(c) >= 0x21U && static_cast(c) <= 0x7EU; + })) + { + return "a TURN URI must be printable ASCII without whitespace"; + } + auto const earlier = uris.begin() + static_cast(index); + if (std::ranges::find(uris.begin(), earlier, uri) != earlier) + { + return "a TURN URI may be listed only once"; + } + } + return std::nullopt; + } + +} // namespace + auto is_valid_federation_policy(std::string_view policy) noexcept -> bool { return policy == "allow" || policy == "deny"; @@ -1151,13 +1286,25 @@ auto validate(Config const& config) -> std::vector // A partially populated turn block (e.g. only a username) is rejected // because it would advertise a broken relay to clients. auto const& turn = config.server().turn; + // server.turn.uris is the list form of server.turn.server (ADR-0821). Two ways to name the relays would leave it + // unclear which one clients get, so both together is refused; each entry is refused, never repaired, when it is + // not a plain turn: or turns: URI. + if (!turn.server.empty() && !turn.uris.empty()) + { + findings.push_back({"server.turn.uris", "set either server.turn.server or server.turn.uris, not both"}); + } + if (auto const uris_error = turn_uris_error(turn.uris); uris_error.has_value()) + { + findings.push_back({"server.turn.uris", std::string{*uris_error}}); + } + auto const turn_configured = !turn.server.empty() || !turn.uris.empty(); if (!turn.shared_secret_file.empty() && (!turn.username.empty() || !turn.password.empty())) { // Two ways to issue credentials would leave it unclear which one clients get (ADR-0480). findings.push_back( {"server.turn.shared_secret_file", "set either shared_secret_file or username and password, not both"}); } - else if (!turn.server.empty() && turn.shared_secret_file.empty()) + else if (turn_configured && turn.shared_secret_file.empty()) { if (turn.username.empty()) { @@ -1168,12 +1315,30 @@ auto validate(Config const& config) -> std::vector findings.push_back({"server.turn.password", "TURN server configured but password is missing"}); } } - else if (turn.server.empty() && - (!turn.username.empty() || !turn.password.empty() || !turn.shared_secret_file.empty())) + else if (!turn_configured && (!turn.username.empty() || !turn.password.empty() || !turn.shared_secret_file.empty())) { findings.push_back({"server.turn.server", "TURN credentials supplied but no server URI is configured"}); } + // MatrixRTC transport discovery (ADR-0822): the service URL is sent to every authenticated client and, in the + // well-known document, to anyone, so it is refused unless it is an absolute https URL with a host. oauth::ParsedUri + // is the project's strict reader: printable ASCII only, no userinfo, no fragment, at most 2048 bytes. Nothing is + // repaired, and this server never fetches the URL. + if (auto const& service_url = config.server().rtc.livekit_service_url; !service_url.empty()) + { + auto const uri = oauth::ParsedUri::read(service_url); + auto const* parsed = std::get_if(&uri); + // Clients append `/sfu/get` or `/get_token` to it, so a query or a trailing slash would build a broken URL. + if (parsed == nullptr || parsed->scheme() != "https" || !parsed->has_authority() || parsed->host().empty() || + parsed->has_query() || parsed->path().ends_with('/')) + { + findings.push_back( + {"server.rtc.livekit.service_url", + "must be an https URL with a host, no userinfo, query or fragment, a path that does not " + "end in /, no whitespace and at most 2048 bytes"}); + } + } + // The built-in OAuth 2.0 API (ADR-0812, ADR-0816). Every OAuth address is derived from public_baseurl, so with the // API on it must be a base URL the OAuth reader accepts (ADR-0773). The other server.oauth.* keys mean nothing // with the API off, and are refused rather than silently ignored. diff --git a/src/config/ConfigParser.cpp b/src/config/ConfigParser.cpp index c564b78c3..0aace1949 100644 --- a/src/config/ConfigParser.cpp +++ b/src/config/ConfigParser.cpp @@ -984,6 +984,15 @@ namespace { server.turn.server = std::string{value}; } + else if (key == "server.turn.uris") + { + server.turn.uris = parse_string_list(value); + } + // MatrixRTC transport discovery (ADR-0822). validate() judges the URL. + else if (key == "server.rtc.livekit.service_url") + { + server.rtc.livekit_service_url = std::string{value}; + } else if (key == "server.turn.username") { server.turn.username = std::string{value}; diff --git a/src/config/ReloadPlan.cpp b/src/config/ReloadPlan.cpp index aa97be467..b15152cb4 100644 --- a/src/config/ReloadPlan.cpp +++ b/src/config/ReloadPlan.cpp @@ -560,6 +560,10 @@ auto build_reload_plan(Config const& current, Config const& next) -> ReloadPlan { add_change(plan, "server.turn.server"); } + if (current.server().turn.uris != next.server().turn.uris) + { + add_change(plan, "server.turn.uris"); + } if (current.server().turn.username != next.server().turn.username) { add_change(plan, "server.turn.username"); @@ -577,6 +581,12 @@ auto build_reload_plan(Config const& current, Config const& next) -> ReloadPlan add_change(plan, "server.turn.ttl_seconds"); } + // MatrixRTC transport discovery. + if (current.server().rtc.livekit_service_url != next.server().rtc.livekit_service_url) + { + add_change(plan, "server.rtc.livekit.service_url"); + } + // The OAuth 2.0 API: every field is diffed, and every change is restart_required (see ReloadPolicy.cpp). if (current.server().oauth.enabled != next.server().oauth.enabled) { diff --git a/src/core/QueryParams.cpp b/src/core/QueryParams.cpp index f85b9d82a..178fb92bc 100644 --- a/src/core/QueryParams.cpp +++ b/src/core/QueryParams.cpp @@ -241,6 +241,10 @@ auto parse_query_params(std::string_view target) -> SyncRequest { request.full_state = (value == "true"); } + else if (key == "use_state_after") + { + request.use_state_after = (value == "true"); + } else if (key == "filter") { request.filter = std::string{value}; diff --git a/src/db_migrate.cpp b/src/db_migrate.cpp index d1d9cfcd7..2cb7fb5d9 100644 --- a/src/db_migrate.cpp +++ b/src/db_migrate.cpp @@ -23,7 +23,7 @@ namespace { -constexpr auto version = std::string_view{"1.1.0"}; +constexpr auto version = std::string_view{"1.1.1"}; auto print_help() -> void { diff --git a/src/homeserver/AGENTS.md b/src/homeserver/AGENTS.md index 2080e8791..ca39f3565 100644 --- a/src/homeserver/AGENTS.md +++ b/src/homeserver/AGENTS.md @@ -71,6 +71,7 @@ This is the largest and most complex module — read this file carefully before | `PresenceService.cpp` | Presence (CS API "Presence", SS API `m.presence`): `read_presence` (GET), `apply_sync_presence` (the `/sync` `set_presence` parameter), `build_sync_presence_events` (`presence.events`), `accept_inbound_presence` (the EDU sink's presence case) and `record_presence`, the one place a presence row is stored. `expire_idle_presence` (the idle sweep, ADR-0492). `presence.enabled=false` turns every entry point into a no-op. Sending the EDU stays in `ClientServerRuntime.cpp` (`broadcast_presence_edu`), beside the other outbound EDUs | | `PushRetry.cpp` | `attempt_push_delivery` (every push attempt: circuit breaker, rejected pushkeys, scheduling retries) and `PushRetryJob`, the one thread that sends retries (R14, ADR-0206); a run is bounded by a time budget, takes retries one recipient at a time in turn and sends with a shorter timeout (ADR-0410), and a slow answer counts against the gateway's circuit (ADR-0409) | | `PasswordReset.cpp` | Password reset by email (ADR-0481): `make_password_reset_token` (8 characters, 40 bits), `normalize_password_reset_token`, `send_password_reset_email` (a background task parked in `orphan_futures_`, at most 8 in flight, no lock held while it sends). The endpoints are in `ClientServerRuntime.cpp` before the auth gate; `reset_local_user_password` is in `AuthService.cpp` | +| `ClientServerRuntime.cpp` (MatrixRTC) | `GET /_matrix/client/v1/rtc/transports` and `GET /_matrix/client/unstable/org.matrix.msc4143/rtc/transports` advertise `server.rtc.livekit.service_url` as `{"type":"livekit","livekit_service_url":...}` (`livekit_transport_json`): `transports` and `[]` when none on the stable path, `rtc_transports` and `{}` on the unstable one; both flags `org.matrix.msc4143` and `org.matrix.msc4143.stable` are always in `/versions`, and the well-known document gains `org.matrix.msc4143.rtc_foci` only with a URL (ADR-0822). The type is never `m.livekit` and there is no `/rtc/livekit/*` route. `voip/turnServer` returns `server.turn.server` or, when that is empty, each `server.turn.uris` entry in order (ADR-0821) | | `TurnCredentials.cpp` | `make_turn_credentials`: the coturn REST API username and password for `GET /voip/turnServer` (ADR-0480) | | `EmailPush.cpp` | Kind `"email"` pushers (ADR-0219, ADR-0220): `owned_email_pusher_address` (the pushkey must be the account's own email 3PID), `remove_email_pushers_for_address`, and `EmailPushJob`, the one thread that sends due digests through `send_due_email_notifications`. It re-reads the pusher, the 3PID, the account and the badge count under `runtime.mutex` (one hold, one `PushBadgeBudget`: rows and glob steps bounded together, ADR-0722), then sends with the mutex released | | `RuntimeSigningKeyStore.cpp` | Production `SigningKeyStore` over the persisted server signing-key rows | diff --git a/src/homeserver/ClientServerRuntime.cpp b/src/homeserver/ClientServerRuntime.cpp index c5f3b11a0..9345930f6 100644 --- a/src/homeserver/ClientServerRuntime.cpp +++ b/src/homeserver/ClientServerRuntime.cpp @@ -856,6 +856,18 @@ namespace return canonicaljson::make_member(std::move(key), std::move(value)); } + // The MatrixRTC transport entry for the LiveKit authorisation service at `service_url` (MSC4143, MSC4195; + // ADR-0822). The type is `livekit`, never `m.livekit`, and there is no `url` member. + [[nodiscard]] auto livekit_transport_json(std::string const& service_url) -> canonicaljson::Value + { + return canonicaljson::Value{ + canonicaljson::Object{ + canonicaljson::make_member("type", canonicaljson::Value{std::string{"livekit"}}), + canonicaljson::make_member("livekit_service_url", canonicaljson::Value{service_url}), + } + }; + } + [[nodiscard]] auto json_serialize(canonicaljson::Value const& value) -> std::string { auto const result = canonicaljson::serialize_canonical(value); @@ -4104,6 +4116,8 @@ namespace "/_matrix/client/v1/media/upload", "/_matrix/client/v1/media/preview_url", "/_matrix/client/v3/voip/turnServer", + "/_matrix/client/v1/rtc/transports", + "/_matrix/client/unstable/org.matrix.msc4143/rtc/transports", "/_matrix/client/v3/room_keys/version", "/_matrix/client/v3/room_keys/keys", "/_matrix/client/v3/devices", @@ -4207,6 +4221,8 @@ namespace {"/_matrix/client/v1/media/upload", "POST" }, {"/_matrix/client/v1/media/preview_url", "GET" }, {"/_matrix/client/v3/voip/turnServer", "GET" }, + {"/_matrix/client/v1/rtc/transports", "GET" }, + {"/_matrix/client/unstable/org.matrix.msc4143/rtc/transports", "GET" }, {"/_matrix/client/v3/room_keys/version", "GET, POST" }, {"/_matrix/client/v3/room_keys/keys", "DELETE, GET, PUT"}, {"/_matrix/client/v3/devices", "GET" }, @@ -5428,8 +5444,12 @@ namespace std::set> senders{}; std::string own_user_id{}; bool own_forced{false}; - // A member event above this stream ordering (and below the timeline) is a gap change. + // A member event above this stream ordering is a change since `since`: in the gap when `state` is built, + // and in the timeline as well for `state_after`, whose client takes no state from the timeline. std::optional gap_after{}; + // The events of a `state_after` delta (ADR-0819): each is a change the client must apply, whatever its + // stream ordering (state resolution can move a key back to an older event). + std::unordered_set changed_event_ids{}; // Drop every state event that is not a member event (an incremental left room's state is a delta). bool members_only{false}; // Do not consult the tracker: a client may discard a room when it leaves it, so after a rejoin it may no @@ -5455,6 +5475,11 @@ namespace return plan_.members_only; } + [[nodiscard]] auto is_changed(std::string const& event_id) const -> bool + { + return plan_.changed_event_ids.contains(event_id); + } + // Whether `event`, the member state event for `state_key`, goes in `state`; notes it when it does. [[nodiscard]] auto keep(database::PersistentEvent const& event, std::string_view state_key) -> bool { @@ -5467,7 +5492,7 @@ namespace return false; } auto const forced = (plan_.gap_after.has_value() && event.stream_ordering > *plan_.gap_after) || - (plan_.own_forced && state_key == plan_.own_user_id); + (plan_.own_forced && state_key == plan_.own_user_id) || is_changed(event.event_id); if (!forced) { if (!plan_.senders.contains(state_key) || @@ -5753,10 +5778,8 @@ namespace // `position` only while an earlier ordering is pending; then the state is the // state before the earliest such event, which no event at or below `position` // follows. Failing that, the events above `position` are left out. - [[nodiscard]] auto build_state_events_at_position(database::PersistentStore const& store, - sync::EventTypeFilter const& filter, std::string_view room_id, - std::uint64_t position, LazySelectorRef lazy = std::nullopt) - -> canonicaljson::Array + [[nodiscard]] auto state_event_ids_at_position(database::PersistentStore const& store, std::string_view room_id, + std::uint64_t position) -> std::vector { auto earliest_above = store.events.end(); auto ids = std::vector{}; @@ -5776,7 +5799,7 @@ namespace }); if (earliest_above == store.events.end()) { - return build_current_state_events_array(store, filter, room_id, lazy); + return ids; } if (auto const* policy = stored_room_version_policy(store, room_id); policy != nullptr) { @@ -5788,7 +5811,7 @@ namespace { before_ids.push_back(entry.event_id); } - return build_state_events_array_for_ids(store, filter, before_ids, lazy); + return before_ids; } } // Each key held above `position` keeps the value it held before, where its @@ -5804,7 +5827,82 @@ namespace } } } - return build_state_events_array_for_ids(store, filter, ids, lazy); + return ids; + } + + [[nodiscard]] auto build_state_events_at_position(database::PersistentStore const& store, + sync::EventTypeFilter const& filter, std::string_view room_id, + std::uint64_t position, LazySelectorRef lazy = std::nullopt) + -> canonicaljson::Array + { + return build_state_events_array_for_ids(store, filter, state_event_ids_at_position(store, room_id, position), + lazy); + } + + // Removes from `ids` what `held`, the state the client holds, already has. An event is the value of one key, so an + // event `held` lacks is exactly a key whose value differs. + auto remove_state_held(std::vector& ids, std::vector const& held) -> void + { + auto const held_ids = std::unordered_set{held.begin(), held.end()}; + std::erase_if(ids, [&](std::string const& id) { + return held_ids.contains(id); + }); + } + + // ADR-0819: the IDs of the state events that make a joined room's state at `position` differ from its state at + // `since_ordering`, for `state_after`. A key can change with no event of the window about it (state resolution can + // move it back), so this compares the two states; it does not list the window's state events. + // + // Cost: nothing for a room with no event since `since` (one look at the newest row). Otherwise the anchor at + // `since` is a binary search of the room's index plus the withheld rows stepped over below it, however many rows + // the window holds (`state_anchor_rows_examined`). With an unforked graph, then the state group rows between the + // two points, none for a window of messages. Otherwise (a fork, a snapshot between the points, an unreadable chain) + // it reads the room's state twice, its own rows only. + [[nodiscard]] auto joined_state_changes(database::PersistentStore const& store, std::string_view room_id, + std::uint64_t since_ordering, std::uint64_t position) + -> std::vector + { + auto newest_first = store.events.room_in_stream_order(room_id) | std::views::reverse; + if (std::ranges::empty(newest_first) || (*newest_first.begin()).stream_ordering <= since_ordering) + { + return {}; + } + auto const access = sync::RoomReadAccess{sync::RoomReadKind::current, {}, 0U}; + auto const* const since_anchor = sync::state_anchor_event(store, room_id, access, since_ordering); + auto const since_group = since_anchor == nullptr + ? std::optional{} + : database::find_event_state_group(store, since_anchor->event_id); + if (since_group.has_value()) + { + // With one extremity the current state is that event's recorded state (ADR-0064). The forward extremity + // index answers for one room: it costs that room's tips. + auto const tips = store.forward_extremities.tips_of_room(room_id); + if (tips.size() == 1U) + { + auto const tip = store.events.find(tips.front()); + auto const tip_group = tip != store.events.end() && tip->stream_ordering <= position + ? database::find_event_state_group(store, tip->event_id) + : std::optional{}; + if (tip_group.has_value()) + { + if (auto changes = sync::state_changes_along_chain(store, *since_group, *tip_group); + changes.has_value()) + { + return std::move(*changes); + } + } + } + } + auto changes = state_event_ids_at_position(store, room_id, position); + // A `since` older than anything recorded here gets all of it: an update the client already holds is harmless. + if (since_anchor != nullptr) + { + if (auto const held = sync::state_event_ids_after(store, *since_anchor); held.has_value()) + { + remove_state_held(changes, *held); + } + } + return changes; } // Whether a timeline carries the join of `user_id`: the join then tells the client everything the spec's "own @@ -5866,6 +5964,83 @@ namespace return current; } + // What stands in for a sender's member event above the position when the state group chain cannot be read: a joined + // user may read the current one and a member too many is valid; a user who left may not read past their leave. + enum class UnreadableMember + { + current_stands_in, + omitted, + }; + + // The `m.room.member` event of `sender` in force at `position`, for `state_after` (ADR-0454's cost rule): two hash + // lookups when their current member event is at or below it, which is nearly always; otherwise one walk of the + // state group chain of the state anchor at `position`. + [[nodiscard]] auto member_event_at_position(database::PersistentStore const& store, std::string_view room_id, + sync::RoomReadAccess const& access, std::uint64_t position, + std::string_view sender, UnreadableMember unreadable) + -> std::optional + { + auto const current = database::find_current_state_event_id(store, room_id, "m.room.member", sender); + if (current.has_value()) + { + auto const event = store.events.find(*current); + if (event != store.events.end() && event->stream_ordering <= position) + { + return current; + } + } + auto const fallback = unreadable == UnreadableMember::current_stands_in ? current : std::nullopt; + auto const* const anchor = sync::state_anchor_event(store, room_id, access, position); + auto const group = anchor == nullptr ? std::optional{} + : database::find_event_state_group(store, anchor->event_id); + if (!group.has_value()) + { + return fallback; + } + auto const found = sync::lookup_state_in_group(store, *group, "m.room.member", sender); + switch (found.outcome) + { + case sync::GroupLookup::found: + return std::string{found.event_id}; + case sync::GroupLookup::absent: + return std::nullopt; + case sync::GroupLookup::broken: + break; + } + return fallback; + } + + // Appends the client event of `event_id`, the member event of `sender`, when the filter and the selector keep it. + auto add_lazy_sender_member(database::PersistentStore const& store, sync::EventTypeFilter const& filter, + std::string const& event_id, std::string const& sender, LazyRoomSelector& selector, + canonicaljson::Array& members) -> void + { + auto const event = store.events.find(event_id); + if (event != store.events.end() && sync::event_passes_filter(filter, "m.room.member", event->sender_user_id) && + selector.keep(*event, sender)) + { + members.push_back(client_event_with_id(store, *event)); + } + } + + // The member events a `state_after` delta adds for `senders`: each as of `position`, unless the delta already holds + // it, that the selector keeps. + auto add_lazy_senders_at_position(database::PersistentStore const& store, sync::EventTypeFilter const& filter, + std::string_view room_id, sync::RoomReadAccess const& access, + std::uint64_t position, std::vector const& senders, + UnreadableMember unreadable, LazyRoomSelector& selector, + canonicaljson::Array& members) -> void + { + for (auto const& sender : senders) + { + auto const event_id = member_event_at_position(store, room_id, access, position, sender, unreadable); + if (event_id.has_value() && !selector.is_changed(*event_id)) + { + add_lazy_sender_member(store, filter, *event_id, sender, selector, members); + } + } + } + // The member events a lazy response carries when `state` is not otherwise built: those of `senders`, as they were // at the start of the timeline whose first event is `first_event`, that the selector keeps. [[nodiscard]] auto build_lazy_sender_members(database::PersistentStore const& store, @@ -5878,18 +6053,10 @@ namespace for (auto const& sender : senders) { auto const event_id = member_event_at_timeline_start(store, first_event.room_id, first_event, sender); - if (!event_id.has_value()) + if (event_id.has_value()) { - continue; + add_lazy_sender_member(store, filter, *event_id, sender, selector, members); } - auto const event = store.events.find(*event_id); - if (event == store.events.end() || - !sync::event_passes_filter(filter, "m.room.member", event->sender_user_id) || - !selector.keep(*event, sender)) - { - continue; - } - members.push_back(client_event_with_id(store, *event)); } return members; } @@ -6350,6 +6517,8 @@ namespace // What room state the user may read (ADR-0357). `none` for a user who never joined: a retracted // knock, a declined invite, a ban before any join. sync::RoomReadAccess access{}; + // GET /sync `use_state_after`: answer `state_after` instead of `state` (ADR-0820). + bool use_state_after{false}; }; // Ignoring Users for a stored event: whether `ignored_senders` withholds it. The event's JSON is parsed for @@ -6363,6 +6532,119 @@ namespace trust_safety::event_json_is_state_event(event.json)); } + // The members of a left room's section. + [[nodiscard]] auto left_room_object(std::string_view state_member, canonicaljson::Array state_events, + canonicaljson::Array timeline_events, bool limited, + std::string const& prev_batch) -> canonicaljson::Value + { + return json_obj({ + json_member(std::string{state_member}, + json_obj({json_member("events", json_arr(std::move(state_events)))})), + json_member("timeline", json_obj({ + json_member("events", json_arr(std::move(timeline_events))), + json_member("limited", json_bool(limited)), + json_member("prev_batch", json_str(prev_batch)), + })), + }); + } + + // ADR-0820: a left room's `state_after`: "The state updates for the room up to the end of the timeline", which ends + // at the leave. The room's state is read only as far as the user may read it (ADR-0357, room_read_access_for), so + // nothing after their leave is told, however late the ban that ended their membership came. The user's own + // membership is the event in `leave_event` (the leave, or the ban that followed it); the client takes no state from + // the timeline, so it is here even though the timeline carries it. + // + // A delta is only a delta for a client that held the room's state at `since`. When the join this departure ended + // began after `since` (`RoomReadAccess::join_ordering`, found by the walk that found the boundary), the client held + // nothing of this room, so the whole readable state as of the leave is sent, as an initial sync sends it, still + // capped by `room_read_access_for`. The test is the one `joined_membership_changed_since` applies to a joined room, + // read from the join event instead of the current member event, which for a departed user is the leave. + [[nodiscard]] auto build_left_room_state_after( + database::PersistentStore const& store, sync::EventTypeFilter const& filter, + sync::ViewerEventUnsigned& viewer_unsigned, LeftRoomRequest const& request, + std::optional> leave_event, std::uint64_t upper_bound, + std::vector const& senders, LazySyncRequest& lazy) -> canonicaljson::Array + { + auto state_events = canonicaljson::Array{}; + auto const joined_in_window = request.since_ordering.has_value() && + request.access.kind == sync::RoomReadKind::as_of && + request.access.join_ordering > *request.since_ordering; + auto const delta_since = joined_in_window ? std::optional{} : request.since_ordering; + if (request.access.kind != sync::RoomReadKind::none) + { + auto const readable_to = request.access.kind == sync::RoomReadKind::as_of + ? std::min(upper_bound, request.access.boundary_ordering) + : upper_bound; + auto const* const anchor = sync::state_anchor_event(store, request.room_id, request.access, readable_to); + auto ids = anchor == nullptr ? std::optional>{} + : sync::state_event_ids_after(store, *anchor); + if (ids.has_value() && leave_event.has_value()) + { + // Replaced by the event that ended their stay, below. + if (auto const group = database::find_event_state_group(store, anchor->event_id); group.has_value()) + { + auto const own = sync::lookup_state_in_group(store, *group, "m.room.member", request.user_id); + if (own.outcome == sync::GroupLookup::found) + { + std::erase(*ids, own.event_id); + } + } + } + if (ids.has_value() && delta_since.has_value()) + { + if (*delta_since >= readable_to) + { + ids->clear(); + } + else if (auto const* const since_anchor = + sync::state_anchor_event(store, request.room_id, request.access, *delta_since); + since_anchor != nullptr) + { + if (auto const held = sync::state_event_ids_after(store, *since_anchor); held.has_value()) + { + remove_state_held(*ids, *held); + } + } + } + auto selector = std::optional{}; + if (lazy.enabled()) + { + auto plan = LazyRoomSelector::Plan{}; + plan.senders.insert(senders.begin(), senders.end()); + plan.own_user_id = std::string{request.user_id}; + plan.own_forced = true; + plan.ignore_tracker = joined_in_window; + if (delta_since.has_value() && ids.has_value()) + { + plan.changed_event_ids.insert(ids->begin(), ids->end()); + } + selector.emplace(lazy, request.room_id, std::move(plan)); + } + auto const lazy_ref = selector.has_value() ? LazySelectorRef{std::ref(*selector)} : LazySelectorRef{}; + if (ids.has_value()) + { + state_events = build_state_events_array_for_ids(store, filter, *ids, lazy_ref); + } + if (selector.has_value() && delta_since.has_value()) + { + // A delta names only what changed: the other senders' members come by key, as of the leave. + auto others = std::vector{}; + std::ranges::copy_if(senders, std::back_inserter(others), [&](std::string const& sender) { + return sender != request.user_id; + }); + add_lazy_senders_at_position(store, filter, request.room_id, request.access, readable_to, others, + UnreadableMember::omitted, *selector, state_events); + } + } + if (leave_event.has_value() && + sync::event_passes_filter(filter, "m.room.member", leave_event->get().sender_user_id)) + { + state_events.push_back( + viewer_unsigned.apply(leave_event->get(), client_event_with_id(store, leave_event->get()))); + } + return state_events; + } + [[nodiscard]] auto build_left_room(database::PersistentStore const& store, sync::SyncFilter const& filter, sync::HistoryVisibility& history_visibility, sync::ViewerEventUnsigned& viewer_unsigned, @@ -6417,6 +6699,27 @@ namespace : std::to_string(window.budget_ran_out ? window.oldest_examined.value_or(since_ordering) : since_ordering); + if (request.use_state_after) + { + auto senders = std::vector{}; + if (lazy.enabled()) + { + auto unique = std::set>{}; + for (auto it = window_begin; it != matched.end(); ++it) + { + unique.insert((*it)->sender_user_id); + } + senders.assign(unique.begin(), unique.end()); + } + auto const leave = leave_event == store.events.end() + ? std::optional>{} + : std::optional{std::cref(*leave_event)}; + return left_room_object("state_after", + build_left_room_state_after(store, filter.room.state, viewer_unsigned, request, + leave, upper_bound, senders, lazy), + std::move(timeline_events), limited, prev_batch); + } + auto state_events = canonicaljson::Array{}; // ADR-0357: a user who never joined (`none`) was never entitled to any of the room's state, so an // initial sync tells them only what an incremental one does: their own leave or ban, when the @@ -6552,14 +6855,7 @@ namespace } } - return json_obj({ - json_member("state", json_obj({json_member("events", json_arr(std::move(state_events)))})), - json_member("timeline", json_obj({ - json_member("events", json_arr(std::move(timeline_events))), - json_member("limited", json_bool(limited)), - json_member("prev_batch", json_str(prev_batch)), - })), - }); + return left_room_object("state", std::move(state_events), std::move(timeline_events), limited, prev_batch); } // Spec (Push Rules: Events): `m.push_rules` "Describes all push rules for this user", and its @@ -6659,6 +6955,7 @@ namespace // may omit a redundant member (not include_redundant_members, not full_state), and fed by one that may; it // is begun here, after any long-poll wait, so a rerun judges afresh and records only what it returns. auto const full_state = request.full_state.value_or(false); + auto const use_state_after = request.use_state_after.value_or(false); auto const lazy_on = filter.present && filter.room.state.lazy_load_members; auto const may_omit = lazy_on && !filter.room.state.include_redundant_members; auto lazy = LazySyncRequest{ @@ -6798,10 +7095,16 @@ namespace since_token.has_value() && joined_membership_changed_since(store, room.room_id, user, since_ordering); auto state_events = canonicaljson::Array{}; // Spec (GET /sync, `full_state`): "all state events will be returned, even if since is non-empty". - auto const state_path = !since_token.has_value() || newly_joined || limited || full_state; + // ADR-0818: `state_after` is the changes since `since`, on a limited sync too: they hold everything the gap + // changed, and whole state would only repeat what the client has. + auto const state_path = + !since_token.has_value() || newly_joined || full_state || (limited && !use_state_after); + auto const state_changes = use_state_after && !state_path + ? joined_state_changes(store, room.room_id, since_ordering, sync_position) + : std::vector{}; auto lazy_senders = std::vector{}; auto selector = std::optional{}; - if (lazy.enabled() && (state_path || window_begin != matched.end())) + if (lazy.enabled() && (state_path || window_begin != matched.end() || !state_changes.empty())) { auto plan = LazyRoomSelector::Plan{}; for (auto it = window_begin; it != matched.end(); ++it) @@ -6811,16 +7114,39 @@ namespace lazy_senders.assign(plan.senders.begin(), plan.senders.end()); plan.own_user_id = std::string{user}; plan.ignore_tracker = newly_joined; + // A timeline event is not state to a `state_after` client: only the join in `state_after` tells it. plan.own_forced = (!since_token.has_value() || full_state || newly_joined) && - !timeline_carries_join_of(timeline_events, user); - if (since_token.has_value() && limited) + (use_state_after || !timeline_carries_join_of(timeline_events, user)); + if (since_token.has_value() && (limited || use_state_after)) { plan.gap_after = since_ordering; } + plan.changed_event_ids.insert(state_changes.begin(), state_changes.end()); selector.emplace(lazy, room.room_id, std::move(plan)); } auto const lazy_ref = selector.has_value() ? LazySelectorRef{std::ref(*selector)} : LazySelectorRef{}; - if (state_path) + if (use_state_after) + { + // ADR-0818: as of the response's position, not the last delivered event: a state event the timeline + // filter hides lies before `next_batch`, and no later sync would report it. + if (state_path) + { + state_events = + build_state_events_at_position(store, filter.room.state, room.room_id, sync_position, lazy_ref); + } + else + { + state_events = build_state_events_array_for_ids(store, filter.room.state, state_changes, lazy_ref); + if (selector.has_value()) + { + add_lazy_senders_at_position(store, filter.room.state, room.room_id, + sync::RoomReadAccess{sync::RoomReadKind::current, {}, 0U}, + sync_position, lazy_senders, UnreadableMember::current_stands_in, + *selector, state_events); + } + } + } + else if (state_path) { auto at_start = window_begin != matched.end() ? build_state_events_at_timeline_start(store, filter.room.state, room.room_id, @@ -6897,7 +7223,8 @@ namespace json_member("limited", json_bool(limited)), json_member("prev_batch", json_str(prev_batch)), })), - json_member("state", json_obj({json_member("events", json_arr(std::move(state_events)))})), + json_member(use_state_after ? "state_after" : "state", + json_obj({json_member("events", json_arr(std::move(state_events)))})), json_member("account_data", json_obj({json_member("events", json_arr(std::move(room_account_data)))})), json_member("ephemeral", json_obj({json_member("events", json_arr(std::move(ephemeral_events)))})), json_member("unread_notifications", counts_object(room_counts)), @@ -6994,7 +7321,8 @@ namespace store, filter, history_visibility, viewer_unsigned, ignored_senders, {membership.room_id, user, membership.stream_ordering, since_token.has_value() ? std::optional{since_ordering} : std::nullopt, - sync_position, timeline_cap, sync::room_read_access_for(store, membership.room_id, user)}, + sync_position, timeline_cap, sync::room_read_access_for(store, membership.room_id, user), + use_state_after}, lazy); leave_members.push_back(json_member(membership.room_id, left_room)); ++leave_count; @@ -15006,10 +15334,18 @@ static auto handle_client_server_request_impl(ClientServerRuntime& rt, LocalHttp if (req.method == "GET" && request_path == "/.well-known/matrix/client") { auto const& base_url = rt.homeserver.config.server().public_baseurl; - return dispatch_resp(req, rt, 200U, - json_serialize(json_obj({ - json_member("m.homeserver", json_obj({json_member("base_url", json_str(base_url))})), - }))); + auto document = canonicaljson::Object{ + json_member("m.homeserver", json_obj({json_member("base_url", json_str(base_url))})), + }; + // MSC4143: the Rust SDK falls back to this member when it cannot read the transports route (ADR-0822). Only + // with a service configured; without one the body is what it always was. + if (auto const& service_url = rt.homeserver.config.server().rtc.livekit_service_url; !service_url.empty()) + { + auto foci = canonicaljson::Array{}; + foci.push_back(livekit_transport_json(service_url)); + document.push_back(json_member("org.matrix.msc4143.rtc_foci", json_arr(std::move(foci)))); + } + return dispatch_resp(req, rt, 200U, json_serialize(json_obj(std::move(document)))); } // GET /_matrix/client/versions is the unauthenticated discovery endpoint @@ -15029,6 +15365,8 @@ static auto handle_client_server_request_impl(ClientServerRuntime& rt, LocalHttp json_member("versions", json_arr(std::move(versions))), json_member("unstable_features", json_obj({ json_member("org.matrix.msc4186", json_bool(true)), + json_member("org.matrix.msc4143", json_bool(true)), + json_member("org.matrix.msc4143.stable", json_bool(true)), json_member("org.matrix.simplified_msc3575", json_bool(true)), })), }))); @@ -19257,7 +19595,7 @@ static auto handle_client_server_request_impl(ClientServerRuntime& rt, LocalHttp if (req.method == "GET" && request_path == "/_matrix/client/v3/voip/turnServer") { auto const& turn = rt.homeserver.config.server().turn; - if (turn.server.empty()) + if (turn.server.empty() && turn.uris.empty()) { return dispatch_resp(req, rt, 200U, "{}"); } @@ -19288,8 +19626,20 @@ static auto handle_client_server_request_impl(ClientServerRuntime& rt, LocalHttp username = std::move(credentials->username); password = std::move(credentials->password); } + // server.turn.server (one URI, kept for 1.0.x configs) or server.turn.uris (ADR-0821), in configured order. + // The two are never both set: validate() refuses it. auto uris = canonicaljson::Array{}; - uris.push_back(json_str(turn.server)); + if (!turn.server.empty()) + { + uris.push_back(json_str(turn.server)); + } + else + { + for (auto const& uri : turn.uris) + { + uris.push_back(json_str(uri)); + } + } auto const body = json_serialize(json_obj({ json_member("username", json_str(username)), json_member("password", json_str(password)), @@ -19299,6 +19649,29 @@ static auto handle_client_server_request_impl(ClientServerRuntime& rt, LocalHttp return dispatch_resp(req, rt, 200U, body); } + // GET /_matrix/client/v1/rtc/transports and its unstable MSC4143 path: where the operator's MatrixRTC + // authorisation service is (ADR-0822). The two differ in the property name and in what they answer when no + // service is configured, as the reference server's do. + if (req.method == "GET" && (request_path == "/_matrix/client/v1/rtc/transports" || + request_path == "/_matrix/client/unstable/org.matrix.msc4143/rtc/transports")) + { + auto const& service_url = rt.homeserver.config.server().rtc.livekit_service_url; + auto const stable = request_path == "/_matrix/client/v1/rtc/transports"; + auto transports = canonicaljson::Array{}; + if (!service_url.empty()) + { + transports.push_back(livekit_transport_json(service_url)); + } + if (!stable && transports.empty()) + { + return dispatch_resp(req, rt, 200U, "{}"); + } + return dispatch_resp(req, rt, 200U, + json_serialize(json_obj({ + json_member(stable ? "transports" : "rtc_transports", json_arr(std::move(transports))), + }))); + } + auto const key_route = auth::match_key_api_route(req.method, req.target); if (key_route.matched) { diff --git a/src/main.cpp b/src/main.cpp index 6cd78e790..da3e7cfd6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -81,7 +81,7 @@ namespace { -constexpr auto version = std::string_view{"1.1.0"}; +constexpr auto version = std::string_view{"1.1.1"}; struct BootstrapConfigResult final { diff --git a/src/sync/AGENTS.md b/src/sync/AGENTS.md index a233d54fe..546cc3a66 100644 --- a/src/sync/AGENTS.md +++ b/src/sync/AGENTS.md @@ -359,6 +359,23 @@ room and, when the user is local, for them. The membership acceptor (`send_join` `device_lists.left` for remote users. A user who joins over federation is also `changed` for themselves (spec: a server may add a user to `changed` when they share a new room). +## `use_state_after` on `/sync` (ADR-0818 to ADR-0820) + +`state_after` is as of `sync_position`, not the last delivered event, or a state event the timeline filter hides is lost. +A delta is `joined_state_changes`: it compares the state at `since` with the state at the position. Do not replace it with a +list of the window's state events (a key state resolution moved back has none), and do not read both whole states when the +graph is unforked (`state_changes_along_chain` costs the rows between them, none for a window of messages). Read the room's +single forward extremity with `ForwardExtremityTable::tips_of_room`, never a walk of every room's. `state_anchor_event` seeks +the first row at or below its position through `EventTable::room_in_stream_order_up_to` (binary search) and steps only over +withheld rows (`state_anchor_rows_examined`); never walk the rows above the position. A left room's delta is taken against +`since` only when the user was joined then (`RoomReadAccess::join_ordering` at or below `since`); a join in the window gets the +whole readable state (ADR-0820). A left room goes through +`build_left_room_state_after`, which reads only as far as `room_read_access_for` allows: never a joined room's delta, which +would tell a departed user what came after their leave. With lazy-loading the delta's member events are always kept +(`Plan::changed_event_ids`), and the senders' come by key from `member_event_at_position`. A timeline event is not state +in this mode, so a rule that relies on the timeline telling the client something applies to `state` only. Invited and knocked +rooms have no `state_after`; sliding sync does not read `use_state_after`. + ## Lazy-loading room members on `/sync` (ADR-0450 to ADR-0454) `room.state.lazy_load_members` (never `room.timeline`'s) turns it on. `state` then carries the non-member state the room would carry without lazy-loading (the state filter and the incremental diff --git a/src/sync/RoomReadAccess.cpp b/src/sync/RoomReadAccess.cpp index 067c3462a..c9ca51c3a 100644 --- a/src/sync/RoomReadAccess.cpp +++ b/src/sync/RoomReadAccess.cpp @@ -79,9 +79,15 @@ namespace // The event that ended the user's most recent join, found by walking the chain of the // user's m.room.member events back from their current one (`ending_event_id`) until a // join. nullopt when there was no join in the chain or the chain is broken. + struct JoinEnding final + { + database::PersistentEvent const* boundary{nullptr}; + std::uint64_t join_ordering{0U}; + }; + [[nodiscard]] auto find_join_ending_event(database::PersistentStore const& store, std::string_view room_id, std::string_view user_id, std::string_view ending_event_id) - -> std::optional + -> std::optional { auto const find = [&store](std::string_view id) -> database::PersistentEvent const* { auto const found = store.events.find(id); @@ -104,7 +110,7 @@ namespace } if (step > 0U && *membership == "join" && !event_is_withheld(*event)) { - return find(child); + return JoinEnding{find(child), event->stream_ordering}; } if (step == 0U && *membership == "join") { @@ -170,11 +176,12 @@ auto room_read_access_for(database::PersistentStore const& store, std::string_vi return {}; } auto const boundary = find_join_ending_event(store, room_id, user_id, *member_event_id); - if (!boundary.has_value() || *boundary == nullptr) + if (!boundary.has_value() || boundary->boundary == nullptr) { return {}; } - return {RoomReadKind::as_of, (*boundary)->event_id, (*boundary)->stream_ordering}; + return {RoomReadKind::as_of, boundary->boundary->event_id, boundary->boundary->stream_ordering, + boundary->join_ordering}; } auto state_anchor_event(database::PersistentStore const& store, std::string_view room_id, RoomReadAccess const& access, @@ -189,16 +196,19 @@ auto state_anchor_event(database::PersistentStore const& store, std::string_view { limit = std::min(limit, access.boundary_ordering); } - // The room's rows newest first (ADR-0435): the first one at or below `limit` that is not withheld has the - // highest stream ordering. Among rows sharing it, the one added first wins, as when every row was compared. + // The room's rows at or below `limit`, newest first (ADR-0435): the seek skips every row above it without + // visiting one, so the cost is the rows stepped over past the limit, not the rows a long absence missed. The + // first one that is not withheld has the highest stream ordering. Among rows sharing it, the one added first + // wins, as when every row was compared. database::PersistentEvent const* newest = nullptr; - for (auto const& event : store.events.room_in_stream_order(room_id) | std::views::reverse) + for (auto const& event : store.events.room_in_stream_order_up_to(room_id, limit) | std::views::reverse) { if (newest != nullptr && event.stream_ordering != newest->stream_ordering) { break; } - if (event.stream_ordering > limit || event_is_withheld(event)) + store.state_anchor_rows_examined.add(1U); + if (event_is_withheld(event)) { continue; } diff --git a/src/sync/StateGroupLookup.cpp b/src/sync/StateGroupLookup.cpp index 496dea725..1d08a9935 100644 --- a/src/sync/StateGroupLookup.cpp +++ b/src/sync/StateGroupLookup.cpp @@ -6,7 +6,9 @@ #include "merovingian/sync/GroupLookup.hpp" #include "merovingian/sync/GroupLookupResult.hpp" +#include #include +#include namespace merovingian::sync { @@ -42,4 +44,33 @@ auto lookup_state_in_group(database::PersistentStore const& store, std::string_v } } +auto state_changes_along_chain(database::PersistentStore const& store, std::string_view ancestor_id, + std::string_view group_id) -> std::optional> +{ + auto changes = std::vector{}; + auto seen = std::set>{}; + auto current = group_id; + for (auto hops = std::size_t{0U}; hops <= events::max_state_group_delta_depth; ++hops) + { + if (current == ancestor_id) + { + return changes; + } + auto const group = store.state_groups.find(current); + if (group == store.state_groups.end() || !group->parent_state_group_id.has_value()) + { + return std::nullopt; + } + for (auto const& entry : store.state_group_state.entries_of(current)) + { + if (seen.emplace(entry.event_type, entry.state_key).second) + { + changes.push_back(entry.event_id); + } + } + current = *group->parent_state_group_id; + } + return std::nullopt; +} + } // namespace merovingian::sync diff --git a/tests/conformance/AGENTS.md b/tests/conformance/AGENTS.md index dccaf0ea3..84e14581e 100644 --- a/tests/conformance/AGENTS.md +++ b/tests/conformance/AGENTS.md @@ -106,6 +106,7 @@ Every test in this directory directly encodes a **MUST** or **SHOULD** from the | `test_sync_filter_conformance.cpp` | [CS API § Filtering](../../docs/matrix-v1.19-spec/client-server-api.md#filtering) | | `test_sync_summary_conformance.cpp` | [CS API § Syncing](../../docs/matrix-v1.19-spec/client-server-api.md#syncing) | | `test_sync_state_conformance.cpp` | [CS API `GET /sync`](../../docs/matrix-v1.19-spec/client-server-api.md#get_matrixclientv3sync) (a joined room's `state` is the state up to the start of the timeline, not current state) | +| `test_sync_state_after_conformance.cpp` | [CS API `GET /sync`](../../docs/matrix-v1.19-spec/client-server-api.md#get_matrixclientv3sync) (`use_state_after`: `state_after` present and `state` omitted with `true`, the reverse with `false` and by default, for joined and left rooms, initial and incremental, `full_state` and `lazy_load_members`; the state as of the end of the timeline; a left room's stops at the leave). Only what the spec rows state: what this project decides (a left room's delta under `full_state`, delta chain limits, an unreported quiet room, a room joined in the window, the lazy-member tracker) is in `tests/integration/test_sync_state_after_flow.cpp` | | `test_typing_conformance.cpp` | [CS API § Typing Notifications](../../docs/matrix-v1.19-spec/client-server-api.md#typing-notifications) (`typing` must be a boolean; typing expires after its `timeout`, never later than the server's ceiling) · [SS API § Typing Notifications](../../docs/matrix-v1.19-spec/server-server-api.md#typing-notifications) and [§ Server ACLs](../../docs/matrix-v1.19-spec/server-server-api.md#server-access-control-lists-acls) (an inbound `m.typing` EDU for a user not joined to the room, or from a server the room's ACL denies, is ignored; a remote flood at the cap never evicts a local user's typing) | | `test_x_matrix_auth_parsing.cpp` | [SS API § X-Matrix Auth](../../docs/matrix-v1.19-spec/server-server-api.md#request-authentication) | diff --git a/tests/conformance/test_route_query_conformance.cpp b/tests/conformance/test_route_query_conformance.cpp index b247f599a..a8f589c65 100644 --- a/tests/conformance/test_route_query_conformance.cpp +++ b/tests/conformance/test_route_query_conformance.cpp @@ -111,7 +111,7 @@ SCENARIO("every client route that matched its whole target answers a request wit // Every route that was compared with `req.target == "..."`. A handler may answer anything // (a UIA challenge, a 400 for the empty body); what it may not do is answer as though the // route does not exist. /logout is last: it ends the session. - constexpr auto routes = std::array{ + constexpr auto routes = std::array{ { {"GET", "/.well-known/matrix/client", ""}, {"GET", "/_matrix/client/versions", ""}, @@ -150,6 +150,8 @@ SCENARIO("every client route that matched its whole target answers a request wit {"GET", "/_matrix/media/v3/config", ""}, {"GET", "/_matrix/client/v1/media/config", ""}, {"GET", "/_matrix/client/v3/voip/turnServer", ""}, + {"GET", "/_matrix/client/v1/rtc/transports", ""}, + {"GET", "/_matrix/client/unstable/org.matrix.msc4143/rtc/transports", ""}, {"GET", "/_matrix/client/v3/devices", ""}, {"POST", "/_matrix/client/v3/delete_devices", "{}"}, {"GET", "/_matrix/client/v3/joined_rooms", ""}, diff --git a/tests/conformance/test_sync_state_after_conformance.cpp b/tests/conformance/test_sync_state_after_conformance.cpp new file mode 100644 index 000000000..41e5d9af9 --- /dev/null +++ b/tests/conformance/test_sync_state_after_conformance.cpp @@ -0,0 +1,781 @@ +// SPDX-FileCopyrightText: 2026 James Chapman +// SPDX-License-Identifier: GPL-3.0-or-later +// +// +-------------------------------------------------------------------------+ +// | !! IMPORTANT - FOR HUMANS AND LLMs ALIKE !! | +// | | +// | Every REQUIRE here encodes a MUST or SHOULD of the Matrix v1.19 spec | +// | (the scenario header quotes it). If one fails, fix the IMPLEMENTATION | +// | first. Do NOT weaken, comment out or remove an assertion, or change an | +// | expected value, without citing the spec section that changed. | +// +-------------------------------------------------------------------------+ +// +// GET /_matrix/client/v3/sync `use_state_after` and the `state_after` section of joined and left rooms +// (client-server-api.md, GET /sync, "Joined Room", "Left Room"; ADR-0818 to ADR-0820). +#include "../support/JsonTestSupport.hpp" +#include "../support/SyncStateAfterSupport.hpp" +#include "merovingian/homeserver/ClientServerRuntime.hpp" +#include "merovingian/homeserver/ClientServerStartResult.hpp" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace +{ + +using namespace merovingian::tests; +using namespace merovingian::tests::state_after_support; + +} // namespace + +// Spec: Matrix Client-Server API v1.19 +// Endpoint / Section: GET /_matrix/client/v3/sync, query parameter `use_state_after`; Joined Room `state`, +// `state_after` URL: ../../docs/matrix-v1.19-spec/client-server-api.md#get_matrixclientv3sync +// +// "If this is set to true, servers MUST respond with the state between the previous sync and the end of the timeline in +// state_after and MUST omit state. If false, servers MUST respond with the state between the previous sync and the +// start of the timeline in state and MUST omit state_after." "By default, this is false." `state_after`: "all state up +// to the end of the timeline, if since is not given, or full_state is true". +SCENARIO("An initial sync answers state_after or state as use_state_after asks", + "[conformance][client-server][sync][state-after]") +{ + GIVEN("a room whose topic changed inside the last two events") + { + auto started = merovingian::homeserver::start_client_server(state_after_config()); + REQUIRE(started.started); + auto& rt = started.runtime; + auto const alice = register_user(rt, "alice"); + auto const room = create_room(rt, alice, "public_chat"); + set_topic(rt, alice, room, "first"); + say(rt, alice, room, "a"); + set_topic(rt, alice, room, "second"); + say(rt, alice, room, "b"); + constexpr auto two_events = std::string_view{R"({"room":{"timeline":{"limit":2}}})"}; + + WHEN("alice syncs with use_state_after=true") + { + auto const synced = sync(rt, alice, two_events, {}, k_state_after); + auto const& joined = required_room(synced, "join", room); + + THEN("state_after is the whole state at the end of the timeline, and state is omitted") + { + // Spec MUST: with use_state_after=true the room carries state_after and omits state. + require_state_after_only(joined); + auto const after = events_of(joined, "state_after"); + REQUIRE(topics_in(after) == std::vector{"second"}); + REQUIRE(event_types(after).contains("m.room.create")); + REQUIRE(member_keys(after) == Keys{user_id("alice")}); + } + } + WHEN("alice syncs with use_state_after=false") + { + auto const synced = sync(rt, alice, two_events, {}, k_state_before); + auto const& joined = required_room(synced, "join", room); + + THEN("state is the state at the start of the timeline, and state_after is omitted") + { + // Spec MUST: with use_state_after false or absent the room carries state and omits state_after. + require_state_only(joined); + REQUIRE(topics_in(events_of(joined, "state")) == std::vector{"first"}); + } + } + WHEN("alice syncs without the parameter") + { + auto const synced = sync(rt, alice, two_events); + auto const& joined = required_room(synced, "join", room); + + THEN("it is as if it were false") + { + // Spec MUST: with use_state_after false or absent the room carries state and omits state_after. + require_state_only(joined); + REQUIRE(topics_in(events_of(joined, "state")) == std::vector{"first"}); + } + } + } +} + +// Spec: Matrix Client-Server API v1.19 +// Endpoint / Section: GET /_matrix/client/v3/sync, query parameter `use_state_after`; Joined Room `state_after` +// URL: ../../docs/matrix-v1.19-spec/client-server-api.md#get_matrixclientv3sync +// +// `state_after`: "Updates to the state, between the time indicated by the since parameter, and the end of the +// timeline". "If this field is set, even if it is empty, clients MUST only update their local state with events in this +// list, and MUST NOT update their local state with events in timeline." "Required if use_state_after was set to true in +// the request, even if it is empty." +SCENARIO("An incremental sync's state_after holds what changed up to the end of the timeline", + "[conformance][client-server][sync][state-after]") +{ + GIVEN("a room alice has synced") + { + auto started = merovingian::homeserver::start_client_server(state_after_config()); + REQUIRE(started.started); + auto& rt = started.runtime; + auto const alice = register_user(rt, "alice"); + auto const room = create_room(rt, alice, "public_chat"); + set_topic(rt, alice, room, "first"); + auto const initial = sync(rt, alice, k_no_filter, {}, k_state_after); + + WHEN("only a message arrived") + { + say(rt, alice, room, "hello"); + auto const synced = sync(rt, alice, k_no_filter, initial.next_batch, k_state_after); + auto const& joined = required_room(synced, "join", room); + + THEN("state_after is present and empty, and state is omitted") + { + // Spec MUST: with use_state_after=true the room carries state_after and omits state. + require_state_after_only(joined); + REQUIRE(events_of(joined, "state_after").empty()); + } + } + WHEN("only a message arrived and the parameter is false or absent") + { + say(rt, alice, room, "hello"); + auto const off = sync(rt, alice, k_no_filter, initial.next_batch, k_state_before); + auto const absent = sync(rt, alice, k_no_filter, initial.next_batch); + + THEN("state is present and state_after is omitted") + { + // Spec MUST: with use_state_after false or absent the room carries state and omits state_after. + require_state_only(required_room(off, "join", room)); + // Spec MUST: with use_state_after false or absent the room carries state and omits state_after. + require_state_only(required_room(absent, "join", room)); + } + } + WHEN("the timeline carries a topic change") + { + say(rt, alice, room, "before"); + set_topic(rt, alice, room, "second"); + say(rt, alice, room, "after"); + auto const synced = sync(rt, alice, k_no_filter, initial.next_batch, k_state_after); + auto const& joined = required_room(synced, "join", room); + + THEN("state_after repeats the change, as the client takes no state from the timeline, and nothing else") + { + // Spec MUST: with use_state_after=true the room carries state_after and omits state. + require_state_after_only(joined); + REQUIRE(topics_in(events_of(joined, "timeline")) == std::vector{"second"}); + auto const after = events_of(joined, "state_after"); + REQUIRE(event_types(after) == Keys{"m.room.topic"}); + REQUIRE(topics_in(after) == std::vector{"second"}); + } + } + WHEN("the topic changed twice since the last sync") + { + set_topic(rt, alice, room, "second"); + set_topic(rt, alice, room, "third"); + auto const synced = sync(rt, alice, k_no_filter, initial.next_batch, k_state_after); + + THEN("state_after holds the value at the end of the timeline, once") + { + REQUIRE(topics_in(events_of(required_room(synced, "join", room), "state_after")) == + std::vector{"third"}); + } + } + WHEN("a topic change falls in the gap of a limited sync") + { + set_topic(rt, alice, room, "second"); + say(rt, alice, room, "one"); + say(rt, alice, room, "two"); + auto const synced = sync(rt, alice, k_one_event, initial.next_batch, k_state_after); + auto const& joined = required_room(synced, "join", room); + + THEN("state_after holds the change and not the state that did not change") + { + auto const* timeline = object_member_as_object(joined, "timeline"); + REQUIRE(timeline != nullptr); + REQUIRE(events_of(joined, "timeline").size() == 1U); + // Spec MUST: with use_state_after=true the room carries state_after and omits state. + require_state_after_only(joined); + auto const after = events_of(joined, "state_after"); + REQUIRE(event_types(after) == Keys{"m.room.topic"}); + REQUIRE(topics_in(after) == std::vector{"second"}); + } + } + WHEN("the timeline filter hides a topic change") + { + constexpr auto hide_topic = std::string_view{R"({"room":{"timeline":{"not_types":["m.room.topic"]}}})"}; + set_topic(rt, alice, room, "hidden"); + auto const synced = sync(rt, alice, hide_topic, initial.next_batch, k_state_after); + + THEN("state_after still reports it, because the next sync starts after it") + { + auto const& joined = required_room(synced, "join", room); + REQUIRE(events_of(joined, "timeline").empty()); + REQUIRE(topics_in(events_of(joined, "state_after")) == std::vector{"hidden"}); + auto const next = sync(rt, alice, hide_topic, synced.next_batch, k_state_after); + auto const* again = room_section(next, "join", room); + REQUIRE((again == nullptr || events_of(*again, "state_after").empty())); + } + } + WHEN("the state filter excludes the type that changed") + { + constexpr auto no_topic = std::string_view{R"({"room":{"state":{"not_types":["m.room.topic"]}}})"}; + set_topic(rt, alice, room, "second"); + auto const synced = sync(rt, alice, no_topic, initial.next_batch, k_state_after); + + THEN("state_after is present and does not hold it") + { + auto const& joined = required_room(synced, "join", room); + // Spec MUST: with use_state_after=true the room carries state_after and omits state. + require_state_after_only(joined); + REQUIRE(events_of(joined, "state_after").empty()); + } + } + } +} + +// Spec: Matrix Client-Server API v1.19 +// Endpoint / Section: GET /_matrix/client/v3/sync, query parameter `use_state_after`; Joined Room `state_after` +// URL: ../../docs/matrix-v1.19-spec/client-server-api.md#get_matrixclientv3sync +// +// `use_state_after`: "the state between the previous sync and the end of the timeline". State resolution can move a key +// back to an older event: no event of the window is about that key, and only comparing the two states shows the change. +SCENARIO("state_after reports a key that state resolution moved back to an older event", + "[conformance][client-server][sync][state-after]") +{ + GIVEN("a room with a forked graph whose resolved topic went back to an earlier event") + { + auto started = merovingian::homeserver::start_client_server(state_after_config()); + REQUIRE(started.started); + auto& rt = started.runtime; + auto const alice = register_user(rt, "alice"); + auto const room = create_room(rt, alice, "public_chat"); + auto const old_topic = set_topic(rt, alice, room, "old"); + set_topic(rt, alice, room, "new"); + auto const initial = sync(rt, alice, k_no_filter, {}, k_state_after); + say(rt, alice, room, "the event that arrived with the fork"); + + auto& store = rt.homeserver.database.persistent_store; + std::ignore = store.forward_extremities.insert({room, old_topic}, user_id("alice")); + for (auto& row : store.state) + { + if (row.room_id == room && row.event_type == "m.room.topic") + { + row.event_id = old_topic; + } + } + merovingian::database::rebuild_state_index(store); + + WHEN("alice syncs with use_state_after=true") + { + auto const synced = sync(rt, alice, k_no_filter, initial.next_batch, k_state_after); + + THEN("state_after holds the older event, and the unchanged state stays out") + { + auto const after = events_of(required_room(synced, "join", room), "state_after"); + REQUIRE(topics_in(after) == std::vector{"old"}); + REQUIRE_FALSE(event_types(after).contains("m.room.create")); + } + } + } +} + +// Spec: Matrix Client-Server API v1.19 +// Endpoint / Section: GET /_matrix/client/v3/sync, query parameter `use_state_after`; Joined Room `state_after` +// URL: ../../docs/matrix-v1.19-spec/client-server-api.md#get_matrixclientv3sync +// +// `full_state`: "If this is set to true, then all state events will be returned, even if since is non-empty." +// `state_after`: "all state up to the end of the timeline, if since is not given, or full_state is true". +SCENARIO("full_state=true returns the whole state in the section use_state_after names", + "[conformance][client-server][sync][state-after]") +{ + GIVEN("a room alice has synced, whose topic changed since") + { + auto started = merovingian::homeserver::start_client_server(state_after_config()); + REQUIRE(started.started); + auto& rt = started.runtime; + auto const alice = register_user(rt, "alice"); + auto const room = create_room(rt, alice, "public_chat"); + set_topic(rt, alice, room, "first"); + auto const initial = sync(rt, alice, k_no_filter); + set_topic(rt, alice, room, "second"); + + WHEN("alice asks for the full state with use_state_after=true") + { + auto const extra = std::string{"&full_state=true"} + std::string{k_state_after}; + auto const synced = sync(rt, alice, k_no_filter, initial.next_batch, extra); + auto const& joined = required_room(synced, "join", room); + + THEN("state_after holds all state, the timeline's change included, and state is omitted") + { + // Spec MUST: with use_state_after=true the room carries state_after and omits state. + require_state_after_only(joined); + auto const after = events_of(joined, "state_after"); + REQUIRE(event_types(after).contains("m.room.create")); + REQUIRE(topics_in(after) == std::vector{"second"}); + } + } + WHEN("alice asks for the full state with use_state_after=false") + { + auto const extra = std::string{"&full_state=true"} + std::string{k_state_before}; + auto const synced = sync(rt, alice, k_no_filter, initial.next_batch, extra); + auto const& joined = required_room(synced, "join", room); + + THEN("state holds all state up to the start of the timeline, and state_after is omitted") + { + // Spec MUST: with use_state_after false or absent the room carries state and omits state_after. + require_state_only(joined); + auto const state = events_of(joined, "state"); + REQUIRE(event_types(state).contains("m.room.create")); + REQUIRE(topics_in(state) == std::vector{"first"}); + } + } + WHEN("nothing changed and alice asks for the full state with use_state_after=true") + { + auto const caught_up = sync(rt, alice, k_no_filter, initial.next_batch); + auto const extra = std::string{"&full_state=true"} + std::string{k_state_after}; + auto const synced = sync(rt, alice, k_no_filter, caught_up.next_batch, extra); + + THEN("the room is still reported, with all state") + { + auto const& joined = required_room(synced, "join", room); + // Spec MUST: with use_state_after=true the room carries state_after and omits state. + require_state_after_only(joined); + REQUIRE(event_types(events_of(joined, "state_after")).contains("m.room.create")); + } + } + } +} + +// Spec: Matrix Client-Server API v1.19 +// Endpoint / Section: GET /_matrix/client/v3/sync, Left Room +// URL: ../../docs/matrix-v1.19-spec/client-server-api.md#get_matrixclientv3sync +// +// Left Room `state`: "The state updates for the room up to the start of the timeline. MUST be omitted if +// use_state_after was set to true in the request." `state_after`: "The state updates for the room up to the end of the +// timeline. If this field is set, even if it is empty, clients MUST only update their local state with events in this +// list, and MUST NOT update their local state with events in timeline." Room History Visibility: "After a user has left +// a room, they may see any events which they were allowed to see before they left the room, but no events received +// after they left." +SCENARIO("A left room answers state_after or state as use_state_after asks", + "[conformance][client-server][sync][state-after]") +{ + GIVEN("a room dave joined and synced, and whose topic changed before he left") + { + auto started = merovingian::homeserver::start_client_server(state_after_config()); + REQUIRE(started.started); + auto& rt = started.runtime; + auto const alice = register_user(rt, "alice"); + auto const dave = register_user(rt, "dave"); + auto const room = create_room(rt, alice, "public_chat"); + set_topic(rt, alice, room, "first"); + room_post(rt, dave, room, "join"); + auto const synced_before = sync(rt, dave, k_no_filter, {}, k_state_after); + set_topic(rt, alice, room, "changed before the leave"); + room_post(rt, dave, room, "leave"); + set_topic(rt, alice, room, "changed after the leave"); + + WHEN("dave makes an initial sync with include_leave and use_state_after=true") + { + auto const synced = sync(rt, dave, k_include_leave, {}, k_state_after); + auto const& left = required_room(synced, "leave", room); + + THEN("state_after is the state up to his leave, the leave included, and state is omitted") + { + // Spec MUST: with use_state_after=true the room carries state_after and omits state. + require_state_after_only(left); + auto const after = events_of(left, "state_after"); + REQUIRE(topics_in(after) == std::vector{"changed before the leave"}); + REQUIRE(event_types(after).contains("m.room.create")); + REQUIRE(member_keys(after).count(user_id("dave")) == 1U); + REQUIRE(content_of(after, "m.room.member", user_id("dave"), "membership") == "leave"); + } + } + WHEN("dave makes an initial sync with include_leave, without the parameter and with it false") + { + auto const absent = sync(rt, dave, k_include_leave); + auto const off = sync(rt, dave, k_include_leave, {}, k_state_before); + + THEN("state is present and state_after is omitted") + { + // Spec MUST: with use_state_after false or absent the room carries state and omits state_after. + require_state_only(required_room(absent, "leave", room)); + // Spec MUST: with use_state_after false or absent the room carries state and omits state_after. + require_state_only(required_room(off, "leave", room)); + } + } + WHEN("dave makes an incremental sync with use_state_after=true") + { + auto const synced = sync(rt, dave, k_no_filter, synced_before.next_batch, k_state_after); + auto const& left = required_room(synced, "leave", room); + + THEN("state_after holds what changed up to his leave and the leave, though the timeline carries it") + { + // Spec MUST: with use_state_after=true the room carries state_after and omits state. + require_state_after_only(left); + REQUIRE(content_of(events_of(left, "timeline"), "m.room.member", user_id("dave"), "membership") == + "leave"); + auto const after = events_of(left, "state_after"); + REQUIRE(topics_in(after) == std::vector{"changed before the leave"}); + REQUIRE(event_types(after) == Keys{"m.room.member", "m.room.topic"}); + REQUIRE(content_of(after, "m.room.member", user_id("dave"), "membership") == "leave"); + } + } + WHEN("dave makes an incremental sync without the parameter") + { + auto const synced = sync(rt, dave, k_no_filter, synced_before.next_batch); + + THEN("state is present and state_after is omitted") + { + // Spec MUST: with use_state_after false or absent the room carries state and omits state_after. + require_state_only(required_room(synced, "leave", room)); + } + } + WHEN("dave makes an incremental sync with full_state=true and use_state_after=true") + { + auto const extra = std::string{"&full_state=true"} + std::string{k_state_after}; + auto const synced = sync(rt, dave, k_no_filter, synced_before.next_batch, extra); + auto const& left = required_room(synced, "leave", room); + + THEN("state_after is present and state is omitted") + { + // Spec MUST: with use_state_after=true the room carries state_after and omits state. + require_state_after_only(left); + } + } + WHEN("dave makes an incremental sync with full_state=true and use_state_after=false") + { + auto const extra = std::string{"&full_state=true"} + std::string{k_state_before}; + auto const synced = sync(rt, dave, k_no_filter, synced_before.next_batch, extra); + + THEN("state is present and state_after is omitted") + { + // Spec MUST: with use_state_after false or absent the room carries state and omits state_after. + require_state_only(required_room(synced, "leave", room)); + } + } + } + GIVEN("a room dave left and synced, then was banned from after its topic changed") + { + auto started = merovingian::homeserver::start_client_server(state_after_config()); + REQUIRE(started.started); + auto& rt = started.runtime; + auto const alice = register_user(rt, "alice"); + auto const dave = register_user(rt, "dave"); + auto const room = create_room(rt, alice, "public_chat"); + room_post(rt, dave, room, "join"); + room_post(rt, dave, room, "leave"); + auto const after_leave = sync(rt, dave, k_no_filter, {}, k_state_after); + set_topic(rt, alice, room, "secret"); + room_post(rt, alice, room, "ban", R"({"user_id":")" + user_id("dave") + R"("})"); + + WHEN("dave syncs with use_state_after=true") + { + auto const synced = sync(rt, dave, k_no_filter, after_leave.next_batch, k_state_after); + auto const& left = required_room(synced, "leave", room); + + THEN("state_after holds his ban and nothing of what happened after he left") + { + // Spec MUST: with use_state_after=true the room carries state_after and omits state. + require_state_after_only(left); + auto const after = events_of(left, "state_after"); + REQUIRE(topics_in(after).empty()); + REQUIRE(event_types(after) == Keys{"m.room.member"}); + REQUIRE(content_of(after, "m.room.member", user_id("dave"), "membership") == "ban"); + } + } + WHEN("dave makes an initial sync with include_leave and use_state_after=true") + { + auto const synced = sync(rt, dave, k_include_leave, {}, k_state_after); + auto const after = events_of(required_room(synced, "leave", room), "state_after"); + + THEN("state_after is the room as of his leave, with his own membership the ban") + { + REQUIRE(topics_in(after).empty()); + REQUIRE(member_keys(after).count(user_id("dave")) == 1U); + REQUIRE(content_of(after, "m.room.member", user_id("dave"), "membership") == "ban"); + } + } + } + GIVEN("a private room erin was invited to and declined, never having joined") + { + auto started = merovingian::homeserver::start_client_server(state_after_config()); + REQUIRE(started.started); + auto& rt = started.runtime; + auto const alice = register_user(rt, "alice"); + auto const erin = register_user(rt, "erin"); + auto const room = create_room(rt, alice, "private_chat"); + set_topic(rt, alice, room, "secret"); + room_post(rt, alice, room, "invite", R"({"user_id":")" + user_id("erin") + R"("})"); + room_post(rt, erin, room, "leave"); + + WHEN("erin makes an initial sync with include_leave and use_state_after=true") + { + auto const synced = sync(rt, erin, k_include_leave, {}, k_state_after); + auto const& left = required_room(synced, "leave", room); + + THEN("state_after holds only her own leave, as she never could read the room") + { + // Spec MUST: with use_state_after=true the room carries state_after and omits state. + require_state_after_only(left); + auto const after = events_of(left, "state_after"); + REQUIRE(event_types(after) == Keys{"m.room.member"}); + REQUIRE(content_of(after, "m.room.member", user_id("erin"), "membership") == "leave"); + } + } + } +} + +// Spec: Matrix Client-Server API v1.19 +// Endpoint / Section: GET /_matrix/client/v3/sync, query parameter `use_state_after`; Joined Room `state_after` +// URL: ../../docs/matrix-v1.19-spec/client-server-api.md#get_matrixclientv3sync +// +// `state_after`: "State updates for m.room.member events will be incomplete if lazy_load_members is enabled in the +// /sync filter, and only return the member events required to display the senders of the timeline events in this +// response." Lazy-loading room members: "servers MUST include the syncing user's own membership event ... when the full +// state of rooms is requested". Redundancy follows ADR-0450; a timeline event is not state here, so ADR-0819 forces +// every change. +// +// The scenario has four GIVENs: a joined room seen through lazy-loading (initial, acknowledged and lost-response +// incrementals, a display-name change, a kick, a limited gap, `full_state`), a departed member's own view, a user who +// joins, speaks and leaves inside one window, and a user banned after a later joiner arrived. +SCENARIO("Lazy-loading selects the members of state_after", "[conformance][client-server][sync][state-after]") +{ + // Bob and carol have both spoken, but a one-event timeline holds only bob's message, so a lazy-loaded answer must + // name bob and leave carol out until she is in a timeline. + GIVEN("a room of alice, bob and carol, in which bob and carol have spoken") + { + auto started = merovingian::homeserver::start_client_server(state_after_config()); + REQUIRE(started.started); + auto& rt = started.runtime; + auto const alice = register_user(rt, "alice"); + auto const bob = register_user(rt, "bob"); + auto const carol = register_user(rt, "carol"); + auto const room = create_room(rt, alice, "public_chat"); + room_post(rt, bob, room, "join"); + room_post(rt, carol, room, "join"); + set_topic(rt, alice, room, "first"); + say(rt, carol, room, "carol"); + say(rt, bob, room, "bob"); + + WHEN("alice makes an initial sync with lazy-loading and use_state_after=true") + { + auto const synced = sync(rt, alice, k_lazy_one_event, {}, k_state_after); + auto const& joined = required_room(synced, "join", room); + + THEN("state_after keeps other state and only the sender's and her own membership") + { + // Spec MUST: with use_state_after=true the room carries state_after and omits state. + require_state_after_only(joined); + auto const after = events_of(joined, "state_after"); + REQUIRE(topics_in(after) == std::vector{"first"}); + REQUIRE(member_keys(after) == Keys{user_id("alice"), user_id("bob")}); + } + } + WHEN("alice makes an initial sync with lazy-loading and use_state_after=false") + { + auto const synced = sync(rt, alice, k_lazy_one_event, {}, k_state_before); + auto const& joined = required_room(synced, "join", room); + + THEN("state holds those members, and state_after is omitted") + { + // Spec MUST: with use_state_after false or absent the room carries state and omits state_after. + require_state_only(joined); + REQUIRE(member_keys(events_of(joined, "state")) == Keys{user_id("alice"), user_id("bob")}); + } + } + // The tracker (ADR-0450) records that the client was sent carol's membership once the next request proves it + // arrived, so the later sync repeats nothing it was told. + WHEN("carol speaks in two incremental syncs, each acknowledging the last") + { + auto const first = sync(rt, alice, k_lazy_one_event, {}, k_state_after); + say(rt, carol, room, "carol again"); + auto const second = sync(rt, alice, k_lazy, first.next_batch, k_state_after); + say(rt, carol, room, "carol once more"); + auto const third = sync(rt, alice, k_lazy, second.next_batch, k_state_after); + + THEN("carol's membership comes once, then is redundant") + { + REQUIRE(member_keys(events_of(required_room(second, "join", room), "state_after")) == + Keys{user_id("carol")}); + auto const after = events_of(required_room(third, "join", room), "state_after"); + // Spec MUST: with use_state_after=true the room carries state_after and omits state. + require_state_after_only(required_room(third, "join", room)); + REQUIRE(member_keys(after).empty()); + } + } + // Two events about bob in one window must not produce two member events: state_after is the state at the end + // of the timeline, so only the later one is sent. + WHEN("bob speaks and then changes his display name in the same window") + { + auto const first = sync(rt, alice, k_lazy_one_event, {}, k_state_after); + say(rt, bob, room, "still bob"); + set_display_name(rt, bob, room, "bob", "Bobby"); + auto const synced = sync(rt, alice, k_lazy, first.next_batch, k_state_after); + auto const after = events_of(required_room(synced, "join", room), "state_after"); + + THEN("state_after holds his membership as of the end of the timeline, once") + { + REQUIRE(member_keys(after) == Keys{user_id("bob")}); + REQUIRE(content_of(after, "m.room.member", user_id("bob"), "displayname") == "Bobby"); + } + } + // A timeline event is not state to a `use_state_after` client, so lazy-loading cannot drop a change merely + // because its subject is not a sender (ADR-0819 forces every change). + WHEN("the timeline carries a membership change about someone who did not speak") + { + auto const first = sync(rt, alice, k_lazy_one_event, {}, k_state_after); + room_post(rt, alice, room, "kick", R"({"user_id":")" + user_id("carol") + R"("})"); + auto const synced = sync(rt, alice, k_lazy, first.next_batch, k_state_after); + auto const after = events_of(required_room(synced, "join", room), "state_after"); + + THEN("state_after holds it, because the client takes no state from the timeline") + { + REQUIRE(content_of(after, "m.room.member", user_id("carol"), "membership") == "leave"); + } + } + // With a one-event timeline limit the leave falls before the timeline's start; the client cannot read it from + // the timeline, so state_after must carry it, while unchanged state (the topic) stays out. + WHEN("a membership change falls in the gap of a limited sync") + { + auto const first = sync(rt, alice, k_lazy_one_event, {}, k_state_after); + room_post(rt, carol, room, "leave"); + say(rt, bob, room, "one"); + say(rt, bob, room, "two"); + auto const synced = sync(rt, alice, k_lazy_one_event, first.next_batch, k_state_after); + auto const after = events_of(required_room(synced, "join", room), "state_after"); + + THEN("state_after holds it, and the state that did not change stays out") + { + REQUIRE(content_of(after, "m.room.member", user_id("carol"), "membership") == "leave"); + REQUIRE(topics_in(after).empty()); + } + } + // The spec requires the syncing user's own membership "when the full state of rooms is requested"; carol, who + // is not in the timeline, is not sent. + WHEN("alice asks for the full state with lazy-loading and use_state_after=true") + { + auto const first = sync(rt, alice, k_lazy_one_event, {}, k_state_after); + auto const acknowledged = sync(rt, alice, k_lazy_one_event, first.next_batch, k_state_after); + auto const extra = std::string{"&full_state=true"} + std::string{k_state_after}; + auto const synced = sync(rt, alice, k_lazy_one_event, acknowledged.next_batch, extra); + auto const& joined = required_room(synced, "join", room); + + THEN("state_after holds her own membership and all other state") + { + // Spec MUST: with use_state_after=true the room carries state_after and omits state. + require_state_after_only(joined); + auto const after = events_of(joined, "state_after"); + REQUIRE(event_types(after).contains("m.room.create")); + REQUIRE(member_keys(after).contains(user_id("alice"))); + REQUIRE_FALSE(member_keys(after).contains(user_id("carol"))); + } + } + } + // A left room takes the same lazy-loading rule: the sender (bob) and the user's own leave are sent, nobody else. + GIVEN("a room of alice and dave that dave leaves after bob spoke") + { + auto started = merovingian::homeserver::start_client_server(state_after_config()); + REQUIRE(started.started); + auto& rt = started.runtime; + auto const alice = register_user(rt, "alice"); + auto const bob = register_user(rt, "bob"); + auto const dave = register_user(rt, "dave"); + auto const room = create_room(rt, alice, "public_chat"); + room_post(rt, bob, room, "join"); + room_post(rt, dave, room, "join"); + auto const before = sync(rt, dave, k_lazy_one_event, {}, k_state_after); + say(rt, bob, room, "bob"); + room_post(rt, dave, room, "leave"); + + WHEN("dave makes an incremental sync with lazy-loading and use_state_after=true") + { + auto const synced = sync(rt, dave, k_lazy, before.next_batch, k_state_after); + auto const& left = required_room(synced, "leave", room); + + THEN("state_after holds his leave and the sender's membership") + { + // Spec MUST: with use_state_after=true the room carries state_after and omits state. + require_state_after_only(left); + auto const after = events_of(left, "state_after"); + REQUIRE(member_keys(after) == Keys{user_id("bob"), user_id("dave")}); + REQUIRE(content_of(after, "m.room.member", user_id("dave"), "membership") == "leave"); + } + } + // An initial sync with include_leave reports the left room as new to the client, so the other state is sent but + // members are still limited to his own. + WHEN("dave makes an initial sync with include_leave, lazy-loading and use_state_after=true") + { + constexpr auto lazy = std::string_view{ + R"({"room":{"include_leave":true,"timeline":{"limit":1},"state":{"lazy_load_members":true}}})"}; + auto const synced = sync(rt, dave, lazy, {}, k_state_after); + auto const& left = required_room(synced, "leave", room); + + THEN("state_after keeps other state and holds only his own membership among members") + { + // Spec MUST: with use_state_after=true the room carries state_after and omits state. + require_state_after_only(left); + auto const after = events_of(left, "state_after"); + REQUIRE(event_types(after).contains("m.room.create")); + REQUIRE(member_keys(after) == Keys{user_id("dave")}); + } + } + } + // Dave is a sender in his own timeline, so the sender rule and the own-membership rule both name him: his member + // key must still appear once, as the leave, not as the earlier join the timeline also carries. + GIVEN("a room dave joins, speaks in and leaves, all after his last sync") + { + auto started = merovingian::homeserver::start_client_server(state_after_config()); + REQUIRE(started.started); + auto& rt = started.runtime; + auto const alice = register_user(rt, "alice"); + auto const dave = register_user(rt, "dave"); + auto const room = create_room(rt, alice, "public_chat"); + auto const before = sync(rt, dave, k_lazy, {}, k_state_after); + room_post(rt, dave, room, "join"); + say(rt, dave, room, "hello and goodbye"); + room_post(rt, dave, room, "leave"); + + WHEN("dave syncs with lazy-loading and use_state_after=true") + { + auto const synced = sync(rt, dave, k_lazy, before.next_batch, k_state_after); + auto const after = events_of(required_room(synced, "leave", room), "state_after"); + + THEN("his own membership is there once, as the leave, so his earlier join cannot override it") + { + REQUIRE(member_keys(after).count(user_id("dave")) == 1U); + REQUIRE(content_of(after, "m.room.member", user_id("dave"), "membership") == "leave"); + } + } + } + // What a departed user may learn is capped at his leave (ADR-0820): the ban is his own membership and may be told, + // but erin's join after he left may not. + GIVEN("a room dave left and synced, which erin then joined, and from which dave was then banned") + { + auto started = merovingian::homeserver::start_client_server(state_after_config()); + REQUIRE(started.started); + auto& rt = started.runtime; + auto const alice = register_user(rt, "alice"); + auto const dave = register_user(rt, "dave"); + auto const erin = register_user(rt, "erin"); + auto const room = create_room(rt, alice, "public_chat"); + room_post(rt, dave, room, "join"); + room_post(rt, dave, room, "leave"); + auto const after_leave = sync(rt, dave, k_lazy_one_event, {}, k_state_after); + room_post(rt, erin, room, "join"); + say(rt, erin, room, "dave cannot know I am here"); + room_post(rt, alice, room, "ban", R"({"user_id":")" + user_id("dave") + R"("})"); + + WHEN("dave makes a limited incremental sync with lazy-loading and use_state_after=true") + { + auto const synced = sync(rt, dave, k_lazy_one_event, after_leave.next_batch, k_state_after); + auto const after = events_of(required_room(synced, "leave", room), "state_after"); + + THEN("state_after holds his ban and does not show who joined after he left") + { + REQUIRE(content_of(after, "m.room.member", user_id("dave"), "membership") == "ban"); + REQUIRE_FALSE(member_keys(after).contains(user_id("erin"))); + } + } + } +} diff --git a/tests/fixtures/AGENTS.md b/tests/fixtures/AGENTS.md index 43a537c2b..99120aff0 100644 --- a/tests/fixtures/AGENTS.md +++ b/tests/fixtures/AGENTS.md @@ -10,7 +10,7 @@ Static fixtures used by the integration and complement test runners. | `complement/client_server_v1_19.json` | Client-server API flow tests: register, login, send, sync, media | | `complement/sync_v1_19.json` | Sync-focused flow steps, loaded via `run_complement_fixture("sync_v1_19.json", ...)` in `test_sync_complement_fixture.cpp` | | `complement/federation_v1_19.json` | Federation-flow fixture; **not currently loaded by any test** (no `.cpp` references `federation_v1_19.json` — confirmed by repo-wide grep). Wire it into a fixture runner or remove it. | -| `upgrade//` | A SQLite database, PostgreSQL dump and manifest written over HTTP by an old release's server, opened by `test_database_upgrade_flow.cpp` (ADR-0216). See `upgrade/README.md` | +| `upgrade/1.0.3/` | The SQLite database, PostgreSQL dump and manifest the 1.0.3 release's server wrote over HTTP, opened, migrated and served by the `[fixture]` scenarios in `test_database_upgrade_flow.cpp`, which read every ID, token and key from `manifest.json` (ADR-0216). See `upgrade/README.md` | ## Complement fixture format diff --git a/tests/fixtures/upgrade/1.0.3/manifest.json b/tests/fixtures/upgrade/1.0.3/manifest.json new file mode 100644 index 000000000..ecf4bc43a --- /dev/null +++ b/tests/fixtures/upgrade/1.0.3/manifest.json @@ -0,0 +1,472 @@ +{ + "release": "1.0.3", + "commit": "5f458d5732809f096042cb5c74392537c2b47c6e", + "schema_version": 1, + "server_name": "example.org", + "master_key_hex": "e20a57ef7ee73bc1cc86594aa3954498e1b4ce7e4f06f7c32c285f8e2b6a2989", + "registration_token": "test-registration-token", + "sqlite": { + "device_keys": { + "device_keys": { + "user_id": "@alice:example.org", + "device_id": "UPGRADE1", + "algorithms": [ + "m.olm.v1.curve25519-aes-sha2", + "m.megolm.v1.aes-sha2" + ], + "keys": { + "curve25519:UPGRADE1": "avkVfi/n0gvWx3G6YuPrB25Fy5tWrqUpFe0NfOvzyGw", + "ed25519:UPGRADE1": "N5GQ6FD/1Zsb98rTHyr22OIGA80WqwICtUZ4X5XPD6s" + }, + "signatures": { + "@alice:example.org": { + "ed25519:UPGRADE1": "UBBsAgbpMe0FdxfQPzzBo7xekw1ImFlqIJdcAuhXafvTbd/1ynySi1jxrc1N5nFSl1CaTAmqhJCeLK1EF3nIDg" + } + } + }, + "one_time_keys": { + "signed_curve25519:AAAAAQ": { + "key": "b60hLnOYxauXUjJqQzghgaK3oPo4ft3LInvHYLRF1xo", + "signatures": { + "@alice:example.org": { + "ed25519:UPGRADE1": "QtIiXHH1v3RHnRxMPRzgWxcyWgImVJnyoDn1CPxf2ZAXmpykFWOAVXDh9Daldfag6MPwNQo8Ir6X4FmAygp5Cg" + } + } + } + }, + "ed25519_public_key": "N5GQ6FD/1Zsb98rTHyr22OIGA80WqwICtUZ4X5XPD6s" + }, + "next_batch": "1a_1a_b_290d4aac260e176b", + "users": { + "alice": { + "user_id": "@alice:example.org", + "password": "CorrectHorse7!", + "device_id": "UPGRADE1", + "access_token": "mvs_ec0853b0434ffd9915e5ecbedf5c9239d1fea2435329e2f68277dd988f66c7a3" + }, + "bob": { + "user_id": "@bob:example.org", + "password": "BatteryStaple9!", + "device_id": "UPGRADE2", + "access_token": "mvs_e32fb00b0b46036c634ed0ce07f31a054b567f87d462351239a12a7ee8ec5e80" + } + }, + "displayname": "Alice Upgrade", + "private_room_id": "!izamUNbT8G68FVAZUuIfKH_NKgSJzyrrD8CJIz9mxTY", + "public_room_id": "!0en5oBPugaFyvTPadaX1TvcE6Y6yAuTJ3e68KXpMojA", + "alias": "#upgrade-public:example.org", + "messages": [ + { + "sender": "@alice:example.org", + "event_id": "$Bvm248Nwe5VYLasWdIIuUcPjIFQLXm-Cn6H6uMX7bfw", + "body": "upgrade message 1" + }, + { + "sender": "@alice:example.org", + "event_id": "$-f3HSwamy2GXuPwpavYDXFIKSgUXyoUClPrX2pBYcfY", + "body": "upgrade message 2" + }, + { + "sender": "@alice:example.org", + "event_id": "$W1InbbGrmfwJJ3llrJzq5dBwrFUau7RDNzzWyqEs0TE", + "body": "upgrade message 3" + }, + { + "sender": "@bob:example.org", + "event_id": "$j9Jx8wXbfA_HTVzxwwNUwT-qc8rp2Sl0kx-naT1Fn6U", + "body": "reply from bob" + } + ], + "media": { + "mxc_uri": "mxc://example.org/Mj56RocdRWUhla3HMB-Crg", + "sha256": "7dbc7d20d54b5924ceb6ba419e522d699394d55f052f8b8815c15d199c357143", + "content_type": "text/plain", + "size": 340 + }, + "account_data": { + "type": "org.merovingian.upgrade", + "content": { + "fixture": "0.11.13" + } + }, + "pusher": { + "kind": "http", + "app_id": "org.merovingian.upgrade", + "app_display_name": "Upgrade Fixture App", + "device_display_name": "Upgrade Fixture Device", + "lang": "en", + "pushkey": "upgrade-pushkey", + "data": { + "url": "https://push.example.org/_matrix/push/v1/notify" + } + }, + "http_log": [ + { + "step": "register alice", + "method": "POST", + "path": "/_matrix/client/v3/register", + "status": 200 + }, + { + "step": "login alice", + "method": "POST", + "path": "/_matrix/client/v3/login", + "status": 200 + }, + { + "step": "register bob", + "method": "POST", + "path": "/_matrix/client/v3/register", + "status": 200 + }, + { + "step": "login bob", + "method": "POST", + "path": "/_matrix/client/v3/login", + "status": 200 + }, + { + "step": "alice displayname", + "method": "PUT", + "path": "/_matrix/client/v3/profile/%40alice%3Aexample.org/displayname", + "status": 200 + }, + { + "step": "alice create private room", + "method": "POST", + "path": "/_matrix/client/v3/createRoom", + "status": 200 + }, + { + "step": "alice invite bob", + "method": "POST", + "path": "/_matrix/client/v3/rooms/%21izamUNbT8G68FVAZUuIfKH_NKgSJzyrrD8CJIz9mxTY/invite", + "status": 200 + }, + { + "step": "bob join", + "method": "POST", + "path": "/_matrix/client/v3/join/%21izamUNbT8G68FVAZUuIfKH_NKgSJzyrrD8CJIz9mxTY", + "status": 200 + }, + { + "step": "send message 1", + "method": "PUT", + "path": "/_matrix/client/v3/rooms/%21izamUNbT8G68FVAZUuIfKH_NKgSJzyrrD8CJIz9mxTY/send/m.room.message/upgrade-txn-1", + "status": 200 + }, + { + "step": "send message 2", + "method": "PUT", + "path": "/_matrix/client/v3/rooms/%21izamUNbT8G68FVAZUuIfKH_NKgSJzyrrD8CJIz9mxTY/send/m.room.message/upgrade-txn-2", + "status": 200 + }, + { + "step": "send message 3", + "method": "PUT", + "path": "/_matrix/client/v3/rooms/%21izamUNbT8G68FVAZUuIfKH_NKgSJzyrrD8CJIz9mxTY/send/m.room.message/upgrade-txn-3", + "status": 200 + }, + { + "step": "send message 4", + "method": "PUT", + "path": "/_matrix/client/v3/rooms/%21izamUNbT8G68FVAZUuIfKH_NKgSJzyrrD8CJIz9mxTY/send/m.room.message/upgrade-txn-4", + "status": 200 + }, + { + "step": "alice create public room", + "method": "POST", + "path": "/_matrix/client/v3/createRoom", + "status": 200 + }, + { + "step": "publicRooms listing", + "method": "GET", + "path": "/_matrix/client/v3/publicRooms", + "status": 200 + }, + { + "step": "resolve alias", + "method": "GET", + "path": "/_matrix/client/v3/directory/room/%23upgrade-public%3Aexample.org", + "status": 200 + }, + { + "step": "alice upload media", + "method": "POST", + "path": "/_matrix/media/v3/upload", + "status": 200 + }, + { + "step": "alice download media", + "method": "GET", + "path": "/_matrix/client/v1/media/download/example.org/Mj56RocdRWUhla3HMB-Crg", + "status": 200 + }, + { + "step": "alice account data", + "method": "PUT", + "path": "/_matrix/client/v3/user/%40alice%3Aexample.org/account_data/org.merovingian.upgrade", + "status": 200 + }, + { + "step": "alice set pusher", + "method": "POST", + "path": "/_matrix/client/v3/pushers/set", + "status": 200 + }, + { + "step": "alice keys/upload", + "method": "POST", + "path": "/_matrix/client/v3/keys/upload", + "status": 200 + }, + { + "step": "alice read messages", + "method": "GET", + "path": "/_matrix/client/v3/rooms/%21izamUNbT8G68FVAZUuIfKH_NKgSJzyrrD8CJIz9mxTY/messages", + "status": 200 + }, + { + "step": "alice initial sync", + "method": "GET", + "path": "/_matrix/client/v3/sync", + "status": 200 + } + ], + "non_2xx": [], + "server_exit_code": 0 + }, + "postgresql": { + "device_keys": { + "device_keys": { + "user_id": "@alice:example.org", + "device_id": "UPGRADE1", + "algorithms": [ + "m.olm.v1.curve25519-aes-sha2", + "m.megolm.v1.aes-sha2" + ], + "keys": { + "curve25519:UPGRADE1": "aJoAYROXT9rrYFhiSAmFkQk8DgPUrZKIq59YFaOAgQg", + "ed25519:UPGRADE1": "xZ6DW0uuhQKl7HY7m4J5dMmK6CWpCCrtYwps1QBYoyE" + }, + "signatures": { + "@alice:example.org": { + "ed25519:UPGRADE1": "khdpySd56eC7863q/p2A8IOUUe2TQ28I4eBVO45kevqFspi6gW12BDvcz2qiB9GpsnS2zCNOxcde/LyLPA7RCw" + } + } + }, + "one_time_keys": { + "signed_curve25519:AAAAAQ": { + "key": "0kBH0U8cIYy+UylyqqSe4teHLhfX/hYBgpiZZlNp4zk", + "signatures": { + "@alice:example.org": { + "ed25519:UPGRADE1": "kAxIom4YQ7T7Q2laPSclXDUngDWrsn4yPReEKDnH+1YVJhB2s8Mdy3x4YtyxOMw8e1c/K6C2UeGeeSyOXuS6CA" + } + } + } + }, + "ed25519_public_key": "xZ6DW0uuhQKl7HY7m4J5dMmK6CWpCCrtYwps1QBYoyE" + }, + "next_batch": "1a_1a_b_e5ec87dc1fb83319", + "users": { + "alice": { + "user_id": "@alice:example.org", + "password": "CorrectHorse7!", + "device_id": "UPGRADE1", + "access_token": "mvs_7a19c309ef7f5e848267afa7e1fe9612b6dde5e761a351c4fa8f2533e2a05287" + }, + "bob": { + "user_id": "@bob:example.org", + "password": "BatteryStaple9!", + "device_id": "UPGRADE2", + "access_token": "mvs_227bf7f91b938d3870b3c8e6e5bec1b25f998cec088857a7ff424d48485a0044" + } + }, + "displayname": "Alice Upgrade", + "private_room_id": "!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY", + "public_room_id": "!WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA", + "alias": "#upgrade-public:example.org", + "messages": [ + { + "sender": "@alice:example.org", + "event_id": "$gbIXT6cBYsLvEAdCmvz_-Z-MLge4BnaLY_O1-PtdjGo", + "body": "upgrade message 1" + }, + { + "sender": "@alice:example.org", + "event_id": "$mC5T62vlKtDEaC4l1ujmOJ3dA5q-PM-ku8SS1xRZCek", + "body": "upgrade message 2" + }, + { + "sender": "@alice:example.org", + "event_id": "$h7M6qztmLUOCjFAmWrrrh-vd87KuCykZl7jvFLSK3Ds", + "body": "upgrade message 3" + }, + { + "sender": "@bob:example.org", + "event_id": "$GcOCV1AahAZenbnTVGpvMmYTyB2XNFzhRLwjkRT0Cy8", + "body": "reply from bob" + } + ], + "media": { + "mxc_uri": "mxc://example.org/eu-rBrEY7MSJKUy6o7pmMw", + "sha256": "7dbc7d20d54b5924ceb6ba419e522d699394d55f052f8b8815c15d199c357143", + "content_type": "text/plain", + "size": 340 + }, + "account_data": { + "type": "org.merovingian.upgrade", + "content": { + "fixture": "0.11.13" + } + }, + "pusher": { + "kind": "http", + "app_id": "org.merovingian.upgrade", + "app_display_name": "Upgrade Fixture App", + "device_display_name": "Upgrade Fixture Device", + "lang": "en", + "pushkey": "upgrade-pushkey", + "data": { + "url": "https://push.example.org/_matrix/push/v1/notify" + } + }, + "http_log": [ + { + "step": "register alice", + "method": "POST", + "path": "/_matrix/client/v3/register", + "status": 200 + }, + { + "step": "login alice", + "method": "POST", + "path": "/_matrix/client/v3/login", + "status": 200 + }, + { + "step": "register bob", + "method": "POST", + "path": "/_matrix/client/v3/register", + "status": 200 + }, + { + "step": "login bob", + "method": "POST", + "path": "/_matrix/client/v3/login", + "status": 200 + }, + { + "step": "alice displayname", + "method": "PUT", + "path": "/_matrix/client/v3/profile/%40alice%3Aexample.org/displayname", + "status": 200 + }, + { + "step": "alice create private room", + "method": "POST", + "path": "/_matrix/client/v3/createRoom", + "status": 200 + }, + { + "step": "alice invite bob", + "method": "POST", + "path": "/_matrix/client/v3/rooms/%21C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY/invite", + "status": 200 + }, + { + "step": "bob join", + "method": "POST", + "path": "/_matrix/client/v3/join/%21C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY", + "status": 200 + }, + { + "step": "send message 1", + "method": "PUT", + "path": "/_matrix/client/v3/rooms/%21C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY/send/m.room.message/upgrade-txn-1", + "status": 200 + }, + { + "step": "send message 2", + "method": "PUT", + "path": "/_matrix/client/v3/rooms/%21C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY/send/m.room.message/upgrade-txn-2", + "status": 200 + }, + { + "step": "send message 3", + "method": "PUT", + "path": "/_matrix/client/v3/rooms/%21C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY/send/m.room.message/upgrade-txn-3", + "status": 200 + }, + { + "step": "send message 4", + "method": "PUT", + "path": "/_matrix/client/v3/rooms/%21C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY/send/m.room.message/upgrade-txn-4", + "status": 200 + }, + { + "step": "alice create public room", + "method": "POST", + "path": "/_matrix/client/v3/createRoom", + "status": 200 + }, + { + "step": "publicRooms listing", + "method": "GET", + "path": "/_matrix/client/v3/publicRooms", + "status": 200 + }, + { + "step": "resolve alias", + "method": "GET", + "path": "/_matrix/client/v3/directory/room/%23upgrade-public%3Aexample.org", + "status": 200 + }, + { + "step": "alice upload media", + "method": "POST", + "path": "/_matrix/media/v3/upload", + "status": 200 + }, + { + "step": "alice download media", + "method": "GET", + "path": "/_matrix/client/v1/media/download/example.org/eu-rBrEY7MSJKUy6o7pmMw", + "status": 200 + }, + { + "step": "alice account data", + "method": "PUT", + "path": "/_matrix/client/v3/user/%40alice%3Aexample.org/account_data/org.merovingian.upgrade", + "status": 200 + }, + { + "step": "alice set pusher", + "method": "POST", + "path": "/_matrix/client/v3/pushers/set", + "status": 200 + }, + { + "step": "alice keys/upload", + "method": "POST", + "path": "/_matrix/client/v3/keys/upload", + "status": 200 + }, + { + "step": "alice read messages", + "method": "GET", + "path": "/_matrix/client/v3/rooms/%21C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY/messages", + "status": 200 + }, + { + "step": "alice initial sync", + "method": "GET", + "path": "/_matrix/client/v3/sync", + "status": 200 + } + ], + "non_2xx": [], + "server_exit_code": 0 + } +} diff --git a/tests/fixtures/upgrade/1.0.3/merovingian.sqlite3 b/tests/fixtures/upgrade/1.0.3/merovingian.sqlite3 new file mode 100644 index 000000000..719ef4cbb Binary files /dev/null and b/tests/fixtures/upgrade/1.0.3/merovingian.sqlite3 differ diff --git a/tests/fixtures/upgrade/1.0.3/postgresql.sql b/tests/fixtures/upgrade/1.0.3/postgresql.sql new file mode 100644 index 000000000..1baccb690 --- /dev/null +++ b/tests/fixtures/upgrade/1.0.3/postgresql.sql @@ -0,0 +1,2035 @@ +-- +-- PostgreSQL database dump +-- + + +-- Dumped from database version 16.15 (Ubuntu 16.15-0ubuntu0.24.04.1) +-- Dumped by pg_dump version 16.15 (Ubuntu 16.15-0ubuntu0.24.04.1) + +SET statement_timeout = 0; +SET lock_timeout = 0; +SET idle_in_transaction_session_timeout = 0; +SET client_encoding = 'UTF8'; +SET standard_conforming_strings = on; +SELECT pg_catalog.set_config('search_path', '', false); +SET check_function_bodies = false; +SET xmloption = content; +SET client_min_messages = warning; +SET row_security = off; + +SET default_tablespace = ''; + +SET default_table_access_method = heap; + +-- +-- Name: access_tokens; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.access_tokens ( + user_id text NOT NULL, + device_id text NOT NULL, + token_hash text NOT NULL, + revoked text NOT NULL, + expires_at text DEFAULT ''::text NOT NULL, + predecessor_refresh_hash text DEFAULT ''::text NOT NULL +); + + +-- +-- Name: account_data; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.account_data ( + user_id text NOT NULL, + event_type text NOT NULL, + json text NOT NULL, + stream_id text DEFAULT '0'::text NOT NULL +); + + +-- +-- Name: account_threepids; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.account_threepids ( + user_id text NOT NULL, + medium text NOT NULL, + address text NOT NULL, + country text DEFAULT ''::text NOT NULL, + id_server text DEFAULT ''::text NOT NULL, + added_at_ms text DEFAULT '0'::text NOT NULL, + validated_at_ms text DEFAULT '0'::text NOT NULL, + bound text DEFAULT '0'::text NOT NULL, + client_secret text DEFAULT ''::text NOT NULL, + sid text DEFAULT ''::text NOT NULL +); + + +-- +-- Name: admin_actions; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.admin_actions ( + admin_user_id text NOT NULL, + action text NOT NULL, + target text NOT NULL +); + + +-- +-- Name: appservice_directory; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.appservice_directory ( + appservice_id text NOT NULL, + network_id text NOT NULL, + room_id text NOT NULL +); + + +-- +-- Name: appservice_outbox; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.appservice_outbox ( + appservice_id text NOT NULL, + stream_ordering text NOT NULL, + event_id text NOT NULL +); + + +-- +-- Name: appservice_txn_cursor; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.appservice_txn_cursor ( + appservice_id text NOT NULL, + next_txn_id text DEFAULT '1'::text NOT NULL, + delivered_stream_ordering text DEFAULT '0'::text NOT NULL, + pending_txn_id text DEFAULT '0'::text NOT NULL, + pending_stream_ordering text DEFAULT '0'::text NOT NULL +); + + +-- +-- Name: audit_log; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.audit_log ( + category text NOT NULL, + event_type text NOT NULL, + actor text NOT NULL, + target text NOT NULL, + reason text NOT NULL, + created_at_ms text DEFAULT '0'::text NOT NULL +); + + +-- +-- Name: client_txn_ids; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.client_txn_ids ( + user_id text NOT NULL, + room_id text NOT NULL, + event_type text NOT NULL, + txn_id text NOT NULL, + event_id text NOT NULL, + device_id text DEFAULT ''::text NOT NULL, + created_at_ms text DEFAULT '0'::text NOT NULL +); + + +-- +-- Name: cross_signing_keys; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.cross_signing_keys ( + user_id text NOT NULL, + key_type text NOT NULL, + json text NOT NULL +); + + +-- +-- Name: current_state; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.current_state ( + room_id text NOT NULL, + event_type text NOT NULL, + state_key text NOT NULL, + event_id text NOT NULL +); + + +-- +-- Name: deferred_pdus; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.deferred_pdus ( + event_id text NOT NULL, + room_id text NOT NULL, + origin text NOT NULL, + pdu_json text NOT NULL, + received_at_ms text DEFAULT '0'::text NOT NULL, + attempts text DEFAULT '0'::text NOT NULL +); + + +-- +-- Name: device_keys; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.device_keys ( + user_id text NOT NULL, + device_id text NOT NULL, + json text NOT NULL +); + + +-- +-- Name: device_list_changes; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.device_list_changes ( + stream_id text NOT NULL, + observer_user_id text NOT NULL, + subject_user_id text NOT NULL, + change_type text DEFAULT 'changed'::text NOT NULL +); + + +-- +-- Name: devices; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.devices ( + user_id text NOT NULL, + device_id text NOT NULL, + display_name text NOT NULL +); + + +-- +-- Name: event_auth; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.event_auth ( + event_id text NOT NULL, + auth_event_id text NOT NULL +); + + +-- +-- Name: event_edges; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.event_edges ( + event_id text NOT NULL, + prev_event_id text NOT NULL +); + + +-- +-- Name: event_json; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.event_json ( + event_id text NOT NULL, + json text NOT NULL +); + + +-- +-- Name: event_signatures; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.event_signatures ( + event_id text NOT NULL, + server_name text NOT NULL, + key_id text NOT NULL, + signature text NOT NULL +); + + +-- +-- Name: event_state_groups; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.event_state_groups ( + event_id text NOT NULL, + state_group_id text NOT NULL +); + + +-- +-- Name: event_stream_watermark; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.event_stream_watermark ( + singleton integer NOT NULL, + watermark text DEFAULT '0'::text NOT NULL, + CONSTRAINT event_stream_watermark_singleton_check CHECK ((singleton = 1)) +); + + +-- +-- Name: events; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.events ( + event_id text NOT NULL, + room_id text NOT NULL, + sender_user_id text NOT NULL, + json text NOT NULL, + depth text NOT NULL, + stream_ordering text DEFAULT '0'::text NOT NULL, + status text DEFAULT 'accepted'::text NOT NULL +); + + +-- +-- Name: fallback_keys; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.fallback_keys ( + user_id text NOT NULL, + device_id text NOT NULL, + key_id text NOT NULL, + json text NOT NULL +); + + +-- +-- Name: federation_destinations; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.federation_destinations ( + server_name text NOT NULL, + state text NOT NULL, + retry_after_ts text NOT NULL, + last_success_ts text NOT NULL, + consecutive_failures text NOT NULL +); + + +-- +-- Name: federation_transactions; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.federation_transactions ( + transaction_id text NOT NULL, + server_name text NOT NULL, + json text NOT NULL, + method text NOT NULL, + target text NOT NULL, + origin text NOT NULL, + origin_server_ts text NOT NULL, + body text NOT NULL, + retry_count text NOT NULL, + next_retry_ts text NOT NULL +); + + +-- +-- Name: filters; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.filters ( + user_id text NOT NULL, + filter_id text NOT NULL, + json text NOT NULL +); + + +-- +-- Name: forward_extremities; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.forward_extremities ( + room_id text NOT NULL, + event_id text NOT NULL +); + + +-- +-- Name: invites; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.invites ( + room_id text NOT NULL, + user_id text NOT NULL, + sender_user_id text NOT NULL, + event_id text DEFAULT ''::text NOT NULL, + signed_event_json text DEFAULT ''::text NOT NULL, + invite_state_json text DEFAULT '[]'::text NOT NULL, + stream_ordering text DEFAULT '0'::text NOT NULL, + resident_server text DEFAULT ''::text NOT NULL +); + + +-- +-- Name: key_backup_sessions; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.key_backup_sessions ( + user_id text NOT NULL, + version text NOT NULL, + room_id text NOT NULL, + session_id text NOT NULL, + json text NOT NULL +); + + +-- +-- Name: key_backup_version_counters; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.key_backup_version_counters ( + user_id text NOT NULL, + last_version text NOT NULL +); + + +-- +-- Name: key_backup_versions; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.key_backup_versions ( + user_id text NOT NULL, + version text NOT NULL, + json text NOT NULL +); + + +-- +-- Name: key_backups; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.key_backups ( + user_id text NOT NULL, + version text NOT NULL, + json text NOT NULL +); + + +-- +-- Name: key_signatures; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.key_signatures ( + signer_user_id text NOT NULL, + target_user_id text NOT NULL, + target_device_id text NOT NULL, + json text NOT NULL +); + + +-- +-- Name: login_tokens; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.login_tokens ( + user_id text NOT NULL, + token_hash text NOT NULL, + expires_at text DEFAULT '0'::text NOT NULL, + used text DEFAULT 'false'::text NOT NULL +); + + +-- +-- Name: media; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.media ( + media_id text NOT NULL, + owner_user_id text NOT NULL, + content_type text NOT NULL, + size_bytes text NOT NULL, + hash_algorithm text NOT NULL, + digest text NOT NULL, + quarantined text NOT NULL, + removed text NOT NULL, + legacy_endpoint_visible text DEFAULT 'true'::text NOT NULL, + upload_name text DEFAULT ''::text NOT NULL +); + + +-- +-- Name: media_blobs; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.media_blobs ( + storage_id text NOT NULL, + hash_algorithm text NOT NULL, + digest text NOT NULL, + size_bytes text NOT NULL, + bytes bytea NOT NULL, + ref_count text NOT NULL +); + + +-- +-- Name: media_pending_uploads; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.media_pending_uploads ( + media_id text NOT NULL, + owner_user_id text NOT NULL, + created_at_ms text NOT NULL, + expires_at_ms text NOT NULL +); + + +-- +-- Name: membership; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.membership ( + room_id text NOT NULL, + user_id text NOT NULL, + membership text DEFAULT 'join'::text NOT NULL, + stream_ordering text DEFAULT '0'::text NOT NULL +); + + +-- +-- Name: notifications; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.notifications ( + user_id text NOT NULL, + room_id text NOT NULL, + event_id text NOT NULL, + stream_ordering text DEFAULT '0'::text NOT NULL, + ts text DEFAULT '0'::text NOT NULL, + actions text DEFAULT '[]'::text NOT NULL, + profile_tag text DEFAULT ''::text NOT NULL, + highlight text DEFAULT 'false'::text NOT NULL +); + + +-- +-- Name: one_time_keys; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.one_time_keys ( + user_id text NOT NULL, + device_id text NOT NULL, + key_id text NOT NULL, + json text NOT NULL +); + + +-- +-- Name: openid_tokens; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.openid_tokens ( + user_id text NOT NULL, + token_hash text NOT NULL, + expires_at text DEFAULT '0'::text NOT NULL +); + + +-- +-- Name: policy_rules; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.policy_rules ( + rule_id text NOT NULL, + scope text NOT NULL, + entity text NOT NULL, + action text NOT NULL, + reason text NOT NULL +); + + +-- +-- Name: presence_state; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.presence_state ( + user_id text NOT NULL, + stream_id text DEFAULT '0'::text NOT NULL, + presence text DEFAULT 'offline'::text NOT NULL, + status_msg text DEFAULT ''::text NOT NULL, + last_active_ago text DEFAULT '0'::text NOT NULL, + currently_active text DEFAULT 'false'::text NOT NULL +); + + +-- +-- Name: profiles; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.profiles ( + user_id text NOT NULL, + displayname text DEFAULT ''::text NOT NULL, + avatar_url text DEFAULT ''::text NOT NULL, + fields_json text DEFAULT '{}'::text NOT NULL +); + + +-- +-- Name: push_rules; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.push_rules ( + user_id text NOT NULL, + rule_id text NOT NULL, + json text NOT NULL +); + + +-- +-- Name: pushers; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.pushers ( + user_id text NOT NULL, + app_id text NOT NULL, + pushkey text NOT NULL, + kind text NOT NULL, + app_display_name text DEFAULT ''::text NOT NULL, + device_display_name text DEFAULT ''::text NOT NULL, + profile_tag text DEFAULT ''::text NOT NULL, + lang text DEFAULT ''::text NOT NULL, + data_url text DEFAULT ''::text NOT NULL, + data_format text DEFAULT ''::text NOT NULL, + data_extra_json text DEFAULT ''::text NOT NULL, + device_id text DEFAULT ''::text NOT NULL +); + + +-- +-- Name: rate_limits; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.rate_limits ( + scope text NOT NULL, + key text NOT NULL, + count text NOT NULL, + reset_ts text NOT NULL +); + + +-- +-- Name: receipts; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.receipts ( + room_id text NOT NULL, + receipt_type text NOT NULL, + user_id text NOT NULL, + thread_id text DEFAULT ''::text NOT NULL, + event_id text NOT NULL, + ts text DEFAULT '0'::text NOT NULL, + stream_id text DEFAULT '0'::text NOT NULL +); + + +-- +-- Name: refresh_tokens; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.refresh_tokens ( + token_hash text NOT NULL, + user_id text NOT NULL, + device_id text NOT NULL, + revoked text NOT NULL, + expires_at text DEFAULT ''::text NOT NULL, + predecessor_hash text DEFAULT ''::text NOT NULL, + issued_at_ms text DEFAULT '0'::text NOT NULL +); + + +-- +-- Name: remote_media; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.remote_media ( + server_name text NOT NULL, + media_id text NOT NULL, + content_type text NOT NULL, + size_bytes text NOT NULL, + quarantined text NOT NULL, + local_media_id text DEFAULT ''::text NOT NULL, + fetched_at_ms text DEFAULT '0'::text NOT NULL +); + + +-- +-- Name: room_account_data; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.room_account_data ( + user_id text NOT NULL, + room_id text NOT NULL, + event_type text NOT NULL, + stream_id text DEFAULT '0'::text NOT NULL, + json text NOT NULL +); + + +-- +-- Name: room_aliases; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.room_aliases ( + room_alias text NOT NULL, + room_id text NOT NULL, + creator_user_id text DEFAULT ''::text NOT NULL +); + + +-- +-- Name: room_versions; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.room_versions ( + room_id text NOT NULL, + version text NOT NULL +); + + +-- +-- Name: rooms; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.rooms ( + room_id text NOT NULL, + creator_user_id text NOT NULL, + directory_public text DEFAULT 'false'::text NOT NULL +); + + +-- +-- Name: schema_migrations; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.schema_migrations ( + version text NOT NULL, + name text NOT NULL, + direction text NOT NULL +); + + +-- +-- Name: server_signing_keys; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.server_signing_keys ( + server_name text NOT NULL, + key_id text NOT NULL, + public_key text NOT NULL, + valid_until_ts text NOT NULL, + secret_key bytea DEFAULT '\x'::bytea NOT NULL, + expired_ts text DEFAULT ''::text NOT NULL +); + + +-- +-- Name: state_group_edges; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.state_group_edges ( + state_group_id text NOT NULL, + prev_state_group_id text NOT NULL +); + + +-- +-- Name: state_group_state; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.state_group_state ( + state_group_id text NOT NULL, + event_type text NOT NULL, + state_key text NOT NULL, + event_id text NOT NULL +); + + +-- +-- Name: state_groups; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.state_groups ( + state_group_id text NOT NULL, + room_id text NOT NULL, + parent_state_group_id text DEFAULT ''::text NOT NULL, + delta_depth text DEFAULT '0'::text NOT NULL +); + + +-- +-- Name: state_transitions; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.state_transitions ( + room_id text NOT NULL, + event_type text NOT NULL, + state_key text NOT NULL, + event_id text NOT NULL, + previous_event_id text DEFAULT ''::text NOT NULL +); + + +-- +-- Name: stream_token_epoch; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.stream_token_epoch ( + singleton integer NOT NULL, + epoch text NOT NULL, + CONSTRAINT stream_token_epoch_singleton_check CHECK ((singleton = 1)) +); + + +-- +-- Name: sync_stream_watermark; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.sync_stream_watermark ( + singleton integer NOT NULL, + watermark text DEFAULT '0'::text NOT NULL, + CONSTRAINT sync_stream_watermark_singleton_check CHECK ((singleton = 1)) +); + + +-- +-- Name: to_device_messages; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.to_device_messages ( + stream_id text NOT NULL, + sender_user_id text NOT NULL, + target_user_id text NOT NULL, + target_device_id text DEFAULT ''::text NOT NULL, + message_type text NOT NULL, + content text NOT NULL, + created_at_ms text DEFAULT '0'::text NOT NULL +); + + +-- +-- Name: users; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.users ( + user_id text NOT NULL, + password_hash text NOT NULL, + locked text NOT NULL, + suspended text NOT NULL, + admin text NOT NULL, + deactivated text DEFAULT 'false'::text NOT NULL +); + + +-- +-- Data for Name: access_tokens; Type: TABLE DATA; Schema: public; Owner: - +-- + +INSERT INTO public.access_tokens (user_id, device_id, token_hash, revoked, expires_at, predecessor_refresh_hash) VALUES ('@alice:example.org', 'UPGRADE1', 'token-hash:v4:533f4f909b4e855e4cfd0a9b2a4bb74a178e19cc8751485a59999226f2638960', 'false', '', ''); +INSERT INTO public.access_tokens (user_id, device_id, token_hash, revoked, expires_at, predecessor_refresh_hash) VALUES ('@bob:example.org', 'UPGRADE2', 'token-hash:v4:37e940791d2f4eeda9c794035450d3807f7384ca47bed4dd1c580e1f53204c19', 'false', '', ''); + + +-- +-- Data for Name: account_data; Type: TABLE DATA; Schema: public; Owner: - +-- + +INSERT INTO public.account_data (user_id, event_type, json, stream_id) VALUES ('@alice:example.org', 'org.merovingian.upgrade', '{"fixture": "0.11.13"}', '9'); + + +-- +-- Data for Name: account_threepids; Type: TABLE DATA; Schema: public; Owner: - +-- + + + +-- +-- Data for Name: admin_actions; Type: TABLE DATA; Schema: public; Owner: - +-- + + + +-- +-- Data for Name: appservice_directory; Type: TABLE DATA; Schema: public; Owner: - +-- + + + +-- +-- Data for Name: appservice_outbox; Type: TABLE DATA; Schema: public; Owner: - +-- + + + +-- +-- Data for Name: appservice_txn_cursor; Type: TABLE DATA; Schema: public; Owner: - +-- + + + +-- +-- Data for Name: audit_log; Type: TABLE DATA; Schema: public; Owner: - +-- + +INSERT INTO public.audit_log (category, event_type, actor, target, reason, created_at_ms) VALUES ('admin', 'runtime.started', 'server', 'homeserver', 'startup', '1794844862997'); +INSERT INTO public.audit_log (category, event_type, actor, target, reason, created_at_ms) VALUES ('auth', 'auth.user_registered', '@alice:example.org', '@alice:example.org', 'created', '1794844863317'); +INSERT INTO public.audit_log (category, event_type, actor, target, reason, created_at_ms) VALUES ('auth', 'auth.login', '@alice:example.org', 'UPGRADE1', 'accepted', '1794844863350'); +INSERT INTO public.audit_log (category, event_type, actor, target, reason, created_at_ms) VALUES ('auth', 'auth.user_registered', '@bob:example.org', '@bob:example.org', 'created', '1794844863412'); +INSERT INTO public.audit_log (category, event_type, actor, target, reason, created_at_ms) VALUES ('auth', 'auth.login', '@bob:example.org', 'UPGRADE2', 'accepted', '1794844863444'); +INSERT INTO public.audit_log (category, event_type, actor, target, reason, created_at_ms) VALUES ('admin', 'room.created', '@alice:example.org', '!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', 'created', '1794844863468'); +INSERT INTO public.audit_log (category, event_type, actor, target, reason, created_at_ms) VALUES ('admin', 'room.invited', '@alice:example.org', '@bob:example.org', '!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', '1794844863474'); +INSERT INTO public.audit_log (category, event_type, actor, target, reason, created_at_ms) VALUES ('admin', 'room.joined', '@bob:example.org', '!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', 'joined', '1794844863479'); +INSERT INTO public.audit_log (category, event_type, actor, target, reason, created_at_ms) VALUES ('admin', 'room.event_sent', '@alice:example.org', '!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', 'stored', '1794844863482'); +INSERT INTO public.audit_log (category, event_type, actor, target, reason, created_at_ms) VALUES ('admin', 'room.event_sent', '@alice:example.org', '!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', 'stored', '1794844863486'); +INSERT INTO public.audit_log (category, event_type, actor, target, reason, created_at_ms) VALUES ('admin', 'room.event_sent', '@alice:example.org', '!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', 'stored', '1794844863489'); +INSERT INTO public.audit_log (category, event_type, actor, target, reason, created_at_ms) VALUES ('admin', 'room.event_sent', '@bob:example.org', '!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', 'stored', '1794844863493'); +INSERT INTO public.audit_log (category, event_type, actor, target, reason, created_at_ms) VALUES ('admin', 'room.created', '@alice:example.org', '!WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA', 'created', '1794844863514'); +INSERT INTO public.audit_log (category, event_type, actor, target, reason, created_at_ms) VALUES ('moderation', 'media.upload_accepted', '@alice:example.org', 'eu-rBrEY7MSJKUy6o7pmMw', 'stored', '1794844863517'); +INSERT INTO public.audit_log (category, event_type, actor, target, reason, created_at_ms) VALUES ('auth', 'key_api.upload_keys', '@alice:example.org', 'UPGRADE1', '[key-payload:redacted:length=697]', '1794844863523'); + + +-- +-- Data for Name: client_txn_ids; Type: TABLE DATA; Schema: public; Owner: - +-- + +INSERT INTO public.client_txn_ids (user_id, room_id, event_type, txn_id, event_id, device_id, created_at_ms) VALUES ('@alice:example.org', '!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', 'm.room.message', 'upgrade-txn-1', '$gbIXT6cBYsLvEAdCmvz_-Z-MLge4BnaLY_O1-PtdjGo', 'UPGRADE1', '1794844863483'); +INSERT INTO public.client_txn_ids (user_id, room_id, event_type, txn_id, event_id, device_id, created_at_ms) VALUES ('@alice:example.org', '!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', 'm.room.message', 'upgrade-txn-2', '$mC5T62vlKtDEaC4l1ujmOJ3dA5q-PM-ku8SS1xRZCek', 'UPGRADE1', '1794844863487'); +INSERT INTO public.client_txn_ids (user_id, room_id, event_type, txn_id, event_id, device_id, created_at_ms) VALUES ('@alice:example.org', '!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', 'm.room.message', 'upgrade-txn-3', '$h7M6qztmLUOCjFAmWrrrh-vd87KuCykZl7jvFLSK3Ds', 'UPGRADE1', '1794844863490'); +INSERT INTO public.client_txn_ids (user_id, room_id, event_type, txn_id, event_id, device_id, created_at_ms) VALUES ('@bob:example.org', '!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', 'm.room.message', 'upgrade-txn-4', '$GcOCV1AahAZenbnTVGpvMmYTyB2XNFzhRLwjkRT0Cy8', 'UPGRADE2', '1794844863494'); + + +-- +-- Data for Name: cross_signing_keys; Type: TABLE DATA; Schema: public; Owner: - +-- + + + +-- +-- Data for Name: current_state; Type: TABLE DATA; Schema: public; Owner: - +-- + +INSERT INTO public.current_state (room_id, event_type, state_key, event_id) VALUES ('!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', 'm.room.create', '', '$C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY'); +INSERT INTO public.current_state (room_id, event_type, state_key, event_id) VALUES ('!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', 'm.room.member', '@alice:example.org', '$iLFuDk8nVttbD9AqXn1viyXUEFEl_2DI7hsgkXGjXN8'); +INSERT INTO public.current_state (room_id, event_type, state_key, event_id) VALUES ('!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', 'm.room.power_levels', '', '$i5rP6Kab--xLmDcMSPRUZxvyQZcPThTiofJjfrSnDtg'); +INSERT INTO public.current_state (room_id, event_type, state_key, event_id) VALUES ('!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', 'm.room.join_rules', '', '$v4aPwfsZiQ4yEz5-T0kS_DWvVTqUxPRltYSFV4P8Jlk'); +INSERT INTO public.current_state (room_id, event_type, state_key, event_id) VALUES ('!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', 'm.room.history_visibility', '', '$jQRkJoCECH7wDkXeK4PAzuiNM5N4-W-klgkSyuKI0Ig'); +INSERT INTO public.current_state (room_id, event_type, state_key, event_id) VALUES ('!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', 'm.room.guest_access', '', '$3DxD43IUhKnopg81UbujM_TWm14GdVq22XKXiThD5Bo'); +INSERT INTO public.current_state (room_id, event_type, state_key, event_id) VALUES ('!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', 'm.room.encryption', '', '$LQujV90cKOa8fkPPU4PQX7sm6KL28V0r8nKCewBnOJ8'); +INSERT INTO public.current_state (room_id, event_type, state_key, event_id) VALUES ('!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', 'm.room.name', '', '$RDqWCB4mWm4fTct25NtZAh5zmiUTG_EsgfQpCS2erxw'); +INSERT INTO public.current_state (room_id, event_type, state_key, event_id) VALUES ('!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', 'm.room.member', '@bob:example.org', '$wVJJm-TLQ6il0h68B5rzA97t20lkmGMK7H0O6YdHEMM'); +INSERT INTO public.current_state (room_id, event_type, state_key, event_id) VALUES ('!WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA', 'm.room.create', '', '$WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA'); +INSERT INTO public.current_state (room_id, event_type, state_key, event_id) VALUES ('!WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA', 'm.room.member', '@alice:example.org', '$gEZRQzCXH4iD07nDrZYaWlyfDmS0tqK_R-gW6JyF32U'); +INSERT INTO public.current_state (room_id, event_type, state_key, event_id) VALUES ('!WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA', 'm.room.power_levels', '', '$PecG6aWhB2mDCM6YMk8crHbTdYzWkYUCN_ipzlMCjiI'); +INSERT INTO public.current_state (room_id, event_type, state_key, event_id) VALUES ('!WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA', 'm.room.canonical_alias', '', '$2oC-K1LNKA47eO1pqEmJrY0s6617pjOSdk68k5LiuZg'); +INSERT INTO public.current_state (room_id, event_type, state_key, event_id) VALUES ('!WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA', 'm.room.join_rules', '', '$V6yysmqZ0o9qaJiimEfXi0Ku7kIFtR9hCAC7vGSowuY'); +INSERT INTO public.current_state (room_id, event_type, state_key, event_id) VALUES ('!WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA', 'm.room.history_visibility', '', '$Lft2RjGrEuDUm8UkT3X25KYA1_81FeaFlJVeWLq8UdM'); +INSERT INTO public.current_state (room_id, event_type, state_key, event_id) VALUES ('!WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA', 'm.room.guest_access', '', '$MDEmZSZMMOOQUjEQxIXi05XzoHayhwFR6YRDMOykvoI'); +INSERT INTO public.current_state (room_id, event_type, state_key, event_id) VALUES ('!WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA', 'm.room.name', '', '$G6T266qKoHUbMYlVFKPN14wSCrqcj7ktb84OYLky32M'); + + +-- +-- Data for Name: deferred_pdus; Type: TABLE DATA; Schema: public; Owner: - +-- + + + +-- +-- Data for Name: device_keys; Type: TABLE DATA; Schema: public; Owner: - +-- + +INSERT INTO public.device_keys (user_id, device_id, json) VALUES ('@alice:example.org', 'UPGRADE1', '{"algorithms":["m.olm.v1.curve25519-aes-sha2","m.megolm.v1.aes-sha2"],"device_id":"UPGRADE1","keys":{"curve25519:UPGRADE1":"aJoAYROXT9rrYFhiSAmFkQk8DgPUrZKIq59YFaOAgQg","ed25519:UPGRADE1":"xZ6DW0uuhQKl7HY7m4J5dMmK6CWpCCrtYwps1QBYoyE"},"signatures":{"@alice:example.org":{"ed25519:UPGRADE1":"khdpySd56eC7863q/p2A8IOUUe2TQ28I4eBVO45kevqFspi6gW12BDvcz2qiB9GpsnS2zCNOxcde/LyLPA7RCw"}},"unsigned":{"device_display_name":"Upgrade fixture UPGRADE1"},"user_id":"@alice:example.org"}'); + + +-- +-- Data for Name: device_list_changes; Type: TABLE DATA; Schema: public; Owner: - +-- + +INSERT INTO public.device_list_changes (stream_id, observer_user_id, subject_user_id, change_type) VALUES ('2', '@bob:example.org', '@bob:example.org', 'changed'); +INSERT INTO public.device_list_changes (stream_id, observer_user_id, subject_user_id, change_type) VALUES ('6', '@alice:example.org', '@bob:example.org', 'changed'); +INSERT INTO public.device_list_changes (stream_id, observer_user_id, subject_user_id, change_type) VALUES ('10', '@alice:example.org', '@alice:example.org', 'changed'); +INSERT INTO public.device_list_changes (stream_id, observer_user_id, subject_user_id, change_type) VALUES ('10', '@bob:example.org', '@alice:example.org', 'changed'); + + +-- +-- Data for Name: devices; Type: TABLE DATA; Schema: public; Owner: - +-- + +INSERT INTO public.devices (user_id, device_id, display_name) VALUES ('@alice:example.org', 'UPGRADE1', 'Upgrade fixture UPGRADE1'); +INSERT INTO public.devices (user_id, device_id, display_name) VALUES ('@bob:example.org', 'UPGRADE2', 'Upgrade fixture UPGRADE2'); + + +-- +-- Data for Name: event_auth; Type: TABLE DATA; Schema: public; Owner: - +-- + +INSERT INTO public.event_auth (event_id, auth_event_id) VALUES ('$i5rP6Kab--xLmDcMSPRUZxvyQZcPThTiofJjfrSnDtg', '$iLFuDk8nVttbD9AqXn1viyXUEFEl_2DI7hsgkXGjXN8'); +INSERT INTO public.event_auth (event_id, auth_event_id) VALUES ('$v4aPwfsZiQ4yEz5-T0kS_DWvVTqUxPRltYSFV4P8Jlk', '$iLFuDk8nVttbD9AqXn1viyXUEFEl_2DI7hsgkXGjXN8'); +INSERT INTO public.event_auth (event_id, auth_event_id) VALUES ('$v4aPwfsZiQ4yEz5-T0kS_DWvVTqUxPRltYSFV4P8Jlk', '$i5rP6Kab--xLmDcMSPRUZxvyQZcPThTiofJjfrSnDtg'); +INSERT INTO public.event_auth (event_id, auth_event_id) VALUES ('$jQRkJoCECH7wDkXeK4PAzuiNM5N4-W-klgkSyuKI0Ig', '$iLFuDk8nVttbD9AqXn1viyXUEFEl_2DI7hsgkXGjXN8'); +INSERT INTO public.event_auth (event_id, auth_event_id) VALUES ('$jQRkJoCECH7wDkXeK4PAzuiNM5N4-W-klgkSyuKI0Ig', '$i5rP6Kab--xLmDcMSPRUZxvyQZcPThTiofJjfrSnDtg'); +INSERT INTO public.event_auth (event_id, auth_event_id) VALUES ('$3DxD43IUhKnopg81UbujM_TWm14GdVq22XKXiThD5Bo', '$iLFuDk8nVttbD9AqXn1viyXUEFEl_2DI7hsgkXGjXN8'); +INSERT INTO public.event_auth (event_id, auth_event_id) VALUES ('$3DxD43IUhKnopg81UbujM_TWm14GdVq22XKXiThD5Bo', '$i5rP6Kab--xLmDcMSPRUZxvyQZcPThTiofJjfrSnDtg'); +INSERT INTO public.event_auth (event_id, auth_event_id) VALUES ('$LQujV90cKOa8fkPPU4PQX7sm6KL28V0r8nKCewBnOJ8', '$iLFuDk8nVttbD9AqXn1viyXUEFEl_2DI7hsgkXGjXN8'); +INSERT INTO public.event_auth (event_id, auth_event_id) VALUES ('$LQujV90cKOa8fkPPU4PQX7sm6KL28V0r8nKCewBnOJ8', '$i5rP6Kab--xLmDcMSPRUZxvyQZcPThTiofJjfrSnDtg'); +INSERT INTO public.event_auth (event_id, auth_event_id) VALUES ('$RDqWCB4mWm4fTct25NtZAh5zmiUTG_EsgfQpCS2erxw', '$iLFuDk8nVttbD9AqXn1viyXUEFEl_2DI7hsgkXGjXN8'); +INSERT INTO public.event_auth (event_id, auth_event_id) VALUES ('$RDqWCB4mWm4fTct25NtZAh5zmiUTG_EsgfQpCS2erxw', '$i5rP6Kab--xLmDcMSPRUZxvyQZcPThTiofJjfrSnDtg'); +INSERT INTO public.event_auth (event_id, auth_event_id) VALUES ('$QzTeY37FC1XCBCS9k5WSqtd_ozVW1B45OBvMLOxOFRY', '$iLFuDk8nVttbD9AqXn1viyXUEFEl_2DI7hsgkXGjXN8'); +INSERT INTO public.event_auth (event_id, auth_event_id) VALUES ('$QzTeY37FC1XCBCS9k5WSqtd_ozVW1B45OBvMLOxOFRY', '$i5rP6Kab--xLmDcMSPRUZxvyQZcPThTiofJjfrSnDtg'); +INSERT INTO public.event_auth (event_id, auth_event_id) VALUES ('$QzTeY37FC1XCBCS9k5WSqtd_ozVW1B45OBvMLOxOFRY', '$v4aPwfsZiQ4yEz5-T0kS_DWvVTqUxPRltYSFV4P8Jlk'); +INSERT INTO public.event_auth (event_id, auth_event_id) VALUES ('$wVJJm-TLQ6il0h68B5rzA97t20lkmGMK7H0O6YdHEMM', '$i5rP6Kab--xLmDcMSPRUZxvyQZcPThTiofJjfrSnDtg'); +INSERT INTO public.event_auth (event_id, auth_event_id) VALUES ('$wVJJm-TLQ6il0h68B5rzA97t20lkmGMK7H0O6YdHEMM', '$v4aPwfsZiQ4yEz5-T0kS_DWvVTqUxPRltYSFV4P8Jlk'); +INSERT INTO public.event_auth (event_id, auth_event_id) VALUES ('$wVJJm-TLQ6il0h68B5rzA97t20lkmGMK7H0O6YdHEMM', '$QzTeY37FC1XCBCS9k5WSqtd_ozVW1B45OBvMLOxOFRY'); +INSERT INTO public.event_auth (event_id, auth_event_id) VALUES ('$gbIXT6cBYsLvEAdCmvz_-Z-MLge4BnaLY_O1-PtdjGo', '$iLFuDk8nVttbD9AqXn1viyXUEFEl_2DI7hsgkXGjXN8'); +INSERT INTO public.event_auth (event_id, auth_event_id) VALUES ('$gbIXT6cBYsLvEAdCmvz_-Z-MLge4BnaLY_O1-PtdjGo', '$i5rP6Kab--xLmDcMSPRUZxvyQZcPThTiofJjfrSnDtg'); +INSERT INTO public.event_auth (event_id, auth_event_id) VALUES ('$mC5T62vlKtDEaC4l1ujmOJ3dA5q-PM-ku8SS1xRZCek', '$iLFuDk8nVttbD9AqXn1viyXUEFEl_2DI7hsgkXGjXN8'); +INSERT INTO public.event_auth (event_id, auth_event_id) VALUES ('$mC5T62vlKtDEaC4l1ujmOJ3dA5q-PM-ku8SS1xRZCek', '$i5rP6Kab--xLmDcMSPRUZxvyQZcPThTiofJjfrSnDtg'); +INSERT INTO public.event_auth (event_id, auth_event_id) VALUES ('$h7M6qztmLUOCjFAmWrrrh-vd87KuCykZl7jvFLSK3Ds', '$iLFuDk8nVttbD9AqXn1viyXUEFEl_2DI7hsgkXGjXN8'); +INSERT INTO public.event_auth (event_id, auth_event_id) VALUES ('$h7M6qztmLUOCjFAmWrrrh-vd87KuCykZl7jvFLSK3Ds', '$i5rP6Kab--xLmDcMSPRUZxvyQZcPThTiofJjfrSnDtg'); +INSERT INTO public.event_auth (event_id, auth_event_id) VALUES ('$GcOCV1AahAZenbnTVGpvMmYTyB2XNFzhRLwjkRT0Cy8', '$i5rP6Kab--xLmDcMSPRUZxvyQZcPThTiofJjfrSnDtg'); +INSERT INTO public.event_auth (event_id, auth_event_id) VALUES ('$GcOCV1AahAZenbnTVGpvMmYTyB2XNFzhRLwjkRT0Cy8', '$wVJJm-TLQ6il0h68B5rzA97t20lkmGMK7H0O6YdHEMM'); +INSERT INTO public.event_auth (event_id, auth_event_id) VALUES ('$PecG6aWhB2mDCM6YMk8crHbTdYzWkYUCN_ipzlMCjiI', '$gEZRQzCXH4iD07nDrZYaWlyfDmS0tqK_R-gW6JyF32U'); +INSERT INTO public.event_auth (event_id, auth_event_id) VALUES ('$2oC-K1LNKA47eO1pqEmJrY0s6617pjOSdk68k5LiuZg', '$gEZRQzCXH4iD07nDrZYaWlyfDmS0tqK_R-gW6JyF32U'); +INSERT INTO public.event_auth (event_id, auth_event_id) VALUES ('$2oC-K1LNKA47eO1pqEmJrY0s6617pjOSdk68k5LiuZg', '$PecG6aWhB2mDCM6YMk8crHbTdYzWkYUCN_ipzlMCjiI'); +INSERT INTO public.event_auth (event_id, auth_event_id) VALUES ('$V6yysmqZ0o9qaJiimEfXi0Ku7kIFtR9hCAC7vGSowuY', '$gEZRQzCXH4iD07nDrZYaWlyfDmS0tqK_R-gW6JyF32U'); +INSERT INTO public.event_auth (event_id, auth_event_id) VALUES ('$V6yysmqZ0o9qaJiimEfXi0Ku7kIFtR9hCAC7vGSowuY', '$PecG6aWhB2mDCM6YMk8crHbTdYzWkYUCN_ipzlMCjiI'); +INSERT INTO public.event_auth (event_id, auth_event_id) VALUES ('$Lft2RjGrEuDUm8UkT3X25KYA1_81FeaFlJVeWLq8UdM', '$gEZRQzCXH4iD07nDrZYaWlyfDmS0tqK_R-gW6JyF32U'); +INSERT INTO public.event_auth (event_id, auth_event_id) VALUES ('$Lft2RjGrEuDUm8UkT3X25KYA1_81FeaFlJVeWLq8UdM', '$PecG6aWhB2mDCM6YMk8crHbTdYzWkYUCN_ipzlMCjiI'); +INSERT INTO public.event_auth (event_id, auth_event_id) VALUES ('$MDEmZSZMMOOQUjEQxIXi05XzoHayhwFR6YRDMOykvoI', '$gEZRQzCXH4iD07nDrZYaWlyfDmS0tqK_R-gW6JyF32U'); +INSERT INTO public.event_auth (event_id, auth_event_id) VALUES ('$MDEmZSZMMOOQUjEQxIXi05XzoHayhwFR6YRDMOykvoI', '$PecG6aWhB2mDCM6YMk8crHbTdYzWkYUCN_ipzlMCjiI'); +INSERT INTO public.event_auth (event_id, auth_event_id) VALUES ('$G6T266qKoHUbMYlVFKPN14wSCrqcj7ktb84OYLky32M', '$gEZRQzCXH4iD07nDrZYaWlyfDmS0tqK_R-gW6JyF32U'); +INSERT INTO public.event_auth (event_id, auth_event_id) VALUES ('$G6T266qKoHUbMYlVFKPN14wSCrqcj7ktb84OYLky32M', '$PecG6aWhB2mDCM6YMk8crHbTdYzWkYUCN_ipzlMCjiI'); + + +-- +-- Data for Name: event_edges; Type: TABLE DATA; Schema: public; Owner: - +-- + +INSERT INTO public.event_edges (event_id, prev_event_id) VALUES ('$iLFuDk8nVttbD9AqXn1viyXUEFEl_2DI7hsgkXGjXN8', '$C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY'); +INSERT INTO public.event_edges (event_id, prev_event_id) VALUES ('$i5rP6Kab--xLmDcMSPRUZxvyQZcPThTiofJjfrSnDtg', '$iLFuDk8nVttbD9AqXn1viyXUEFEl_2DI7hsgkXGjXN8'); +INSERT INTO public.event_edges (event_id, prev_event_id) VALUES ('$v4aPwfsZiQ4yEz5-T0kS_DWvVTqUxPRltYSFV4P8Jlk', '$i5rP6Kab--xLmDcMSPRUZxvyQZcPThTiofJjfrSnDtg'); +INSERT INTO public.event_edges (event_id, prev_event_id) VALUES ('$jQRkJoCECH7wDkXeK4PAzuiNM5N4-W-klgkSyuKI0Ig', '$v4aPwfsZiQ4yEz5-T0kS_DWvVTqUxPRltYSFV4P8Jlk'); +INSERT INTO public.event_edges (event_id, prev_event_id) VALUES ('$3DxD43IUhKnopg81UbujM_TWm14GdVq22XKXiThD5Bo', '$jQRkJoCECH7wDkXeK4PAzuiNM5N4-W-klgkSyuKI0Ig'); +INSERT INTO public.event_edges (event_id, prev_event_id) VALUES ('$LQujV90cKOa8fkPPU4PQX7sm6KL28V0r8nKCewBnOJ8', '$3DxD43IUhKnopg81UbujM_TWm14GdVq22XKXiThD5Bo'); +INSERT INTO public.event_edges (event_id, prev_event_id) VALUES ('$RDqWCB4mWm4fTct25NtZAh5zmiUTG_EsgfQpCS2erxw', '$LQujV90cKOa8fkPPU4PQX7sm6KL28V0r8nKCewBnOJ8'); +INSERT INTO public.event_edges (event_id, prev_event_id) VALUES ('$QzTeY37FC1XCBCS9k5WSqtd_ozVW1B45OBvMLOxOFRY', '$RDqWCB4mWm4fTct25NtZAh5zmiUTG_EsgfQpCS2erxw'); +INSERT INTO public.event_edges (event_id, prev_event_id) VALUES ('$wVJJm-TLQ6il0h68B5rzA97t20lkmGMK7H0O6YdHEMM', '$QzTeY37FC1XCBCS9k5WSqtd_ozVW1B45OBvMLOxOFRY'); +INSERT INTO public.event_edges (event_id, prev_event_id) VALUES ('$gbIXT6cBYsLvEAdCmvz_-Z-MLge4BnaLY_O1-PtdjGo', '$wVJJm-TLQ6il0h68B5rzA97t20lkmGMK7H0O6YdHEMM'); +INSERT INTO public.event_edges (event_id, prev_event_id) VALUES ('$mC5T62vlKtDEaC4l1ujmOJ3dA5q-PM-ku8SS1xRZCek', '$gbIXT6cBYsLvEAdCmvz_-Z-MLge4BnaLY_O1-PtdjGo'); +INSERT INTO public.event_edges (event_id, prev_event_id) VALUES ('$h7M6qztmLUOCjFAmWrrrh-vd87KuCykZl7jvFLSK3Ds', '$mC5T62vlKtDEaC4l1ujmOJ3dA5q-PM-ku8SS1xRZCek'); +INSERT INTO public.event_edges (event_id, prev_event_id) VALUES ('$GcOCV1AahAZenbnTVGpvMmYTyB2XNFzhRLwjkRT0Cy8', '$h7M6qztmLUOCjFAmWrrrh-vd87KuCykZl7jvFLSK3Ds'); +INSERT INTO public.event_edges (event_id, prev_event_id) VALUES ('$gEZRQzCXH4iD07nDrZYaWlyfDmS0tqK_R-gW6JyF32U', '$WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA'); +INSERT INTO public.event_edges (event_id, prev_event_id) VALUES ('$PecG6aWhB2mDCM6YMk8crHbTdYzWkYUCN_ipzlMCjiI', '$gEZRQzCXH4iD07nDrZYaWlyfDmS0tqK_R-gW6JyF32U'); +INSERT INTO public.event_edges (event_id, prev_event_id) VALUES ('$2oC-K1LNKA47eO1pqEmJrY0s6617pjOSdk68k5LiuZg', '$PecG6aWhB2mDCM6YMk8crHbTdYzWkYUCN_ipzlMCjiI'); +INSERT INTO public.event_edges (event_id, prev_event_id) VALUES ('$V6yysmqZ0o9qaJiimEfXi0Ku7kIFtR9hCAC7vGSowuY', '$2oC-K1LNKA47eO1pqEmJrY0s6617pjOSdk68k5LiuZg'); +INSERT INTO public.event_edges (event_id, prev_event_id) VALUES ('$Lft2RjGrEuDUm8UkT3X25KYA1_81FeaFlJVeWLq8UdM', '$V6yysmqZ0o9qaJiimEfXi0Ku7kIFtR9hCAC7vGSowuY'); +INSERT INTO public.event_edges (event_id, prev_event_id) VALUES ('$MDEmZSZMMOOQUjEQxIXi05XzoHayhwFR6YRDMOykvoI', '$Lft2RjGrEuDUm8UkT3X25KYA1_81FeaFlJVeWLq8UdM'); +INSERT INTO public.event_edges (event_id, prev_event_id) VALUES ('$G6T266qKoHUbMYlVFKPN14wSCrqcj7ktb84OYLky32M', '$MDEmZSZMMOOQUjEQxIXi05XzoHayhwFR6YRDMOykvoI'); + + +-- +-- Data for Name: event_json; Type: TABLE DATA; Schema: public; Owner: - +-- + + + +-- +-- Data for Name: event_signatures; Type: TABLE DATA; Schema: public; Owner: - +-- + +INSERT INTO public.event_signatures (event_id, server_name, key_id, signature) VALUES ('$C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', 'example.org', 'ed25519:76d6613f', '3frnQABSc2K4/37LcTVL4b0IiCRWhvkzuxzVTSqRQtpaIDqIx1gfPNtaqD6tflS6HbHGDQFvKHeuEZOk1gY9AQ'); +INSERT INTO public.event_signatures (event_id, server_name, key_id, signature) VALUES ('$iLFuDk8nVttbD9AqXn1viyXUEFEl_2DI7hsgkXGjXN8', 'example.org', 'ed25519:76d6613f', 'jFuZOKy4ewxJYHWCb9SKxDFhKaVUFBCBq8NQtFnYD+UKtyEVzioaDqEfRS75XpBf+eJf30pei2wi5QO507mNAg'); +INSERT INTO public.event_signatures (event_id, server_name, key_id, signature) VALUES ('$i5rP6Kab--xLmDcMSPRUZxvyQZcPThTiofJjfrSnDtg', 'example.org', 'ed25519:76d6613f', '9Ya2JwLzuQDA1nZrZKnvbCwYLx7v6BtdoRXKatBWFSMC6aXktuxuMiazcc/2qntlcZDRvHAM+eJKVpPoMscVDQ'); +INSERT INTO public.event_signatures (event_id, server_name, key_id, signature) VALUES ('$v4aPwfsZiQ4yEz5-T0kS_DWvVTqUxPRltYSFV4P8Jlk', 'example.org', 'ed25519:76d6613f', 'LWYtQ01lNNgR6yxoy4iVxydEYTXAydCCNZU9Lo5QJCd8hhov30fNObIMeCpQkjWynhKc+xFsj0cWMUiv7Gh+Bw'); +INSERT INTO public.event_signatures (event_id, server_name, key_id, signature) VALUES ('$jQRkJoCECH7wDkXeK4PAzuiNM5N4-W-klgkSyuKI0Ig', 'example.org', 'ed25519:76d6613f', 'zpusmcvsriZtMqnVBtMI0uFKTGFNMqHkC9tIR00WJAFTTqnl5n+wpEyypeFxhuR6JJMZLZp2kPbVEny0xikhCw'); +INSERT INTO public.event_signatures (event_id, server_name, key_id, signature) VALUES ('$3DxD43IUhKnopg81UbujM_TWm14GdVq22XKXiThD5Bo', 'example.org', 'ed25519:76d6613f', 'Ox1jSZc8TlPxsi51n4x39UKVR2O/bDtKtgaHxXd2bo1J5ezwy9aOpezQoSGX8cGa5RARdnR2r9N/he0XmisnCg'); +INSERT INTO public.event_signatures (event_id, server_name, key_id, signature) VALUES ('$LQujV90cKOa8fkPPU4PQX7sm6KL28V0r8nKCewBnOJ8', 'example.org', 'ed25519:76d6613f', 'yey6hQSQYCBHDCovmGoILewHu58iLc3K8LlA95SmhOA5yH4/f4Auo2oGmwBKCNOLQ2L8bbqUzynWoyZy0OYqAA'); +INSERT INTO public.event_signatures (event_id, server_name, key_id, signature) VALUES ('$RDqWCB4mWm4fTct25NtZAh5zmiUTG_EsgfQpCS2erxw', 'example.org', 'ed25519:76d6613f', 'gfX0vOva648wvwThP7IggMyqxCksfZjo7mPmH+9/RE3lyf8RaQaH2GQKGB6Ad9nbuDl0H+8hPUeDfGIw3E3dDQ'); +INSERT INTO public.event_signatures (event_id, server_name, key_id, signature) VALUES ('$QzTeY37FC1XCBCS9k5WSqtd_ozVW1B45OBvMLOxOFRY', 'example.org', 'ed25519:76d6613f', 'bRSdsgOyEaKnxNVQTbr+CSm4IZTkJ7S82mbptEc+mt6ywg2gYpqNKXbWdGskABIYoH66floDHymiT3RnAJwZCA'); +INSERT INTO public.event_signatures (event_id, server_name, key_id, signature) VALUES ('$wVJJm-TLQ6il0h68B5rzA97t20lkmGMK7H0O6YdHEMM', 'example.org', 'ed25519:76d6613f', 'cz1hP8TbklKANszH+xcEbfBx/FS9eh5fxN4Hwnjxdn8qtRCL6hP77BAp6sF2FmlG7P8pkoOq8v7w76J0udX1Ag'); +INSERT INTO public.event_signatures (event_id, server_name, key_id, signature) VALUES ('$gbIXT6cBYsLvEAdCmvz_-Z-MLge4BnaLY_O1-PtdjGo', 'example.org', 'ed25519:76d6613f', 'QXpHWG51uFHmhLxnCvfM+bvpKTtmqVSsltF1/q7wQlpBoQmaLaPiRBhtCTVHOxvET/4Q7RlqhhD2Bfam/ZEUAw'); +INSERT INTO public.event_signatures (event_id, server_name, key_id, signature) VALUES ('$mC5T62vlKtDEaC4l1ujmOJ3dA5q-PM-ku8SS1xRZCek', 'example.org', 'ed25519:76d6613f', 'qFvolB96ql4o6ApfoP+SWYcMbDI7FfQYa7qKiFwgM8LcdTtIL9unkj0bi3+a2b1Z/G8G+PdF+Q4CixMfkFNEDg'); +INSERT INTO public.event_signatures (event_id, server_name, key_id, signature) VALUES ('$h7M6qztmLUOCjFAmWrrrh-vd87KuCykZl7jvFLSK3Ds', 'example.org', 'ed25519:76d6613f', 'jVD/fxDVi44OlM0xryZwEeZkV+OQq4C/qvY2oSB6hTaQtq2UPfKYQcdy8fJGi0mAGtbGPSeKCBl0rqmkd53uAw'); +INSERT INTO public.event_signatures (event_id, server_name, key_id, signature) VALUES ('$GcOCV1AahAZenbnTVGpvMmYTyB2XNFzhRLwjkRT0Cy8', 'example.org', 'ed25519:76d6613f', '0Ej0RJCDtIzH5ISMF6PKtdBQKl20J5E1Tq5Ud9dSJVxuh7Xc9zt1R2p1eTdYnaEKMqRSelx1DmE5AarEdFG8CA'); +INSERT INTO public.event_signatures (event_id, server_name, key_id, signature) VALUES ('$WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA', 'example.org', 'ed25519:76d6613f', '0kLHXj9ow1MkrnOT1KYeb69Hdk/W0uDxZhTNw4Nz0YHODNfKcHqCsZ1yGJLA4vE2EaC8QBfaekTd9Fq+kALTBw'); +INSERT INTO public.event_signatures (event_id, server_name, key_id, signature) VALUES ('$gEZRQzCXH4iD07nDrZYaWlyfDmS0tqK_R-gW6JyF32U', 'example.org', 'ed25519:76d6613f', '9bfA6431NNhLsvcAJ0dRJ4Ruqql1cFl6A7XmwaBLT2CQNji5Xpd/+HczGIT4E+Kft0IIkH8FfrdHUETK/IaRCw'); +INSERT INTO public.event_signatures (event_id, server_name, key_id, signature) VALUES ('$PecG6aWhB2mDCM6YMk8crHbTdYzWkYUCN_ipzlMCjiI', 'example.org', 'ed25519:76d6613f', 'j/PZ2/oF/fNiLaXx44nkSEg4AN7HgpdD66Y1gsPkmLQKRNJBwHl4SPodxJy0Dsc3nWgwqJfFOqlZH/a5JwGDCg'); +INSERT INTO public.event_signatures (event_id, server_name, key_id, signature) VALUES ('$2oC-K1LNKA47eO1pqEmJrY0s6617pjOSdk68k5LiuZg', 'example.org', 'ed25519:76d6613f', 'itC4d6HfjT7XS9dOyL5PyP8e0s7hv6EwfBHNT8oH8bHS70+Xo+Zt8jeRFYZtYsdm6DTqYRdiVTrDL6q6msvtAg'); +INSERT INTO public.event_signatures (event_id, server_name, key_id, signature) VALUES ('$V6yysmqZ0o9qaJiimEfXi0Ku7kIFtR9hCAC7vGSowuY', 'example.org', 'ed25519:76d6613f', '20xjkZeHqAE/2mlNEwtqENmyEusYotibPGAPn0A3ntL90O1t33MYoyWHL9baYuHCglqtxIVPyAXYptllhVZxAA'); +INSERT INTO public.event_signatures (event_id, server_name, key_id, signature) VALUES ('$Lft2RjGrEuDUm8UkT3X25KYA1_81FeaFlJVeWLq8UdM', 'example.org', 'ed25519:76d6613f', 'tEAp2KuW8C+AVb18hpUq6FF3kQ1U75ayzWMPUx/DHPipAfajQ6MnQe8Ts3gqIo6MJg5ZXe9T6ASN2MPAQ7qFDg'); +INSERT INTO public.event_signatures (event_id, server_name, key_id, signature) VALUES ('$MDEmZSZMMOOQUjEQxIXi05XzoHayhwFR6YRDMOykvoI', 'example.org', 'ed25519:76d6613f', 'fB5PjFjkA/TR7+hXy8/+MQeWh5VRA+aGLS+6Q2zHL2pGCBLPS+cX1+jqlweSKifxGnWtOM8tPH6GZhZ3BFXDCw'); +INSERT INTO public.event_signatures (event_id, server_name, key_id, signature) VALUES ('$G6T266qKoHUbMYlVFKPN14wSCrqcj7ktb84OYLky32M', 'example.org', 'ed25519:76d6613f', 'yCI4HRCLRor9+l4NIlnbUWiiel/Fn1WhOMsSeRQVn9RTV3zOn2DAlTKaFDyTz8NeBM/B9hcb1UGLVtWDMBiGCQ'); + + +-- +-- Data for Name: event_state_groups; Type: TABLE DATA; Schema: public; Owner: - +-- + +INSERT INTO public.event_state_groups (event_id, state_group_id) VALUES ('$C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', 'sg:$C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY'); +INSERT INTO public.event_state_groups (event_id, state_group_id) VALUES ('$iLFuDk8nVttbD9AqXn1viyXUEFEl_2DI7hsgkXGjXN8', 'sg:$iLFuDk8nVttbD9AqXn1viyXUEFEl_2DI7hsgkXGjXN8'); +INSERT INTO public.event_state_groups (event_id, state_group_id) VALUES ('$i5rP6Kab--xLmDcMSPRUZxvyQZcPThTiofJjfrSnDtg', 'sg:$i5rP6Kab--xLmDcMSPRUZxvyQZcPThTiofJjfrSnDtg'); +INSERT INTO public.event_state_groups (event_id, state_group_id) VALUES ('$v4aPwfsZiQ4yEz5-T0kS_DWvVTqUxPRltYSFV4P8Jlk', 'sg:$v4aPwfsZiQ4yEz5-T0kS_DWvVTqUxPRltYSFV4P8Jlk'); +INSERT INTO public.event_state_groups (event_id, state_group_id) VALUES ('$jQRkJoCECH7wDkXeK4PAzuiNM5N4-W-klgkSyuKI0Ig', 'sg:$jQRkJoCECH7wDkXeK4PAzuiNM5N4-W-klgkSyuKI0Ig'); +INSERT INTO public.event_state_groups (event_id, state_group_id) VALUES ('$3DxD43IUhKnopg81UbujM_TWm14GdVq22XKXiThD5Bo', 'sg:$3DxD43IUhKnopg81UbujM_TWm14GdVq22XKXiThD5Bo'); +INSERT INTO public.event_state_groups (event_id, state_group_id) VALUES ('$LQujV90cKOa8fkPPU4PQX7sm6KL28V0r8nKCewBnOJ8', 'sg:$LQujV90cKOa8fkPPU4PQX7sm6KL28V0r8nKCewBnOJ8'); +INSERT INTO public.event_state_groups (event_id, state_group_id) VALUES ('$RDqWCB4mWm4fTct25NtZAh5zmiUTG_EsgfQpCS2erxw', 'sg:$RDqWCB4mWm4fTct25NtZAh5zmiUTG_EsgfQpCS2erxw'); +INSERT INTO public.event_state_groups (event_id, state_group_id) VALUES ('$QzTeY37FC1XCBCS9k5WSqtd_ozVW1B45OBvMLOxOFRY', 'sg:$QzTeY37FC1XCBCS9k5WSqtd_ozVW1B45OBvMLOxOFRY'); +INSERT INTO public.event_state_groups (event_id, state_group_id) VALUES ('$wVJJm-TLQ6il0h68B5rzA97t20lkmGMK7H0O6YdHEMM', 'sg:$wVJJm-TLQ6il0h68B5rzA97t20lkmGMK7H0O6YdHEMM'); +INSERT INTO public.event_state_groups (event_id, state_group_id) VALUES ('$gbIXT6cBYsLvEAdCmvz_-Z-MLge4BnaLY_O1-PtdjGo', 'sg:$wVJJm-TLQ6il0h68B5rzA97t20lkmGMK7H0O6YdHEMM'); +INSERT INTO public.event_state_groups (event_id, state_group_id) VALUES ('$mC5T62vlKtDEaC4l1ujmOJ3dA5q-PM-ku8SS1xRZCek', 'sg:$wVJJm-TLQ6il0h68B5rzA97t20lkmGMK7H0O6YdHEMM'); +INSERT INTO public.event_state_groups (event_id, state_group_id) VALUES ('$h7M6qztmLUOCjFAmWrrrh-vd87KuCykZl7jvFLSK3Ds', 'sg:$wVJJm-TLQ6il0h68B5rzA97t20lkmGMK7H0O6YdHEMM'); +INSERT INTO public.event_state_groups (event_id, state_group_id) VALUES ('$GcOCV1AahAZenbnTVGpvMmYTyB2XNFzhRLwjkRT0Cy8', 'sg:$wVJJm-TLQ6il0h68B5rzA97t20lkmGMK7H0O6YdHEMM'); +INSERT INTO public.event_state_groups (event_id, state_group_id) VALUES ('$WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA', 'sg:$WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA'); +INSERT INTO public.event_state_groups (event_id, state_group_id) VALUES ('$gEZRQzCXH4iD07nDrZYaWlyfDmS0tqK_R-gW6JyF32U', 'sg:$gEZRQzCXH4iD07nDrZYaWlyfDmS0tqK_R-gW6JyF32U'); +INSERT INTO public.event_state_groups (event_id, state_group_id) VALUES ('$PecG6aWhB2mDCM6YMk8crHbTdYzWkYUCN_ipzlMCjiI', 'sg:$PecG6aWhB2mDCM6YMk8crHbTdYzWkYUCN_ipzlMCjiI'); +INSERT INTO public.event_state_groups (event_id, state_group_id) VALUES ('$2oC-K1LNKA47eO1pqEmJrY0s6617pjOSdk68k5LiuZg', 'sg:$2oC-K1LNKA47eO1pqEmJrY0s6617pjOSdk68k5LiuZg'); +INSERT INTO public.event_state_groups (event_id, state_group_id) VALUES ('$V6yysmqZ0o9qaJiimEfXi0Ku7kIFtR9hCAC7vGSowuY', 'sg:$V6yysmqZ0o9qaJiimEfXi0Ku7kIFtR9hCAC7vGSowuY'); +INSERT INTO public.event_state_groups (event_id, state_group_id) VALUES ('$Lft2RjGrEuDUm8UkT3X25KYA1_81FeaFlJVeWLq8UdM', 'sg:$Lft2RjGrEuDUm8UkT3X25KYA1_81FeaFlJVeWLq8UdM'); +INSERT INTO public.event_state_groups (event_id, state_group_id) VALUES ('$MDEmZSZMMOOQUjEQxIXi05XzoHayhwFR6YRDMOykvoI', 'sg:$MDEmZSZMMOOQUjEQxIXi05XzoHayhwFR6YRDMOykvoI'); +INSERT INTO public.event_state_groups (event_id, state_group_id) VALUES ('$G6T266qKoHUbMYlVFKPN14wSCrqcj7ktb84OYLky32M', 'sg:$G6T266qKoHUbMYlVFKPN14wSCrqcj7ktb84OYLky32M'); + + +-- +-- Data for Name: event_stream_watermark; Type: TABLE DATA; Schema: public; Owner: - +-- + +INSERT INTO public.event_stream_watermark (singleton, watermark) VALUES (1, '26'); + + +-- +-- Data for Name: events; Type: TABLE DATA; Schema: public; Owner: - +-- + +INSERT INTO public.events (event_id, room_id, sender_user_id, json, depth, stream_ordering, status) VALUES ('$C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', '!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', '@alice:example.org', '{"auth_events":[],"content":{"room_version":"12"},"depth":1,"hashes":{"sha256":"ukIzSXsuaLcnKGrLS+GZdhoFOlOuSA/0UMlSw9nrgzA"},"origin_server_ts":1794844863448,"prev_events":[],"sender":"@alice:example.org","signatures":{"example.org":{"ed25519:76d6613f":"3frnQABSc2K4/37LcTVL4b0IiCRWhvkzuxzVTSqRQtpaIDqIx1gfPNtaqD6tflS6HbHGDQFvKHeuEZOk1gY9AQ"}},"state_key":"","type":"m.room.create"}', '1', '1', 'accepted'); +INSERT INTO public.events (event_id, room_id, sender_user_id, json, depth, stream_ordering, status) VALUES ('$iLFuDk8nVttbD9AqXn1viyXUEFEl_2DI7hsgkXGjXN8', '!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', '@alice:example.org', '{"auth_events":[],"content":{"displayname":"Alice Upgrade","membership":"join"},"depth":2,"hashes":{"sha256":"8A2gIEu0GzYtN2aGqWDl39PwQM7Xf9qsTKGnUiCziOo"},"origin_server_ts":1794844863452,"prev_events":["$C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY"],"room_id":"!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY","sender":"@alice:example.org","signatures":{"example.org":{"ed25519:76d6613f":"jFuZOKy4ewxJYHWCb9SKxDFhKaVUFBCBq8NQtFnYD+UKtyEVzioaDqEfRS75XpBf+eJf30pei2wi5QO507mNAg"}},"state_key":"@alice:example.org","type":"m.room.member"}', '2', '2', 'accepted'); +INSERT INTO public.events (event_id, room_id, sender_user_id, json, depth, stream_ordering, status) VALUES ('$i5rP6Kab--xLmDcMSPRUZxvyQZcPThTiofJjfrSnDtg', '!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', '@alice:example.org', '{"auth_events":["$iLFuDk8nVttbD9AqXn1viyXUEFEl_2DI7hsgkXGjXN8"],"content":{"ban":50,"events":{"m.room.tombstone":150},"events_default":0,"invite":50,"kick":50,"redact":50,"state_default":50,"users":{},"users_default":0},"depth":3,"hashes":{"sha256":"FtybYJrEQHsaBRUNVnvseKDUPMdqpQ5MrijDyGn/dFU"},"origin_server_ts":1794844863455,"prev_events":["$iLFuDk8nVttbD9AqXn1viyXUEFEl_2DI7hsgkXGjXN8"],"room_id":"!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY","sender":"@alice:example.org","signatures":{"example.org":{"ed25519:76d6613f":"9Ya2JwLzuQDA1nZrZKnvbCwYLx7v6BtdoRXKatBWFSMC6aXktuxuMiazcc/2qntlcZDRvHAM+eJKVpPoMscVDQ"}},"state_key":"","type":"m.room.power_levels"}', '3', '4', 'accepted'); +INSERT INTO public.events (event_id, room_id, sender_user_id, json, depth, stream_ordering, status) VALUES ('$v4aPwfsZiQ4yEz5-T0kS_DWvVTqUxPRltYSFV4P8Jlk', '!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', '@alice:example.org', '{"auth_events":["$iLFuDk8nVttbD9AqXn1viyXUEFEl_2DI7hsgkXGjXN8","$i5rP6Kab--xLmDcMSPRUZxvyQZcPThTiofJjfrSnDtg"],"content":{"join_rule":"invite"},"depth":4,"hashes":{"sha256":"X0Afy9IeLAyzLieQ3+gaXSiYv7EgExqMxVdC00dKZ9E"},"origin_server_ts":1794844863457,"prev_events":["$i5rP6Kab--xLmDcMSPRUZxvyQZcPThTiofJjfrSnDtg"],"room_id":"!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY","sender":"@alice:example.org","signatures":{"example.org":{"ed25519:76d6613f":"LWYtQ01lNNgR6yxoy4iVxydEYTXAydCCNZU9Lo5QJCd8hhov30fNObIMeCpQkjWynhKc+xFsj0cWMUiv7Gh+Bw"}},"state_key":"","type":"m.room.join_rules"}', '4', '5', 'accepted'); +INSERT INTO public.events (event_id, room_id, sender_user_id, json, depth, stream_ordering, status) VALUES ('$jQRkJoCECH7wDkXeK4PAzuiNM5N4-W-klgkSyuKI0Ig', '!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', '@alice:example.org', '{"auth_events":["$iLFuDk8nVttbD9AqXn1viyXUEFEl_2DI7hsgkXGjXN8","$i5rP6Kab--xLmDcMSPRUZxvyQZcPThTiofJjfrSnDtg"],"content":{"history_visibility":"shared"},"depth":5,"hashes":{"sha256":"eDH3ElCu4q1EVxOIlwnLXIEWwLP8QD64jdQJwmRXt68"},"origin_server_ts":1794844863459,"prev_events":["$v4aPwfsZiQ4yEz5-T0kS_DWvVTqUxPRltYSFV4P8Jlk"],"room_id":"!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY","sender":"@alice:example.org","signatures":{"example.org":{"ed25519:76d6613f":"zpusmcvsriZtMqnVBtMI0uFKTGFNMqHkC9tIR00WJAFTTqnl5n+wpEyypeFxhuR6JJMZLZp2kPbVEny0xikhCw"}},"state_key":"","type":"m.room.history_visibility"}', '5', '6', 'accepted'); +INSERT INTO public.events (event_id, room_id, sender_user_id, json, depth, stream_ordering, status) VALUES ('$3DxD43IUhKnopg81UbujM_TWm14GdVq22XKXiThD5Bo', '!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', '@alice:example.org', '{"auth_events":["$iLFuDk8nVttbD9AqXn1viyXUEFEl_2DI7hsgkXGjXN8","$i5rP6Kab--xLmDcMSPRUZxvyQZcPThTiofJjfrSnDtg"],"content":{"guest_access":"can_join"},"depth":6,"hashes":{"sha256":"d3Vm0bnFOKntl1bI6w02yiF8/91+SGx8FuNg46lmu4g"},"origin_server_ts":1794844863461,"prev_events":["$jQRkJoCECH7wDkXeK4PAzuiNM5N4-W-klgkSyuKI0Ig"],"room_id":"!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY","sender":"@alice:example.org","signatures":{"example.org":{"ed25519:76d6613f":"Ox1jSZc8TlPxsi51n4x39UKVR2O/bDtKtgaHxXd2bo1J5ezwy9aOpezQoSGX8cGa5RARdnR2r9N/he0XmisnCg"}},"state_key":"","type":"m.room.guest_access"}', '6', '7', 'accepted'); +INSERT INTO public.events (event_id, room_id, sender_user_id, json, depth, stream_ordering, status) VALUES ('$LQujV90cKOa8fkPPU4PQX7sm6KL28V0r8nKCewBnOJ8', '!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', '@alice:example.org', '{"auth_events":["$iLFuDk8nVttbD9AqXn1viyXUEFEl_2DI7hsgkXGjXN8","$i5rP6Kab--xLmDcMSPRUZxvyQZcPThTiofJjfrSnDtg"],"content":{"algorithm":"m.megolm.v1.aes-sha2"},"depth":7,"hashes":{"sha256":"4CelsPBgavq/meNLZT9RkEarQ3D6DXTkVZFIwDBug60"},"origin_server_ts":1794844863464,"prev_events":["$3DxD43IUhKnopg81UbujM_TWm14GdVq22XKXiThD5Bo"],"room_id":"!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY","sender":"@alice:example.org","signatures":{"example.org":{"ed25519:76d6613f":"yey6hQSQYCBHDCovmGoILewHu58iLc3K8LlA95SmhOA5yH4/f4Auo2oGmwBKCNOLQ2L8bbqUzynWoyZy0OYqAA"}},"state_key":"","type":"m.room.encryption"}', '7', '8', 'accepted'); +INSERT INTO public.events (event_id, room_id, sender_user_id, json, depth, stream_ordering, status) VALUES ('$RDqWCB4mWm4fTct25NtZAh5zmiUTG_EsgfQpCS2erxw', '!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', '@alice:example.org', '{"auth_events":["$iLFuDk8nVttbD9AqXn1viyXUEFEl_2DI7hsgkXGjXN8","$i5rP6Kab--xLmDcMSPRUZxvyQZcPThTiofJjfrSnDtg"],"content":{"name":"Upgrade Room"},"depth":8,"hashes":{"sha256":"6NStMj7U7YomSwV7ENPL+MBSSxVBCP0qPBVo51PAm54"},"origin_server_ts":1794844863466,"prev_events":["$LQujV90cKOa8fkPPU4PQX7sm6KL28V0r8nKCewBnOJ8"],"room_id":"!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY","sender":"@alice:example.org","signatures":{"example.org":{"ed25519:76d6613f":"gfX0vOva648wvwThP7IggMyqxCksfZjo7mPmH+9/RE3lyf8RaQaH2GQKGB6Ad9nbuDl0H+8hPUeDfGIw3E3dDQ"}},"state_key":"","type":"m.room.name"}', '8', '9', 'accepted'); +INSERT INTO public.events (event_id, room_id, sender_user_id, json, depth, stream_ordering, status) VALUES ('$QzTeY37FC1XCBCS9k5WSqtd_ozVW1B45OBvMLOxOFRY', '!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', '@alice:example.org', '{"auth_events":["$iLFuDk8nVttbD9AqXn1viyXUEFEl_2DI7hsgkXGjXN8","$i5rP6Kab--xLmDcMSPRUZxvyQZcPThTiofJjfrSnDtg","$v4aPwfsZiQ4yEz5-T0kS_DWvVTqUxPRltYSFV4P8Jlk"],"content":{"membership":"invite"},"depth":9,"hashes":{"sha256":"sjUHm4r1CbS/JXJwBwbQUGIV7/0M53udfCPcYviFkF0"},"origin_server_ts":1794844863469,"prev_events":["$RDqWCB4mWm4fTct25NtZAh5zmiUTG_EsgfQpCS2erxw"],"room_id":"!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY","sender":"@alice:example.org","signatures":{"example.org":{"ed25519:76d6613f":"bRSdsgOyEaKnxNVQTbr+CSm4IZTkJ7S82mbptEc+mt6ywg2gYpqNKXbWdGskABIYoH66floDHymiT3RnAJwZCA"}},"state_key":"@bob:example.org","type":"m.room.member"}', '9', '10', 'accepted'); +INSERT INTO public.events (event_id, room_id, sender_user_id, json, depth, stream_ordering, status) VALUES ('$wVJJm-TLQ6il0h68B5rzA97t20lkmGMK7H0O6YdHEMM', '!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', '@bob:example.org', '{"auth_events":["$i5rP6Kab--xLmDcMSPRUZxvyQZcPThTiofJjfrSnDtg","$v4aPwfsZiQ4yEz5-T0kS_DWvVTqUxPRltYSFV4P8Jlk","$QzTeY37FC1XCBCS9k5WSqtd_ozVW1B45OBvMLOxOFRY"],"content":{"membership":"join"},"depth":10,"hashes":{"sha256":"YHZrm5GlQ1gT6uJDyj4JRyVUKnBbaNc5asBNz33ioms"},"origin_server_ts":1794844863475,"prev_events":["$QzTeY37FC1XCBCS9k5WSqtd_ozVW1B45OBvMLOxOFRY"],"room_id":"!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY","sender":"@bob:example.org","signatures":{"example.org":{"ed25519:76d6613f":"cz1hP8TbklKANszH+xcEbfBx/FS9eh5fxN4Hwnjxdn8qtRCL6hP77BAp6sF2FmlG7P8pkoOq8v7w76J0udX1Ag"}},"state_key":"@bob:example.org","type":"m.room.member"}', '10', '12', 'accepted'); +INSERT INTO public.events (event_id, room_id, sender_user_id, json, depth, stream_ordering, status) VALUES ('$gbIXT6cBYsLvEAdCmvz_-Z-MLge4BnaLY_O1-PtdjGo', '!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', '@alice:example.org', '{"auth_events":["$iLFuDk8nVttbD9AqXn1viyXUEFEl_2DI7hsgkXGjXN8","$i5rP6Kab--xLmDcMSPRUZxvyQZcPThTiofJjfrSnDtg"],"content":{"body":"upgrade message 1","msgtype":"m.text"},"depth":11,"hashes":{"sha256":"Vl/8CSiisu6XsaNl3H27wdujyobKJhrB1SBq7fSsscc"},"origin_server_ts":1794844863480,"prev_events":["$wVJJm-TLQ6il0h68B5rzA97t20lkmGMK7H0O6YdHEMM"],"room_id":"!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY","sender":"@alice:example.org","signatures":{"example.org":{"ed25519:76d6613f":"QXpHWG51uFHmhLxnCvfM+bvpKTtmqVSsltF1/q7wQlpBoQmaLaPiRBhtCTVHOxvET/4Q7RlqhhD2Bfam/ZEUAw"}},"type":"m.room.message"}', '11', '14', 'accepted'); +INSERT INTO public.events (event_id, room_id, sender_user_id, json, depth, stream_ordering, status) VALUES ('$mC5T62vlKtDEaC4l1ujmOJ3dA5q-PM-ku8SS1xRZCek', '!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', '@alice:example.org', '{"auth_events":["$iLFuDk8nVttbD9AqXn1viyXUEFEl_2DI7hsgkXGjXN8","$i5rP6Kab--xLmDcMSPRUZxvyQZcPThTiofJjfrSnDtg"],"content":{"body":"upgrade message 2","msgtype":"m.text"},"depth":12,"hashes":{"sha256":"vdLJp+90spZ3AZRQ2IAMLvitqfNC/h25ABSoubMLW9o"},"origin_server_ts":1794844863484,"prev_events":["$gbIXT6cBYsLvEAdCmvz_-Z-MLge4BnaLY_O1-PtdjGo"],"room_id":"!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY","sender":"@alice:example.org","signatures":{"example.org":{"ed25519:76d6613f":"qFvolB96ql4o6ApfoP+SWYcMbDI7FfQYa7qKiFwgM8LcdTtIL9unkj0bi3+a2b1Z/G8G+PdF+Q4CixMfkFNEDg"}},"type":"m.room.message"}', '12', '15', 'accepted'); +INSERT INTO public.events (event_id, room_id, sender_user_id, json, depth, stream_ordering, status) VALUES ('$h7M6qztmLUOCjFAmWrrrh-vd87KuCykZl7jvFLSK3Ds', '!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', '@alice:example.org', '{"auth_events":["$iLFuDk8nVttbD9AqXn1viyXUEFEl_2DI7hsgkXGjXN8","$i5rP6Kab--xLmDcMSPRUZxvyQZcPThTiofJjfrSnDtg"],"content":{"body":"upgrade message 3","msgtype":"m.text"},"depth":13,"hashes":{"sha256":"9E410+O1F9fy18uEx0d+xHruRsFgt79awbugTv5iqvo"},"origin_server_ts":1794844863488,"prev_events":["$mC5T62vlKtDEaC4l1ujmOJ3dA5q-PM-ku8SS1xRZCek"],"room_id":"!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY","sender":"@alice:example.org","signatures":{"example.org":{"ed25519:76d6613f":"jVD/fxDVi44OlM0xryZwEeZkV+OQq4C/qvY2oSB6hTaQtq2UPfKYQcdy8fJGi0mAGtbGPSeKCBl0rqmkd53uAw"}},"type":"m.room.message"}', '13', '16', 'accepted'); +INSERT INTO public.events (event_id, room_id, sender_user_id, json, depth, stream_ordering, status) VALUES ('$GcOCV1AahAZenbnTVGpvMmYTyB2XNFzhRLwjkRT0Cy8', '!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', '@bob:example.org', '{"auth_events":["$i5rP6Kab--xLmDcMSPRUZxvyQZcPThTiofJjfrSnDtg","$wVJJm-TLQ6il0h68B5rzA97t20lkmGMK7H0O6YdHEMM"],"content":{"body":"reply from bob","msgtype":"m.text"},"depth":14,"hashes":{"sha256":"8BHGFi/vfvzAQvL8UvYZHq01NV4hWo+xXY9IW8vqrNg"},"origin_server_ts":1794844863491,"prev_events":["$h7M6qztmLUOCjFAmWrrrh-vd87KuCykZl7jvFLSK3Ds"],"room_id":"!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY","sender":"@bob:example.org","signatures":{"example.org":{"ed25519:76d6613f":"0Ej0RJCDtIzH5ISMF6PKtdBQKl20J5E1Tq5Ud9dSJVxuh7Xc9zt1R2p1eTdYnaEKMqRSelx1DmE5AarEdFG8CA"}},"type":"m.room.message"}', '14', '17', 'accepted'); +INSERT INTO public.events (event_id, room_id, sender_user_id, json, depth, stream_ordering, status) VALUES ('$WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA', '!WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA', '@alice:example.org', '{"auth_events":[],"content":{"room_version":"12"},"depth":1,"hashes":{"sha256":"amReiy3Oq8u2hvqvO5WU0J45yPU/Z4CnJUyWy3xXlNc"},"origin_server_ts":1794844863495,"prev_events":[],"sender":"@alice:example.org","signatures":{"example.org":{"ed25519:76d6613f":"0kLHXj9ow1MkrnOT1KYeb69Hdk/W0uDxZhTNw4Nz0YHODNfKcHqCsZ1yGJLA4vE2EaC8QBfaekTd9Fq+kALTBw"}},"state_key":"","type":"m.room.create"}', '1', '18', 'accepted'); +INSERT INTO public.events (event_id, room_id, sender_user_id, json, depth, stream_ordering, status) VALUES ('$gEZRQzCXH4iD07nDrZYaWlyfDmS0tqK_R-gW6JyF32U', '!WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA', '@alice:example.org', '{"auth_events":[],"content":{"displayname":"Alice Upgrade","membership":"join"},"depth":2,"hashes":{"sha256":"rtx4neMEAic2lzzpqx49fl+VBIvCEvL7sPKT5KtE7Ls"},"origin_server_ts":1794844863497,"prev_events":["$WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA"],"room_id":"!WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA","sender":"@alice:example.org","signatures":{"example.org":{"ed25519:76d6613f":"9bfA6431NNhLsvcAJ0dRJ4Ruqql1cFl6A7XmwaBLT2CQNji5Xpd/+HczGIT4E+Kft0IIkH8FfrdHUETK/IaRCw"}},"state_key":"@alice:example.org","type":"m.room.member"}', '2', '19', 'accepted'); +INSERT INTO public.events (event_id, room_id, sender_user_id, json, depth, stream_ordering, status) VALUES ('$PecG6aWhB2mDCM6YMk8crHbTdYzWkYUCN_ipzlMCjiI', '!WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA', '@alice:example.org', '{"auth_events":["$gEZRQzCXH4iD07nDrZYaWlyfDmS0tqK_R-gW6JyF32U"],"content":{"ban":50,"events":{"m.room.tombstone":150},"events_default":0,"invite":50,"kick":50,"redact":50,"state_default":50,"users":{},"users_default":0},"depth":3,"hashes":{"sha256":"yZDVwHFW+YhhT1biiT35RacPmcxSWcuu2J8QXUdf/lw"},"origin_server_ts":1794844863500,"prev_events":["$gEZRQzCXH4iD07nDrZYaWlyfDmS0tqK_R-gW6JyF32U"],"room_id":"!WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA","sender":"@alice:example.org","signatures":{"example.org":{"ed25519:76d6613f":"j/PZ2/oF/fNiLaXx44nkSEg4AN7HgpdD66Y1gsPkmLQKRNJBwHl4SPodxJy0Dsc3nWgwqJfFOqlZH/a5JwGDCg"}},"state_key":"","type":"m.room.power_levels"}', '3', '21', 'accepted'); +INSERT INTO public.events (event_id, room_id, sender_user_id, json, depth, stream_ordering, status) VALUES ('$2oC-K1LNKA47eO1pqEmJrY0s6617pjOSdk68k5LiuZg', '!WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA', '@alice:example.org', '{"auth_events":["$gEZRQzCXH4iD07nDrZYaWlyfDmS0tqK_R-gW6JyF32U","$PecG6aWhB2mDCM6YMk8crHbTdYzWkYUCN_ipzlMCjiI"],"content":{"alias":"#upgrade-public:example.org"},"depth":4,"hashes":{"sha256":"AtPWemAN0xoJA3FQ4zN3a+LcfNHs9Lq/5LhFox/Wx30"},"origin_server_ts":1794844863502,"prev_events":["$PecG6aWhB2mDCM6YMk8crHbTdYzWkYUCN_ipzlMCjiI"],"room_id":"!WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA","sender":"@alice:example.org","signatures":{"example.org":{"ed25519:76d6613f":"itC4d6HfjT7XS9dOyL5PyP8e0s7hv6EwfBHNT8oH8bHS70+Xo+Zt8jeRFYZtYsdm6DTqYRdiVTrDL6q6msvtAg"}},"state_key":"","type":"m.room.canonical_alias"}', '4', '22', 'accepted'); +INSERT INTO public.events (event_id, room_id, sender_user_id, json, depth, stream_ordering, status) VALUES ('$V6yysmqZ0o9qaJiimEfXi0Ku7kIFtR9hCAC7vGSowuY', '!WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA', '@alice:example.org', '{"auth_events":["$gEZRQzCXH4iD07nDrZYaWlyfDmS0tqK_R-gW6JyF32U","$PecG6aWhB2mDCM6YMk8crHbTdYzWkYUCN_ipzlMCjiI"],"content":{"join_rule":"public"},"depth":5,"hashes":{"sha256":"tlurMOyhg28NSfFRtQWAAG/PMbgA8PyNKNxhQ4Cfpwk"},"origin_server_ts":1794844863504,"prev_events":["$2oC-K1LNKA47eO1pqEmJrY0s6617pjOSdk68k5LiuZg"],"room_id":"!WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA","sender":"@alice:example.org","signatures":{"example.org":{"ed25519:76d6613f":"20xjkZeHqAE/2mlNEwtqENmyEusYotibPGAPn0A3ntL90O1t33MYoyWHL9baYuHCglqtxIVPyAXYptllhVZxAA"}},"state_key":"","type":"m.room.join_rules"}', '5', '23', 'accepted'); +INSERT INTO public.events (event_id, room_id, sender_user_id, json, depth, stream_ordering, status) VALUES ('$Lft2RjGrEuDUm8UkT3X25KYA1_81FeaFlJVeWLq8UdM', '!WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA', '@alice:example.org', '{"auth_events":["$gEZRQzCXH4iD07nDrZYaWlyfDmS0tqK_R-gW6JyF32U","$PecG6aWhB2mDCM6YMk8crHbTdYzWkYUCN_ipzlMCjiI"],"content":{"history_visibility":"shared"},"depth":6,"hashes":{"sha256":"mdMuLqxz219YJ/n0NZRO685BByJ8U3pP1dXf8KV9dv8"},"origin_server_ts":1794844863507,"prev_events":["$V6yysmqZ0o9qaJiimEfXi0Ku7kIFtR9hCAC7vGSowuY"],"room_id":"!WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA","sender":"@alice:example.org","signatures":{"example.org":{"ed25519:76d6613f":"tEAp2KuW8C+AVb18hpUq6FF3kQ1U75ayzWMPUx/DHPipAfajQ6MnQe8Ts3gqIo6MJg5ZXe9T6ASN2MPAQ7qFDg"}},"state_key":"","type":"m.room.history_visibility"}', '6', '24', 'accepted'); +INSERT INTO public.events (event_id, room_id, sender_user_id, json, depth, stream_ordering, status) VALUES ('$MDEmZSZMMOOQUjEQxIXi05XzoHayhwFR6YRDMOykvoI', '!WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA', '@alice:example.org', '{"auth_events":["$gEZRQzCXH4iD07nDrZYaWlyfDmS0tqK_R-gW6JyF32U","$PecG6aWhB2mDCM6YMk8crHbTdYzWkYUCN_ipzlMCjiI"],"content":{"guest_access":"forbidden"},"depth":7,"hashes":{"sha256":"inDn0YnyX8TXjn6JrzQSjTXUq1S4o5LOOqr66VRdIHo"},"origin_server_ts":1794844863509,"prev_events":["$Lft2RjGrEuDUm8UkT3X25KYA1_81FeaFlJVeWLq8UdM"],"room_id":"!WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA","sender":"@alice:example.org","signatures":{"example.org":{"ed25519:76d6613f":"fB5PjFjkA/TR7+hXy8/+MQeWh5VRA+aGLS+6Q2zHL2pGCBLPS+cX1+jqlweSKifxGnWtOM8tPH6GZhZ3BFXDCw"}},"state_key":"","type":"m.room.guest_access"}', '7', '25', 'accepted'); +INSERT INTO public.events (event_id, room_id, sender_user_id, json, depth, stream_ordering, status) VALUES ('$G6T266qKoHUbMYlVFKPN14wSCrqcj7ktb84OYLky32M', '!WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA', '@alice:example.org', '{"auth_events":["$gEZRQzCXH4iD07nDrZYaWlyfDmS0tqK_R-gW6JyF32U","$PecG6aWhB2mDCM6YMk8crHbTdYzWkYUCN_ipzlMCjiI"],"content":{"name":"Upgrade Public"},"depth":8,"hashes":{"sha256":"qloB0h2f4DXFVXg3IEA5Kn83TU386BH5OIXAOJ7/D2U"},"origin_server_ts":1794844863512,"prev_events":["$MDEmZSZMMOOQUjEQxIXi05XzoHayhwFR6YRDMOykvoI"],"room_id":"!WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA","sender":"@alice:example.org","signatures":{"example.org":{"ed25519:76d6613f":"yCI4HRCLRor9+l4NIlnbUWiiel/Fn1WhOMsSeRQVn9RTV3zOn2DAlTKaFDyTz8NeBM/B9hcb1UGLVtWDMBiGCQ"}},"state_key":"","type":"m.room.name"}', '8', '26', 'accepted'); + + +-- +-- Data for Name: fallback_keys; Type: TABLE DATA; Schema: public; Owner: - +-- + + + +-- +-- Data for Name: federation_destinations; Type: TABLE DATA; Schema: public; Owner: - +-- + + + +-- +-- Data for Name: federation_transactions; Type: TABLE DATA; Schema: public; Owner: - +-- + + + +-- +-- Data for Name: filters; Type: TABLE DATA; Schema: public; Owner: - +-- + + + +-- +-- Data for Name: forward_extremities; Type: TABLE DATA; Schema: public; Owner: - +-- + +INSERT INTO public.forward_extremities (room_id, event_id) VALUES ('!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', '$GcOCV1AahAZenbnTVGpvMmYTyB2XNFzhRLwjkRT0Cy8'); +INSERT INTO public.forward_extremities (room_id, event_id) VALUES ('!WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA', '$G6T266qKoHUbMYlVFKPN14wSCrqcj7ktb84OYLky32M'); + + +-- +-- Data for Name: invites; Type: TABLE DATA; Schema: public; Owner: - +-- + + + +-- +-- Data for Name: key_backup_sessions; Type: TABLE DATA; Schema: public; Owner: - +-- + + + +-- +-- Data for Name: key_backup_version_counters; Type: TABLE DATA; Schema: public; Owner: - +-- + + + +-- +-- Data for Name: key_backup_versions; Type: TABLE DATA; Schema: public; Owner: - +-- + + + +-- +-- Data for Name: key_backups; Type: TABLE DATA; Schema: public; Owner: - +-- + + + +-- +-- Data for Name: key_signatures; Type: TABLE DATA; Schema: public; Owner: - +-- + + + +-- +-- Data for Name: login_tokens; Type: TABLE DATA; Schema: public; Owner: - +-- + + + +-- +-- Data for Name: media; Type: TABLE DATA; Schema: public; Owner: - +-- + +INSERT INTO public.media (media_id, owner_user_id, content_type, size_bytes, hash_algorithm, digest, quarantined, removed, legacy_endpoint_visible, upload_name) VALUES ('eu-rBrEY7MSJKUy6o7pmMw', '@alice:example.org', 'text/plain', '340', 'blake2b', '9070012d53f92cf3bbfd1c8987cb29cf9ba6d7b9804e90883c9912e0e6c83288', 'false', 'false', 'false', 'upgrade-fixture.txt'); + + +-- +-- Data for Name: media_blobs; Type: TABLE DATA; Schema: public; Owner: - +-- + +INSERT INTO public.media_blobs (storage_id, hash_algorithm, digest, size_bytes, bytes, ref_count) VALUES ('blob_9070012d53f92cf3bbfd1c8987cb29cf9ba6d7b9804e90883c9912e0e6c83288_340', 'blake2b', '9070012d53f92cf3bbfd1c8987cb29cf9ba6d7b9804e90883c9912e0e6c83288', '340', '\x6d65726f76696e6769616e20757067726164652066697874757265206d656469610a6d65726f76696e6769616e20757067726164652066697874757265206d656469610a6d65726f76696e6769616e20757067726164652066697874757265206d656469610a6d65726f76696e6769616e20757067726164652066697874757265206d656469610a6d65726f76696e6769616e20757067726164652066697874757265206d656469610a6d65726f76696e6769616e20757067726164652066697874757265206d656469610a6d65726f76696e6769616e20757067726164652066697874757265206d656469610a6d65726f76696e6769616e20757067726164652066697874757265206d656469610a6d65726f76696e6769616e20757067726164652066697874757265206d656469610a6d65726f76696e6769616e20757067726164652066697874757265206d656469610a', '1'); + + +-- +-- Data for Name: media_pending_uploads; Type: TABLE DATA; Schema: public; Owner: - +-- + + + +-- +-- Data for Name: membership; Type: TABLE DATA; Schema: public; Owner: - +-- + +INSERT INTO public.membership (room_id, user_id, membership, stream_ordering) VALUES ('!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', '@alice:example.org', 'join', '3'); +INSERT INTO public.membership (room_id, user_id, membership, stream_ordering) VALUES ('!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', '@bob:example.org', 'join', '13'); +INSERT INTO public.membership (room_id, user_id, membership, stream_ordering) VALUES ('!WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA', '@alice:example.org', 'join', '20'); + + +-- +-- Data for Name: notifications; Type: TABLE DATA; Schema: public; Owner: - +-- + +INSERT INTO public.notifications (user_id, room_id, event_id, stream_ordering, ts, actions, profile_tag, highlight) VALUES ('@bob:example.org', '!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', '$QzTeY37FC1XCBCS9k5WSqtd_ozVW1B45OBvMLOxOFRY', '10', '1794844863469', '["notify",{"set_tweak":"sound","value":"default"}]', '', 'false'); +INSERT INTO public.notifications (user_id, room_id, event_id, stream_ordering, ts, actions, profile_tag, highlight) VALUES ('@bob:example.org', '!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', '$gbIXT6cBYsLvEAdCmvz_-Z-MLge4BnaLY_O1-PtdjGo', '14', '1794844863480', '["notify",{"set_tweak":"sound","value":"default"}]', '', 'false'); +INSERT INTO public.notifications (user_id, room_id, event_id, stream_ordering, ts, actions, profile_tag, highlight) VALUES ('@bob:example.org', '!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', '$mC5T62vlKtDEaC4l1ujmOJ3dA5q-PM-ku8SS1xRZCek', '15', '1794844863484', '["notify",{"set_tweak":"sound","value":"default"}]', '', 'false'); +INSERT INTO public.notifications (user_id, room_id, event_id, stream_ordering, ts, actions, profile_tag, highlight) VALUES ('@bob:example.org', '!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', '$h7M6qztmLUOCjFAmWrrrh-vd87KuCykZl7jvFLSK3Ds', '16', '1794844863488', '["notify",{"set_tweak":"sound","value":"default"}]', '', 'false'); +INSERT INTO public.notifications (user_id, room_id, event_id, stream_ordering, ts, actions, profile_tag, highlight) VALUES ('@alice:example.org', '!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', '$GcOCV1AahAZenbnTVGpvMmYTyB2XNFzhRLwjkRT0Cy8', '17', '1794844863491', '["notify",{"set_tweak":"sound","value":"default"}]', '', 'false'); + + +-- +-- Data for Name: one_time_keys; Type: TABLE DATA; Schema: public; Owner: - +-- + +INSERT INTO public.one_time_keys (user_id, device_id, key_id, json) VALUES ('@alice:example.org', 'UPGRADE1', 'signed_curve25519:AAAAAQ', '{"key":"0kBH0U8cIYy+UylyqqSe4teHLhfX/hYBgpiZZlNp4zk","signatures":{"@alice:example.org":{"ed25519:UPGRADE1":"kAxIom4YQ7T7Q2laPSclXDUngDWrsn4yPReEKDnH+1YVJhB2s8Mdy3x4YtyxOMw8e1c/K6C2UeGeeSyOXuS6CA"}}}'); + + +-- +-- Data for Name: openid_tokens; Type: TABLE DATA; Schema: public; Owner: - +-- + + + +-- +-- Data for Name: policy_rules; Type: TABLE DATA; Schema: public; Owner: - +-- + + + +-- +-- Data for Name: presence_state; Type: TABLE DATA; Schema: public; Owner: - +-- + +INSERT INTO public.presence_state (user_id, stream_id, presence, status_msg, last_active_ago, currently_active) VALUES ('@alice:example.org', '11', 'online', '', '0', 'true'); + + +-- +-- Data for Name: profiles; Type: TABLE DATA; Schema: public; Owner: - +-- + +INSERT INTO public.profiles (user_id, displayname, avatar_url, fields_json) VALUES ('@bob:example.org', '', '', '{}'); +INSERT INTO public.profiles (user_id, displayname, avatar_url, fields_json) VALUES ('@alice:example.org', 'Alice Upgrade', '', '{}'); + + +-- +-- Data for Name: push_rules; Type: TABLE DATA; Schema: public; Owner: - +-- + + + +-- +-- Data for Name: pushers; Type: TABLE DATA; Schema: public; Owner: - +-- + +INSERT INTO public.pushers (user_id, app_id, pushkey, kind, app_display_name, device_display_name, profile_tag, lang, data_url, data_format, data_extra_json, device_id) VALUES ('@alice:example.org', 'org.merovingian.upgrade', 'upgrade-pushkey', 'http', 'Upgrade Fixture App', 'Upgrade Fixture Device', '', 'en', 'https://push.example.org/_matrix/push/v1/notify', '', '', 'UPGRADE1'); + + +-- +-- Data for Name: rate_limits; Type: TABLE DATA; Schema: public; Owner: - +-- + + + +-- +-- Data for Name: receipts; Type: TABLE DATA; Schema: public; Owner: - +-- + + + +-- +-- Data for Name: refresh_tokens; Type: TABLE DATA; Schema: public; Owner: - +-- + + + +-- +-- Data for Name: remote_media; Type: TABLE DATA; Schema: public; Owner: - +-- + + + +-- +-- Data for Name: room_account_data; Type: TABLE DATA; Schema: public; Owner: - +-- + + + +-- +-- Data for Name: room_aliases; Type: TABLE DATA; Schema: public; Owner: - +-- + +INSERT INTO public.room_aliases (room_alias, room_id, creator_user_id) VALUES ('#upgrade-public:example.org', '!WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA', '@alice:example.org'); + + +-- +-- Data for Name: room_versions; Type: TABLE DATA; Schema: public; Owner: - +-- + + + +-- +-- Data for Name: rooms; Type: TABLE DATA; Schema: public; Owner: - +-- + +INSERT INTO public.rooms (room_id, creator_user_id, directory_public) VALUES ('!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', '@alice:example.org', 'false'); +INSERT INTO public.rooms (room_id, creator_user_id, directory_public) VALUES ('!WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA', '@alice:example.org', 'true'); + + +-- +-- Data for Name: schema_migrations; Type: TABLE DATA; Schema: public; Owner: - +-- + +INSERT INTO public.schema_migrations (version, name, direction) VALUES ('1', 'initial_schema', 'upgrade'); + + +-- +-- Data for Name: server_signing_keys; Type: TABLE DATA; Schema: public; Owner: - +-- + +INSERT INTO public.server_signing_keys (server_name, key_id, public_key, valid_until_ts, secret_key, expired_ts) VALUES ('example.org', 'ed25519:76d6613f', 'dtZhP3rtHU2B+6kXQ1k+RAaRli8kwXxGvn41qUywvBs', '1795449662996', '\x736563726574626f783a76313a547949436e37714f635477584838525842785a542b7559504242395a44492f695973474c505a533072554c6963656d392b565a566b726143364d7972747532304d42324a586457696b7965304f3878316651524c4e484171364e46397530507530684b53504c556252454e395271423439454a334478524657724b6e6b4e69644665754566434b456c7851', ''); + + +-- +-- Data for Name: state_group_edges; Type: TABLE DATA; Schema: public; Owner: - +-- + + + +-- +-- Data for Name: state_group_state; Type: TABLE DATA; Schema: public; Owner: - +-- + +INSERT INTO public.state_group_state (state_group_id, event_type, state_key, event_id) VALUES ('sg:$C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', 'm.room.create', '', '$C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY'); +INSERT INTO public.state_group_state (state_group_id, event_type, state_key, event_id) VALUES ('sg:$iLFuDk8nVttbD9AqXn1viyXUEFEl_2DI7hsgkXGjXN8', 'm.room.member', '@alice:example.org', '$iLFuDk8nVttbD9AqXn1viyXUEFEl_2DI7hsgkXGjXN8'); +INSERT INTO public.state_group_state (state_group_id, event_type, state_key, event_id) VALUES ('sg:$i5rP6Kab--xLmDcMSPRUZxvyQZcPThTiofJjfrSnDtg', 'm.room.power_levels', '', '$i5rP6Kab--xLmDcMSPRUZxvyQZcPThTiofJjfrSnDtg'); +INSERT INTO public.state_group_state (state_group_id, event_type, state_key, event_id) VALUES ('sg:$v4aPwfsZiQ4yEz5-T0kS_DWvVTqUxPRltYSFV4P8Jlk', 'm.room.join_rules', '', '$v4aPwfsZiQ4yEz5-T0kS_DWvVTqUxPRltYSFV4P8Jlk'); +INSERT INTO public.state_group_state (state_group_id, event_type, state_key, event_id) VALUES ('sg:$jQRkJoCECH7wDkXeK4PAzuiNM5N4-W-klgkSyuKI0Ig', 'm.room.history_visibility', '', '$jQRkJoCECH7wDkXeK4PAzuiNM5N4-W-klgkSyuKI0Ig'); +INSERT INTO public.state_group_state (state_group_id, event_type, state_key, event_id) VALUES ('sg:$3DxD43IUhKnopg81UbujM_TWm14GdVq22XKXiThD5Bo', 'm.room.guest_access', '', '$3DxD43IUhKnopg81UbujM_TWm14GdVq22XKXiThD5Bo'); +INSERT INTO public.state_group_state (state_group_id, event_type, state_key, event_id) VALUES ('sg:$LQujV90cKOa8fkPPU4PQX7sm6KL28V0r8nKCewBnOJ8', 'm.room.encryption', '', '$LQujV90cKOa8fkPPU4PQX7sm6KL28V0r8nKCewBnOJ8'); +INSERT INTO public.state_group_state (state_group_id, event_type, state_key, event_id) VALUES ('sg:$RDqWCB4mWm4fTct25NtZAh5zmiUTG_EsgfQpCS2erxw', 'm.room.name', '', '$RDqWCB4mWm4fTct25NtZAh5zmiUTG_EsgfQpCS2erxw'); +INSERT INTO public.state_group_state (state_group_id, event_type, state_key, event_id) VALUES ('sg:$QzTeY37FC1XCBCS9k5WSqtd_ozVW1B45OBvMLOxOFRY', 'm.room.member', '@bob:example.org', '$QzTeY37FC1XCBCS9k5WSqtd_ozVW1B45OBvMLOxOFRY'); +INSERT INTO public.state_group_state (state_group_id, event_type, state_key, event_id) VALUES ('sg:$wVJJm-TLQ6il0h68B5rzA97t20lkmGMK7H0O6YdHEMM', 'm.room.member', '@bob:example.org', '$wVJJm-TLQ6il0h68B5rzA97t20lkmGMK7H0O6YdHEMM'); +INSERT INTO public.state_group_state (state_group_id, event_type, state_key, event_id) VALUES ('sg:$WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA', 'm.room.create', '', '$WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA'); +INSERT INTO public.state_group_state (state_group_id, event_type, state_key, event_id) VALUES ('sg:$gEZRQzCXH4iD07nDrZYaWlyfDmS0tqK_R-gW6JyF32U', 'm.room.member', '@alice:example.org', '$gEZRQzCXH4iD07nDrZYaWlyfDmS0tqK_R-gW6JyF32U'); +INSERT INTO public.state_group_state (state_group_id, event_type, state_key, event_id) VALUES ('sg:$PecG6aWhB2mDCM6YMk8crHbTdYzWkYUCN_ipzlMCjiI', 'm.room.power_levels', '', '$PecG6aWhB2mDCM6YMk8crHbTdYzWkYUCN_ipzlMCjiI'); +INSERT INTO public.state_group_state (state_group_id, event_type, state_key, event_id) VALUES ('sg:$2oC-K1LNKA47eO1pqEmJrY0s6617pjOSdk68k5LiuZg', 'm.room.canonical_alias', '', '$2oC-K1LNKA47eO1pqEmJrY0s6617pjOSdk68k5LiuZg'); +INSERT INTO public.state_group_state (state_group_id, event_type, state_key, event_id) VALUES ('sg:$V6yysmqZ0o9qaJiimEfXi0Ku7kIFtR9hCAC7vGSowuY', 'm.room.join_rules', '', '$V6yysmqZ0o9qaJiimEfXi0Ku7kIFtR9hCAC7vGSowuY'); +INSERT INTO public.state_group_state (state_group_id, event_type, state_key, event_id) VALUES ('sg:$Lft2RjGrEuDUm8UkT3X25KYA1_81FeaFlJVeWLq8UdM', 'm.room.history_visibility', '', '$Lft2RjGrEuDUm8UkT3X25KYA1_81FeaFlJVeWLq8UdM'); +INSERT INTO public.state_group_state (state_group_id, event_type, state_key, event_id) VALUES ('sg:$MDEmZSZMMOOQUjEQxIXi05XzoHayhwFR6YRDMOykvoI', 'm.room.guest_access', '', '$MDEmZSZMMOOQUjEQxIXi05XzoHayhwFR6YRDMOykvoI'); +INSERT INTO public.state_group_state (state_group_id, event_type, state_key, event_id) VALUES ('sg:$G6T266qKoHUbMYlVFKPN14wSCrqcj7ktb84OYLky32M', 'm.room.name', '', '$G6T266qKoHUbMYlVFKPN14wSCrqcj7ktb84OYLky32M'); + + +-- +-- Data for Name: state_groups; Type: TABLE DATA; Schema: public; Owner: - +-- + +INSERT INTO public.state_groups (state_group_id, room_id, parent_state_group_id, delta_depth) VALUES ('sg:$C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', '!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', '', '0'); +INSERT INTO public.state_groups (state_group_id, room_id, parent_state_group_id, delta_depth) VALUES ('sg:$iLFuDk8nVttbD9AqXn1viyXUEFEl_2DI7hsgkXGjXN8', '!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', 'sg:$C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', '1'); +INSERT INTO public.state_groups (state_group_id, room_id, parent_state_group_id, delta_depth) VALUES ('sg:$i5rP6Kab--xLmDcMSPRUZxvyQZcPThTiofJjfrSnDtg', '!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', 'sg:$iLFuDk8nVttbD9AqXn1viyXUEFEl_2DI7hsgkXGjXN8', '2'); +INSERT INTO public.state_groups (state_group_id, room_id, parent_state_group_id, delta_depth) VALUES ('sg:$v4aPwfsZiQ4yEz5-T0kS_DWvVTqUxPRltYSFV4P8Jlk', '!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', 'sg:$i5rP6Kab--xLmDcMSPRUZxvyQZcPThTiofJjfrSnDtg', '3'); +INSERT INTO public.state_groups (state_group_id, room_id, parent_state_group_id, delta_depth) VALUES ('sg:$jQRkJoCECH7wDkXeK4PAzuiNM5N4-W-klgkSyuKI0Ig', '!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', 'sg:$v4aPwfsZiQ4yEz5-T0kS_DWvVTqUxPRltYSFV4P8Jlk', '4'); +INSERT INTO public.state_groups (state_group_id, room_id, parent_state_group_id, delta_depth) VALUES ('sg:$3DxD43IUhKnopg81UbujM_TWm14GdVq22XKXiThD5Bo', '!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', 'sg:$jQRkJoCECH7wDkXeK4PAzuiNM5N4-W-klgkSyuKI0Ig', '5'); +INSERT INTO public.state_groups (state_group_id, room_id, parent_state_group_id, delta_depth) VALUES ('sg:$LQujV90cKOa8fkPPU4PQX7sm6KL28V0r8nKCewBnOJ8', '!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', 'sg:$3DxD43IUhKnopg81UbujM_TWm14GdVq22XKXiThD5Bo', '6'); +INSERT INTO public.state_groups (state_group_id, room_id, parent_state_group_id, delta_depth) VALUES ('sg:$RDqWCB4mWm4fTct25NtZAh5zmiUTG_EsgfQpCS2erxw', '!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', 'sg:$LQujV90cKOa8fkPPU4PQX7sm6KL28V0r8nKCewBnOJ8', '7'); +INSERT INTO public.state_groups (state_group_id, room_id, parent_state_group_id, delta_depth) VALUES ('sg:$QzTeY37FC1XCBCS9k5WSqtd_ozVW1B45OBvMLOxOFRY', '!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', 'sg:$RDqWCB4mWm4fTct25NtZAh5zmiUTG_EsgfQpCS2erxw', '8'); +INSERT INTO public.state_groups (state_group_id, room_id, parent_state_group_id, delta_depth) VALUES ('sg:$wVJJm-TLQ6il0h68B5rzA97t20lkmGMK7H0O6YdHEMM', '!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', 'sg:$QzTeY37FC1XCBCS9k5WSqtd_ozVW1B45OBvMLOxOFRY', '9'); +INSERT INTO public.state_groups (state_group_id, room_id, parent_state_group_id, delta_depth) VALUES ('sg:$WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA', '!WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA', '', '0'); +INSERT INTO public.state_groups (state_group_id, room_id, parent_state_group_id, delta_depth) VALUES ('sg:$gEZRQzCXH4iD07nDrZYaWlyfDmS0tqK_R-gW6JyF32U', '!WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA', 'sg:$WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA', '1'); +INSERT INTO public.state_groups (state_group_id, room_id, parent_state_group_id, delta_depth) VALUES ('sg:$PecG6aWhB2mDCM6YMk8crHbTdYzWkYUCN_ipzlMCjiI', '!WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA', 'sg:$gEZRQzCXH4iD07nDrZYaWlyfDmS0tqK_R-gW6JyF32U', '2'); +INSERT INTO public.state_groups (state_group_id, room_id, parent_state_group_id, delta_depth) VALUES ('sg:$2oC-K1LNKA47eO1pqEmJrY0s6617pjOSdk68k5LiuZg', '!WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA', 'sg:$PecG6aWhB2mDCM6YMk8crHbTdYzWkYUCN_ipzlMCjiI', '3'); +INSERT INTO public.state_groups (state_group_id, room_id, parent_state_group_id, delta_depth) VALUES ('sg:$V6yysmqZ0o9qaJiimEfXi0Ku7kIFtR9hCAC7vGSowuY', '!WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA', 'sg:$2oC-K1LNKA47eO1pqEmJrY0s6617pjOSdk68k5LiuZg', '4'); +INSERT INTO public.state_groups (state_group_id, room_id, parent_state_group_id, delta_depth) VALUES ('sg:$Lft2RjGrEuDUm8UkT3X25KYA1_81FeaFlJVeWLq8UdM', '!WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA', 'sg:$V6yysmqZ0o9qaJiimEfXi0Ku7kIFtR9hCAC7vGSowuY', '5'); +INSERT INTO public.state_groups (state_group_id, room_id, parent_state_group_id, delta_depth) VALUES ('sg:$MDEmZSZMMOOQUjEQxIXi05XzoHayhwFR6YRDMOykvoI', '!WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA', 'sg:$Lft2RjGrEuDUm8UkT3X25KYA1_81FeaFlJVeWLq8UdM', '6'); +INSERT INTO public.state_groups (state_group_id, room_id, parent_state_group_id, delta_depth) VALUES ('sg:$G6T266qKoHUbMYlVFKPN14wSCrqcj7ktb84OYLky32M', '!WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA', 'sg:$MDEmZSZMMOOQUjEQxIXi05XzoHayhwFR6YRDMOykvoI', '7'); + + +-- +-- Data for Name: state_transitions; Type: TABLE DATA; Schema: public; Owner: - +-- + +INSERT INTO public.state_transitions (room_id, event_type, state_key, event_id, previous_event_id) VALUES ('!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', 'm.room.create', '', '$C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', ''); +INSERT INTO public.state_transitions (room_id, event_type, state_key, event_id, previous_event_id) VALUES ('!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', 'm.room.member', '@alice:example.org', '$iLFuDk8nVttbD9AqXn1viyXUEFEl_2DI7hsgkXGjXN8', ''); +INSERT INTO public.state_transitions (room_id, event_type, state_key, event_id, previous_event_id) VALUES ('!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', 'm.room.power_levels', '', '$i5rP6Kab--xLmDcMSPRUZxvyQZcPThTiofJjfrSnDtg', ''); +INSERT INTO public.state_transitions (room_id, event_type, state_key, event_id, previous_event_id) VALUES ('!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', 'm.room.join_rules', '', '$v4aPwfsZiQ4yEz5-T0kS_DWvVTqUxPRltYSFV4P8Jlk', ''); +INSERT INTO public.state_transitions (room_id, event_type, state_key, event_id, previous_event_id) VALUES ('!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', 'm.room.history_visibility', '', '$jQRkJoCECH7wDkXeK4PAzuiNM5N4-W-klgkSyuKI0Ig', ''); +INSERT INTO public.state_transitions (room_id, event_type, state_key, event_id, previous_event_id) VALUES ('!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', 'm.room.guest_access', '', '$3DxD43IUhKnopg81UbujM_TWm14GdVq22XKXiThD5Bo', ''); +INSERT INTO public.state_transitions (room_id, event_type, state_key, event_id, previous_event_id) VALUES ('!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', 'm.room.encryption', '', '$LQujV90cKOa8fkPPU4PQX7sm6KL28V0r8nKCewBnOJ8', ''); +INSERT INTO public.state_transitions (room_id, event_type, state_key, event_id, previous_event_id) VALUES ('!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', 'm.room.name', '', '$RDqWCB4mWm4fTct25NtZAh5zmiUTG_EsgfQpCS2erxw', ''); +INSERT INTO public.state_transitions (room_id, event_type, state_key, event_id, previous_event_id) VALUES ('!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', 'm.room.member', '@bob:example.org', '$QzTeY37FC1XCBCS9k5WSqtd_ozVW1B45OBvMLOxOFRY', ''); +INSERT INTO public.state_transitions (room_id, event_type, state_key, event_id, previous_event_id) VALUES ('!C7Cym0uRg_x2vckbuDPCwO4QgdsxfXpDiOi1WoH89NY', 'm.room.member', '@bob:example.org', '$wVJJm-TLQ6il0h68B5rzA97t20lkmGMK7H0O6YdHEMM', '$QzTeY37FC1XCBCS9k5WSqtd_ozVW1B45OBvMLOxOFRY'); +INSERT INTO public.state_transitions (room_id, event_type, state_key, event_id, previous_event_id) VALUES ('!WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA', 'm.room.create', '', '$WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA', ''); +INSERT INTO public.state_transitions (room_id, event_type, state_key, event_id, previous_event_id) VALUES ('!WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA', 'm.room.member', '@alice:example.org', '$gEZRQzCXH4iD07nDrZYaWlyfDmS0tqK_R-gW6JyF32U', ''); +INSERT INTO public.state_transitions (room_id, event_type, state_key, event_id, previous_event_id) VALUES ('!WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA', 'm.room.power_levels', '', '$PecG6aWhB2mDCM6YMk8crHbTdYzWkYUCN_ipzlMCjiI', ''); +INSERT INTO public.state_transitions (room_id, event_type, state_key, event_id, previous_event_id) VALUES ('!WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA', 'm.room.canonical_alias', '', '$2oC-K1LNKA47eO1pqEmJrY0s6617pjOSdk68k5LiuZg', ''); +INSERT INTO public.state_transitions (room_id, event_type, state_key, event_id, previous_event_id) VALUES ('!WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA', 'm.room.join_rules', '', '$V6yysmqZ0o9qaJiimEfXi0Ku7kIFtR9hCAC7vGSowuY', ''); +INSERT INTO public.state_transitions (room_id, event_type, state_key, event_id, previous_event_id) VALUES ('!WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA', 'm.room.history_visibility', '', '$Lft2RjGrEuDUm8UkT3X25KYA1_81FeaFlJVeWLq8UdM', ''); +INSERT INTO public.state_transitions (room_id, event_type, state_key, event_id, previous_event_id) VALUES ('!WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA', 'm.room.guest_access', '', '$MDEmZSZMMOOQUjEQxIXi05XzoHayhwFR6YRDMOykvoI', ''); +INSERT INTO public.state_transitions (room_id, event_type, state_key, event_id, previous_event_id) VALUES ('!WLDmyNQlQnw_RhR08m7Jk_JO2mbtD9pY5COByGjLODA', 'm.room.name', '', '$G6T266qKoHUbMYlVFKPN14wSCrqcj7ktb84OYLky32M', ''); + + +-- +-- Data for Name: stream_token_epoch; Type: TABLE DATA; Schema: public; Owner: - +-- + +INSERT INTO public.stream_token_epoch (singleton, epoch) VALUES (1, '16567766508683932441'); + + +-- +-- Data for Name: sync_stream_watermark; Type: TABLE DATA; Schema: public; Owner: - +-- + +INSERT INTO public.sync_stream_watermark (singleton, watermark) VALUES (1, '11'); + + +-- +-- Data for Name: to_device_messages; Type: TABLE DATA; Schema: public; Owner: - +-- + + + +-- +-- Data for Name: users; Type: TABLE DATA; Schema: public; Owner: - +-- + +INSERT INTO public.users (user_id, password_hash, locked, suspended, admin, deactivated) VALUES ('@alice:example.org', 'password-hash:v2:$argon2id$v=19$m=65536,t=2,p=1$BZ7AtwwKDlS7ACuBTaSqRQ$XMFrVx+V7GGaglCHcA/1Mgjsi/uugNpiLnUEzc0YLhE', 'false', 'false', 'false', 'false'); +INSERT INTO public.users (user_id, password_hash, locked, suspended, admin, deactivated) VALUES ('@bob:example.org', 'password-hash:v2:$argon2id$v=19$m=65536,t=2,p=1$jshxQqXojCFoET4WBT2BbA$jT1sZbXil+kpLLG3uDqhY9U4ZAIe5UEASLUYOsIByg0', 'false', 'false', 'false', 'false'); + + +-- +-- Name: access_tokens access_tokens_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.access_tokens + ADD CONSTRAINT access_tokens_pkey PRIMARY KEY (token_hash); + + +-- +-- Name: account_data account_data_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.account_data + ADD CONSTRAINT account_data_pkey PRIMARY KEY (user_id, event_type); + + +-- +-- Name: account_threepids account_threepids_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.account_threepids + ADD CONSTRAINT account_threepids_pkey PRIMARY KEY (user_id, medium, address); + + +-- +-- Name: appservice_directory appservice_directory_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.appservice_directory + ADD CONSTRAINT appservice_directory_pkey PRIMARY KEY (appservice_id, network_id, room_id); + + +-- +-- Name: appservice_outbox appservice_outbox_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.appservice_outbox + ADD CONSTRAINT appservice_outbox_pkey PRIMARY KEY (appservice_id, stream_ordering); + + +-- +-- Name: appservice_txn_cursor appservice_txn_cursor_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.appservice_txn_cursor + ADD CONSTRAINT appservice_txn_cursor_pkey PRIMARY KEY (appservice_id); + + +-- +-- Name: client_txn_ids client_txn_ids_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.client_txn_ids + ADD CONSTRAINT client_txn_ids_pkey PRIMARY KEY (user_id, device_id, room_id, event_type, txn_id); + + +-- +-- Name: cross_signing_keys cross_signing_keys_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.cross_signing_keys + ADD CONSTRAINT cross_signing_keys_pkey PRIMARY KEY (user_id, key_type); + + +-- +-- Name: current_state current_state_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.current_state + ADD CONSTRAINT current_state_pkey PRIMARY KEY (room_id, event_type, state_key); + + +-- +-- Name: deferred_pdus deferred_pdus_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.deferred_pdus + ADD CONSTRAINT deferred_pdus_pkey PRIMARY KEY (event_id); + + +-- +-- Name: device_keys device_keys_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.device_keys + ADD CONSTRAINT device_keys_pkey PRIMARY KEY (user_id, device_id); + + +-- +-- Name: device_list_changes device_list_changes_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.device_list_changes + ADD CONSTRAINT device_list_changes_pkey PRIMARY KEY (stream_id, observer_user_id, subject_user_id); + + +-- +-- Name: devices devices_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.devices + ADD CONSTRAINT devices_pkey PRIMARY KEY (user_id, device_id); + + +-- +-- Name: event_auth event_auth_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.event_auth + ADD CONSTRAINT event_auth_pkey PRIMARY KEY (event_id, auth_event_id); + + +-- +-- Name: event_edges event_edges_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.event_edges + ADD CONSTRAINT event_edges_pkey PRIMARY KEY (event_id, prev_event_id); + + +-- +-- Name: event_json event_json_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.event_json + ADD CONSTRAINT event_json_pkey PRIMARY KEY (event_id); + + +-- +-- Name: event_signatures event_signatures_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.event_signatures + ADD CONSTRAINT event_signatures_pkey PRIMARY KEY (event_id, server_name, key_id); + + +-- +-- Name: event_state_groups event_state_groups_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.event_state_groups + ADD CONSTRAINT event_state_groups_pkey PRIMARY KEY (event_id); + + +-- +-- Name: event_stream_watermark event_stream_watermark_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.event_stream_watermark + ADD CONSTRAINT event_stream_watermark_pkey PRIMARY KEY (singleton); + + +-- +-- Name: events events_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.events + ADD CONSTRAINT events_pkey PRIMARY KEY (event_id); + + +-- +-- Name: fallback_keys fallback_keys_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.fallback_keys + ADD CONSTRAINT fallback_keys_pkey PRIMARY KEY (user_id, device_id, key_id); + + +-- +-- Name: federation_destinations federation_destinations_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.federation_destinations + ADD CONSTRAINT federation_destinations_pkey PRIMARY KEY (server_name); + + +-- +-- Name: federation_transactions federation_transactions_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.federation_transactions + ADD CONSTRAINT federation_transactions_pkey PRIMARY KEY (transaction_id); + + +-- +-- Name: filters filters_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.filters + ADD CONSTRAINT filters_pkey PRIMARY KEY (user_id, filter_id); + + +-- +-- Name: forward_extremities forward_extremities_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.forward_extremities + ADD CONSTRAINT forward_extremities_pkey PRIMARY KEY (room_id, event_id); + + +-- +-- Name: invites invites_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.invites + ADD CONSTRAINT invites_pkey PRIMARY KEY (room_id, user_id); + + +-- +-- Name: key_backup_sessions key_backup_sessions_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.key_backup_sessions + ADD CONSTRAINT key_backup_sessions_pkey PRIMARY KEY (user_id, version, room_id, session_id); + + +-- +-- Name: key_backup_version_counters key_backup_version_counters_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.key_backup_version_counters + ADD CONSTRAINT key_backup_version_counters_pkey PRIMARY KEY (user_id); + + +-- +-- Name: key_backup_versions key_backup_versions_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.key_backup_versions + ADD CONSTRAINT key_backup_versions_pkey PRIMARY KEY (user_id, version); + + +-- +-- Name: key_backups key_backups_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.key_backups + ADD CONSTRAINT key_backups_pkey PRIMARY KEY (user_id, version); + + +-- +-- Name: key_signatures key_signatures_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.key_signatures + ADD CONSTRAINT key_signatures_pkey PRIMARY KEY (signer_user_id, target_user_id, target_device_id); + + +-- +-- Name: login_tokens login_tokens_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.login_tokens + ADD CONSTRAINT login_tokens_pkey PRIMARY KEY (token_hash); + + +-- +-- Name: media_blobs media_blobs_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.media_blobs + ADD CONSTRAINT media_blobs_pkey PRIMARY KEY (storage_id); + + +-- +-- Name: media_pending_uploads media_pending_uploads_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.media_pending_uploads + ADD CONSTRAINT media_pending_uploads_pkey PRIMARY KEY (media_id); + + +-- +-- Name: media media_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.media + ADD CONSTRAINT media_pkey PRIMARY KEY (media_id); + + +-- +-- Name: membership membership_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.membership + ADD CONSTRAINT membership_pkey PRIMARY KEY (room_id, user_id); + + +-- +-- Name: notifications notifications_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.notifications + ADD CONSTRAINT notifications_pkey PRIMARY KEY (user_id, event_id); + + +-- +-- Name: one_time_keys one_time_keys_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.one_time_keys + ADD CONSTRAINT one_time_keys_pkey PRIMARY KEY (user_id, device_id, key_id); + + +-- +-- Name: openid_tokens openid_tokens_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.openid_tokens + ADD CONSTRAINT openid_tokens_pkey PRIMARY KEY (token_hash); + + +-- +-- Name: policy_rules policy_rules_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.policy_rules + ADD CONSTRAINT policy_rules_pkey PRIMARY KEY (rule_id); + + +-- +-- Name: presence_state presence_state_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.presence_state + ADD CONSTRAINT presence_state_pkey PRIMARY KEY (user_id); + + +-- +-- Name: profiles profiles_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.profiles + ADD CONSTRAINT profiles_pkey PRIMARY KEY (user_id); + + +-- +-- Name: push_rules push_rules_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.push_rules + ADD CONSTRAINT push_rules_pkey PRIMARY KEY (user_id, rule_id); + + +-- +-- Name: pushers pushers_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.pushers + ADD CONSTRAINT pushers_pkey PRIMARY KEY (user_id, app_id, pushkey); + + +-- +-- Name: rate_limits rate_limits_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.rate_limits + ADD CONSTRAINT rate_limits_pkey PRIMARY KEY (scope, key); + + +-- +-- Name: receipts receipts_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.receipts + ADD CONSTRAINT receipts_pkey PRIMARY KEY (room_id, receipt_type, user_id, thread_id); + + +-- +-- Name: refresh_tokens refresh_tokens_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.refresh_tokens + ADD CONSTRAINT refresh_tokens_pkey PRIMARY KEY (token_hash); + + +-- +-- Name: remote_media remote_media_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.remote_media + ADD CONSTRAINT remote_media_pkey PRIMARY KEY (server_name, media_id); + + +-- +-- Name: room_account_data room_account_data_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.room_account_data + ADD CONSTRAINT room_account_data_pkey PRIMARY KEY (user_id, room_id, event_type); + + +-- +-- Name: room_aliases room_aliases_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.room_aliases + ADD CONSTRAINT room_aliases_pkey PRIMARY KEY (room_alias); + + +-- +-- Name: room_versions room_versions_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.room_versions + ADD CONSTRAINT room_versions_pkey PRIMARY KEY (room_id); + + +-- +-- Name: rooms rooms_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.rooms + ADD CONSTRAINT rooms_pkey PRIMARY KEY (room_id); + + +-- +-- Name: schema_migrations schema_migrations_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.schema_migrations + ADD CONSTRAINT schema_migrations_pkey PRIMARY KEY (version); + + +-- +-- Name: server_signing_keys server_signing_keys_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.server_signing_keys + ADD CONSTRAINT server_signing_keys_pkey PRIMARY KEY (server_name, key_id); + + +-- +-- Name: state_group_edges state_group_edges_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.state_group_edges + ADD CONSTRAINT state_group_edges_pkey PRIMARY KEY (state_group_id, prev_state_group_id); + + +-- +-- Name: state_group_state state_group_state_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.state_group_state + ADD CONSTRAINT state_group_state_pkey PRIMARY KEY (state_group_id, event_type, state_key); + + +-- +-- Name: state_groups state_groups_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.state_groups + ADD CONSTRAINT state_groups_pkey PRIMARY KEY (state_group_id); + + +-- +-- Name: state_transitions state_transitions_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.state_transitions + ADD CONSTRAINT state_transitions_pkey PRIMARY KEY (room_id, event_type, state_key, event_id); + + +-- +-- Name: stream_token_epoch stream_token_epoch_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.stream_token_epoch + ADD CONSTRAINT stream_token_epoch_pkey PRIMARY KEY (singleton); + + +-- +-- Name: sync_stream_watermark sync_stream_watermark_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.sync_stream_watermark + ADD CONSTRAINT sync_stream_watermark_pkey PRIMARY KEY (singleton); + + +-- +-- Name: to_device_messages to_device_messages_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.to_device_messages + ADD CONSTRAINT to_device_messages_pkey PRIMARY KEY (stream_id, target_user_id, target_device_id); + + +-- +-- Name: users users_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.users + ADD CONSTRAINT users_pkey PRIMARY KEY (user_id); + + +-- +-- Name: event_edges_prev_event_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX event_edges_prev_event_id ON public.event_edges USING btree (prev_event_id); + + +-- +-- Name: idx_access_tokens_user_device; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX idx_access_tokens_user_device ON public.access_tokens USING btree (user_id, device_id); + + +-- +-- Name: idx_deferred_pdus_room_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX idx_deferred_pdus_room_id ON public.deferred_pdus USING btree (room_id); + + +-- +-- Name: idx_events_room_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX idx_events_room_id ON public.events USING btree (room_id); + + +-- +-- Name: idx_media_pending_uploads_owner; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX idx_media_pending_uploads_owner ON public.media_pending_uploads USING btree (owner_user_id); + + +-- +-- Name: idx_refresh_tokens_predecessor; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX idx_refresh_tokens_predecessor ON public.refresh_tokens USING btree (predecessor_hash); + + +-- +-- Name: idx_refresh_tokens_user_device; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX idx_refresh_tokens_user_device ON public.refresh_tokens USING btree (user_id, device_id); + + +-- +-- Name: idx_state_groups_room_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX idx_state_groups_room_id ON public.state_groups USING btree (room_id); + + +-- +-- Name: idx_to_device_messages_recipient_age; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX idx_to_device_messages_recipient_age ON public.to_device_messages USING btree (target_user_id, target_device_id, created_at_ms); + + +-- +-- Name: key_backup_sessions key_backup_sessions_user_id_version_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.key_backup_sessions + ADD CONSTRAINT key_backup_sessions_user_id_version_fkey FOREIGN KEY (user_id, version) REFERENCES public.key_backup_versions(user_id, version) ON DELETE CASCADE; + + +-- +-- PostgreSQL database dump complete +-- + + diff --git a/tests/fixtures/upgrade/README.md b/tests/fixtures/upgrade/README.md index 6700fc5b5..83adaaa69 100644 --- a/tests/fixtures/upgrade/README.md +++ b/tests/fixtures/upgrade/README.md @@ -5,20 +5,26 @@ release, so a test can prove the current server opens, migrates and serves it. Nothing in these files is hand-written: the old `merovingian-server` produced every row through its real HTTP Client-Server API (ADR-0216). -## No fixture yet - -There is none today. In 0.12.47 every pre-1.0 migration collapsed into one v1 -schema (ADR-0224), so no database a pre-1.0 release wrote can be opened any more, -and the 0.11.13 fixture that stood here was removed with the chain it tested. -Upgrade compatibility is promised from 1.0.0, which is cut. - -1.1.0 adds migration 002, the first migration after 1.0, so it is where the next -fixture belongs: the last 1.0.x release writes it into -`tests/fixtures/upgrade//`, and `tests/integration/test_database_upgrade_flow.cpp` -gains the scenarios that open, migrate and serve it. It has not been generated -yet: the generator needs the PostgreSQL server binaries (`initdb`, `pg_ctl`), -and the build VM has none. Until it exists, nothing proves that 1.1.0 opens a -database a 1.0.x release wrote. +## What exists + +`1.0.3/` holds the database the last 1.0.x release wrote, generated by +`scripts/generate_upgrade_fixture.py` from release commit `5f458d57` (version 1.0.3). In 0.12.47 +every pre-1.0 migration collapsed into one v1 schema (ADR-0224), so no database a pre-1.0 +release wrote can be opened any more, and the 0.11.13 fixture that once stood here was removed +with the chain it tested. Upgrade compatibility is promised from 1.0.0. + +1.1.0 adds migration 002 (the OAuth 2.0 tables), the first migration after 1.0, so the +1.0.3 fixture is the proof that 1.1.x opens a database a 1.0.x release wrote. +`tests/integration/test_database_upgrade_flow.cpp` has one `[fixture]` scenario per backend +(SQLite, and PostgreSQL when `MEROVINGIAN_TEST_POSTGRESQL_URI` is set; it reports itself +skipped otherwise). Each opens the v1 database, runs `migrate_*_schema_to`, which applies the +v1 to v2 step, checks the schema is at the current version and the OAuth tables exist and are +usable, starts the current runtime on it and reads back, from `manifest.json` alone, both +users' access tokens and passwords, the rooms, events, media, account data, pusher and device +keys, then sends a new event and checks it is signed with the old release's server key. + +The next fixture is added when the 1.2 series starts, written by the last 1.1.x release, and +replaces this one. ## Generating diff --git a/tests/integration/AGENTS.md b/tests/integration/AGENTS.md index 373f90a7f..c678d30cb 100644 --- a/tests/integration/AGENTS.md +++ b/tests/integration/AGENTS.md @@ -30,6 +30,14 @@ Same SCENARIO/GIVEN/WHEN/THEN structure as unit tests. Set up the full server st database fixture in `GIVEN`; trigger the user-visible action in `WHEN`; assert the observable outcome in `THEN`. +## Upgrade fixture scenarios + +`test_database_upgrade_flow.cpp` also opens the previous series' last release's own database +(`tests/fixtures/upgrade/1.0.3/`, ADR-0216) on SQLite and PostgreSQL and serves it. Read every +ID, token and key from `manifest.json`; never hard-code one, and never regenerate the fixture with +current code. Run them with the `[fixture]` tag. The PostgreSQL one needs `MEROVINGIAN_TEST_POSTGRESQL_URI` +and skips without it, so check that it ran. + ## Live federation tests `test_live_synapse_federation.cpp` is guarded by the `build_live_tests` Meson option. diff --git a/tests/integration/test_database_upgrade_flow.cpp b/tests/integration/test_database_upgrade_flow.cpp index 3465ab971..7379a1e7e 100644 --- a/tests/integration/test_database_upgrade_flow.cpp +++ b/tests/integration/test_database_upgrade_flow.cpp @@ -8,17 +8,41 @@ // current version and then holds exactly the schema a fresh one does, the // forward-only seam (migrate_*_schema_to) never moves past this build or // backwards, and a database a pre-1.0 build created is refused rather than -// misread. A fixture written by the last 1.0.x release joins them. +// misread. The 1.0.3 release's own databases (tests/fixtures/upgrade/1.0.3/) +// are opened, migrated and served at the end of the file: opening one applies +// the v1 to v2 step, and what the manifest lists is still served afterwards. +#include "../support/JsonTestSupport.hpp" #include "../support/TempDirectory.hpp" #include "ScratchPostgresqlDatabase.hpp" +#include "merovingian/canonicaljson/CanonicalJsonError.hpp" +#include "merovingian/canonicaljson/ParseError.hpp" +#include "merovingian/canonicaljson/Parser.hpp" +#include "merovingian/canonicaljson/Value.hpp" +#include "merovingian/config/ClientRateLimitsConfig.hpp" +#include "merovingian/config/Config.hpp" +#include "merovingian/config/DatabaseBackend.hpp" +#include "merovingian/config/DatabaseConfig.hpp" +#include "merovingian/config/ListenersConfig.hpp" +#include "merovingian/config/LogModulesConfig.hpp" +#include "merovingian/config/SecurityConfig.hpp" +#include "merovingian/config/ServerConfig.hpp" +#include "merovingian/crypto/Ed25519.hpp" +#include "merovingian/crypto/Ed25519PublicKey.hpp" +#include "merovingian/crypto/Ed25519Signature.hpp" #include "merovingian/database/ExaminedRows.hpp" #include "merovingian/database/PersistentStore.hpp" #include "merovingian/database/PostgresqlStore.hpp" #include "merovingian/database/Schema.hpp" #include "merovingian/database/SchemaState.hpp" +#include "merovingian/events/EventSigner.hpp" +#include "merovingian/homeserver/ClientServerRuntime.hpp" +#include "merovingian/homeserver/ClientServerStartResult.hpp" +#include "merovingian/homeserver/StoredRoomVersion.hpp" +#include "merovingian/sync/StreamToken.hpp" #include #include +#include #include #include @@ -28,11 +52,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include namespace @@ -311,6 +337,469 @@ constexpr auto pre_collapse_step_names = std::array{ constexpr auto pre_collapse_ledger_rows = static_cast(pre_collapse_step_names.size() + 1U); +// --------------------------------------------------------------------------- +// The previous series' last release's own database (ADR-0216). +// tests/fixtures/upgrade// was written over HTTP by that release's +// server; manifest.json records what it was asked to store and the credentials +// to read it back with. Nothing below names an ID, token or key: every value +// comes from the manifest. Never regenerate the fixture with current code. +// --------------------------------------------------------------------------- + +constexpr auto previous_series_fixture_release = std::string_view{"1.0.3"}; + +[[nodiscard]] auto fixture_directory() -> std::filesystem::path +{ + return std::filesystem::path{MEROVINGIAN_TEST_SOURCE_ROOT} / "tests" / "fixtures" / "upgrade" / + std::string{previous_series_fixture_release}; +} + +[[nodiscard]] auto read_binary_file(std::filesystem::path const& path) -> std::string +{ + auto input = std::ifstream{path, std::ios::binary}; + return {std::istreambuf_iterator{input}, std::istreambuf_iterator{}}; +} + +[[nodiscard]] auto string_at(merovingian::canonicaljson::Object const& object, std::string_view key) -> std::string +{ + auto const* value = merovingian::tests::string_member(object, key); + return value == nullptr ? std::string{} : *value; +} + +[[nodiscard]] auto object_at(merovingian::canonicaljson::Object const& object, std::string_view key) + -> merovingian::canonicaljson::Object +{ + auto const* value = merovingian::tests::object_member_as_object(object, key); + return value == nullptr ? merovingian::canonicaljson::Object{} : *value; +} + +struct FixtureUser final +{ + std::string user_id{}; + std::string password{}; + std::string device_id{}; + std::string access_token{}; +}; + +struct FixtureMessage final +{ + std::string sender{}; + std::string event_id{}; + std::string body{}; +}; + +// What one backend's run of the old release stored, as manifest.json records it. +struct FixtureExpectations final +{ + std::string release{}; + std::int64_t schema_version{0}; + std::string server_name{}; + std::string master_key_hex{}; + FixtureUser alice{}; + FixtureUser bob{}; + std::string displayname{}; + std::string private_room_id{}; + std::string public_room_id{}; + std::string alias{}; + std::vector messages{}; + std::string media_mxc_uri{}; + std::string media_sha256{}; + std::string account_data_type{}; + std::string account_data_fixture_value{}; + std::string pushkey{}; + std::string device_ed25519_key{}; + std::string next_batch{}; + std::size_t non_2xx_steps{0U}; +}; + +[[nodiscard]] auto fixture_user_at(merovingian::canonicaljson::Object const& users, std::string_view name) + -> FixtureUser +{ + auto const user = object_at(users, name); + return {string_at(user, "user_id"), string_at(user, "password"), string_at(user, "device_id"), + string_at(user, "access_token")}; +} + +[[nodiscard]] auto load_fixture_expectations(std::string_view backend) -> FixtureExpectations +{ + auto const manifest = + merovingian::tests::parse_object_json(read_binary_file(fixture_directory() / "manifest.json")); + auto const run = object_at(manifest, backend); + auto const users = object_at(run, "users"); + auto expected = FixtureExpectations{}; + expected.release = string_at(manifest, "release"); + if (auto const* version = merovingian::tests::int_member(manifest, "schema_version"); version != nullptr) + { + expected.schema_version = *version; + } + expected.server_name = string_at(manifest, "server_name"); + expected.master_key_hex = string_at(manifest, "master_key_hex"); + expected.alice = fixture_user_at(users, "alice"); + expected.bob = fixture_user_at(users, "bob"); + expected.displayname = string_at(run, "displayname"); + expected.private_room_id = string_at(run, "private_room_id"); + expected.public_room_id = string_at(run, "public_room_id"); + expected.alias = string_at(run, "alias"); + if (auto const* messages = merovingian::tests::object_member_as_array(run, "messages"); messages != nullptr) + { + for (auto const& message : *messages) + { + if (auto const* fields = std::get_if(&message.storage())) + { + expected.messages.push_back( + {string_at(*fields, "sender"), string_at(*fields, "event_id"), string_at(*fields, "body")}); + } + } + } + auto const media = object_at(run, "media"); + expected.media_mxc_uri = string_at(media, "mxc_uri"); + expected.media_sha256 = string_at(media, "sha256"); + auto const account_data = object_at(run, "account_data"); + expected.account_data_type = string_at(account_data, "type"); + expected.account_data_fixture_value = string_at(object_at(account_data, "content"), "fixture"); + expected.pushkey = string_at(object_at(run, "pusher"), "pushkey"); + expected.device_ed25519_key = string_at(object_at(run, "device_keys"), "ed25519_public_key"); + expected.next_batch = string_at(run, "next_batch"); + if (auto const* non_2xx = merovingian::tests::object_member_as_array(run, "non_2xx"); non_2xx != nullptr) + { + expected.non_2xx_steps = non_2xx->size(); + } + return expected; +} + +// The old release encrypted its signing secret under this key, so the current +// runtime needs the same one to read it. +[[nodiscard]] auto write_fixture_master_key(std::string const& hex) -> std::filesystem::path +{ + auto key = std::vector(crypto_generichash_KEYBYTES); + auto length = std::size_t{0U}; + REQUIRE(sodium_hex2bin(key.data(), key.size(), hex.c_str(), hex.size(), nullptr, &length, nullptr) == 0); + REQUIRE(length == key.size()); + auto const path = merovingian::tests::unique_temporary_path("merovingian-upgrade-fixture-master", ".key"); + { + auto output = std::ofstream{path, std::ios::binary}; + REQUIRE(output.is_open()); + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) + output.write(reinterpret_cast(key.data()), static_cast(key.size())); + output.close(); + REQUIRE_FALSE(output.fail()); + } + std::filesystem::permissions(path, std::filesystem::perms::owner_read); + return path; +} + +[[nodiscard]] auto sha256_hex(std::string const& bytes) -> std::string +{ + auto digest = std::vector(crypto_hash_sha256_BYTES); + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) + crypto_hash_sha256(digest.data(), reinterpret_cast(bytes.data()), bytes.size()); + auto hex = std::string(digest.size() * 2U + 1U, '\0'); + sodium_bin2hex(hex.data(), hex.size(), digest.data(), digest.size()); + hex.resize(digest.size() * 2U); + return hex; +} + +[[nodiscard]] auto fixture_config(merovingian::config::DatabaseConfig database, std::filesystem::path const& master_key, + std::string const& server_name) -> merovingian::config::Config +{ + auto server = merovingian::config::ServerConfig{}; + server.server_name = server_name; + auto security = merovingian::config::SecurityConfig{}; + security.secrets.master_key_file = master_key.string(); + return {server, merovingian::config::ListenersConfig{}, std::move(database), + security, merovingian::config::ClientRateLimitsConfig{}, merovingian::config::LogModulesConfig{}}; +} + +[[nodiscard]] auto sqlite_fixture_config(std::filesystem::path const& path, std::filesystem::path const& master_key, + std::string const& server_name) -> merovingian::config::Config +{ + auto database = merovingian::config::DatabaseConfig{}; + database.backend = merovingian::config::DatabaseBackend::sqlite; + database.sqlite_path = path.string(); + return fixture_config(std::move(database), master_key, server_name); +} + +[[nodiscard]] auto postgresql_fixture_config(std::filesystem::path const& uri_file, + std::filesystem::path const& master_key, std::string const& server_name) + -> merovingian::config::Config +{ + auto database = merovingian::config::DatabaseConfig{}; + database.backend = merovingian::config::DatabaseBackend::postgresql; + database.uri_file = uri_file.string(); + return fixture_config(std::move(database), master_key, server_name); +} + +// The runtime reads its database URI only from an owner-read-only file (ISO-7). +[[nodiscard]] auto write_uri_file(std::string const& conninfo) -> std::filesystem::path +{ + auto const path = merovingian::tests::unique_temporary_path("merovingian-upgrade-uri", ""); + { + auto output = std::ofstream{path}; + REQUIRE(output.is_open()); + output << conninfo << '\n'; + output.close(); + REQUIRE_FALSE(output.fail()); + } + std::filesystem::permissions(path, std::filesystem::perms::owner_read); + return path; +} + +// Runs a whole dump (plain SQL, no COPY, no psql meta-commands) in one PQexec. +[[nodiscard]] auto pg_execute_script(std::string const& conninfo, std::string const& script) -> bool +{ + auto const connection = std::unique_ptr{PQconnectdb(conninfo.c_str())}; + if (PQstatus(connection.get()) != CONNECTION_OK) + { + return false; + } + auto const result = std::unique_ptr{PQexec(connection.get(), script.c_str())}; + auto const status = PQresultStatus(result.get()); + return status == PGRES_COMMAND_OK || status == PGRES_TUPLES_OK; +} + +// The server signing key the old release stored for the server, read from its +// own database rather than the manifest: what the runtime must keep signing with. +struct FixtureSigningKey final +{ + std::string key_id{}; + std::string public_key{}; +}; + +[[nodiscard]] auto sqlite_fixture_signing_key(std::filesystem::path const& path, std::string const& server_name) + -> FixtureSigningKey +{ + auto* raw = static_cast(nullptr); + auto const opened = sqlite3_open_v2(path.string().c_str(), &raw, SQLITE_OPEN_READONLY, nullptr); + auto const connection = std::unique_ptr{raw}; + auto* raw_statement = static_cast(nullptr); + if (opened != SQLITE_OK || + sqlite3_prepare_v2(connection.get(), + "SELECT key_id, public_key FROM server_signing_keys WHERE server_name = ?1", -1, + &raw_statement, nullptr) != SQLITE_OK) + { + return {}; + } + auto const statement = std::unique_ptr{raw_statement}; + if (sqlite3_bind_text(statement.get(), 1, server_name.c_str(), static_cast(server_name.size()), nullptr) != + SQLITE_OK || + sqlite3_step(statement.get()) != SQLITE_ROW) + { + return {}; + } + auto const text = [&statement](int column) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) + auto const* value = reinterpret_cast(sqlite3_column_text(statement.get(), column)); + return value == nullptr ? std::string{} : std::string{value}; + }; + return {text(0), text(1)}; +} + +[[nodiscard]] auto postgresql_fixture_signing_key(std::string const& conninfo, std::string const& server_name) + -> FixtureSigningKey +{ + auto const connection = std::unique_ptr{PQconnectdb(conninfo.c_str())}; + auto const* values = server_name.c_str(); + auto const result = std::unique_ptr{ + PQexecParams(connection.get(), "SELECT key_id, public_key FROM server_signing_keys WHERE server_name = $1", 1, + nullptr, &values, nullptr, nullptr, 0)}; + if (PQresultStatus(result.get()) != PGRES_TUPLES_OK || PQntuples(result.get()) != 1) + { + return {}; + } + return {PQgetvalue(result.get(), 0, 0), PQgetvalue(result.get(), 0, 1)}; +} + +struct Response final +{ + unsigned status{0U}; + std::string body{}; +}; + +[[nodiscard]] auto request(merovingian::homeserver::ClientServerRuntime& runtime, std::string method, + std::string target, std::string token, std::string body = {}) -> Response +{ + auto const handled = merovingian::homeserver::handle_client_server_request( + runtime, {std::move(method), std::move(target), std::move(token), std::move(body)}); + return {handled.response.status, handled.response.body}; +} + +[[nodiscard]] auto json_string_field(std::string const& body, std::string_view name) -> std::string +{ + return string_at(merovingian::tests::parse_object_json(body), name); +} + +// Everything a client can read back of the old release's data, and writes that +// need its signing secret. Not the room directory: it is checked by neither +// release's fixture run beyond the old server's own read-back. +struct FixtureView final +{ + Response alice_whoami{}; + Response bob_whoami{}; + Response bob_login{}; + Response displayname{}; + Response account_data{}; + Response messages{}; + Response members{}; + Response alias{}; + Response pushers{}; + Response media{}; + Response device_keys{}; + Response sync_since_old_token{}; + Response initial_sync{}; + Response replay_old_transaction{}; + Response send_into_old_room{}; + Response read_new_event{}; +}; + +[[nodiscard]] auto view_fixture(merovingian::homeserver::ClientServerRuntime& runtime, + FixtureExpectations const& expected) -> FixtureView +{ + auto const& alice = expected.alice.access_token; + auto const media_id = expected.media_mxc_uri.substr(expected.media_mxc_uri.rfind('/') + 1U); + auto const private_room = "/_matrix/client/v3/rooms/" + expected.private_room_id; + auto view = FixtureView{}; + view.alice_whoami = request(runtime, "GET", "/_matrix/client/v3/account/whoami", alice); + view.bob_whoami = request(runtime, "GET", "/_matrix/client/v3/account/whoami", expected.bob.access_token); + view.bob_login = request(runtime, "POST", "/_matrix/client/v3/login", {}, + R"({"type":"m.login.password","identifier":{"type":"m.id.user","user":")" + + expected.bob.user_id + R"("},"password":")" + expected.bob.password + R"("})"); + view.displayname = + request(runtime, "GET", "/_matrix/client/v3/profile/" + expected.alice.user_id + "/displayname", alice); + view.account_data = request( + runtime, "GET", + "/_matrix/client/v3/user/" + expected.alice.user_id + "/account_data/" + expected.account_data_type, alice); + view.messages = request(runtime, "GET", private_room + "/messages?dir=b&limit=50", alice); + view.members = request(runtime, "GET", private_room + "/joined_members", alice); + view.alias = request(runtime, "GET", "/_matrix/client/v3/directory/room/%23" + expected.alias.substr(1U), alice); + view.pushers = request(runtime, "GET", "/_matrix/client/v3/pushers", alice); + view.media = + request(runtime, "GET", "/_matrix/client/v1/media/download/" + expected.server_name + "/" + media_id, alice); + view.device_keys = request(runtime, "POST", "/_matrix/client/v3/keys/query", alice, + R"({"device_keys":{")" + expected.alice.user_id + R"(":[]}})"); + view.sync_since_old_token = + request(runtime, "GET", "/_matrix/client/v3/sync?timeout=0&since=" + expected.next_batch, alice); + // The control: a sync with no token, which must replay the room's timeline. + view.initial_sync = request(runtime, "GET", "/_matrix/client/v3/sync?timeout=0", alice); + // The old release sent the first fixture message as `upgrade-txn-1` from this + // device, so repeating it must replay that event, not create one. + view.replay_old_transaction = request(runtime, "PUT", private_room + "/send/m.room.message/upgrade-txn-1", alice, + R"({"msgtype":"m.text","body":")" + expected.messages.front().body + R"("})"); + // A transaction ID the old release never saw, so a new event is created and signed. + view.send_into_old_room = request(runtime, "PUT", private_room + "/send/m.room.message/after-upgrade-txn-1", alice, + R"({"msgtype":"m.text","body":"sent after the upgrade"})"); + view.read_new_event = request( + runtime, "GET", private_room + "/event/" + json_string_field(view.send_into_old_room.body, "event_id"), alice); + return view; +} + +auto require_fixture_served(FixtureView const& view, FixtureExpectations const& expected) -> void +{ + // The old release wrote a clean, complete run: it is the manifest that says what to expect. + REQUIRE(expected.release == previous_series_fixture_release); + REQUIRE(expected.non_2xx_steps == 0U); + REQUIRE_FALSE(expected.alice.access_token.empty()); + REQUIRE_FALSE(expected.bob.access_token.empty()); + // Both users' old access tokens still authenticate: their hash format is read. + REQUIRE(view.alice_whoami.status == 200U); + REQUIRE(json_string_field(view.alice_whoami.body, "user_id") == expected.alice.user_id); + REQUIRE(json_string_field(view.alice_whoami.body, "device_id") == expected.alice.device_id); + REQUIRE(view.bob_whoami.status == 200U); + REQUIRE(json_string_field(view.bob_whoami.body, "user_id") == expected.bob.user_id); + // Its password hashes still verify. + REQUIRE(view.bob_login.status == 200U); + REQUIRE(json_string_field(view.bob_login.body, "user_id") == expected.bob.user_id); + REQUIRE(view.displayname.status == 200U); + REQUIRE(json_string_field(view.displayname.body, "displayname") == expected.displayname); + REQUIRE(view.account_data.status == 200U); + REQUIRE(json_string_field(view.account_data.body, "fixture") == expected.account_data_fixture_value); + REQUIRE(view.messages.status == 200U); + REQUIRE_FALSE(expected.messages.empty()); + for (auto const& message : expected.messages) + { + INFO("message " << message.event_id); + REQUIRE(view.messages.body.find(message.event_id) != std::string::npos); + REQUIRE(view.messages.body.find(message.body) != std::string::npos); + REQUIRE(view.messages.body.find(message.sender) != std::string::npos); + } + REQUIRE(view.members.status == 200U); + REQUIRE(view.members.body.find(expected.alice.user_id) != std::string::npos); + REQUIRE(view.members.body.find(expected.bob.user_id) != std::string::npos); + REQUIRE(view.alias.status == 200U); + REQUIRE(json_string_field(view.alias.body, "room_id") == expected.public_room_id); + REQUIRE(view.pushers.status == 200U); + REQUIRE(view.pushers.body.find(expected.pushkey) != std::string::npos); + REQUIRE(view.media.status == 200U); + REQUIRE(sha256_hex(view.media.body) == expected.media_sha256); + REQUIRE(view.device_keys.status == 200U); + REQUIRE(view.device_keys.body.find(expected.device_ed25519_key) != std::string::npos); + // A client that synced against the old release carries on from its token. A token whose epoch is not the + // store's is served as an initial sync, also with a 200 (src/sync/AGENTS.md), so the status alone would pass a + // migration that replaced the stream token epoch. Prove the answer is incremental and the epoch survived. + REQUIRE(view.sync_since_old_token.status == 200U); + REQUIRE(view.initial_sync.status == 200U); + for (auto const& message : expected.messages) + { + INFO("message " << message.event_id); + // The control replays what the old release had already delivered; the answer to the old token must not. + REQUIRE(view.initial_sync.body.find(message.event_id) != std::string::npos); + REQUIRE(view.sync_since_old_token.body.find(message.event_id) == std::string::npos); + } + auto const old_token = merovingian::sync::decode_stream_token(expected.next_batch); + REQUIRE(old_token.has_value()); + REQUIRE(old_token->epoch != 0U); + auto const new_token = + merovingian::sync::decode_stream_token(json_string_field(view.sync_since_old_token.body, "next_batch")); + REQUIRE(new_token.has_value()); + REQUIRE(new_token->epoch == old_token->epoch); + // The old release's transaction IDs still deduplicate: a retried send replays its event. + REQUIRE(view.replay_old_transaction.status == 200U); + REQUIRE(json_string_field(view.replay_old_transaction.body, "event_id") == expected.messages.front().event_id); + // A new event in an old room needs the old signing secret, decrypted. + REQUIRE(view.send_into_old_room.status == 200U); + auto const new_event_id = json_string_field(view.send_into_old_room.body, "event_id"); + REQUIRE_FALSE(new_event_id.empty()); + REQUIRE(std::ranges::none_of(expected.messages, [&new_event_id](FixtureMessage const& message) { + return message.event_id == new_event_id; + })); + REQUIRE(view.read_new_event.status == 200U); + REQUIRE(view.read_new_event.body.find("sent after the upgrade") != std::string::npos); +} + +// The event created after the upgrade carries the server's signature under the +// old release's key ID, and that signature verifies against the old public key: +// the runtime decrypted the old secret rather than signing with a replacement. +auto require_signed_with_fixture_key(merovingian::homeserver::ClientServerRuntime& runtime, + FixtureExpectations const& expected, FixtureView const& view, + FixtureSigningKey const& key) -> void +{ + REQUIRE_FALSE(key.key_id.empty()); + REQUIRE_FALSE(key.public_key.empty()); + auto const& store = runtime.homeserver.database.persistent_store; + auto const event_id = json_string_field(view.send_into_old_room.body, "event_id"); + auto const stored = store.events.find(event_id); + REQUIRE(stored != store.events.end()); + auto const parsed = merovingian::canonicaljson::parse_lossless(stored->json); + REQUIRE(parsed.error == merovingian::canonicaljson::ParseError::none); + auto const* event = std::get_if(&parsed.value.storage()); + REQUIRE(event != nullptr); + auto const* signatures = merovingian::tests::object_member_as_object(*event, "signatures"); + REQUIRE(signatures != nullptr); + auto const* by_server = merovingian::tests::object_member_as_object(*signatures, expected.server_name); + REQUIRE(by_server != nullptr); + auto const* signature = merovingian::tests::string_member(*by_server, key.key_id); + INFO("signing key " << key.key_id); + REQUIRE(signature != nullptr); + + auto const* policy = merovingian::homeserver::stored_room_version_policy(store, expected.private_room_id); + REQUIRE(policy != nullptr); + auto const payload = merovingian::events::make_event_signing_payload(parsed.value, *policy); + REQUIRE(payload.error == merovingian::canonicaljson::CanonicalJsonError::none); + auto const verified = merovingian::crypto::ed25519_verify( + merovingian::crypto::Ed25519PublicKey{merovingian::events::matrix_bytes_from_base64(key.public_key)}, + payload.output, + merovingian::crypto::Ed25519Signature{merovingian::events::matrix_bytes_from_base64(*signature)}); + REQUIRE(verified.valid); +} + } // namespace SCENARIO("A SQLite schema is built at v1 and stops there", "[database][upgrade][sqlite]") @@ -846,3 +1335,128 @@ SCENARIO("A PostgreSQL database a pre-1.0 build created is refused, not upgraded } } } + +SCENARIO("The 1.0.3 release's own SQLite database is migrated and served by this build", + "[database][upgrade][sqlite][homeserver][fixture]") +{ + GIVEN("a copy of the SQLite database the last 1.0.x release wrote, and its master key") + { + auto const expected = load_fixture_expectations("sqlite"); + auto const path = merovingian::tests::unique_temporary_path("merovingian-upgrade-fixture", ".sqlite3"); + std::filesystem::copy_file(fixture_directory() / "merovingian.sqlite3", path, + std::filesystem::copy_options::overwrite_existing); + std::filesystem::permissions(path, std::filesystem::perms::owner_read | std::filesystem::perms::owner_write); + auto const master_key = write_fixture_master_key(expected.master_key_hex); + auto const signing_key = sqlite_fixture_signing_key(path, expected.server_name); + // The release wrote schema v1: one ledger row, and none of version 2's tables. + auto const ledger_rows_before = sqlite_count(path, "SELECT count(*) FROM schema_migrations"); + auto const oauth_objects_before = + sqlite_count(path, "SELECT count(*) FROM sqlite_master WHERE name LIKE 'oauth%'"); + + WHEN("the migration path runs on it and the current runtime starts on the result") + { + auto const migrated = merovingian::database::migrate_sqlite_schema_to( + path.string(), merovingian::database::current_schema_version()); + // Version 2's tables take a row and give it back; the runtime is not started yet, so nothing else holds the + // file. + auto const oauth_tables_usable = + sqlite_execute(path, "INSERT INTO oauth_clients VALUES ('upgrade-probe', '{}', '0', '0')") && + sqlite_count(path, "SELECT count(*) FROM oauth_clients WHERE client_id = 'upgrade-probe'") == 1 && + sqlite_execute(path, "DELETE FROM oauth_clients WHERE client_id = 'upgrade-probe'"); + auto started = merovingian::homeserver::start_client_server( + sqlite_fixture_config(path, master_key, expected.server_name)); + REQUIRE(started.started); + auto const view = view_fixture(started.runtime, expected); + + THEN( + "the v1 to v2 step ran, version 2's tables are usable, and everything the old release stored is served") + { + REQUIRE(migrated.ok); + REQUIRE(expected.schema_version == 1); + REQUIRE(ledger_rows_before == 1); + REQUIRE(oauth_objects_before == 0); + REQUIRE(migrated.state.version == merovingian::database::current_schema_version()); + REQUIRE(static_cast(migrated.state.version) > expected.schema_version); + REQUIRE(static_cast(migrated.state.applied_migrations.size()) > ledger_rows_before); + REQUIRE(migrated.state.applied_migrations.back().name == "oauth_tables"); + REQUIRE(sqlite_count(path, "SELECT count(*) FROM schema_migrations") == + static_cast(migrated.state.applied_migrations.size())); + REQUIRE(sqlite_count(path, "SELECT count(*) FROM oauth_clients") == 0); + REQUIRE(sqlite_count(path, "SELECT count(*) FROM oauth_sessions") == 0); + REQUIRE(sqlite_count(path, "SELECT count(*) FROM sqlite_master WHERE type = 'index' AND " + "name = 'idx_oauth_sessions_client_id'") == 1); + REQUIRE(oauth_tables_usable); + REQUIRE(started.runtime.homeserver.database.schema_version == + merovingian::database::current_schema_version()); + require_fixture_served(view, expected); + require_signed_with_fixture_key(started.runtime, expected, view, signing_key); + } + } + std::filesystem::remove(path); + std::filesystem::remove(master_key); + } +} + +SCENARIO("The 1.0.3 release's own PostgreSQL database is migrated and served by this build", + "[database][upgrade][postgresql][integration][homeserver][fixture]") +{ + GIVEN("a PostgreSQL database restored from the dump the last 1.0.x release wrote") + { + auto const uri = postgresql_uri_from_environment(); + if (uri.empty()) + { + SUCCEED("skipped: MEROVINGIAN_TEST_POSTGRESQL_URI is not set"); + return; + } + auto const expected = load_fixture_expectations("postgresql"); + auto const scratch = merovingian::tests::ScratchPostgresqlDatabase{uri}; + REQUIRE(scratch.created()); + REQUIRE(pg_execute_script(scratch.conninfo(), read_binary_file(fixture_directory() / "postgresql.sql"))); + auto const uri_file = write_uri_file(scratch.conninfo()); + auto const master_key = write_fixture_master_key(expected.master_key_hex); + auto const signing_key = postgresql_fixture_signing_key(scratch.conninfo(), expected.server_name); + // The release wrote schema v1: one ledger row, and none of version 2's tables. + auto const ledger_rows_before = pg_count(scratch.conninfo(), "SELECT count(*) FROM schema_migrations"); + auto const oauth_tables_before = + pg_count(scratch.conninfo(), "SELECT count(*) FROM information_schema.tables WHERE " + "table_schema = 'public' AND table_name LIKE 'oauth%'"); + + WHEN("the migration path runs on it and the current runtime starts on the result") + { + auto const migrated = merovingian::database::migrate_postgresql_schema_to( + scratch.conninfo(), merovingian::database::current_schema_version()); + // Version 2's tables take a row and give it back; the runtime is not started yet. + auto const oauth_tables_usable = + pg_execute(scratch.conninfo(), "INSERT INTO oauth_clients VALUES ('upgrade-probe', '{}', '0', '0')") && + pg_count(scratch.conninfo(), "SELECT count(*) FROM oauth_clients WHERE client_id = 'upgrade-probe'") == + 1 && + pg_execute(scratch.conninfo(), "DELETE FROM oauth_clients WHERE client_id = 'upgrade-probe'"); + auto started = merovingian::homeserver::start_client_server( + postgresql_fixture_config(uri_file, master_key, expected.server_name)); + REQUIRE(started.started); + auto const view = view_fixture(started.runtime, expected); + + THEN( + "the v1 to v2 step ran, version 2's tables are usable, and everything the old release stored is served") + { + REQUIRE(migrated.ok); + REQUIRE(expected.schema_version == 1); + REQUIRE(ledger_rows_before == 1); + REQUIRE(oauth_tables_before == 0); + REQUIRE(migrated.state.version == merovingian::database::current_schema_version()); + REQUIRE(static_cast(migrated.state.version) > expected.schema_version); + REQUIRE(static_cast(migrated.state.applied_migrations.size()) > ledger_rows_before); + REQUIRE(migrated.state.applied_migrations.back().name == "oauth_tables"); + REQUIRE(pg_count(scratch.conninfo(), "SELECT count(*) FROM schema_migrations") == + static_cast(migrated.state.applied_migrations.size())); + REQUIRE(oauth_tables_usable); + REQUIRE(started.runtime.homeserver.database.schema_version == + merovingian::database::current_schema_version()); + require_fixture_served(view, expected); + require_signed_with_fixture_key(started.runtime, expected, view, signing_key); + } + } + std::filesystem::remove(uri_file); + std::filesystem::remove(master_key); + } +} diff --git a/tests/integration/test_sync_state_after_flow.cpp b/tests/integration/test_sync_state_after_flow.cpp new file mode 100644 index 000000000..b229d100c --- /dev/null +++ b/tests/integration/test_sync_state_after_flow.cpp @@ -0,0 +1,449 @@ +// SPDX-FileCopyrightText: 2026 James Chapman +// SPDX-License-Identifier: GPL-3.0-or-later +// +// GET /_matrix/client/v3/sync `use_state_after`: what this project decides beyond the spec's rows, driven through the +// client-server stack (ADR-0818 to ADR-0820). What the spec states is in +// tests/conformance/test_sync_state_after_conformance.cpp. +#include "../support/JsonTestSupport.hpp" +#include "../support/SyncStateAfterSupport.hpp" +#include "merovingian/homeserver/ClientServerRuntime.hpp" +#include "merovingian/homeserver/ClientServerStartResult.hpp" + +#include + +#include +#include +#include +#include + +namespace +{ + +using namespace merovingian::tests; +using namespace merovingian::tests::state_after_support; + +constexpr auto k_full_state_after = std::string_view{"&full_state=true&use_state_after=true"}; + +} // namespace + +// ADR-0818: a sync that finds nothing new in a joined room does not report it. +SCENARIO("A joined room with nothing new is not reported with use_state_after", + "[integration][sync][state-after][flow]") +{ + GIVEN("a room alice has synced") + { + auto started = merovingian::homeserver::start_client_server(state_after_config()); + REQUIRE(started.started); + auto& rt = started.runtime; + auto const alice = register_user(rt, "alice"); + auto const room = create_room(rt, alice, "public_chat"); + auto const initial = sync(rt, alice, k_no_filter, {}, k_state_after); + + WHEN("nothing happened") + { + auto const synced = sync(rt, alice, k_no_filter, initial.next_batch, k_state_after); + + THEN("the room is not reported") + { + REQUIRE(room_section(synced, "join", room) == nullptr); + } + } + } +} + +// ADR-0819: a delta chain is bounded (`max_state_group_delta_depth`); a window with more changes than it holds falls +// back to comparing the two states and still sends one event per changed key. +SCENARIO("A state_after delta survives more state changes than one delta chain can hold", + "[integration][sync][state-after][flow]") +{ + GIVEN("a room alice has synced") + { + auto started = merovingian::homeserver::start_client_server(state_after_config()); + REQUIRE(started.started); + auto& rt = started.runtime; + auto const alice = register_user(rt, "alice"); + auto const room = create_room(rt, alice, "public_chat"); + set_topic(rt, alice, room, "first"); + auto const initial = sync(rt, alice, k_no_filter, {}, k_state_after); + + WHEN("more state changes than one delta chain can hold happened") + { + for (auto index = 0; index < 120; ++index) + { + set_topic(rt, alice, room, "t" + std::to_string(index)); + } + auto const synced = sync(rt, alice, k_one_event, initial.next_batch, k_state_after); + + THEN("state_after still holds only the key that changed, with its last value") + { + auto const after = events_of(required_room(synced, "join", room), "state_after"); + REQUIRE(event_types(after) == Keys{"m.room.topic"}); + REQUIRE(topics_in(after) == std::vector{"t119"}); + } + } + } +} + +// ADR-0819: the chain walk (`state_changes_along_chain`) answers a single-extremity room from the state groups alone. +// The fallback reads the room's current state rows, which `state_rows_examined` counts, so a wide state shows which +// path ran. +SCENARIO("A state_after delta of an unforked room is read from the state groups, not the room's state", + "[integration][sync][state-after][flow][state-index]") +{ + GIVEN("a room with sixty state events that alice has synced, and one forward extremity") + { + auto started = merovingian::homeserver::start_client_server(state_after_config()); + REQUIRE(started.started); + auto& rt = started.runtime; + auto const alice = register_user(rt, "alice"); + auto const room = create_room(rt, alice, "public_chat"); + for (auto index = 0; index < 60; ++index) + { + auto const sent = + call(rt, "PUT", "/_matrix/client/v3/rooms/" + room + "/state/org.example.key/k" + std::to_string(index), + alice, R"({"value":"v"})"); + REQUIRE(sent.status == 200U); + } + auto const initial = sync(rt, alice, k_no_filter, {}, k_state_after); + auto const& store = rt.homeserver.database.persistent_store; + REQUIRE(store.forward_extremities.tips_of_room(room).size() == 1U); + + WHEN("a topic change arrives and alice syncs with use_state_after=true") + { + set_topic(rt, alice, room, "second"); + auto const before = store.state_rows_examined.value(); + auto const synced = sync(rt, alice, k_no_filter, initial.next_batch, k_state_after); + auto const examined = store.state_rows_examined.value() - before; + + THEN("only the topic is sent, and far fewer than sixty state rows were read") + { + auto const after = events_of(required_room(synced, "join", room), "state_after"); + REQUIRE(event_types(after) == Keys{"m.room.topic"}); + REQUIRE(examined < 30U); + } + } + WHEN("only a message arrives and alice syncs with use_state_after=true") + { + say(rt, alice, room, "hello"); + auto const before = store.state_rows_examined.value(); + auto const synced = sync(rt, alice, k_no_filter, initial.next_batch, k_state_after); + auto const examined = store.state_rows_examined.value() - before; + + THEN("state_after is empty, and far fewer than sixty state rows were read") + { + REQUIRE(events_of(required_room(synced, "join", room), "state_after").empty()); + REQUIRE(examined < 30U); + } + } + } +} + +// The parser accepts only the exact string `true`, as `full_state` does (ADR-0818). +SCENARIO("use_state_after is true only for the exact string true", "[integration][sync][state-after][flow]") +{ + GIVEN("a room alice has synced") + { + auto started = merovingian::homeserver::start_client_server(state_after_config()); + REQUIRE(started.started); + auto& rt = started.runtime; + auto const alice = register_user(rt, "alice"); + auto const room = create_room(rt, alice, "public_chat"); + auto const initial = sync(rt, alice, k_no_filter); + set_topic(rt, alice, room, "second"); + + WHEN("the value is True, 1 or empty") + { + auto const capital = sync(rt, alice, k_no_filter, initial.next_batch, "&use_state_after=True"); + auto const one = sync(rt, alice, k_no_filter, initial.next_batch, "&use_state_after=1"); + auto const empty = sync(rt, alice, k_no_filter, initial.next_batch, "&use_state_after="); + + THEN("each is read as false: state is present and state_after is omitted") + { + require_state_only(required_room(capital, "join", room)); + require_state_only(required_room(one, "join", room)); + require_state_only(required_room(empty, "join", room)); + } + } + WHEN("the value is true") + { + auto const exact = sync(rt, alice, k_no_filter, initial.next_batch, k_state_after); + + THEN("state_after is present and state is omitted") + { + require_state_after_only(required_room(exact, "join", room)); + } + } + } +} + +// ADR-0818: a client that joined inside the window held nothing of the room, so it is sent the whole state, with its +// own join, as an initial sync would. (The spec does not state it for an incremental sync.) +SCENARIO("state_after of a room joined in the window is the room's whole state", + "[integration][sync][state-after][flow]") +{ + GIVEN("a room bob joins after his first sync") + { + auto started = merovingian::homeserver::start_client_server(state_after_config()); + REQUIRE(started.started); + auto& rt = started.runtime; + auto const alice = register_user(rt, "alice"); + auto const bob = register_user(rt, "bob"); + auto const room = create_room(rt, alice, "public_chat"); + set_topic(rt, alice, room, "first"); + auto const initial = sync(rt, bob, k_no_filter, {}, k_state_after); + room_post(rt, bob, room, "join"); + + WHEN("bob syncs with use_state_after=true") + { + auto const synced = sync(rt, bob, k_no_filter, initial.next_batch, k_state_after); + auto const& joined = required_room(synced, "join", room); + + THEN("state_after holds all state, his own join included, and state is omitted") + { + require_state_after_only(joined); + auto const after = events_of(joined, "state_after"); + REQUIRE(event_types(after).contains("m.room.create")); + REQUIRE(topics_in(after) == std::vector{"first"}); + REQUIRE(content_of(after, "m.room.member", user_id("bob"), "membership") == "join"); + } + } + } +} + +// ADR-0820: the spec's Left Room `state_after` row does not name `full_state`, so a left room's `state_after` stays a +// delta, as its `state` does (ADR-0453). +SCENARIO("full_state=true leaves a left room's state_after a delta", "[integration][sync][state-after][flow]") +{ + GIVEN("a room dave joined and synced, and whose topic changed before he left") + { + auto started = merovingian::homeserver::start_client_server(state_after_config()); + REQUIRE(started.started); + auto& rt = started.runtime; + auto const alice = register_user(rt, "alice"); + auto const dave = register_user(rt, "dave"); + auto const room = create_room(rt, alice, "public_chat"); + set_topic(rt, alice, room, "first"); + room_post(rt, dave, room, "join"); + auto const synced_before = sync(rt, dave, k_no_filter, {}, k_state_after); + set_topic(rt, alice, room, "changed before the leave"); + room_post(rt, dave, room, "leave"); + + WHEN("dave makes an incremental sync with full_state=true and use_state_after=true") + { + auto const synced = sync(rt, dave, k_no_filter, synced_before.next_batch, k_full_state_after); + auto const& left = required_room(synced, "leave", room); + + THEN("state_after is the delta: the topic and his leave, not the whole state") + { + require_state_after_only(left); + auto const after = events_of(left, "state_after"); + REQUIRE_FALSE(event_types(after).contains("m.room.create")); + REQUIRE(event_types(after) == Keys{"m.room.member", "m.room.topic"}); + } + } + } +} + +// ADR-0820: a client that was not joined at `since` held nothing of the room, so a left room's `state_after` is the +// whole state as of the leave, not a delta that would hide the create event, power levels and join rules. +// +// Each GIVEN is one way the join that the leave ended can fall relative to `since`: after it (a join and leave inside +// one window, the first GIVEN; a rejoin after an earlier departure, the second), before it (the third, which must stay +// a delta so the rule is not widened to every left room), or never at all (the fourth, an invite that was declined). +SCENARIO("A room joined and left inside one sync window gives state_after its whole readable state", + "[integration][sync][state-after][flow]") +{ + GIVEN("a room dave joins and leaves after his last sync, in which the topic changed before he joined") + { + auto started = merovingian::homeserver::start_client_server(state_after_config()); + REQUIRE(started.started); + auto& rt = started.runtime; + auto const alice = register_user(rt, "alice"); + auto const dave = register_user(rt, "dave"); + auto const room = create_room(rt, alice, "public_chat"); + // The sync that fixes `since` is taken before dave is in the room, so he holds none of its state. + auto const before = sync(rt, dave, k_no_filter, {}, k_state_after); + // A topic set before his join is state he is entitled to read, and the one a delta would wrongly leave out. + set_topic(rt, alice, room, "before dave"); + room_post(rt, dave, room, "join"); + say(rt, dave, room, "hello and goodbye"); + room_post(rt, dave, room, "leave"); + // A change after the leave is beyond what he may read (ADR-0357), so it must not appear in his state_after. + set_topic(rt, alice, room, "after dave left"); + + WHEN("dave syncs with use_state_after=true") + { + auto const synced = sync(rt, dave, k_no_filter, before.next_batch, k_state_after); + auto const& left = required_room(synced, "leave", room); + + THEN("state_after is the room as of his leave: create, power levels, join rules, the topic and his leave") + { + require_state_after_only(left); + auto const after = events_of(left, "state_after"); + auto const types = event_types(after); + // The create event, power levels and join rules never changed in the window, so only a whole-state + // answer, not a delta, sends them. + REQUIRE(types.contains("m.room.create")); + REQUIRE(types.contains("m.room.power_levels")); + REQUIRE(types.contains("m.room.join_rules")); + // The topic is the one in force at his leave: "before dave", not the later "after dave left". + REQUIRE(topics_in(after) == std::vector{"before dave"}); + // His own key is the current member event, the leave, and it appears once (ADR-0820). + REQUIRE(content_of(after, "m.room.member", user_id("dave"), "membership") == "leave"); + REQUIRE(member_keys(after).count(user_id("dave")) == 1U); + } + } + // ADR-0820: a whole-state answer treats the room as new to the client, so lazy-loading does not consult the + // tracker and does not send his membership a second time. + WHEN("dave syncs with lazy-loading and use_state_after=true") + { + auto const synced = sync(rt, dave, k_lazy, before.next_batch, k_state_after); + auto const after = events_of(required_room(synced, "leave", room), "state_after"); + + THEN("the whole state comes with only his own membership, once, as the leave") + { + REQUIRE(event_types(after).contains("m.room.create")); + REQUIRE(member_keys(after).count(user_id("dave")) == 1U); + REQUIRE(content_of(after, "m.room.member", user_id("dave"), "membership") == "leave"); + } + } + } + // The join this leave ended began after `since` although dave had an earlier membership of the room: the rule + // reads the join's ordering, not whether the room was ever known to him. + GIVEN("a room dave left and synced, then rejoined and left again before his next sync") + { + auto started = merovingian::homeserver::start_client_server(state_after_config()); + REQUIRE(started.started); + auto& rt = started.runtime; + auto const alice = register_user(rt, "alice"); + auto const dave = register_user(rt, "dave"); + auto const room = create_room(rt, alice, "public_chat"); + room_post(rt, dave, room, "join"); + room_post(rt, dave, room, "leave"); + auto const after_first_leave = sync(rt, dave, k_no_filter, {}, k_state_after); + room_post(rt, dave, room, "join"); + room_post(rt, dave, room, "leave"); + + WHEN("dave syncs with use_state_after=true") + { + auto const synced = sync(rt, dave, k_no_filter, after_first_leave.next_batch, k_state_after); + auto const& left = required_room(synced, "leave", room); + + THEN("state_after is the whole readable state as of the second leave") + { + auto const after = events_of(left, "state_after"); + REQUIRE(event_types(after).contains("m.room.create")); + REQUIRE(content_of(after, "m.room.member", user_id("dave"), "membership") == "leave"); + } + } + } + // The control: he was joined at `since`, so he holds the room's state and a delta is correct. Without this case a + // rule that made every left room whole would pass the scenarios above. + GIVEN("a room dave was joined in at his last sync and left after its topic changed") + { + auto started = merovingian::homeserver::start_client_server(state_after_config()); + REQUIRE(started.started); + auto& rt = started.runtime; + auto const alice = register_user(rt, "alice"); + auto const dave = register_user(rt, "dave"); + auto const room = create_room(rt, alice, "public_chat"); + room_post(rt, dave, room, "join"); + auto const joined = sync(rt, dave, k_no_filter, {}, k_state_after); + set_topic(rt, alice, room, "changed"); + room_post(rt, dave, room, "leave"); + + WHEN("dave syncs with use_state_after=true") + { + auto const synced = sync(rt, dave, k_no_filter, joined.next_batch, k_state_after); + auto const after = events_of(required_room(synced, "leave", room), "state_after"); + + THEN("state_after is still the delta, as the client holds the rest of the state") + { + REQUIRE_FALSE(event_types(after).contains("m.room.create")); + REQUIRE(event_types(after) == Keys{"m.room.member", "m.room.topic"}); + } + } + } + // An invitee was never joined, so there is no join to cap the readable state at: the answer is only her own + // membership (ADR-0820, a user who never joined), not the private room's state. + GIVEN("a private room erin was invited to and declined inside one window") + { + auto started = merovingian::homeserver::start_client_server(state_after_config()); + REQUIRE(started.started); + auto& rt = started.runtime; + auto const alice = register_user(rt, "alice"); + auto const erin = register_user(rt, "erin"); + auto const room = create_room(rt, alice, "private_chat"); + auto const before = sync(rt, erin, k_no_filter, {}, k_state_after); + room_post(rt, alice, room, "invite", R"({"user_id":")" + user_id("erin") + R"("})"); + room_post(rt, erin, room, "leave"); + + WHEN("erin syncs with use_state_after=true") + { + auto const synced = sync(rt, erin, k_no_filter, before.next_batch, k_state_after); + auto const after = events_of(required_room(synced, "leave", room), "state_after"); + + THEN("she is told only her own leave, as she never could read the room") + { + REQUIRE(event_types(after) == Keys{"m.room.member"}); + REQUIRE(content_of(after, "m.room.member", user_id("erin"), "membership") == "leave"); + } + } + } +} + +// ADR-0450: a lost response must not make the server think the client holds a member it never received. +SCENARIO("A lazy-loaded member whose response was lost is sent again in state_after", + "[integration][sync][state-after][flow]") +{ + GIVEN("a room of alice, bob and carol, in which bob and carol have spoken") + { + auto started = merovingian::homeserver::start_client_server(state_after_config()); + REQUIRE(started.started); + auto& rt = started.runtime; + auto const alice = register_user(rt, "alice"); + auto const bob = register_user(rt, "bob"); + auto const carol = register_user(rt, "carol"); + auto const room = create_room(rt, alice, "public_chat"); + room_post(rt, bob, room, "join"); + room_post(rt, carol, room, "join"); + set_topic(rt, alice, room, "first"); + say(rt, carol, room, "carol"); + say(rt, bob, room, "bob"); + + WHEN("the response that carried carol's membership is lost and the client retries") + { + auto const first = sync(rt, alice, k_lazy_one_event, {}, k_state_after); + say(rt, carol, room, "carol again"); + auto const lost = sync(rt, alice, k_lazy, first.next_batch, k_state_after); + REQUIRE(member_keys(events_of(required_room(lost, "join", room), "state_after")) == Keys{user_id("carol")}); + auto const retried = sync(rt, alice, k_lazy, first.next_batch, k_state_after); + + THEN("it is sent again") + { + REQUIRE(member_keys(events_of(required_room(retried, "join", room), "state_after")) == + Keys{user_id("carol")}); + } + } + WHEN("the client acknowledged bob, and bob leaves and rejoins") + { + auto const bob_first = sync(rt, bob, k_lazy, {}, k_state_after); + say(rt, alice, room, "alice"); + auto const bob_second = sync(rt, bob, k_lazy, bob_first.next_batch, k_state_after); + auto const bob_third = sync(rt, bob, k_lazy, bob_second.next_batch, k_state_after); + room_post(rt, bob, room, "leave"); + auto const bob_left = sync(rt, bob, k_lazy, bob_third.next_batch, k_state_after); + room_post(rt, bob, room, "join"); + say(rt, alice, room, "welcome back"); + auto const rejoined = sync(rt, bob, k_lazy, bob_left.next_batch, k_state_after); + auto const after = events_of(required_room(rejoined, "join", room), "state_after"); + + THEN("the tracker is not consulted, and his own join is in state_after though the timeline carries it") + { + REQUIRE(member_keys(after).contains(user_id("alice"))); + REQUIRE(content_of(after, "m.room.member", user_id("bob"), "membership") == "join"); + REQUIRE(event_types(after).contains("m.room.create")); + } + } + } +} diff --git a/tests/integration/test_turn_shared_secret_flow.cpp b/tests/integration/test_turn_shared_secret_flow.cpp index e64722b68..ffdc24c2b 100644 --- a/tests/integration/test_turn_shared_secret_flow.cpp +++ b/tests/integration/test_turn_shared_secret_flow.cpp @@ -11,12 +11,12 @@ #include "../support/TempDirectory.hpp" #include "merovingian/config/ClientRateLimitsConfig.hpp" #include "merovingian/config/Config.hpp" +#include "merovingian/config/ConfigParser.hpp" #include "merovingian/config/ListenersConfig.hpp" #include "merovingian/config/LogModulesConfig.hpp" #include "merovingian/config/ReloadPlan.hpp" #include "merovingian/config/SecurityConfig.hpp" #include "merovingian/config/ServerConfig.hpp" -#include "merovingian/config/ConfigParser.hpp" #include "merovingian/crypto/HmacSha1.hpp" #include "merovingian/homeserver/ClientServerClock.hpp" #include "merovingian/homeserver/ClientServerRuntime.hpp" @@ -35,6 +35,7 @@ #include #include #include +#include #include namespace @@ -194,3 +195,43 @@ SCENARIO("GET /voip/turnServer issues per-user time-limited credentials from a s } } } + +SCENARIO("GET /voip/turnServer lists every server.turn.uris entry in order with shared-secret credentials", + "[homeserver][turn][turn-uris][client-server]") +{ + GIVEN("a server with two TURN URIs in server.turn.uris and a shared secret file") + { + auto const secret = SecretFile{"north\n"}; + auto config = secret_turn_config(secret.path(), 3600U); + config.server().turn.server.clear(); + config.server().turn.uris = {"turn:turn.example.org:3478?transport=udp", "turns:turn.example.org:5349"}; + auto started = merovingian::homeserver::start_client_server(std::move(config)); + REQUIRE(started.started); + auto& runtime = started.runtime; + auto const alice = login(runtime, "alice"); + + WHEN("a client asks for credentials") + { + auto const response = merovingian::homeserver::handle_client_server_request( + runtime, {"GET", "/_matrix/client/v3/voip/turnServer", alice, {}}); + + THEN("the credentials are per-user and uris holds both entries in the configured order") + { + REQUIRE(response.response.status == 200U); + auto const body = parse_object(response.response.body); + auto const* username = string_member(body, "username"); + REQUIRE(username != nullptr); + REQUIRE(username->ends_with(":@alice:example.org")); + auto const* uris = object_member_as_array(body, "uris"); + REQUIRE(uris != nullptr); + REQUIRE(uris->size() == 2U); + auto const* first = std::get_if(&(*uris)[0U].storage()); + auto const* second = std::get_if(&(*uris)[1U].storage()); + REQUIRE(first != nullptr); + REQUIRE(second != nullptr); + REQUIRE(*first == "turn:turn.example.org:3478?transport=udp"); + REQUIRE(*second == "turns:turn.example.org:5349"); + } + } + } +} diff --git a/tests/integration/test_voip_discovery_flow.cpp b/tests/integration/test_voip_discovery_flow.cpp new file mode 100644 index 000000000..5055442e2 --- /dev/null +++ b/tests/integration/test_voip_discovery_flow.cpp @@ -0,0 +1,552 @@ +// SPDX-FileCopyrightText: 2026 James Chapman +// SPDX-License-Identifier: GPL-3.0-or-later +// +// Voice and video call discovery at request level: several TURN URIs in GET /voip/turnServer (ADR-0821) and the +// MatrixRTC transports (MSC4143, ADR-0822). The transports routes are not in the Matrix v1.19 specification, so they +// have no conformance scenario. + +#include "../support/InMemoryDatabaseConfig.hpp" +#include "../support/JsonTestSupport.hpp" +#include "../support/MasterKey.hpp" +#include "../support/RegistrationToken.hpp" +#include "merovingian/canonicaljson/Value.hpp" +#include "merovingian/config/ClientRateLimitsConfig.hpp" +#include "merovingian/config/Config.hpp" +#include "merovingian/config/ListenersConfig.hpp" +#include "merovingian/config/LogModulesConfig.hpp" +#include "merovingian/config/SecurityConfig.hpp" +#include "merovingian/config/ServerConfig.hpp" +#include "merovingian/homeserver/AuthService.hpp" +#include "merovingian/homeserver/ClientServerRuntime.hpp" +#include "merovingian/homeserver/ClientServerStartResult.hpp" +#include "merovingian/homeserver/LocalHttpResponse.hpp" + +#include +#include + +#include +#include +#include +#include +#include +#include + +namespace +{ + +using namespace merovingian::tests; + +[[nodiscard]] auto voip_config(merovingian::config::ServerConfig server) -> merovingian::config::Config +{ + auto security = merovingian::config::SecurityConfig{}; + security.secrets.master_key_file = merovingian::tests::shared_master_key_file(); + merovingian::tests::enable_token_registration(security); + return { + std::move(server), + merovingian::config::ListenersConfig{}, + merovingian::tests::in_memory_database_config(), + std::move(security), + merovingian::config::ClientRateLimitsConfig{}, + merovingian::config::LogModulesConfig{}, + }; +} + +[[nodiscard]] auto login(merovingian::homeserver::ClientServerRuntime& runtime) -> std::string +{ + REQUIRE(merovingian::homeserver::handle_client_server_request( + runtime, {"POST", + "/_matrix/client/v3/register", + {}, + merovingian::tests::registration_json("alice", "CorrectHorse7!")}) + .response.status == 200U); + auto const response = merovingian::homeserver::handle_client_server_request( + runtime, {"POST", + "/_matrix/client/v3/login", + {}, + R"({"type":"m.login.password","identifier":{"type":"m.id.user","user":"@alice:example.org"},)" + R"("password":"CorrectHorse7!","device_id":"D1"})"}); + REQUIRE(response.response.status == 200U); + auto const body = parse_object(response.response.body); + auto const* token = string_member(body, "access_token"); + REQUIRE(token != nullptr); + return *token; +} + +[[nodiscard]] auto text_at(merovingian::canonicaljson::Array const& array, std::size_t index) -> std::string +{ + auto const* text = std::get_if(&array.at(index).storage()); + return text == nullptr ? std::string{""} : *text; +} + +[[nodiscard]] auto get(merovingian::homeserver::ClientServerRuntime& runtime, std::string const& target, + std::string const& token = {}) -> merovingian::homeserver::LocalHttpResponse +{ + return merovingian::homeserver::handle_client_server_request(runtime, {"GET", target, token, {}}).response; +} + +} // namespace + +SCENARIO("GET /voip/turnServer returns every server.turn.uris entry in order with static credentials", + "[homeserver][turn][turn-uris][client-server]") +{ + GIVEN("a server with three TURN URIs and static credentials") + { + auto server = merovingian::config::ServerConfig{}; + server.turn.uris = {"turn:turn.example.org:3478?transport=udp", "turn:turn.example.org:3478?transport=tcp", + "turns:turn.example.org:5349?transport=tcp"}; + server.turn.username = "turnuser"; + server.turn.password = "turnpass"; + server.turn.ttl_seconds = 600U; + auto started = merovingian::homeserver::start_client_server(voip_config(std::move(server))); + REQUIRE(started.started); + auto const token = login(started.runtime); + + WHEN("a client asks for TURN credentials") + { + auto const response = get(started.runtime, "/_matrix/client/v3/voip/turnServer", token); + + THEN("the uris array holds the three entries in the configured order") + { + REQUIRE(response.status == 200U); + auto const body = parse_object(response.body); + auto const* username = string_member(body, "username"); + REQUIRE(username != nullptr); + CHECK(*username == "turnuser"); + auto const* password = string_member(body, "password"); + REQUIRE(password != nullptr); + CHECK(*password == "turnpass"); + auto const* ttl = int_member(body, "ttl"); + REQUIRE(ttl != nullptr); + CHECK(*ttl == 600); + auto const* uris = object_member_as_array(body, "uris"); + REQUIRE(uris != nullptr); + REQUIRE(uris->size() == 3U); + CHECK(text_at(*uris, 0U) == "turn:turn.example.org:3478?transport=udp"); + CHECK(text_at(*uris, 1U) == "turn:turn.example.org:3478?transport=tcp"); + CHECK(text_at(*uris, 2U) == "turns:turn.example.org:5349?transport=tcp"); + } + } + } + + GIVEN("a server configured the 1.0.x way with the single server.turn.server") + { + auto server = merovingian::config::ServerConfig{}; + server.turn.server = "turn:turn.example.org:3478"; + server.turn.username = "turnuser"; + server.turn.password = "turnpass"; + auto started = merovingian::homeserver::start_client_server(voip_config(std::move(server))); + REQUIRE(started.started); + auto const token = login(started.runtime); + + WHEN("a client asks for TURN credentials") + { + auto const response = get(started.runtime, "/_matrix/client/v3/voip/turnServer", token); + + THEN("uris holds that one entry, as before") + { + REQUIRE(response.status == 200U); + auto const body = parse_object(response.body); + auto const* uris = object_member_as_array(body, "uris"); + REQUIRE(uris != nullptr); + REQUIRE(uris->size() == 1U); + CHECK(text_at(*uris, 0U) == "turn:turn.example.org:3478"); + } + } + } + + GIVEN("a server with neither TURN key") + { + auto started = merovingian::homeserver::start_client_server(voip_config({})); + REQUIRE(started.started); + auto const token = login(started.runtime); + + WHEN("a client asks for TURN credentials") + { + auto const response = get(started.runtime, "/_matrix/client/v3/voip/turnServer", token); + + THEN("the answer is the empty object") + { + REQUIRE(response.status == 200U); + CHECK(response.body == "{}"); + } + } + } +} + +namespace +{ + +constexpr auto livekit_url = "https://livekit-jwt.example.org/lk-jwt-service"; + +[[nodiscard]] auto rtc_server(std::string url) -> merovingian::config::ServerConfig +{ + auto server = merovingian::config::ServerConfig{}; + server.rtc.livekit_service_url = std::move(url); + return server; +} + +} // namespace + +// The same configured LiveKit service URL is served on two routes that differ in path and in the name of the array: +// the stable route as `transports`, the MSC4143 unstable route as `rtc_transports`. A client written against either +// must find the same single entry. With no URL configured neither route fails: the two answer their own empty shape. +SCENARIO("MatrixRTC transports are advertised on the stable and unstable paths", "[homeserver][rtc][client-server]") +{ + GIVEN("a server with a LiveKit service URL") + { + auto started = merovingian::homeserver::start_client_server(voip_config(rtc_server(livekit_url))); + REQUIRE(started.started); + auto const token = login(started.runtime); + + WHEN("a client reads the stable transports route") + { + auto const response = get(started.runtime, "/_matrix/client/v1/rtc/transports", token); + + THEN("it gets a livekit transport under `transports`") + { + REQUIRE(response.status == 200U); + auto const body = parse_object(response.body); + auto const* transports = object_member_as_array(body, "transports"); + REQUIRE(transports != nullptr); + REQUIRE(transports->size() == 1U); + // The exact body pins the serialised form (keys in canonical order, nothing extra) ... + CHECK( + response.body == + R"({"transports":[{"livekit_service_url":"https://livekit-jwt.example.org/lk-jwt-service","type":"livekit"}]})"); + auto const* entry = std::get_if(&(*transports)[0U].storage()); + REQUIRE(entry != nullptr); + // ... and the parsed checks name the two members a client reads, so a failure points at the member. + CHECK(entry->size() == 2U); + auto const* type = string_member(*entry, "type"); + REQUIRE(type != nullptr); + CHECK(*type == "livekit"); + auto const* service_url = string_member(*entry, "livekit_service_url"); + REQUIRE(service_url != nullptr); + CHECK(*service_url == livekit_url); + } + } + + // The query string is ignored by the route, as on the other client-server routes, but must not stop the route + // from matching. + WHEN("a client reads the unstable transports route, with a query string") + { + auto const response = + get(started.runtime, "/_matrix/client/unstable/org.matrix.msc4143/rtc/transports?unused=1", token); + + THEN("it gets the same entry under `rtc_transports`") + { + REQUIRE(response.status == 200U); + auto const body = parse_object(response.body); + CHECK( + response.body == + R"({"rtc_transports":[{"livekit_service_url":"https://livekit-jwt.example.org/lk-jwt-service","type":"livekit"}]})"); + auto const* transports = object_member_as_array(body, "rtc_transports"); + REQUIRE(transports != nullptr); + REQUIRE(transports->size() == 1U); + auto const* entry = std::get_if(&(*transports)[0U].storage()); + REQUIRE(entry != nullptr); + CHECK(entry->size() == 2U); + auto const* type = string_member(*entry, "type"); + REQUIRE(type != nullptr); + CHECK(*type == "livekit"); + auto const* service_url = string_member(*entry, "livekit_service_url"); + REQUIRE(service_url != nullptr); + CHECK(*service_url == livekit_url); + } + } + + // The stable route's own match with a query string; the unstable one is covered by the previous WHEN. + WHEN("a client reads the stable route with a query string") + { + auto const response = get(started.runtime, "/_matrix/client/v1/rtc/transports?unused=1", token); + + THEN("it still routes") + { + CHECK(response.status == 200U); + } + } + } + + // Without a URL the feature is off, but a client that asks is not told an error: it gets an empty answer in the + // shape of each route, so it can tell "none offered" from "route unknown". + GIVEN("a server with no LiveKit service URL") + { + auto started = merovingian::homeserver::start_client_server(voip_config({})); + REQUIRE(started.started); + auto const token = login(started.runtime); + + WHEN("a client reads each route") + { + auto const stable = get(started.runtime, "/_matrix/client/v1/rtc/transports", token); + auto const unstable = + get(started.runtime, "/_matrix/client/unstable/org.matrix.msc4143/rtc/transports", token); + + THEN("the stable path answers an empty list and the unstable path an empty object") + { + REQUIRE(stable.status == 200U); + CHECK(stable.body == R"({"transports":[]})"); + REQUIRE(unstable.status == 200U); + CHECK(unstable.body == "{}"); + } + } + } +} + +SCENARIO("MatrixRTC transports need an access token", "[homeserver][rtc][client-server]") +{ + GIVEN("a server with a LiveKit service URL") + { + auto started = merovingian::homeserver::start_client_server(voip_config(rtc_server(livekit_url))); + REQUIRE(started.started); + std::ignore = login(started.runtime); + + WHEN("each route is read without a token, and with an unknown one") + { + THEN("each answers 401 and names no URL") + { + for (auto const* path : {"/_matrix/client/v1/rtc/transports", + "/_matrix/client/unstable/org.matrix.msc4143/rtc/transports"}) + { + INFO(path); + auto const none = get(started.runtime, path); + auto const unknown = get(started.runtime, path, "not-a-token"); + CHECK(none.status == 401U); + CHECK(unknown.status == 401U); + CHECK(none.body.find("livekit") == std::string::npos); + CHECK(unknown.body.find("livekit") == std::string::npos); + } + } + } + } +} + +SCENARIO("/versions announces MatrixRTC discovery whether or not a service is configured", + "[homeserver][rtc][client-server]") +{ + GIVEN("servers with and without a LiveKit service URL") + { + auto with_url = merovingian::homeserver::start_client_server(voip_config(rtc_server(livekit_url))); + auto without = merovingian::homeserver::start_client_server(voip_config({})); + REQUIRE(with_url.started); + REQUIRE(without.started); + + WHEN("/versions is read on each") + { + auto const a = get(with_url.runtime, "/_matrix/client/versions"); + auto const b = get(without.runtime, "/_matrix/client/versions"); + + THEN("both carry org.matrix.msc4143 and org.matrix.msc4143.stable as true") + { + for (auto const* response : {&a, &b}) + { + REQUIRE(response->status == 200U); + auto const body = parse_object(response->body); + auto const* features = object_member_as_object(body, "unstable_features"); + REQUIRE(features != nullptr); + for (auto const* flag : {"org.matrix.msc4143", "org.matrix.msc4143.stable"}) + { + auto const* value = bool_member(*features, flag); + REQUIRE(value != nullptr); + CHECK(*value); + } + CHECK(bool_member(*features, "org.matrix.msc4186") != nullptr); + } + } + } + } +} + +SCENARIO("/.well-known/matrix/client carries rtc_foci only when a service is configured", + "[homeserver][rtc][client-server]") +{ + GIVEN("a server with a LiveKit service URL and a public base URL") + { + auto server = rtc_server(livekit_url); + server.public_baseurl = "https://matrix.example.org"; + auto started = merovingian::homeserver::start_client_server(voip_config(std::move(server))); + REQUIRE(started.started); + + WHEN("the well-known document is read") + { + auto const response = get(started.runtime, "/.well-known/matrix/client"); + + THEN("it adds org.matrix.msc4143.rtc_foci beside m.homeserver") + { + REQUIRE(response.status == 200U); + auto const body = parse_object(response.body); + CHECK( + response.body == + R"({"m.homeserver":{"base_url":"https://matrix.example.org"},"org.matrix.msc4143.rtc_foci":[{"livekit_service_url":"https://livekit-jwt.example.org/lk-jwt-service","type":"livekit"}]})"); + REQUIRE(object_member_as_object(body, "m.homeserver") != nullptr); + auto const* foci = object_member_as_array(body, "org.matrix.msc4143.rtc_foci"); + REQUIRE(foci != nullptr); + REQUIRE(foci->size() == 1U); + auto const* entry = std::get_if(&(*foci)[0U].storage()); + REQUIRE(entry != nullptr); + CHECK(entry->size() == 2U); + auto const* type = string_member(*entry, "type"); + REQUIRE(type != nullptr); + CHECK(*type == "livekit"); + auto const* service_url = string_member(*entry, "livekit_service_url"); + REQUIRE(service_url != nullptr); + CHECK(*service_url == livekit_url); + } + } + } + + GIVEN("a server with no LiveKit service URL") + { + auto server = merovingian::config::ServerConfig{}; + server.public_baseurl = "https://matrix.example.org"; + auto started = merovingian::homeserver::start_client_server(voip_config(std::move(server))); + REQUIRE(started.started); + + WHEN("the well-known document is read") + { + auto const response = get(started.runtime, "/.well-known/matrix/client"); + + THEN("the body is exactly what it was before MatrixRTC") + { + REQUIRE(response.status == 200U); + CHECK(response.body == R"({"m.homeserver":{"base_url":"https://matrix.example.org"}})"); + } + } + } +} + +namespace +{ + +[[nodiscard]] auto send(merovingian::homeserver::ClientServerRuntime& runtime, std::string const& method, + std::string const& target, std::string const& token = {}) + -> merovingian::homeserver::LocalHttpResponse +{ + return merovingian::homeserver::handle_client_server_request(runtime, {method, target, token, {}}).response; +} + +[[nodiscard]] auto header_of(merovingian::homeserver::LocalHttpResponse const& response, std::string_view name) + -> std::string +{ + for (auto const& [header_name, value] : response.headers) + { + if (header_name == name) + { + return value; + } + } + return {}; +} + +[[nodiscard]] auto errcode_of(merovingian::homeserver::LocalHttpResponse const& response) -> std::string +{ + auto const body = parse_object(response.body); + auto const* errcode = string_member(body, "errcode"); + return errcode == nullptr ? std::string{} : *errcode; +} + +constexpr auto turn_path = "/_matrix/client/v3/voip/turnServer"; +constexpr auto rtc_stable_path = "/_matrix/client/v1/rtc/transports"; +constexpr auto rtc_unstable_path = "/_matrix/client/unstable/org.matrix.msc4143/rtc/transports"; + +} // namespace + +SCENARIO("The MatrixRTC routes refuse other methods as voip/turnServer does", "[homeserver][rtc][client-server]") +{ + GIVEN("a server with a LiveKit service URL and a logged-in user") + { + auto started = merovingian::homeserver::start_client_server(voip_config(rtc_server(livekit_url))); + REQUIRE(started.started); + auto const token = login(started.runtime); + + WHEN("POST and PUT are sent to each route and to voip/turnServer") + { + THEN("each route answers the same status, errcode and Allow header as voip/turnServer") + { + for (auto const* method : {"POST", "PUT"}) + { + auto const reference = send(started.runtime, method, turn_path, token); + REQUIRE(reference.status == 405U); + for (auto const* path : {rtc_stable_path, rtc_unstable_path}) + { + INFO(method << ' ' << path); + auto const response = send(started.runtime, method, path, token); + CHECK(response.status == reference.status); + CHECK(errcode_of(response) == errcode_of(reference)); + CHECK(header_of(response, "Allow") == header_of(reference, "Allow")); + CHECK(header_of(response, "Allow") == "GET"); + } + } + } + } + } +} + +SCENARIO("The MatrixRTC routes treat a locked or suspended account as voip/turnServer does", + "[homeserver][rtc][client-server]") +{ + GIVEN("a logged-in user whose account is then locked or suspended") + { + auto server = rtc_server(livekit_url); + server.turn.server = "turn:turn.example.org:3478"; + server.turn.username = "turnuser"; + server.turn.password = "turnpass"; + auto started = merovingian::homeserver::start_client_server(voip_config(std::move(server))); + REQUIRE(started.started); + auto const token = login(started.runtime); + auto const suspended = GENERATE(false, true); + REQUIRE( + merovingian::homeserver::bootstrap_admin_user(started.runtime.homeserver, "admin", "CorrectHorse7!").ok); + REQUIRE(merovingian::homeserver::set_local_user_moderation(started.runtime.homeserver, "@admin:example.org", + "@alice:example.org", suspended, !suspended, + "account.locked", "locked") + .ok); + + WHEN("the user asks for TURN credentials and for each transports route") + { + auto const reference = send(started.runtime, "GET", turn_path, token); + + THEN("each route answers the same status and errcode, and a refusal names no service URL") + { + for (auto const* path : {rtc_stable_path, rtc_unstable_path}) + { + INFO((suspended ? "suspended " : "locked ") << path); + auto const response = send(started.runtime, "GET", path, token); + CHECK(response.status == reference.status); + CHECK(errcode_of(response) == errcode_of(reference)); + if (reference.status != 200U) + { + CHECK(response.body.find("livekit") == std::string::npos); + } + } + } + } + } +} + +SCENARIO("With only server.turn.server and static credentials voip/turnServer answers as in 1.0.x", + "[homeserver][turn][client-server]") +{ + GIVEN("a server configured the 1.0.x way") + { + auto server = merovingian::config::ServerConfig{}; + server.turn.server = "turn:turn.example.org:3478?transport=udp"; + server.turn.username = "turnuser"; + server.turn.password = "turnpass"; + auto started = merovingian::homeserver::start_client_server(voip_config(std::move(server))); + REQUIRE(started.started); + auto const token = login(started.runtime); + + WHEN("a client asks for TURN credentials") + { + auto const response = get(started.runtime, turn_path, token); + + THEN("the whole body is the one the 1.0 series sent") + { + REQUIRE(response.status == 200U); + CHECK( + response.body == + R"({"password":"turnpass","ttl":86400,"uris":["turn:turn.example.org:3478?transport=udp"],"username":"turnuser"})"); + } + } + } +} diff --git a/tests/meson.build b/tests/meson.build index 90aa1fca2..ecd15dfcd 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -335,6 +335,8 @@ shell = find_program('sh') 'unit/test_config_oauth.cpp', 'unit/test_config_sso.cpp', 'unit/test_config_identity_server.cpp', + 'unit/test_config_turn_uris.cpp', + 'unit/test_config_rtc.cpp', 'unit/test_identity_bind_domains.cpp', 'unit/test_config_parser.cpp', 'unit/test_config_reload_plan.cpp', @@ -544,6 +546,7 @@ shell = find_program('sh') 'unit/test_invite_room_state.cpp', 'unit/test_redaction_service.cpp', 'unit/test_sync_history_visibility.cpp', + 'unit/test_sync_state_anchor.cpp', 'unit/test_sync_notifier.cpp', 'unit/test_parked_poll_registry.cpp', 'unit/test_lazy_member_tracker.cpp', @@ -709,6 +712,7 @@ shell = find_program('sh') 'conformance/test_sync_archive_conformance.cpp', 'conformance/test_sync_state_conformance.cpp', 'conformance/test_lazy_load_members_conformance.cpp', + 'conformance/test_sync_state_after_conformance.cpp', 'conformance/test_identifier_grammar.cpp', 'conformance/test_ignoring_users_conformance.cpp', 'conformance/test_client_txn_scope_conformance.cpp', @@ -1002,8 +1006,10 @@ shell = find_program('sh') 'integration/test_server_signing_key_lifecycle_flow.cpp', 'integration/test_sync_dag_gap_flow.cpp', 'integration/test_sync_handler_flow.cpp', + 'integration/test_sync_state_after_flow.cpp', 'integration/test_sync_stream_position_flow.cpp', 'integration/test_turn_shared_secret_flow.cpp', + 'integration/test_voip_discovery_flow.cpp', ), include_directories: inc, link_args: password_hash_cost_link_args, diff --git a/tests/support/AGENTS.md b/tests/support/AGENTS.md index e6ed7cd03..9ff3cd6fb 100644 --- a/tests/support/AGENTS.md +++ b/tests/support/AGENTS.md @@ -20,6 +20,7 @@ Shared test utilities used across unit, conformance, and integration tests. | `IngestedStateFixture.hpp` | `record_ingested_state()` / `record_ingested_state_for_room()`: for a fixture that writes events straight into a `PersistentStore` and then asks for the state AT an event (federation `/state`, `/state_ids`, client `/context`), records the state group ingestion would have recorded for each event (state before = resolution of the prev_events' states, state after = that plus the event, unchanged for a rejected one). Those reads answer from the recorded state, never from a walk of the event graph (ADR-0363). Call it parents first | | `CrossSigningFixture.hpp` | `make_cross_signing_set()`: a master, self-signing and user-signing key with real Ed25519 keys and real signatures (the self-signing and user-signing keys signed by the master key), plus `sign_cross_signing_key_json()`, `cross_signing_upload_body()` and `fresh_cross_signing_upload_body()`. `POST /keys/device_signing/upload` verifies those signatures (ADR-0421), so a test that uploads cross-signing keys uses this, never invented key or signature text | | `ForgedUnsigned.hpp` | `with_forged_unsigned()` / `forged_unsigned_json`: a signed PDU with the `unsigned` a hostile relaying server would write (`m.relations`, `redacted_because`, `prev_content`, `age`, `transaction_id`, `membership`). The signatures and event ID still hold, so it ingests like the genuine PDU (ADR-0402) | +| `SyncStateAfterSupport.hpp` | `state_after_support`: the config, request, `/sync` and response-reading helpers the `use_state_after` conformance and integration scenarios share (`state_after_config`, `call`, `register_user`, `create_room`, `sync`, `required_room`, `events_of`, `event_types`, `member_keys`, ...). Drives the runtime the caller started | | `RegistrationToken.hpp` | Generates registration tokens for test users without going through the full UIAA flow | | `FakeClamdServer.hpp` | `FakeClamdServer`: a clamd stand-in on a temporary AF_UNIX socket. Reads INSTREAM exchanges, records the streamed bytes and answers with a fixed reply (or stays silent for the timeout case). Another I/O exception, shared by the unit and integration suites (G15, ADR-0565); assert on its recorded data from the test thread only | | `TempDirectory.hpp` | `temporary_directory()`: the fallback-aware temporary directory for test scratch files; `unique_temporary_path(stem, extension)`: a name under it unique to the process and call (pid, counter, random), not created. Every scratch file or directory a test creates is named with it, never a fixed name (ADR-0753) | diff --git a/tests/support/SyncStateAfterSupport.hpp b/tests/support/SyncStateAfterSupport.hpp new file mode 100644 index 000000000..d4f75b66b --- /dev/null +++ b/tests/support/SyncStateAfterSupport.hpp @@ -0,0 +1,274 @@ +// SPDX-FileCopyrightText: 2026 James Chapman +// SPDX-License-Identifier: GPL-3.0-or-later +#pragma once + +// Helpers the `use_state_after` conformance and integration scenarios share: a runtime configuration, requests against +// the in-process client-server stack, and readers of a `/sync` response's rooms and state. They drive the runtime the +// caller started and assert with Catch2; they open nothing themselves. + +#include "InMemoryDatabaseConfig.hpp" +#include "JsonTestSupport.hpp" +#include "MasterKey.hpp" +#include "RegistrationToken.hpp" +#include "merovingian/config/ClientRateLimitsConfig.hpp" +#include "merovingian/config/Config.hpp" +#include "merovingian/config/ListenersConfig.hpp" +#include "merovingian/config/LogModulesConfig.hpp" +#include "merovingian/config/SecurityConfig.hpp" +#include "merovingian/config/ServerConfig.hpp" +#include "merovingian/core/QueryParams.hpp" +#include "merovingian/homeserver/ClientServerRuntime.hpp" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace merovingian::tests::state_after_support +{ + +using merovingian::canonicaljson::Object; +using merovingian::homeserver::ClientServerRuntime; + +constexpr auto k_state_after = std::string_view{"&use_state_after=true"}; +constexpr auto k_state_before = std::string_view{"&use_state_after=false"}; +constexpr auto k_no_filter = std::string_view{"{}"}; +constexpr auto k_one_event = std::string_view{R"({"room":{"timeline":{"limit":1}}})"}; +constexpr auto k_lazy = std::string_view{R"({"room":{"state":{"lazy_load_members":true}}})"}; +constexpr auto k_lazy_one_event = + std::string_view{R"({"room":{"timeline":{"limit":1},"state":{"lazy_load_members":true}}})"}; +constexpr auto k_include_leave = std::string_view{R"({"room":{"include_leave":true}})"}; + +[[nodiscard]] inline auto state_after_config() -> merovingian::config::Config +{ + auto security = merovingian::config::SecurityConfig{}; + security.secrets.master_key_file = shared_master_key_file(); + enable_token_registration(security); + return { + merovingian::config::ServerConfig{}, + merovingian::config::ListenersConfig{}, + in_memory_database_config(), + security, + merovingian::config::ClientRateLimitsConfig{}, + merovingian::config::LogModulesConfig{}, + }; +} + +struct Reply final +{ + std::uint16_t status{0U}; + std::string body{}; +}; + +[[nodiscard]] inline auto call(ClientServerRuntime& rt, std::string method, std::string target, + std::string const& token, std::string body = {}) -> Reply +{ + auto const result = merovingian::homeserver::handle_client_server_request( + rt, {std::move(method), std::move(target), token, std::move(body)}, /*can_wait=*/false); + return {static_cast(result.response.status), result.response.body}; +} + +[[nodiscard]] inline auto user_id(std::string_view localpart) -> std::string +{ + return "@" + std::string{localpart} + ":example.org"; +} + +[[nodiscard]] inline auto register_user(ClientServerRuntime& rt, std::string const& localpart) -> std::string +{ + auto const registered = + call(rt, "POST", "/_matrix/client/v3/register", {}, registration_json(localpart, "CorrectHorse7!")); + REQUIRE(registered.status == 200U); + return *string_member(parse_object(registered.body), "access_token"); +} + +[[nodiscard]] inline auto create_room(ClientServerRuntime& rt, std::string const& token, std::string const& preset) + -> std::string +{ + auto const created = call(rt, "POST", "/_matrix/client/v3/createRoom", token, R"({"preset":")" + preset + R"("})"); + REQUIRE(created.status == 200U); + return *string_member(parse_object(created.body), "room_id"); +} + +inline auto room_post(ClientServerRuntime& rt, std::string const& token, std::string const& room_id, + std::string const& action, std::string body = "{}") -> void +{ + REQUIRE(call(rt, "POST", "/_matrix/client/v3/rooms/" + room_id + "/" + action, token, std::move(body)).status == + 200U); +} + +inline auto say(ClientServerRuntime& rt, std::string const& token, std::string const& room_id, std::string const& text) + -> void +{ + static auto counter = std::uint64_t{0U}; + auto const sent = + call(rt, "PUT", "/_matrix/client/v3/rooms/" + room_id + "/send/m.room.message/sa" + std::to_string(++counter), + token, R"({"msgtype":"m.text","body":")" + text + R"("})"); + REQUIRE(sent.status == 200U); +} + +inline auto set_topic(ClientServerRuntime& rt, std::string const& token, std::string const& room_id, + std::string const& topic) -> std::string +{ + auto const sent = call(rt, "PUT", "/_matrix/client/v3/rooms/" + room_id + "/state/m.room.topic/", token, + R"({"topic":")" + topic + R"("})"); + REQUIRE(sent.status == 200U); + return *string_member(parse_object(sent.body), "event_id"); +} + +inline auto set_display_name(ClientServerRuntime& rt, std::string const& token, std::string const& room_id, + std::string const& localpart, std::string const& name) -> void +{ + auto const sent = + call(rt, "PUT", "/_matrix/client/v3/rooms/" + room_id + "/state/m.room.member/" + user_id(localpart), token, + R"({"membership":"join","displayname":")" + name + R"("})"); + REQUIRE(sent.status == 200U); +} + +struct Synced final +{ + Object body{}; + std::string next_batch{}; +}; + +[[nodiscard]] inline auto sync(ClientServerRuntime& rt, std::string const& token, std::string_view filter, + std::string const& since = {}, std::string_view extra = {}) -> Synced +{ + auto target = + std::string{"/_matrix/client/v3/sync?filter="} + merovingian::core::percent_encode_path_component(filter); + if (!since.empty()) + { + target += "&since=" + merovingian::core::percent_encode_path_component(since); + } + target += extra; + auto const reply = call(rt, "GET", target, token); + REQUIRE(reply.status == 200U); + auto body = parse_object(reply.body); + auto next = *string_member(body, "next_batch"); + return {std::move(body), std::move(next)}; +} + +// rooms.
., or nullptr. +[[nodiscard]] inline auto room_section(Synced const& synced, std::string_view section, std::string const& room_id) + -> Object const* +{ + auto const* rooms = object_member_as_object(synced.body, "rooms"); + auto const* group = rooms == nullptr ? nullptr : object_member_as_object(*rooms, section); + return group == nullptr ? nullptr : object_member_as_object(*group, room_id); +} + +[[nodiscard]] inline auto required_room(Synced const& synced, std::string_view section, std::string const& room_id) + -> Object const& +{ + auto const* room = room_section(synced, section, room_id); + REQUIRE(room != nullptr); + return *room; +} + +// Whether `room` has the member `part`, whatever it holds. +[[nodiscard]] inline auto has_part(Object const& room, std::string_view part) -> bool +{ + return object_member(room, part) != nullptr; +} + +// The events of `room.`, which must be present. +[[nodiscard]] inline auto events_of(Object const& room, std::string_view part) -> std::vector +{ + auto const* section = object_member_as_object(room, part); + REQUIRE(section != nullptr); + auto const* events = object_member_as_array(*section, "events"); + REQUIRE(events != nullptr); + auto out = std::vector{}; + for (auto const& entry : *events) + { + out.push_back(std::get(entry.storage())); + } + return out; +} + +using Keys = std::multiset; + +[[nodiscard]] inline auto event_types(std::vector const& events) -> Keys +{ + auto types = Keys{}; + for (auto const& event : events) + { + types.insert(*string_member(event, "type")); + } + return types; +} + +// The state_key of every m.room.member event. +[[nodiscard]] inline auto member_keys(std::vector const& events) -> Keys +{ + auto keys = Keys{}; + for (auto const& event : events) + { + if (*string_member(event, "type") == "m.room.member") + { + keys.insert(*string_member(event, "state_key")); + } + } + return keys; +} + +// `content.` of the event of (type, state_key), or nullopt when `events` has none. +[[nodiscard]] inline auto content_of(std::vector const& events, std::string_view type, + std::string_view state_key, std::string_view field) -> std::optional +{ + for (auto const& event : events) + { + auto const* key = string_member(event, "state_key"); + if (*string_member(event, "type") == type && key != nullptr && *key == state_key) + { + auto const* content = object_member_as_object(event, "content"); + auto const* value = content == nullptr ? nullptr : string_member(*content, field); + return value == nullptr ? std::optional{} : std::optional{*value}; + } + } + return std::nullopt; +} + +// The `content.topic` of every m.room.topic event in `events`. +[[nodiscard]] inline auto topics_in(std::vector const& events) -> std::vector +{ + auto topics = std::vector{}; + for (auto const& event : events) + { + if (*string_member(event, "type") == "m.room.topic") + { + auto const* content = object_member_as_object(event, "content"); + topics.push_back(*string_member(*content, "topic")); + } + } + return topics; +} + +// The required section must exist, be an object and hold an `events` array, even an empty one (the spec's `State`). +inline auto require_state_section(Object const& room, std::string_view part) -> void +{ + REQUIRE(has_part(room, part)); + auto const* section = object_member_as_object(room, part); + REQUIRE(section != nullptr); + REQUIRE(object_member_as_array(*section, "events") != nullptr); +} + +// The forbidden section is judged by presence: the key must not exist, whatever its value. +inline auto require_state_after_only(Object const& room) -> void +{ + require_state_section(room, "state_after"); + REQUIRE_FALSE(has_part(room, "state")); +} + +inline auto require_state_only(Object const& room) -> void +{ + require_state_section(room, "state"); + REQUIRE_FALSE(has_part(room, "state_after")); +} + +} // namespace merovingian::tests::state_after_support diff --git a/tests/unit/test_config_rtc.cpp b/tests/unit/test_config_rtc.cpp new file mode 100644 index 000000000..dccb8374f --- /dev/null +++ b/tests/unit/test_config_rtc.cpp @@ -0,0 +1,181 @@ +// SPDX-FileCopyrightText: 2026 James Chapman +// SPDX-License-Identifier: GPL-3.0-or-later +// +// server.rtc.livekit.service_url: where MatrixRTC clients get a LiveKit token (MSC4143, MSC4195; ADR-0822). The +// routes that advertise it are not in Matrix v1.19, so these are project-level checks. + +#include "merovingian/config/Config.hpp" +#include "merovingian/config/ConfigParseResult.hpp" +#include "merovingian/config/ConfigParser.hpp" +#include "merovingian/config/ConfigValidationFinding.hpp" +#include "merovingian/config/ReloadPlan.hpp" +#include "merovingian/config/ReloadPolicy.hpp" +#include "merovingian/config/ServerConfig.hpp" + +#include + +#include +#include +#include +#include + +namespace +{ + +[[nodiscard]] auto has_finding(std::vector const& findings, + std::string_view field) -> bool +{ + for (auto const& finding : findings) + { + if (finding.field == field) + { + return true; + } + } + return false; +} + +[[nodiscard]] auto parse_url(std::string const& url) -> merovingian::config::ConfigParseResult +{ + return merovingian::config::parse_key_value_config("server.rtc.livekit.service_url=" + url + "\n"); +} + +} // namespace + +SCENARIO("server.rtc.livekit.service_url accepts an https URL and defaults to none", "[config][rtc]") +{ + GIVEN("a configuration that does not mention the key") + { + WHEN("it is parsed") + { + auto const parsed = merovingian::config::parse_key_value_config(""); + + THEN("no transport is configured and nothing is reported") + { + CHECK(parsed.config.server().rtc.livekit_service_url.empty()); + CHECK_FALSE(has_finding(parsed.findings, "server.rtc.livekit.service_url")); + } + } + } + + GIVEN("a valid https URL, with a port and a path") + { + WHEN("it is parsed") + { + auto const parsed = parse_url("https://livekit-jwt.example.org:8443/lk-jwt-service"); + + THEN("it is kept exactly as written") + { + CHECK_FALSE(has_finding(parsed.findings, "server.rtc.livekit.service_url")); + CHECK(parsed.config.server().rtc.livekit_service_url == + "https://livekit-jwt.example.org:8443/lk-jwt-service"); + } + } + } +} + +SCENARIO("server.rtc.livekit.service_url accepts a URL a client can append to", "[config][rtc]") +{ + GIVEN("URLs that /sfu/get or /get_token can be appended to") + { + auto const good_urls = std::vector{"https://livekit-jwt.example.org", + "https://livekit-jwt.example.org:8443", "https://[2001:db8::1]", + "https://[2001:db8::1]:8443/jwt", "https://example.org/a/b"}; + + WHEN("each is parsed") + { + auto parsed = std::vector{}; + for (auto const& good : good_urls) + { + parsed.push_back(parse_url(good)); + } + + THEN("each is accepted: a bare host, a port, an IPv6 literal, a path with no trailing slash") + { + REQUIRE(parsed.size() == good_urls.size()); + for (auto index = std::size_t{0U}; index < good_urls.size(); ++index) + { + INFO(good_urls[index]); + REQUIRE_FALSE(has_finding(parsed[index].findings, "server.rtc.livekit.service_url")); + REQUIRE(parsed[index].config.server().rtc.livekit_service_url == good_urls[index]); + } + } + } + } +} + +SCENARIO("server.rtc.livekit.service_url refuses anything but a plain https URL", "[config][rtc]") +{ + GIVEN("values that are not acceptable") + { + auto const long_url = "https://example.org/" + std::string(2100U, 'a'); + auto const bad = std::vector{ + "http://livekit.example.org", + "HTTPS://livekit.example.org", + "ftp://livekit.example.org", + "livekit.example.org", + "//livekit.example.org", + "https://", + "https:///path", + "https://user@livekit.example.org", + "https://user:pw@livekit.example.org", + "https://livekit.example.org/#frag", + "https://livekit.example.org/a b", + "https://livekit.example.org/\x01", + "https://livekit.example.org/caf\xC3\xA9", + "https://livekit.example.org/x?a=1", + "https://livekit.example.org?a=1", + "https://livekit.example.org/x?", + "https://livekit.example.org/jwt/", + "https://livekit.example.org/", + "https://livekit.example.org:8443/", + long_url, + }; + + WHEN("each is parsed") + { + auto parsed = std::vector{}; + for (auto const& url : bad) + { + parsed.push_back(parse_url(url)); + } + + THEN("each is refused with a finding on the key, and is never repaired") + { + REQUIRE(parsed.size() == bad.size()); + for (auto index = std::size_t{0U}; index < bad.size(); ++index) + { + INFO(bad[index].substr(0U, 60U)); + REQUIRE(has_finding(parsed[index].findings, "server.rtc.livekit.service_url")); + REQUIRE_FALSE(merovingian::config::is_valid(parsed[index].config)); + } + } + } + } +} + +SCENARIO("server.rtc.livekit.service_url is reloadable and diffed by the reload plan", "[config][rtc]") +{ + GIVEN("two configurations that differ only in the service URL") + { + auto const before = parse_url("https://a.example.org"); + auto const after = parse_url("https://b.example.org"); + + WHEN("a reload is planned") + { + auto const plan = merovingian::config::build_reload_plan(before.config, after.config); + + THEN("the key is named and needs no restart") + { + auto found = false; + for (auto const& change : plan.changes()) + { + found = found || change.key == "server.rtc.livekit.service_url"; + } + CHECK(found); + CHECK(merovingian::config::reload_policy_for_key("server.rtc.livekit.service_url") == + merovingian::config::ReloadPolicy::reloadable); + } + } + } +} diff --git a/tests/unit/test_config_turn_uris.cpp b/tests/unit/test_config_turn_uris.cpp new file mode 100644 index 000000000..0c8547e0f --- /dev/null +++ b/tests/unit/test_config_turn_uris.cpp @@ -0,0 +1,429 @@ +// SPDX-FileCopyrightText: 2026 James Chapman +// SPDX-License-Identifier: GPL-3.0-or-later +// +// server.turn.uris: several TURN URIs beside the older single server.turn.server (ADR-0821). +// Spec: docs/matrix-v1.19-spec/client-server-api.md, "Voice over IP": `uris` is a list of TURN URIs. + +#include "merovingian/config/Config.hpp" +#include "merovingian/config/ConfigParseResult.hpp" +#include "merovingian/config/ConfigParser.hpp" +#include "merovingian/config/ConfigValidationFinding.hpp" +#include "merovingian/config/ReloadPlan.hpp" +#include "merovingian/config/ReloadPolicy.hpp" +#include "merovingian/config/ServerConfig.hpp" + +#include + +#include +#include +#include +#include + +namespace +{ + +[[nodiscard]] auto has_finding(std::vector const& findings, + std::string_view field) -> bool +{ + for (auto const& finding : findings) + { + if (finding.field == field) + { + return true; + } + } + return false; +} + +[[nodiscard]] auto parse_uris(std::string const& uris) -> merovingian::config::ConfigParseResult +{ + return merovingian::config::parse_key_value_config("server.turn.uris=" + uris + + "\nserver.turn.username=u\nserver.turn.password=p\n"); +} + +// Each entry parsed as the whole list, after `prefix`, in order. +[[nodiscard]] auto parse_each(std::vector const& entries, std::string const& prefix = {}) + -> std::vector +{ + auto results = std::vector{}; + for (auto const& entry : entries) + { + results.push_back(parse_uris(prefix + entry)); + } + return results; +} + +// `count` distinct turn: URIs, comma-separated. +[[nodiscard]] auto numbered_uris(int count) -> std::string +{ + auto list = std::string{}; + for (int i = 0; i < count; ++i) + { + list += (i == 0 ? "" : ","); + list += "turn:t" + std::to_string(i) + ".example.org"; + } + return list; +} + +} // namespace + +SCENARIO("server.turn.uris lists several TURN URIs in order", "[config][turn][turn-uris]") +{ + GIVEN("a UDP, a TCP and a TLS relay and static credentials") + { + auto const parsed = + parse_uris("turn:turn.example.org:3478?transport=udp, turn:turn.example.org:3478?transport=tcp," + "turns:turn.example.org:5349?transport=tcp"); + + WHEN("validated") + { + THEN("the entries are kept in the configured order and nothing is reported") + { + REQUIRE(merovingian::config::is_valid(parsed.config)); + REQUIRE(parsed.findings.empty()); + auto const& uris = parsed.config.server().turn.uris; + REQUIRE(uris.size() == 3U); + CHECK(uris[0U] == "turn:turn.example.org:3478?transport=udp"); + CHECK(uris[1U] == "turn:turn.example.org:3478?transport=tcp"); + CHECK(uris[2U] == "turns:turn.example.org:5349?transport=tcp"); + CHECK(parsed.config.server().turn.server.empty()); + } + } + } + + GIVEN("only the older server.turn.server key, as a 1.0.x config sets it") + { + auto const parsed = merovingian::config::parse_key_value_config( + "server.turn.server=turn:turn.example.org:3478\nserver.turn.username=u\nserver.turn.password=p\n"); + + WHEN("validated") + { + THEN("it is accepted unchanged and server.turn.uris stays empty") + { + REQUIRE(merovingian::config::is_valid(parsed.config)); + CHECK(parsed.config.server().turn.server == "turn:turn.example.org:3478"); + CHECK(parsed.config.server().turn.uris.empty()); + } + } + } + + GIVEN("server.turn.uris with a shared secret file and no username or password") + { + auto const parsed = merovingian::config::parse_key_value_config( + "server.turn.uris=turn:t.example.org\nserver.turn.shared_secret_file=/run/secrets/turn\n"); + + WHEN("validated") + { + THEN("the list alone enables TURN, so nothing is reported") + { + REQUIRE(merovingian::config::is_valid(parsed.config)); + } + } + } +} + +SCENARIO("server.turn.uris accepts the RFC 7065 forms and refuses everything else", "[config][turn][turn-uris]") +{ + GIVEN("entries that follow the TURN URI grammar") + { + auto const good_entries = std::vector{"turn:turn.example.org", + "turn:turn.example.org:3478", + "turn:turn.example.org:3478?transport=udp", + "turns:turn.example.org:5349?transport=tcp", + "turn:192.0.2.1:3478", + "turn:[2001:db8::1]:3478", + "turn:[::1]", + "turn:[::ffff:192.0.2.1]:3478?transport=tcp", + "turn:[2001:db8::1]", + "turn:a-b.example.org:65535", + "turn:turn.example.org:1?transport=tcp"}; + + WHEN("each is parsed as the whole list") + { + auto const parsed = parse_each(good_entries); + + THEN("each is accepted") + { + REQUIRE(parsed.size() == good_entries.size()); + for (auto index = std::size_t{0U}; index < good_entries.size(); ++index) + { + INFO(good_entries[index]); + REQUIRE(merovingian::config::is_valid(parsed[index].config)); + REQUIRE_FALSE(has_finding(parsed[index].findings, "server.turn.uris")); + } + } + } + } + + GIVEN("entries with no host, or that leave the grammar") + { + auto const bad_entries = std::vector{"turn:?transport=udp", + "turn::3478", + "turn:@x", + "turns:/x", + "turn:turn.example.org:", + "turn:turn.example.org:0", + "turn:turn.example.org:65536", + "turn:turn.example.org:+3478", + "turn:turn.example.org:34a8", + "turn:turn.example.org:3478?transport=sctp", + "turn:turn.example.org:3478?transport=udp&x=1", + "turn:turn.example.org:3478?x=1", + "turn:turn.example.org:3478?transport=", + "turn:turn.example.org:3478?transport=udp?x", + "turn:turn.example.org.", + "turn:.example.org", + "turn:-example.org", + "turn:example.org-", + "turn:u@turn.example.org", + "turn:turn.example.org/path", + "turn:turn.example.org#frag", + "turn:turn.example.org:3478#frag", + "turn:turn_example.org", + "turn:[2001:db8::1", + "turn:2001:db8::1]:3478", + "turn:[]:3478", + "turn:[2001:db8::g]:3478", + "turn:[2001:db8::1]x", + "turn:[2001:db8::1]:", + "turn:[example.org]", + "turn:[:]", + "turn:[::::]", + "turn:[12345::1]", + "turn:[]", + "turn:[::1", + "turn:[fe80::1%eth0]"}; + + // The valid first entry shows that one good entry does not carry a bad one with it. + WHEN("each is parsed after a valid entry") + { + auto const parsed = parse_each(bad_entries, "turn:ok.example.org,"); + + THEN("each is refused") + { + REQUIRE(parsed.size() == bad_entries.size()); + for (auto index = std::size_t{0U}; index < bad_entries.size(); ++index) + { + INFO(bad_entries[index]); + REQUIRE_FALSE(merovingian::config::is_valid(parsed[index].config)); + REQUIRE(has_finding(parsed[index].findings, "server.turn.uris")); + } + } + } + } +} + +SCENARIO("server.turn.uris uses the config's ordinary comma-separated list syntax", "[config][turn][turn-uris]") +{ + GIVEN("a list with an empty entry between two URIs") + { + WHEN("it is parsed") + { + auto const parsed = parse_uris("turn:a.example,,turn:b.example"); + + THEN("the empty entry is ignored") + { + REQUIRE(merovingian::config::is_valid(parsed.config)); + REQUIRE(parsed.config.server().turn.uris.size() == 2U); + CHECK(parsed.config.server().turn.uris[0U] == "turn:a.example"); + CHECK(parsed.config.server().turn.uris[1U] == "turn:b.example"); + } + } + } + + GIVEN("a list with a trailing comma and whitespace around entries") + { + WHEN("it is parsed") + { + auto const parsed = parse_uris(" turn:a.example ,\tturn:b.example , "); + + THEN("whitespace around an entry and the empty last entry are ignored") + { + REQUIRE(merovingian::config::is_valid(parsed.config)); + REQUIRE(parsed.config.server().turn.uris.size() == 2U); + CHECK(parsed.config.server().turn.uris[0U] == "turn:a.example"); + CHECK(parsed.config.server().turn.uris[1U] == "turn:b.example"); + } + } + } + + GIVEN("a value of only a comma") + { + WHEN("it is parsed") + { + auto const parsed = merovingian::config::parse_key_value_config("server.turn.uris=,\n"); + + THEN("the list is empty and TURN is not configured") + { + REQUIRE(merovingian::config::is_valid(parsed.config)); + CHECK(parsed.config.server().turn.uris.empty()); + } + } + } +} + +// ADR-0821: every entry of server.turn.uris is sent to every client, so a bad one is refused at parse time and never +// repaired (trimmed, lower-cased, dropped). Each GIVEN is one way a list can be unsafe or ambiguous: which key sets it, +// the entry's scheme, its characters, its length, the list's length, a repeat, and missing credentials. The valid +// shapes, and the host, port and transport grammar, are in the scenarios above. +SCENARIO("server.turn.uris refuses a bad list and never repairs it", "[config][turn][turn-uris]") +{ + // Both keys would leave it unclear which URI clients get, so the configuration is refused rather than one chosen. + GIVEN("both server.turn.server and server.turn.uris") + { + WHEN("the configuration is parsed") + { + auto const parsed = merovingian::config::parse_key_value_config( + "server.turn.server=turn:a.example.org\nserver.turn.uris=turn:b.example.org\n" + "server.turn.username=u\nserver.turn.password=p\n"); + + THEN("the configuration is refused naming server.turn.uris") + { + REQUIRE_FALSE(merovingian::config::is_valid(parsed.config)); + REQUIRE(has_finding(parsed.findings, "server.turn.uris")); + } + } + } + + GIVEN("an entry with a scheme other than turn: or turns:") + { + // Each entry fails the scheme rule alone: a foreign scheme, a STUN URI, an upper-case scheme (the grammar is + // case-sensitive, so it is not folded), a bare host:port, and a scheme with nothing after it. + auto const bad_entries = std::vector{"https://t.example.org", "stun:t.example.org", + "TURN:t.example.org", "turn.example.org:3478", "turn:"}; + + WHEN("each is parsed after a valid entry") + { + auto const parsed = parse_each(bad_entries, "turn:ok.example.org,"); + + THEN("each is refused") + { + REQUIRE(parsed.size() == bad_entries.size()); + for (auto index = std::size_t{0U}; index < bad_entries.size(); ++index) + { + INFO(bad_entries[index]); + REQUIRE_FALSE(merovingian::config::is_valid(parsed[index].config)); + REQUIRE(has_finding(parsed[index].findings, "server.turn.uris")); + } + } + } + } + + GIVEN("an entry holding whitespace or a control character") + { + WHEN("each is parsed") + { + // Whitespace inside an entry is not the separator the list trims around, so it is not repaired by splitting + // or trimming. The last entry is non-ASCII (UTF-8 for an e with an acute accent); only printable ASCII + // is accepted. + auto const inner_space = parse_uris("turn:a b.example.org"); + auto const tab = parse_uris("turn:a\tb.example.org"); + auto const bell = parse_uris("turn:a\x07.example.org"); + auto const high = parse_uris("turn:caf\xC3\xA9.example.org"); + + THEN("each is refused") + { + for (auto const* parsed : {&inner_space, &tab, &bell, &high}) + { + REQUIRE_FALSE(merovingian::config::is_valid(parsed->config)); + REQUIRE(has_finding(parsed->findings, "server.turn.uris")); + } + } + } + } + + GIVEN("an entry longer than 512 bytes") + { + // "turn:" is five bytes, so 507 further bytes is exactly the 512-byte limit and 508 is the first byte over it. + auto const longest = "turn:" + std::string(507U, 'a'); + auto const too_long = "turn:" + std::string(508U, 'a'); + + WHEN("an entry of 512 bytes and one of 513 bytes are parsed") + { + auto const accepted = parse_uris(longest); + auto const refused = parse_uris(too_long); + + THEN("512 bytes is accepted and 513 is refused") + { + REQUIRE(merovingian::config::is_valid(accepted.config)); + REQUIRE_FALSE(merovingian::config::is_valid(refused.config)); + REQUIRE(has_finding(refused.findings, "server.turn.uris")); + } + } + } + + GIVEN("more than 16 entries") + { + // The boundary is tested from both sides, so the limit is exactly 16 and not an off-by-one either way. + WHEN("a list of 16 and a list of 17 are parsed") + { + auto const accepted = parse_uris(numbered_uris(16)); + auto const refused = parse_uris(numbered_uris(17)); + + THEN("16 are accepted and 17 are refused") + { + REQUIRE(merovingian::config::is_valid(accepted.config)); + REQUIRE_FALSE(merovingian::config::is_valid(refused.config)); + REQUIRE(has_finding(refused.findings, "server.turn.uris")); + } + } + } + + GIVEN("the same entry twice") + { + WHEN("the list is parsed") + { + // The repeat is the third entry, not adjacent to the first, and the different scheme between them must not + // hide it from the check. + auto const parsed = parse_uris("turn:t.example.org,turns:t.example.org,turn:t.example.org"); + + THEN("the configuration is refused") + { + REQUIRE_FALSE(merovingian::config::is_valid(parsed.config)); + REQUIRE(has_finding(parsed.findings, "server.turn.uris")); + } + } + } + + // The list turns TURN on by itself, so it must be held to the same credential rule as server.turn.server; it is + // not a way to publish a relay with no username or password. + GIVEN("server.turn.uris set but credentials missing") + { + WHEN("the configuration is parsed") + { + auto const parsed = merovingian::config::parse_key_value_config("server.turn.uris=turn:t.example.org\n"); + + THEN("the missing username and password are reported, as for server.turn.server") + { + REQUIRE(has_finding(parsed.findings, "server.turn.username")); + REQUIRE(has_finding(parsed.findings, "server.turn.password")); + } + } + } +} + +SCENARIO("server.turn.uris is reloadable and diffed like the other server.turn keys", "[config][turn][turn-uris]") +{ + GIVEN("two configurations that differ only in server.turn.uris") + { + auto const before = parse_uris("turn:a.example.org"); + auto const after = parse_uris("turn:a.example.org,turns:a.example.org"); + + WHEN("a reload is planned") + { + auto const plan = merovingian::config::build_reload_plan(before.config, after.config); + + THEN("the key is reported and needs no restart") + { + bool found = false; + for (auto const& change : plan.changes()) + { + found = found || change.key == "server.turn.uris"; + } + CHECK(found); + CHECK(merovingian::config::reload_policy_for_key("server.turn.uris") == + merovingian::config::ReloadPolicy::reloadable); + } + } + } +} diff --git a/tests/unit/test_event_table.cpp b/tests/unit/test_event_table.cpp index 53ab27c5c..66fdfbbfe 100644 --- a/tests/unit/test_event_table.cpp +++ b/tests/unit/test_event_table.cpp @@ -1052,3 +1052,31 @@ SCENARIO("An event table lists the children of an event without scanning its row } } } + +SCENARIO("An event table walks one room's rows at or below a stream ordering", "[database][event-table][room-stream]") +{ + GIVEN("a room with rows sharing an ordering and another room") + { + auto table = EventTable{}; + REQUIRE(table.insert(make_event("$a3", 30U, "!a:example.org"))); + REQUIRE(table.insert(make_event("$a1", 10U, "!a:example.org"))); + REQUIRE(table.insert(make_event("$a2", 20U, "!a:example.org"))); + REQUIRE(table.insert(make_event("$a2b", 20U, "!a:example.org"))); + REQUIRE(table.insert(make_event("$b1", 15U, "!b:example.org"))); + + WHEN("it is read up to several limits") + { + THEN("the rows at or below the limit come in stream order, equal orderings in the order added") + { + REQUIRE(ids_of(table.room_in_stream_order_up_to("!a:example.org", 20U)) == + std::vector{"$a1", "$a2", "$a2b"}); + REQUIRE(ids_of(table.room_in_stream_order_up_to("!a:example.org", 19U)) == + std::vector{"$a1"}); + REQUIRE(ids_of(table.room_in_stream_order_up_to("!a:example.org", 9U)).empty()); + REQUIRE(ids_of(table.room_in_stream_order_up_to("!a:example.org", UINT64_MAX)) == + ids_of(table.room_in_stream_order("!a:example.org"))); + REQUIRE(ids_of(table.room_in_stream_order_up_to("!none:example.org", UINT64_MAX)).empty()); + } + } + } +} diff --git a/tests/unit/test_query_params.cpp b/tests/unit/test_query_params.cpp index f3a21ccea..b4947cdf6 100644 --- a/tests/unit/test_query_params.cpp +++ b/tests/unit/test_query_params.cpp @@ -1,10 +1,11 @@ // SPDX-License-Identifier: GPL-3.0-or-later -#include "merovingian/core/SyncRequest.hpp" #include "merovingian/core/QueryParams.hpp" +#include "merovingian/core/SyncRequest.hpp" #include +#include #include SCENARIO("Query parameter parser extracts key-value pairs from URL query strings", "[core][http][query]") @@ -276,3 +277,26 @@ SCENARIO("Sync timeout query parameter rejects overflowing values", "[core][quer } } } + +SCENARIO("The sync use_state_after parameter is read as sent and absent when not sent", "[core][query]") +{ + GIVEN("sync targets with use_state_after true, false, another value, and none") + { + WHEN("the query parameters are parsed") + { + auto const enabled = merovingian::core::parse_query_params("/_matrix/client/v3/sync?use_state_after=true"); + auto const disabled = + merovingian::core::parse_query_params("/_matrix/client/v3/sync?use_state_after=false"); + auto const other = merovingian::core::parse_query_params("/_matrix/client/v3/sync?use_state_after=1"); + auto const absent = merovingian::core::parse_query_params("/_matrix/client/v3/sync"); + + THEN("true turns it on, anything else leaves it off, and an absent one stays absent") + { + REQUIRE(enabled.use_state_after == std::optional{true}); + REQUIRE(disabled.use_state_after == std::optional{false}); + REQUIRE(other.use_state_after == std::optional{false}); + REQUIRE_FALSE(absent.use_state_after.has_value()); + } + } + } +} diff --git a/tests/unit/test_sync_state_anchor.cpp b/tests/unit/test_sync_state_anchor.cpp new file mode 100644 index 000000000..d92b9759a --- /dev/null +++ b/tests/unit/test_sync_state_anchor.cpp @@ -0,0 +1,150 @@ +// SPDX-FileCopyrightText: 2026 James Chapman +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "merovingian/database/PersistentEvent.hpp" +#include "merovingian/database/PersistentStore.hpp" +#include "merovingian/sync/RoomReadAccess.hpp" +#include "merovingian/sync/RoomReadKind.hpp" + +#include + +#include +#include +#include +#include + +namespace +{ + +using merovingian::database::PersistentEvent; +using merovingian::database::PersistentStore; +using merovingian::sync::RoomReadAccess; +using merovingian::sync::RoomReadKind; + +constexpr auto room = "!room:example.org"; + +[[nodiscard]] auto make_event(std::string event_id, std::uint64_t stream_ordering, std::string status = "accepted") + -> PersistentEvent +{ + auto event = PersistentEvent{std::move(event_id), + room, + "@alice:example.org", + R"({"type":"m.room.message","content":{"body":"hello"}})", + stream_ordering, + stream_ordering, + {}, + {}, + {}}; + event.status = std::move(status); + return event; +} + +[[nodiscard]] auto current_access() -> RoomReadAccess +{ + return RoomReadAccess{RoomReadKind::current, {}, 0U}; +} + +} // namespace + +// `state_anchor_event` finds the newest accepted event at or below a stream position, the event whose state a +// state_after delta is read from. It must be a bounded lookup, not a scan of every newer event, and it must never +// anchor on an event that was rejected or soft-failed. `state_anchor_rows_examined` counts the rows it looks at, so a +// scan shows up as a number, not as a slow test. +SCENARIO("The state anchor of a room is found without visiting the rows above the position", "[sync][state-anchor]") +{ + // 3000 events lie above the position and only one below it, so a scan from the newest end would examine them all. + GIVEN("a room with an old event and thousands of newer ones") + { + auto store = PersistentStore{}; + REQUIRE(store.events.insert(make_event("$old", 5U))); + for (auto ordering = std::uint64_t{100U}; ordering < 3100U; ++ordering) + { + REQUIRE(store.events.insert(make_event("$new" + std::to_string(ordering), ordering))); + } + + WHEN("the anchor at a position below all the newer events is read") + { + auto const before = store.state_anchor_rows_examined.value(); + auto const* const anchor = merovingian::sync::state_anchor_event(store, room, current_access(), 50U); + auto const examined = store.state_anchor_rows_examined.value() - before; + + THEN("it is the old event, found by examining one row, not the 3000 above the position") + { + REQUIRE(anchor != nullptr); + REQUIRE(anchor->event_id == "$old"); + REQUIRE(examined == 1U); + } + } + + // The control: with no position the newest event is the anchor, so the bound above is the position's doing. + WHEN("the anchor is read with no position") + { + auto const* const anchor = + merovingian::sync::state_anchor_event(store, room, current_access(), std::nullopt); + + THEN("it is the newest event") + { + REQUIRE(anchor != nullptr); + REQUIRE(anchor->event_id == "$new3099"); + } + } + } + + // Two events can share one ordering; the choice among them must be stable and must not pick the rejected row, + // which was added last. + GIVEN("rows sharing the newest ordering at the position, the newest added row being withheld") + { + auto store = PersistentStore{}; + REQUIRE(store.events.insert(make_event("$first", 20U))); + REQUIRE(store.events.insert(make_event("$second", 20U))); + REQUIRE(store.events.insert(make_event("$withheld", 20U, "rejected"))); + REQUIRE(store.events.insert(make_event("$above", 30U))); + + WHEN("the anchor at 25 is read") + { + auto const* const anchor = merovingian::sync::state_anchor_event(store, room, current_access(), 25U); + + THEN("the row added first among the accepted rows of that ordering wins") + { + REQUIRE(anchor != nullptr); + REQUIRE(anchor->event_id == "$first"); + } + } + } + + // A soft-failed event is not part of the room's state, so the walk steps over it to the accepted row below. + GIVEN("a withheld event at the position and an accepted one below it") + { + auto store = PersistentStore{}; + REQUIRE(store.events.insert(make_event("$below", 10U))); + REQUIRE(store.events.insert(make_event("$soft", 20U, "soft_failed"))); + + WHEN("the anchor at 20 is read") + { + auto const* const anchor = merovingian::sync::state_anchor_event(store, room, current_access(), 20U); + + THEN("the withheld row is stepped over") + { + REQUIRE(anchor != nullptr); + REQUIRE(anchor->event_id == "$below"); + } + } + } + + // A position before the room's first event anchors nothing, rather than the first event above the position. + GIVEN("a room whose events all lie above the position") + { + auto store = PersistentStore{}; + REQUIRE(store.events.insert(make_event("$a", 10U))); + + WHEN("the anchor at 5 is read") + { + auto const* const anchor = merovingian::sync::state_anchor_event(store, room, current_access(), 5U); + + THEN("there is no anchor") + { + REQUIRE(anchor == nullptr); + } + } + } +}