mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-09-08 02:22:39 +00:00
Remove access-token support from RegistrationStore.register (#5642)
The 'token' param is no longer used anywhere except the tests, so let's kill that off too.
This commit is contained in:
parent
f281714583
commit
953dbb7980
1
changelog.d/5642.misc
Normal file
1
changelog.d/5642.misc
Normal file
@ -0,0 +1 @@
|
|||||||
|
Remove access-token support from `RegistrationStore.register`, and rename it.
|
@ -584,7 +584,7 @@ class RegistrationHandler(BaseHandler):
|
|||||||
address=address,
|
address=address,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
return self.store.register(
|
return self.store.register_user(
|
||||||
user_id=user_id,
|
user_id=user_id,
|
||||||
password_hash=password_hash,
|
password_hash=password_hash,
|
||||||
was_guest=was_guest,
|
was_guest=was_guest,
|
||||||
|
@ -698,10 +698,9 @@ class RegistrationStore(
|
|||||||
desc="add_access_token_to_user",
|
desc="add_access_token_to_user",
|
||||||
)
|
)
|
||||||
|
|
||||||
def register(
|
def register_user(
|
||||||
self,
|
self,
|
||||||
user_id,
|
user_id,
|
||||||
token=None,
|
|
||||||
password_hash=None,
|
password_hash=None,
|
||||||
was_guest=False,
|
was_guest=False,
|
||||||
make_guest=False,
|
make_guest=False,
|
||||||
@ -714,9 +713,6 @@ class RegistrationStore(
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
user_id (str): The desired user ID to register.
|
user_id (str): The desired user ID to register.
|
||||||
token (str): The desired access token to use for this user. If this
|
|
||||||
is not None, the given access token is associated with the user
|
|
||||||
id.
|
|
||||||
password_hash (str): Optional. The password hash for this user.
|
password_hash (str): Optional. The password hash for this user.
|
||||||
was_guest (bool): Optional. Whether this is a guest account being
|
was_guest (bool): Optional. Whether this is a guest account being
|
||||||
upgraded to a non-guest account.
|
upgraded to a non-guest account.
|
||||||
@ -733,10 +729,9 @@ class RegistrationStore(
|
|||||||
StoreError if the user_id could not be registered.
|
StoreError if the user_id could not be registered.
|
||||||
"""
|
"""
|
||||||
return self.runInteraction(
|
return self.runInteraction(
|
||||||
"register",
|
"register_user",
|
||||||
self._register,
|
self._register_user,
|
||||||
user_id,
|
user_id,
|
||||||
token,
|
|
||||||
password_hash,
|
password_hash,
|
||||||
was_guest,
|
was_guest,
|
||||||
make_guest,
|
make_guest,
|
||||||
@ -746,11 +741,10 @@ class RegistrationStore(
|
|||||||
user_type,
|
user_type,
|
||||||
)
|
)
|
||||||
|
|
||||||
def _register(
|
def _register_user(
|
||||||
self,
|
self,
|
||||||
txn,
|
txn,
|
||||||
user_id,
|
user_id,
|
||||||
token,
|
|
||||||
password_hash,
|
password_hash,
|
||||||
was_guest,
|
was_guest,
|
||||||
make_guest,
|
make_guest,
|
||||||
@ -763,8 +757,6 @@ class RegistrationStore(
|
|||||||
|
|
||||||
now = int(self.clock.time())
|
now = int(self.clock.time())
|
||||||
|
|
||||||
next_id = self._access_tokens_id_gen.get_next()
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if was_guest:
|
if was_guest:
|
||||||
# Ensure that the guest user actually exists
|
# Ensure that the guest user actually exists
|
||||||
@ -812,14 +804,6 @@ class RegistrationStore(
|
|||||||
if self._account_validity.enabled:
|
if self._account_validity.enabled:
|
||||||
self.set_expiration_date_for_user_txn(txn, user_id)
|
self.set_expiration_date_for_user_txn(txn, user_id)
|
||||||
|
|
||||||
if token:
|
|
||||||
# it's possible for this to get a conflict, but only for a single user
|
|
||||||
# since tokens are namespaced based on their user ID
|
|
||||||
txn.execute(
|
|
||||||
"INSERT INTO access_tokens(id, user_id, token)" " VALUES (?,?,?)",
|
|
||||||
(next_id, user_id, token),
|
|
||||||
)
|
|
||||||
|
|
||||||
if create_profile_with_displayname:
|
if create_profile_with_displayname:
|
||||||
# set a default displayname serverside to avoid ugly race
|
# set a default displayname serverside to avoid ugly race
|
||||||
# between auto-joins and clients trying to set displaynames
|
# between auto-joins and clients trying to set displaynames
|
||||||
|
@ -325,7 +325,7 @@ class AuthTestCase(unittest.TestCase):
|
|||||||
unknown_threepid = {"medium": "email", "address": "unreserved@server.com"}
|
unknown_threepid = {"medium": "email", "address": "unreserved@server.com"}
|
||||||
self.hs.config.mau_limits_reserved_threepids = [threepid]
|
self.hs.config.mau_limits_reserved_threepids = [threepid]
|
||||||
|
|
||||||
yield self.store.register(user_id="user1", token="123", password_hash=None)
|
yield self.store.register_user(user_id="user1", password_hash=None)
|
||||||
with self.assertRaises(ResourceLimitError):
|
with self.assertRaises(ResourceLimitError):
|
||||||
yield self.auth.check_auth_blocking()
|
yield self.auth.check_auth_blocking()
|
||||||
|
|
||||||
|
@ -77,11 +77,7 @@ class RegistrationTestCase(unittest.HomeserverTestCase):
|
|||||||
store = self.hs.get_datastore()
|
store = self.hs.get_datastore()
|
||||||
frank = UserID.from_string("@frank:test")
|
frank = UserID.from_string("@frank:test")
|
||||||
self.get_success(
|
self.get_success(
|
||||||
store.register(
|
store.register_user(user_id=frank.to_string(), password_hash=None)
|
||||||
user_id=frank.to_string(),
|
|
||||||
token="jkv;g498752-43gj['eamb!-5",
|
|
||||||
password_hash=None,
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
local_part = frank.localpart
|
local_part = frank.localpart
|
||||||
user_id = frank.to_string()
|
user_id = frank.to_string()
|
||||||
|
@ -47,11 +47,8 @@ class UserDirectoryTestCase(unittest.HomeserverTestCase):
|
|||||||
def test_handle_local_profile_change_with_support_user(self):
|
def test_handle_local_profile_change_with_support_user(self):
|
||||||
support_user_id = "@support:test"
|
support_user_id = "@support:test"
|
||||||
self.get_success(
|
self.get_success(
|
||||||
self.store.register(
|
self.store.register_user(
|
||||||
user_id=support_user_id,
|
user_id=support_user_id, password_hash=None, user_type=UserTypes.SUPPORT
|
||||||
token="123",
|
|
||||||
password_hash=None,
|
|
||||||
user_type=UserTypes.SUPPORT,
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -73,11 +70,8 @@ class UserDirectoryTestCase(unittest.HomeserverTestCase):
|
|||||||
def test_handle_user_deactivated_support_user(self):
|
def test_handle_user_deactivated_support_user(self):
|
||||||
s_user_id = "@support:test"
|
s_user_id = "@support:test"
|
||||||
self.get_success(
|
self.get_success(
|
||||||
self.store.register(
|
self.store.register_user(
|
||||||
user_id=s_user_id,
|
user_id=s_user_id, password_hash=None, user_type=UserTypes.SUPPORT
|
||||||
token="123",
|
|
||||||
password_hash=None,
|
|
||||||
user_type=UserTypes.SUPPORT,
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -90,7 +84,7 @@ class UserDirectoryTestCase(unittest.HomeserverTestCase):
|
|||||||
def test_handle_user_deactivated_regular_user(self):
|
def test_handle_user_deactivated_regular_user(self):
|
||||||
r_user_id = "@regular:test"
|
r_user_id = "@regular:test"
|
||||||
self.get_success(
|
self.get_success(
|
||||||
self.store.register(user_id=r_user_id, token="123", password_hash=None)
|
self.store.register_user(user_id=r_user_id, password_hash=None)
|
||||||
)
|
)
|
||||||
self.store.remove_from_user_dir = Mock()
|
self.store.remove_from_user_dir = Mock()
|
||||||
self.get_success(self.handler.handle_user_deactivated(r_user_id))
|
self.get_success(self.handler.handle_user_deactivated(r_user_id))
|
||||||
|
@ -185,9 +185,7 @@ class ClientIpStoreTestCase(unittest.HomeserverTestCase):
|
|||||||
self.hs.config.limit_usage_by_mau = True
|
self.hs.config.limit_usage_by_mau = True
|
||||||
self.hs.config.max_mau_value = 50
|
self.hs.config.max_mau_value = 50
|
||||||
user_id = "@user:server"
|
user_id = "@user:server"
|
||||||
self.get_success(
|
self.get_success(self.store.register_user(user_id=user_id, password_hash=None))
|
||||||
self.store.register(user_id=user_id, token="123", password_hash=None)
|
|
||||||
)
|
|
||||||
|
|
||||||
active = self.get_success(self.store.user_last_seen_monthly_active(user_id))
|
active = self.get_success(self.store.user_last_seen_monthly_active(user_id))
|
||||||
self.assertFalse(active)
|
self.assertFalse(active)
|
||||||
|
@ -53,10 +53,10 @@ class MonthlyActiveUsersTestCase(unittest.HomeserverTestCase):
|
|||||||
# -1 because user3 is a support user and does not count
|
# -1 because user3 is a support user and does not count
|
||||||
user_num = len(threepids) - 1
|
user_num = len(threepids) - 1
|
||||||
|
|
||||||
self.store.register(user_id=user1, token="123", password_hash=None)
|
self.store.register_user(user_id=user1, password_hash=None)
|
||||||
self.store.register(user_id=user2, token="456", password_hash=None)
|
self.store.register_user(user_id=user2, password_hash=None)
|
||||||
self.store.register(
|
self.store.register_user(
|
||||||
user_id=user3, token="789", password_hash=None, user_type=UserTypes.SUPPORT
|
user_id=user3, password_hash=None, user_type=UserTypes.SUPPORT
|
||||||
)
|
)
|
||||||
self.pump()
|
self.pump()
|
||||||
|
|
||||||
@ -161,9 +161,7 @@ class MonthlyActiveUsersTestCase(unittest.HomeserverTestCase):
|
|||||||
def test_populate_monthly_users_is_guest(self):
|
def test_populate_monthly_users_is_guest(self):
|
||||||
# Test that guest users are not added to mau list
|
# Test that guest users are not added to mau list
|
||||||
user_id = "@user_id:host"
|
user_id = "@user_id:host"
|
||||||
self.store.register(
|
self.store.register_user(user_id=user_id, password_hash=None, make_guest=True)
|
||||||
user_id=user_id, token="123", password_hash=None, make_guest=True
|
|
||||||
)
|
|
||||||
self.store.upsert_monthly_active_user = Mock()
|
self.store.upsert_monthly_active_user = Mock()
|
||||||
self.store.populate_monthly_active_users(user_id)
|
self.store.populate_monthly_active_users(user_id)
|
||||||
self.pump()
|
self.pump()
|
||||||
@ -216,8 +214,8 @@ class MonthlyActiveUsersTestCase(unittest.HomeserverTestCase):
|
|||||||
self.assertEquals(self.get_success(count), 0)
|
self.assertEquals(self.get_success(count), 0)
|
||||||
|
|
||||||
# Test reserved registed users
|
# Test reserved registed users
|
||||||
self.store.register(user_id=user1, token="123", password_hash=None)
|
self.store.register_user(user_id=user1, password_hash=None)
|
||||||
self.store.register(user_id=user2, token="456", password_hash=None)
|
self.store.register_user(user_id=user2, password_hash=None)
|
||||||
self.pump()
|
self.pump()
|
||||||
|
|
||||||
now = int(self.hs.get_clock().time_msec())
|
now = int(self.hs.get_clock().time_msec())
|
||||||
@ -232,11 +230,8 @@ class MonthlyActiveUsersTestCase(unittest.HomeserverTestCase):
|
|||||||
self.pump()
|
self.pump()
|
||||||
self.assertEqual(self.get_success(count), 0)
|
self.assertEqual(self.get_success(count), 0)
|
||||||
|
|
||||||
self.store.register(
|
self.store.register_user(
|
||||||
user_id=support_user_id,
|
user_id=support_user_id, password_hash=None, user_type=UserTypes.SUPPORT
|
||||||
token="123",
|
|
||||||
password_hash=None,
|
|
||||||
user_type=UserTypes.SUPPORT,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
self.store.upsert_monthly_active_user(support_user_id)
|
self.store.upsert_monthly_active_user(support_user_id)
|
||||||
|
@ -37,7 +37,7 @@ class RegistrationStoreTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def test_register(self):
|
def test_register(self):
|
||||||
yield self.store.register(self.user_id, self.tokens[0], self.pwhash)
|
yield self.store.register_user(self.user_id, self.pwhash)
|
||||||
|
|
||||||
self.assertEquals(
|
self.assertEquals(
|
||||||
{
|
{
|
||||||
@ -53,15 +53,9 @@ class RegistrationStoreTestCase(unittest.TestCase):
|
|||||||
(yield self.store.get_user_by_id(self.user_id)),
|
(yield self.store.get_user_by_id(self.user_id)),
|
||||||
)
|
)
|
||||||
|
|
||||||
result = yield self.store.get_user_by_access_token(self.tokens[0])
|
|
||||||
|
|
||||||
self.assertDictContainsSubset({"name": self.user_id}, result)
|
|
||||||
|
|
||||||
self.assertTrue("token_id" in result)
|
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def test_add_tokens(self):
|
def test_add_tokens(self):
|
||||||
yield self.store.register(self.user_id, self.tokens[0], self.pwhash)
|
yield self.store.register_user(self.user_id, self.pwhash)
|
||||||
yield self.store.add_access_token_to_user(
|
yield self.store.add_access_token_to_user(
|
||||||
self.user_id, self.tokens[1], self.device_id
|
self.user_id, self.tokens[1], self.device_id
|
||||||
)
|
)
|
||||||
@ -77,7 +71,8 @@ class RegistrationStoreTestCase(unittest.TestCase):
|
|||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def test_user_delete_access_tokens(self):
|
def test_user_delete_access_tokens(self):
|
||||||
# add some tokens
|
# add some tokens
|
||||||
yield self.store.register(self.user_id, self.tokens[0], self.pwhash)
|
yield self.store.register_user(self.user_id, self.pwhash)
|
||||||
|
yield self.store.add_access_token_to_user(self.user_id, self.tokens[0])
|
||||||
yield self.store.add_access_token_to_user(
|
yield self.store.add_access_token_to_user(
|
||||||
self.user_id, self.tokens[1], self.device_id
|
self.user_id, self.tokens[1], self.device_id
|
||||||
)
|
)
|
||||||
@ -108,24 +103,12 @@ class RegistrationStoreTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
res = yield self.store.is_support_user(None)
|
res = yield self.store.is_support_user(None)
|
||||||
self.assertFalse(res)
|
self.assertFalse(res)
|
||||||
yield self.store.register(user_id=TEST_USER, token="123", password_hash=None)
|
yield self.store.register_user(user_id=TEST_USER, password_hash=None)
|
||||||
res = yield self.store.is_support_user(TEST_USER)
|
res = yield self.store.is_support_user(TEST_USER)
|
||||||
self.assertFalse(res)
|
self.assertFalse(res)
|
||||||
|
|
||||||
yield self.store.register(
|
yield self.store.register_user(
|
||||||
user_id=SUPPORT_USER,
|
user_id=SUPPORT_USER, password_hash=None, user_type=UserTypes.SUPPORT
|
||||||
token="456",
|
|
||||||
password_hash=None,
|
|
||||||
user_type=UserTypes.SUPPORT,
|
|
||||||
)
|
)
|
||||||
res = yield self.store.is_support_user(SUPPORT_USER)
|
res = yield self.store.is_support_user(SUPPORT_USER)
|
||||||
self.assertTrue(res)
|
self.assertTrue(res)
|
||||||
|
|
||||||
|
|
||||||
class TokenGenerator:
|
|
||||||
def __init__(self):
|
|
||||||
self._last_issued_token = 0
|
|
||||||
|
|
||||||
def generate(self, user_id):
|
|
||||||
self._last_issued_token += 1
|
|
||||||
return "%s-%d" % (user_id, self._last_issued_token)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user