2016-07-20 17:34:00 +02:00
|
|
|
# Copyright 2016 OpenMarket Ltd
|
2018-09-20 12:14:34 +02:00
|
|
|
# Copyright 2018 New Vector Ltd
|
2016-07-20 17:34:00 +02:00
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
2018-09-20 12:14:34 +02:00
|
|
|
|
2021-04-09 19:44:38 +02:00
|
|
|
from unittest.mock import Mock
|
2016-07-20 17:34:00 +02:00
|
|
|
|
2019-05-01 16:32:38 +02:00
|
|
|
import synapse.rest.admin
|
2018-09-20 12:14:34 +02:00
|
|
|
from synapse.http.site import XForwardedForRequest
|
2019-05-01 16:32:38 +02:00
|
|
|
from synapse.rest.client.v1 import login
|
2018-09-20 12:14:34 +02:00
|
|
|
|
|
|
|
from tests import unittest
|
2020-11-16 15:45:22 +01:00
|
|
|
from tests.server import make_request
|
2020-08-27 23:24:37 +02:00
|
|
|
from tests.test_utils import make_awaitable
|
2020-05-22 22:47:07 +02:00
|
|
|
from tests.unittest import override_config
|
2016-07-20 17:34:00 +02:00
|
|
|
|
|
|
|
|
2018-09-20 12:14:34 +02:00
|
|
|
class ClientIpStoreTestCase(unittest.HomeserverTestCase):
|
|
|
|
def make_homeserver(self, reactor, clock):
|
|
|
|
hs = self.setup_test_homeserver()
|
|
|
|
return hs
|
2016-07-20 17:34:00 +02:00
|
|
|
|
2018-09-20 12:14:34 +02:00
|
|
|
def prepare(self, hs, reactor, clock):
|
2018-08-02 14:47:19 +02:00
|
|
|
self.store = self.hs.get_datastore()
|
2016-07-20 17:34:00 +02:00
|
|
|
|
|
|
|
def test_insert_new_client_ip(self):
|
2018-09-20 12:14:34 +02:00
|
|
|
self.reactor.advance(12345678)
|
|
|
|
|
2016-07-20 17:34:00 +02:00
|
|
|
user_id = "@user:id"
|
2019-12-10 17:22:29 +01:00
|
|
|
device_id = "MY_DEVICE"
|
|
|
|
|
|
|
|
# Insert a user IP
|
|
|
|
self.get_success(
|
|
|
|
self.store.store_device(
|
|
|
|
user_id,
|
|
|
|
device_id,
|
|
|
|
"display name",
|
|
|
|
)
|
2021-02-16 23:32:34 +01:00
|
|
|
)
|
2018-09-20 12:14:34 +02:00
|
|
|
self.get_success(
|
|
|
|
self.store.insert_client_ip(
|
2019-12-10 17:22:29 +01:00
|
|
|
user_id, "access_token", "ip", "user_agent", device_id
|
2018-09-20 12:14:34 +02:00
|
|
|
)
|
2016-07-20 17:34:00 +02:00
|
|
|
)
|
|
|
|
|
2018-09-20 12:14:34 +02:00
|
|
|
# Trigger the storage loop
|
|
|
|
self.reactor.advance(10)
|
|
|
|
|
|
|
|
result = self.get_success(
|
2019-12-10 17:22:29 +01:00
|
|
|
self.store.get_last_client_ip_by_device(user_id, device_id)
|
2018-09-20 12:14:34 +02:00
|
|
|
)
|
2016-07-20 17:34:00 +02:00
|
|
|
|
2019-12-10 17:22:29 +01:00
|
|
|
r = result[(user_id, device_id)]
|
2016-07-20 17:34:00 +02:00
|
|
|
self.assertDictContainsSubset(
|
|
|
|
{
|
|
|
|
"user_id": user_id,
|
2019-12-10 17:22:29 +01:00
|
|
|
"device_id": device_id,
|
2016-07-20 17:34:00 +02:00
|
|
|
"ip": "ip",
|
|
|
|
"user_agent": "user_agent",
|
|
|
|
"last_seen": 12345678000,
|
|
|
|
},
|
2018-08-10 15:54:09 +02:00
|
|
|
r,
|
2016-07-20 17:34:00 +02:00
|
|
|
)
|
2018-08-02 14:47:19 +02:00
|
|
|
|
2019-01-09 12:26:25 +01:00
|
|
|
def test_insert_new_client_ip_none_device_id(self):
|
|
|
|
"""
|
|
|
|
An insert with a device ID of NULL will not create a new entry, but
|
|
|
|
update an existing entry in the user_ips table.
|
|
|
|
"""
|
|
|
|
self.reactor.advance(12345678)
|
|
|
|
|
|
|
|
user_id = "@user:id"
|
|
|
|
|
|
|
|
# Add & trigger the storage loop
|
|
|
|
self.get_success(
|
|
|
|
self.store.insert_client_ip(
|
|
|
|
user_id, "access_token", "ip", "user_agent", None
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self.reactor.advance(200)
|
|
|
|
self.pump(0)
|
|
|
|
|
|
|
|
result = self.get_success(
|
2020-08-05 22:38:57 +02:00
|
|
|
self.store.db_pool.simple_select_list(
|
2019-01-09 12:26:25 +01:00
|
|
|
table="user_ips",
|
|
|
|
keyvalues={"user_id": user_id},
|
|
|
|
retcols=["access_token", "ip", "user_agent", "device_id", "last_seen"],
|
|
|
|
desc="get_user_ip_and_agents",
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
result,
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"access_token": "access_token",
|
|
|
|
"ip": "ip",
|
|
|
|
"user_agent": "user_agent",
|
|
|
|
"device_id": None,
|
|
|
|
"last_seen": 12345678000,
|
|
|
|
}
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
# Add another & trigger the storage loop
|
|
|
|
self.get_success(
|
|
|
|
self.store.insert_client_ip(
|
|
|
|
user_id, "access_token", "ip", "user_agent", None
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self.reactor.advance(10)
|
|
|
|
self.pump(0)
|
|
|
|
|
|
|
|
result = self.get_success(
|
2020-08-05 22:38:57 +02:00
|
|
|
self.store.db_pool.simple_select_list(
|
2019-01-09 12:26:25 +01:00
|
|
|
table="user_ips",
|
|
|
|
keyvalues={"user_id": user_id},
|
|
|
|
retcols=["access_token", "ip", "user_agent", "device_id", "last_seen"],
|
|
|
|
desc="get_user_ip_and_agents",
|
|
|
|
)
|
|
|
|
)
|
|
|
|
# Only one result, has been upserted.
|
|
|
|
self.assertEqual(
|
|
|
|
result,
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"access_token": "access_token",
|
|
|
|
"ip": "ip",
|
|
|
|
"user_agent": "user_agent",
|
|
|
|
"device_id": None,
|
|
|
|
"last_seen": 12345878000,
|
|
|
|
}
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
2020-05-22 22:47:07 +02:00
|
|
|
@override_config({"limit_usage_by_mau": False, "max_mau_value": 50})
|
2018-08-02 14:47:19 +02:00
|
|
|
def test_disabled_monthly_active_user(self):
|
|
|
|
user_id = "@user:server"
|
2018-09-20 12:14:34 +02:00
|
|
|
self.get_success(
|
|
|
|
self.store.insert_client_ip(
|
|
|
|
user_id, "access_token", "ip", "user_agent", "device_id"
|
|
|
|
)
|
2018-08-02 14:47:19 +02:00
|
|
|
)
|
2018-09-20 12:14:34 +02:00
|
|
|
active = self.get_success(self.store.user_last_seen_monthly_active(user_id))
|
2018-08-02 14:47:19 +02:00
|
|
|
self.assertFalse(active)
|
|
|
|
|
2020-05-22 22:47:07 +02:00
|
|
|
@override_config({"limit_usage_by_mau": True, "max_mau_value": 50})
|
2018-08-02 14:47:19 +02:00
|
|
|
def test_adding_monthly_active_user_when_full(self):
|
|
|
|
lots_of_users = 100
|
|
|
|
user_id = "@user:server"
|
|
|
|
|
|
|
|
self.store.get_monthly_active_count = Mock(
|
2020-09-08 13:26:55 +02:00
|
|
|
return_value=make_awaitable(lots_of_users)
|
2018-08-02 14:47:19 +02:00
|
|
|
)
|
2018-09-20 12:14:34 +02:00
|
|
|
self.get_success(
|
|
|
|
self.store.insert_client_ip(
|
|
|
|
user_id, "access_token", "ip", "user_agent", "device_id"
|
|
|
|
)
|
2018-08-02 14:47:19 +02:00
|
|
|
)
|
2018-09-20 12:14:34 +02:00
|
|
|
active = self.get_success(self.store.user_last_seen_monthly_active(user_id))
|
2018-08-02 14:47:19 +02:00
|
|
|
self.assertFalse(active)
|
|
|
|
|
2020-05-22 22:47:07 +02:00
|
|
|
@override_config({"limit_usage_by_mau": True, "max_mau_value": 50})
|
2018-08-02 14:47:19 +02:00
|
|
|
def test_adding_monthly_active_user_when_space(self):
|
|
|
|
user_id = "@user:server"
|
2018-09-20 12:14:34 +02:00
|
|
|
active = self.get_success(self.store.user_last_seen_monthly_active(user_id))
|
2018-08-02 14:47:19 +02:00
|
|
|
self.assertFalse(active)
|
|
|
|
|
2018-09-20 12:14:34 +02:00
|
|
|
# Trigger the saving loop
|
|
|
|
self.reactor.advance(10)
|
|
|
|
|
|
|
|
self.get_success(
|
|
|
|
self.store.insert_client_ip(
|
|
|
|
user_id, "access_token", "ip", "user_agent", "device_id"
|
|
|
|
)
|
2018-08-02 14:47:19 +02:00
|
|
|
)
|
2018-09-20 12:14:34 +02:00
|
|
|
active = self.get_success(self.store.user_last_seen_monthly_active(user_id))
|
2018-08-02 14:47:19 +02:00
|
|
|
self.assertTrue(active)
|
|
|
|
|
2020-05-22 22:47:07 +02:00
|
|
|
@override_config({"limit_usage_by_mau": True, "max_mau_value": 50})
|
2018-08-02 14:47:19 +02:00
|
|
|
def test_updating_monthly_active_user_when_space(self):
|
|
|
|
user_id = "@user:server"
|
2019-07-10 17:26:49 +02:00
|
|
|
self.get_success(self.store.register_user(user_id=user_id, password_hash=None))
|
2018-08-02 14:47:19 +02:00
|
|
|
|
2018-09-20 12:14:34 +02:00
|
|
|
active = self.get_success(self.store.user_last_seen_monthly_active(user_id))
|
2018-08-02 14:47:19 +02:00
|
|
|
self.assertFalse(active)
|
|
|
|
|
2018-09-20 12:14:34 +02:00
|
|
|
# Trigger the saving loop
|
|
|
|
self.reactor.advance(10)
|
|
|
|
|
|
|
|
self.get_success(
|
|
|
|
self.store.insert_client_ip(
|
|
|
|
user_id, "access_token", "ip", "user_agent", "device_id"
|
|
|
|
)
|
2018-08-02 14:47:19 +02:00
|
|
|
)
|
2018-09-20 12:14:34 +02:00
|
|
|
active = self.get_success(self.store.user_last_seen_monthly_active(user_id))
|
2018-08-02 14:47:19 +02:00
|
|
|
self.assertTrue(active)
|
2018-09-20 12:14:34 +02:00
|
|
|
|
2019-09-23 17:50:31 +02:00
|
|
|
def test_devices_last_seen_bg_update(self):
|
|
|
|
# First make sure we have completed all updates.
|
2019-12-04 16:09:36 +01:00
|
|
|
while not self.get_success(
|
2020-08-05 22:38:57 +02:00
|
|
|
self.store.db_pool.updates.has_completed_background_updates()
|
2019-12-04 16:09:36 +01:00
|
|
|
):
|
|
|
|
self.get_success(
|
2020-08-05 22:38:57 +02:00
|
|
|
self.store.db_pool.updates.do_next_background_update(100), by=0.1
|
2019-12-04 16:09:36 +01:00
|
|
|
)
|
2019-09-23 17:50:31 +02:00
|
|
|
|
|
|
|
user_id = "@user:id"
|
2019-12-10 17:22:29 +01:00
|
|
|
device_id = "MY_DEVICE"
|
|
|
|
|
|
|
|
# Insert a user IP
|
|
|
|
self.get_success(
|
|
|
|
self.store.store_device(
|
|
|
|
user_id,
|
|
|
|
device_id,
|
|
|
|
"display name",
|
|
|
|
)
|
2021-02-16 23:32:34 +01:00
|
|
|
)
|
2019-09-23 17:50:31 +02:00
|
|
|
self.get_success(
|
|
|
|
self.store.insert_client_ip(
|
2019-12-10 17:22:29 +01:00
|
|
|
user_id, "access_token", "ip", "user_agent", device_id
|
2019-09-23 17:50:31 +02:00
|
|
|
)
|
|
|
|
)
|
|
|
|
# Force persisting to disk
|
|
|
|
self.reactor.advance(200)
|
|
|
|
|
|
|
|
# But clear the associated entry in devices table
|
|
|
|
self.get_success(
|
2020-08-05 22:38:57 +02:00
|
|
|
self.store.db_pool.simple_update(
|
2019-09-23 17:50:31 +02:00
|
|
|
table="devices",
|
2019-12-10 17:22:29 +01:00
|
|
|
keyvalues={"user_id": user_id, "device_id": device_id},
|
2019-09-23 17:50:31 +02:00
|
|
|
updatevalues={"last_seen": None, "ip": None, "user_agent": None},
|
|
|
|
desc="test_devices_last_seen_bg_update",
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
# We should now get nulls when querying
|
|
|
|
result = self.get_success(
|
2019-12-10 17:22:29 +01:00
|
|
|
self.store.get_last_client_ip_by_device(user_id, device_id)
|
2019-09-23 17:50:31 +02:00
|
|
|
)
|
|
|
|
|
2019-12-10 17:22:29 +01:00
|
|
|
r = result[(user_id, device_id)]
|
2019-09-23 17:50:31 +02:00
|
|
|
self.assertDictContainsSubset(
|
|
|
|
{
|
|
|
|
"user_id": user_id,
|
2019-12-10 17:22:29 +01:00
|
|
|
"device_id": device_id,
|
2019-09-23 17:50:31 +02:00
|
|
|
"ip": None,
|
|
|
|
"user_agent": None,
|
|
|
|
"last_seen": None,
|
|
|
|
},
|
|
|
|
r,
|
|
|
|
)
|
|
|
|
|
|
|
|
# Register the background update to run again.
|
|
|
|
self.get_success(
|
2020-08-05 22:38:57 +02:00
|
|
|
self.store.db_pool.simple_insert(
|
2019-09-23 17:50:31 +02:00
|
|
|
table="background_updates",
|
|
|
|
values={
|
|
|
|
"update_name": "devices_last_seen",
|
|
|
|
"progress_json": "{}",
|
|
|
|
"depends_on": None,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
# ... and tell the DataStore that it hasn't finished all updates yet
|
2020-08-05 22:38:57 +02:00
|
|
|
self.store.db_pool.updates._all_done = False
|
2019-09-23 17:50:31 +02:00
|
|
|
|
|
|
|
# Now let's actually drive the updates to completion
|
2019-12-04 16:09:36 +01:00
|
|
|
while not self.get_success(
|
2020-08-05 22:38:57 +02:00
|
|
|
self.store.db_pool.updates.has_completed_background_updates()
|
2019-12-04 16:09:36 +01:00
|
|
|
):
|
|
|
|
self.get_success(
|
2020-08-05 22:38:57 +02:00
|
|
|
self.store.db_pool.updates.do_next_background_update(100), by=0.1
|
2019-12-04 16:09:36 +01:00
|
|
|
)
|
2019-09-23 17:50:31 +02:00
|
|
|
|
|
|
|
# We should now get the correct result again
|
|
|
|
result = self.get_success(
|
2019-12-10 17:22:29 +01:00
|
|
|
self.store.get_last_client_ip_by_device(user_id, device_id)
|
2019-09-23 17:50:31 +02:00
|
|
|
)
|
|
|
|
|
2019-12-10 17:22:29 +01:00
|
|
|
r = result[(user_id, device_id)]
|
2019-09-23 17:50:31 +02:00
|
|
|
self.assertDictContainsSubset(
|
|
|
|
{
|
|
|
|
"user_id": user_id,
|
2019-12-10 17:22:29 +01:00
|
|
|
"device_id": device_id,
|
2019-09-23 17:50:31 +02:00
|
|
|
"ip": "ip",
|
|
|
|
"user_agent": "user_agent",
|
|
|
|
"last_seen": 0,
|
|
|
|
},
|
|
|
|
r,
|
|
|
|
)
|
|
|
|
|
2019-09-24 16:51:42 +02:00
|
|
|
def test_old_user_ips_pruned(self):
|
|
|
|
# First make sure we have completed all updates.
|
2019-12-04 16:09:36 +01:00
|
|
|
while not self.get_success(
|
2020-08-05 22:38:57 +02:00
|
|
|
self.store.db_pool.updates.has_completed_background_updates()
|
2019-12-04 16:09:36 +01:00
|
|
|
):
|
|
|
|
self.get_success(
|
2020-08-05 22:38:57 +02:00
|
|
|
self.store.db_pool.updates.do_next_background_update(100), by=0.1
|
2019-12-04 16:09:36 +01:00
|
|
|
)
|
2019-09-24 16:51:42 +02:00
|
|
|
|
|
|
|
user_id = "@user:id"
|
2019-12-10 17:22:29 +01:00
|
|
|
device_id = "MY_DEVICE"
|
|
|
|
|
|
|
|
# Insert a user IP
|
|
|
|
self.get_success(
|
|
|
|
self.store.store_device(
|
|
|
|
user_id,
|
|
|
|
device_id,
|
|
|
|
"display name",
|
|
|
|
)
|
2021-02-16 23:32:34 +01:00
|
|
|
)
|
2019-09-24 16:51:42 +02:00
|
|
|
self.get_success(
|
|
|
|
self.store.insert_client_ip(
|
2019-12-10 17:22:29 +01:00
|
|
|
user_id, "access_token", "ip", "user_agent", device_id
|
2019-09-24 16:51:42 +02:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
# Force persisting to disk
|
|
|
|
self.reactor.advance(200)
|
|
|
|
|
|
|
|
# We should see that in the DB
|
|
|
|
result = self.get_success(
|
2020-08-05 22:38:57 +02:00
|
|
|
self.store.db_pool.simple_select_list(
|
2019-09-24 16:51:42 +02:00
|
|
|
table="user_ips",
|
|
|
|
keyvalues={"user_id": user_id},
|
|
|
|
retcols=["access_token", "ip", "user_agent", "device_id", "last_seen"],
|
|
|
|
desc="get_user_ip_and_agents",
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
result,
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"access_token": "access_token",
|
|
|
|
"ip": "ip",
|
|
|
|
"user_agent": "user_agent",
|
2019-12-10 17:22:29 +01:00
|
|
|
"device_id": device_id,
|
2019-09-24 16:51:42 +02:00
|
|
|
"last_seen": 0,
|
|
|
|
}
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
# Now advance by a couple of months
|
|
|
|
self.reactor.advance(60 * 24 * 60 * 60)
|
|
|
|
|
|
|
|
# We should get no results.
|
|
|
|
result = self.get_success(
|
2020-08-05 22:38:57 +02:00
|
|
|
self.store.db_pool.simple_select_list(
|
2019-09-24 16:51:42 +02:00
|
|
|
table="user_ips",
|
|
|
|
keyvalues={"user_id": user_id},
|
|
|
|
retcols=["access_token", "ip", "user_agent", "device_id", "last_seen"],
|
|
|
|
desc="get_user_ip_and_agents",
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
self.assertEqual(result, [])
|
|
|
|
|
|
|
|
# But we should still get the correct values for the device
|
|
|
|
result = self.get_success(
|
2019-12-10 17:22:29 +01:00
|
|
|
self.store.get_last_client_ip_by_device(user_id, device_id)
|
2019-09-24 16:51:42 +02:00
|
|
|
)
|
|
|
|
|
2019-12-10 17:22:29 +01:00
|
|
|
r = result[(user_id, device_id)]
|
2019-09-24 16:51:42 +02:00
|
|
|
self.assertDictContainsSubset(
|
|
|
|
{
|
|
|
|
"user_id": user_id,
|
2019-12-10 17:22:29 +01:00
|
|
|
"device_id": device_id,
|
2019-09-24 16:51:42 +02:00
|
|
|
"ip": "ip",
|
|
|
|
"user_agent": "user_agent",
|
|
|
|
"last_seen": 0,
|
|
|
|
},
|
|
|
|
r,
|
|
|
|
)
|
|
|
|
|
2018-09-20 12:14:34 +02:00
|
|
|
|
|
|
|
class ClientIpAuthTestCase(unittest.HomeserverTestCase):
|
|
|
|
|
2019-05-02 12:59:16 +02:00
|
|
|
servlets = [
|
2021-04-09 10:44:40 +02:00
|
|
|
synapse.rest.admin.register_servlets,
|
2019-05-02 12:59:16 +02:00
|
|
|
login.register_servlets,
|
|
|
|
]
|
2018-09-20 12:14:34 +02:00
|
|
|
|
|
|
|
def make_homeserver(self, reactor, clock):
|
|
|
|
hs = self.setup_test_homeserver()
|
|
|
|
return hs
|
|
|
|
|
|
|
|
def prepare(self, hs, reactor, clock):
|
|
|
|
self.store = self.hs.get_datastore()
|
2018-10-01 16:11:58 +02:00
|
|
|
self.user_id = self.register_user("bob", "abc123", True)
|
2018-09-20 12:14:34 +02:00
|
|
|
|
|
|
|
def test_request_with_xforwarded(self):
|
|
|
|
"""
|
|
|
|
The IP in X-Forwarded-For is entered into the client IPs table.
|
|
|
|
"""
|
|
|
|
self._runtest(
|
|
|
|
{b"X-Forwarded-For": b"127.9.0.1"},
|
|
|
|
"127.9.0.1",
|
|
|
|
{"request": XForwardedForRequest},
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_request_from_getPeer(self):
|
|
|
|
"""
|
|
|
|
The IP returned by getPeer is entered into the client IPs table, if
|
|
|
|
there's no X-Forwarded-For header.
|
|
|
|
"""
|
|
|
|
self._runtest({}, "127.0.0.1", {})
|
|
|
|
|
|
|
|
def _runtest(self, headers, expected_ip, make_request_args):
|
|
|
|
device_id = "bleb"
|
|
|
|
|
2018-10-01 16:11:58 +02:00
|
|
|
access_token = self.login("bob", "abc123", device_id=device_id)
|
2018-09-20 12:14:34 +02:00
|
|
|
|
|
|
|
# Advance to a known time
|
|
|
|
self.reactor.advance(123456 - self.reactor.seconds())
|
|
|
|
|
2020-11-16 15:45:22 +01:00
|
|
|
headers1 = {b"User-Agent": b"Mozzila pizza"}
|
|
|
|
headers1.update(headers)
|
|
|
|
|
2020-11-15 23:49:21 +01:00
|
|
|
make_request(
|
2020-11-16 15:45:22 +01:00
|
|
|
self.reactor,
|
2020-11-16 16:51:47 +01:00
|
|
|
self.site,
|
2018-09-20 12:14:34 +02:00
|
|
|
"GET",
|
2021-04-09 10:44:40 +02:00
|
|
|
"/_synapse/admin/v2/users/" + self.user_id,
|
2018-09-20 12:14:34 +02:00
|
|
|
access_token=access_token,
|
2020-11-16 15:45:22 +01:00
|
|
|
custom_headers=headers1.items(),
|
2018-09-20 12:14:34 +02:00
|
|
|
**make_request_args,
|
|
|
|
)
|
|
|
|
|
|
|
|
# Advance so the save loop occurs
|
|
|
|
self.reactor.advance(100)
|
|
|
|
|
|
|
|
result = self.get_success(
|
|
|
|
self.store.get_last_client_ip_by_device(self.user_id, device_id)
|
|
|
|
)
|
|
|
|
r = result[(self.user_id, device_id)]
|
|
|
|
self.assertDictContainsSubset(
|
|
|
|
{
|
|
|
|
"user_id": self.user_id,
|
|
|
|
"device_id": device_id,
|
|
|
|
"ip": expected_ip,
|
|
|
|
"user_agent": "Mozzila pizza",
|
|
|
|
"last_seen": 123456100,
|
|
|
|
},
|
|
|
|
r,
|
|
|
|
)
|