Skip to content

Commit 78c621f

Browse files
authored
Fix breaking change with dropped support for userids with colons (#3572)
* Fix breaking change with dropped support for userids with colons * Add tests for users with colons
1 parent 525e150 commit 78c621f

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

kinto/core/initialization.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,9 @@ def on_new_response(event):
475475
# Count unique users.
476476
user_id = request.prefixed_userid
477477
if user_id:
478-
# Get rid of colons in metric packet (see #1282).
479-
auth, user_id = user_id.split(":")
478+
auth, user_id = user_id.split(":", 1)
479+
# Get rid of colons in metric packet (see #1282 and #3571).
480+
user_id = user_id.replace(":", ".")
480481
metrics_service.count("users", unique=[("auth", auth), ("userid", user_id)])
481482

482483
status = event.response.status_code

tests/core/test_initialization.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,16 @@ def test_statsd_counts_unique_users(self, digest_mocked):
382382
"users", unique=[("auth", "basicauth"), ("userid", "mat")]
383383
)
384384

385+
@mock.patch("kinto.core.utils.hmac_digest")
386+
def test_statsd_counts_unique_users_with_colons(self, digest_mocked):
387+
digest_mocked.return_value = "user:with:colons"
388+
kinto.core.initialize(self.config, "0.0.1", "settings_prefix")
389+
app = webtest.TestApp(self.config.make_wsgi_app())
390+
app.get("/v0/", headers=get_user_headers("user:with:colons"))
391+
self.mocked().count.assert_any_call(
392+
"users", unique=[("auth", "basicauth"), ("userid", "user.with.colons")]
393+
)
394+
385395
def test_statsd_counts_authentication_types(self):
386396
kinto.core.initialize(self.config, "0.0.1", "settings_prefix")
387397
app = webtest.TestApp(self.config.make_wsgi_app())

0 commit comments

Comments
 (0)