Skip to content

Commit c9adbc6

Browse files
authored
make tests tolerant to authlib 1.5.2 error messages (#18390)
authlib 1.5.2 now single-quotes error messages in the claims, causing three tests to fail. Replace the comparison with a regex that accepts both single or double quotes. This succeeds the tests with both authlib 1.5.1 and 1.5.2. See NixOS/nixpkgs#402797 for context. ### Pull Request Checklist <!-- Please read https://element-hq.github.io/synapse/latest/development/contributing_guide.html before submitting your pull request --> * [x] Pull request is based on the develop branch * [x] Pull request includes a [changelog file](https://element-hq.github.io/synapse/latest/development/contributing_guide.html#changelog). The entry should: - Be a short description of your change which makes sense to users. "Fixed a bug that prevented receiving messages from other servers." instead of "Moved X method from `EventStore` to `EventWorkerStore`.". - Use markdown where necessary, mostly for `code blocks`. - End with either a period (.) or an exclamation mark (!). - Start with a capital letter. - Feel free to credit yourself, by adding a sentence "Contributed by @github_username." or "Contributed by [Your Name]." to the end of the entry. * [x] [Code style](https://element-hq.github.io/synapse/latest/code_style.html) is correct (run the [linters](https://element-hq.github.io/synapse/latest/development/contributing_guide.html#run-the-linters))
1 parent 9f9eb56 commit c9adbc6

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

changelog.d/18390.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed test failures when using authlib 1.5.2.

tests/rest/client/test_login.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,18 +1262,18 @@ def test_login_iss(self) -> None:
12621262
channel = self.jwt_login({"sub": "kermit", "iss": "invalid"})
12631263
self.assertEqual(channel.code, 403, msg=channel.result)
12641264
self.assertEqual(channel.json_body["errcode"], "M_FORBIDDEN")
1265-
self.assertEqual(
1265+
self.assertRegex(
12661266
channel.json_body["error"],
1267-
'JWT validation failed: invalid_claim: Invalid claim "iss"',
1267+
r"^JWT validation failed: invalid_claim: Invalid claim [\"']iss[\"']$",
12681268
)
12691269

12701270
# Not providing an issuer.
12711271
channel = self.jwt_login({"sub": "kermit"})
12721272
self.assertEqual(channel.code, 403, msg=channel.result)
12731273
self.assertEqual(channel.json_body["errcode"], "M_FORBIDDEN")
1274-
self.assertEqual(
1274+
self.assertRegex(
12751275
channel.json_body["error"],
1276-
'JWT validation failed: missing_claim: Missing "iss" claim',
1276+
r"^JWT validation failed: missing_claim: Missing [\"']iss[\"'] claim$",
12771277
)
12781278

12791279
def test_login_iss_no_config(self) -> None:
@@ -1294,28 +1294,28 @@ def test_login_aud(self) -> None:
12941294
channel = self.jwt_login({"sub": "kermit", "aud": "invalid"})
12951295
self.assertEqual(channel.code, 403, msg=channel.result)
12961296
self.assertEqual(channel.json_body["errcode"], "M_FORBIDDEN")
1297-
self.assertEqual(
1297+
self.assertRegex(
12981298
channel.json_body["error"],
1299-
'JWT validation failed: invalid_claim: Invalid claim "aud"',
1299+
r"^JWT validation failed: invalid_claim: Invalid claim [\"']aud[\"']$",
13001300
)
13011301

13021302
# Not providing an audience.
13031303
channel = self.jwt_login({"sub": "kermit"})
13041304
self.assertEqual(channel.code, 403, msg=channel.result)
13051305
self.assertEqual(channel.json_body["errcode"], "M_FORBIDDEN")
1306-
self.assertEqual(
1306+
self.assertRegex(
13071307
channel.json_body["error"],
1308-
'JWT validation failed: missing_claim: Missing "aud" claim',
1308+
r"^JWT validation failed: missing_claim: Missing [\"']aud[\"'] claim$",
13091309
)
13101310

13111311
def test_login_aud_no_config(self) -> None:
13121312
"""Test providing an audience without requiring it in the configuration."""
13131313
channel = self.jwt_login({"sub": "kermit", "aud": "invalid"})
13141314
self.assertEqual(channel.code, 403, msg=channel.result)
13151315
self.assertEqual(channel.json_body["errcode"], "M_FORBIDDEN")
1316-
self.assertEqual(
1316+
self.assertRegex(
13171317
channel.json_body["error"],
1318-
'JWT validation failed: invalid_claim: Invalid claim "aud"',
1318+
r"^JWT validation failed: invalid_claim: Invalid claim [\"']aud[\"']$",
13191319
)
13201320

13211321
def test_login_default_sub(self) -> None:

0 commit comments

Comments
 (0)