Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Use add_hashes_and_signatures_from_other_server
Browse files Browse the repository at this point in the history
- rename the method to distinguish it from `add_hashes_and_signatures`
- use it in a few other places where it makes sense
  • Loading branch information
David Robertson committed Jul 11, 2022
1 parent 81eb4ab commit 8377172
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 22 deletions.
6 changes: 3 additions & 3 deletions tests/federation/test_federation_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_get_room_state(self):
# mock up some events to use in the response.
# In real life, these would have things in `prev_events` and `auth_events`, but that's
# a bit annoying to mock up, and the code under test doesn't care, so we don't bother.
create_event_dict = self.add_hashes_and_signatures(
create_event_dict = self.add_hashes_and_signatures_from_other_server(
{
"room_id": test_room_id,
"type": "m.room.create",
Expand All @@ -57,7 +57,7 @@ def test_get_room_state(self):
"origin_server_ts": 500,
}
)
member_event_dict = self.add_hashes_and_signatures(
member_event_dict = self.add_hashes_and_signatures_from_other_server(
{
"room_id": test_room_id,
"type": "m.room.member",
Expand All @@ -69,7 +69,7 @@ def test_get_room_state(self):
"origin_server_ts": 600,
}
)
pl_event_dict = self.add_hashes_and_signatures(
pl_event_dict = self.add_hashes_and_signatures_from_other_server(
{
"room_id": test_room_id,
"type": "m.room.power_levels",
Expand Down
19 changes: 6 additions & 13 deletions tests/federation/test_federation_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

from synapse.api.room_versions import KNOWN_ROOM_VERSIONS
from synapse.config.server import DEFAULT_ROOM_VERSION
from synapse.crypto.event_signing import add_hashes_and_signatures
from synapse.events import make_event_from_dict
from synapse.federation.federation_server import server_matches_acl_event
from synapse.rest import admin
Expand Down Expand Up @@ -164,11 +163,9 @@ def test_send_join(self):
join_result = self._make_join(joining_user)

join_event_dict = join_result["event"]
add_hashes_and_signatures(
KNOWN_ROOM_VERSIONS[DEFAULT_ROOM_VERSION],
self.add_hashes_and_signatures_from_other_server(
join_event_dict,
signature_name=self.OTHER_SERVER_NAME,
signing_key=self.OTHER_SERVER_SIGNATURE_KEY,
KNOWN_ROOM_VERSIONS[DEFAULT_ROOM_VERSION],
)
channel = self.make_signed_federation_request(
"PUT",
Expand Down Expand Up @@ -221,11 +218,9 @@ def test_send_join_partial_state(self):
join_result = self._make_join(joining_user)

join_event_dict = join_result["event"]
add_hashes_and_signatures(
KNOWN_ROOM_VERSIONS[DEFAULT_ROOM_VERSION],
self.add_hashes_and_signatures_from_other_server(
join_event_dict,
signature_name=self.OTHER_SERVER_NAME,
signing_key=self.OTHER_SERVER_SIGNATURE_KEY,
KNOWN_ROOM_VERSIONS[DEFAULT_ROOM_VERSION],
)
channel = self.make_signed_federation_request(
"PUT",
Expand Down Expand Up @@ -296,11 +291,9 @@ def test_send_join_contributes_to_room_join_rate_limit_and_is_limited(self) -> N
joining_user = f"@misspiggy{i}:{self.OTHER_SERVER_NAME}"
join_result = self._make_join(joining_user)
join_event_dict = join_result["event"]
add_hashes_and_signatures(
KNOWN_ROOM_VERSIONS[DEFAULT_ROOM_VERSION],
self.add_hashes_and_signatures_from_other_server(
join_event_dict,
signature_name=self.OTHER_SERVER_NAME,
signing_key=self.OTHER_SERVER_SIGNATURE_KEY,
KNOWN_ROOM_VERSIONS[DEFAULT_ROOM_VERSION],
)
join_event_dicts.append(join_event_dict)

Expand Down
2 changes: 1 addition & 1 deletion tests/handlers/test_federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def test_backfill_with_many_backward_extremities(self) -> None:
]
for _ in range(0, 8):
event = make_event_from_dict(
self.add_hashes_and_signatures(
self.add_hashes_and_signatures_from_other_server(
{
"origin_server_ts": 1,
"type": "m.room.message",
Expand Down
6 changes: 3 additions & 3 deletions tests/handlers/test_federation_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def _test_process_pulled_event_with_missing_state(
# mock up a load of state events which we are missing
state_events = [
make_event_from_dict(
self.add_hashes_and_signatures(
self.add_hashes_and_signatures_from_other_server(
{
"type": "test_state_type",
"state_key": f"state_{i}",
Expand All @@ -131,7 +131,7 @@ def _test_process_pulled_event_with_missing_state(
# Depending on the test, we either persist this upfront (as an outlier),
# or let the server request it.
prev_event = make_event_from_dict(
self.add_hashes_and_signatures(
self.add_hashes_and_signatures_from_other_server(
{
"type": "test_regular_type",
"room_id": room_id,
Expand Down Expand Up @@ -165,7 +165,7 @@ async def get_event(destination: str, event_id: str, timeout=None):

# mock up a regular event to pass into _process_pulled_event
pulled_event = make_event_from_dict(
self.add_hashes_and_signatures(
self.add_hashes_and_signatures_from_other_server(
{
"type": "test_regular_type",
"room_id": room_id,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_visibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def test_out_of_band_invite_rejection(self):
"state_key": "@user:test",
"content": {"membership": "invite"},
}
self.add_hashes_and_signatures(invite_pdu)
self.add_hashes_and_signatures_from_other_server(invite_pdu)
invite_event_id = make_event_from_dict(invite_pdu, RoomVersions.V9).event_id

self.get_success(
Expand Down
2 changes: 1 addition & 1 deletion tests/unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ def make_signed_federation_request(
client_ip=client_ip,
)

def add_hashes_and_signatures(
def add_hashes_and_signatures_from_other_server(
self,
event_dict: JsonDict,
room_version: RoomVersion = KNOWN_ROOM_VERSIONS[DEFAULT_ROOM_VERSION],
Expand Down

0 comments on commit 8377172

Please sign in to comment.