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

Rename get_access_token_for_user_id method to create_access_token_for_user_id #11369

Merged
merged 3 commits into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/11369.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Rename `get_access_token_for_user_id` to `create_access_token_for_user_id` to better reflect what it does.
4 changes: 2 additions & 2 deletions synapse/handlers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ async def refresh_token(
) = await self.get_refresh_token_for_user_id(
user_id=existing_token.user_id, device_id=existing_token.device_id
)
access_token = await self.get_access_token_for_user_id(
access_token = await self.create_access_token_for_user_id(
user_id=existing_token.user_id,
device_id=existing_token.device_id,
valid_until_ms=valid_until_ms,
Expand Down Expand Up @@ -855,7 +855,7 @@ async def get_refresh_token_for_user_id(
)
return refresh_token, refresh_token_id

async def get_access_token_for_user_id(
async def create_access_token_for_user_id(
self,
user_id: str,
device_id: Optional[str],
Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ class and RegisterDeviceReplicationServlet.
)
valid_until_ms = self.clock.time_msec() + self.access_token_lifetime

access_token = await self._auth_handler.get_access_token_for_user_id(
access_token = await self._auth_handler.create_access_token_for_user_id(
user_id,
device_id=registered_device_id,
valid_until_ms=valid_until_ms,
Expand Down
2 changes: 1 addition & 1 deletion synapse/rest/admin/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ async def on_POST(
if auth_user.to_string() == user_id:
raise SynapseError(400, "Cannot use admin API to login as self")

token = await self.auth_handler.get_access_token_for_user_id(
token = await self.auth_handler.create_access_token_for_user_id(
user_id=auth_user.to_string(),
device_id=None,
valid_until_ms=valid_until_ms,
Expand Down
10 changes: 5 additions & 5 deletions tests/handlers/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def test_mau_limits_disabled(self):
self.auth_blocking._limit_usage_by_mau = False
# Ensure does not throw exception
self.get_success(
self.auth_handler.get_access_token_for_user_id(
self.auth_handler.create_access_token_for_user_id(
self.user1, device_id=None, valid_until_ms=None
)
)
Expand All @@ -134,7 +134,7 @@ def test_mau_limits_exceeded_large(self):
)

self.get_failure(
self.auth_handler.get_access_token_for_user_id(
self.auth_handler.create_access_token_for_user_id(
self.user1, device_id=None, valid_until_ms=None
),
ResourceLimitError,
Expand Down Expand Up @@ -162,7 +162,7 @@ def test_mau_limits_parity(self):

# If not in monthly active cohort
self.get_failure(
self.auth_handler.get_access_token_for_user_id(
self.auth_handler.create_access_token_for_user_id(
self.user1, device_id=None, valid_until_ms=None
),
ResourceLimitError,
Expand All @@ -179,7 +179,7 @@ def test_mau_limits_parity(self):
return_value=make_awaitable(self.clock.time_msec())
)
self.get_success(
self.auth_handler.get_access_token_for_user_id(
self.auth_handler.create_access_token_for_user_id(
self.user1, device_id=None, valid_until_ms=None
)
)
Expand All @@ -197,7 +197,7 @@ def test_mau_limits_not_exceeded(self):
)
# Ensure does not raise exception
self.get_success(
self.auth_handler.get_access_token_for_user_id(
self.auth_handler.create_access_token_for_user_id(
self.user1, device_id=None, valid_until_ms=None
)
)
Expand Down
4 changes: 2 additions & 2 deletions tests/rest/admin/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -1169,14 +1169,14 @@ def prepare(self, reactor, clock, hs):
# regardless of whether password login or SSO is allowed
self.admin_user = self.register_user("admin", "pass", admin=True)
self.admin_user_tok = self.get_success(
self.auth_handler.get_access_token_for_user_id(
self.auth_handler.create_access_token_for_user_id(
self.admin_user, device_id=None, valid_until_ms=None
)
)

self.other_user = self.register_user("user", "pass", displayname="User")
self.other_user_token = self.get_success(
self.auth_handler.get_access_token_for_user_id(
self.auth_handler.create_access_token_for_user_id(
self.other_user, device_id=None, valid_until_ms=None
)
)
Expand Down
8 changes: 4 additions & 4 deletions tests/rest/client/test_capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def test_get_change_password_capabilities_password_login(self):
@override_config({"password_config": {"localdb_enabled": False}})
def test_get_change_password_capabilities_localdb_disabled(self):
access_token = self.get_success(
self.auth_handler.get_access_token_for_user_id(
self.auth_handler.create_access_token_for_user_id(
self.user, device_id=None, valid_until_ms=None
)
)
Expand All @@ -85,7 +85,7 @@ def test_get_change_password_capabilities_localdb_disabled(self):
@override_config({"password_config": {"enabled": False}})
def test_get_change_password_capabilities_password_disabled(self):
access_token = self.get_success(
self.auth_handler.get_access_token_for_user_id(
self.auth_handler.create_access_token_for_user_id(
self.user, device_id=None, valid_until_ms=None
)
)
Expand Down Expand Up @@ -174,7 +174,7 @@ def test_change_3pid_capabilities_3pid_disabled(self):
@override_config({"experimental_features": {"msc3244_enabled": False}})
def test_get_does_not_include_msc3244_fields_when_disabled(self):
access_token = self.get_success(
self.auth_handler.get_access_token_for_user_id(
self.auth_handler.create_access_token_for_user_id(
self.user, device_id=None, valid_until_ms=None
)
)
Expand All @@ -189,7 +189,7 @@ def test_get_does_not_include_msc3244_fields_when_disabled(self):

def test_get_does_include_msc3244_fields_when_enabled(self):
access_token = self.get_success(
self.auth_handler.get_access_token_for_user_id(
self.auth_handler.create_access_token_for_user_id(
self.user, device_id=None, valid_until_ms=None
)
)
Expand Down