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

Fix error in get_user_ip_and_agents when fetching from the database #10968

Merged
merged 2 commits into from
Oct 1, 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/10968.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix `/admin/whois/{user_id}` endpoint, which was broken in v1.44.0rc1.
4 changes: 2 additions & 2 deletions synapse/storage/databases/main/client_ips.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,8 +591,8 @@ def get_recent(txn):
)

results.update(
((row["access_token"], row["ip"]), (row["user_agent"], row["last_seen"]))
for row in rows
((access_token, ip), (user_agent, last_seen))
for access_token, ip, user_agent, last_seen in rows
)
return [
{
Expand Down
34 changes: 34 additions & 0 deletions tests/storage/test_client_ips.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@

from unittest.mock import Mock

from parameterized import parameterized

import synapse.rest.admin
from synapse.http.site import XForwardedForRequest
from synapse.rest.client import login
from synapse.types import UserID

from tests import unittest
from tests.server import make_request
Expand Down Expand Up @@ -143,6 +146,37 @@ def test_insert_new_client_ip_none_device_id(self):
],
)

@parameterized.expand([(False,), (True,)])
def test_get_user_ip_and_agents(self, after_persisting: bool):
"""Test `get_user_ip_and_agents` for persisted and unpersisted data"""
self.reactor.advance(12345678)
clokep marked this conversation as resolved.
Show resolved Hide resolved

user_id = "@user:id"
user = UserID.from_string(user_id)

# Insert a user IP
self.get_success(
self.store.insert_client_ip(
user_id, "access_token", "ip", "user_agent", "MY_DEVICE"
)
)

if after_persisting:
# Trigger the storage loop
self.reactor.advance(10)

self.assertEqual(
self.get_success(self.store.get_user_ip_and_agents(user)),
[
{
"access_token": "access_token",
"ip": "ip",
"user_agent": "user_agent",
"last_seen": 12345678000,
},
],
)

@override_config({"limit_usage_by_mau": False, "max_mau_value": 50})
def test_disabled_monthly_active_user(self):
user_id = "@user:server"
Expand Down