7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1 | // Copyright 2024 The Matrix.org Foundation C.I.C. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2 | // |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 4 | // you may not use this file except in compliance with the License. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 5 | // You may obtain a copy of the License at |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 6 | // |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 8 | // |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 9 | // Unless required by applicable law or agreed to in writing, software |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 12 | // See the License for the specific language governing permissions and |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 13 | // limitations under the License. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 14 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 15 | //! Mocks useful to reuse across different testing contexts. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 16 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 17 | use wiremock::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 18 | Mock, MockServer, ResponseTemplate, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 19 | matchers::{header, method, path_regex}, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 20 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 21 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 22 | use crate::{event_factory::EventFactory, test_json}; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 23 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 24 | /// Mount a Mock on the given server to handle the `GET |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 25 | /// /rooms/.../state/m.room.encryption` endpoint with an option whether it |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 26 | /// should return an encryption event or not. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 27 | pub async fn mock_encryption_state(server: &MockServer, is_encrypted: bool) { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 28 | let builder = Mock::given(method("GET")) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 29 | .and(path_regex(r"^/_matrix/client/r0/rooms/.*/state/m.*room.*encryption.?")) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 30 | .and(header("authorization", "Bearer 1234")); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 31 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 32 | if is_encrypted { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 33 | builder |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 34 | .respond_with( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 35 | ResponseTemplate::new(200) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 36 | .set_body_json(EventFactory::new().room_encryption().into_content()), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 37 | ) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 38 | .mount(server) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 39 | .await; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 40 | } else { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 41 | builder |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 42 | .respond_with(ResponseTemplate::new(404).set_body_json(&*test_json::NOT_FOUND)) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 43 | .mount(server) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 44 | .await; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 45 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 46 | } |