Replace restricted UserResultByIdQuery endpoint

Fixes #1433
This commit is contained in:
Zed 2026-08-17 06:30:18 +07:00
commit 0ac9bc2678
3 changed files with 29 additions and 2 deletions

View file

@ -58,7 +58,7 @@ proc getGraphUser*(username: string): Future[User] {.async.} =
proc getGraphUserById*(id: string): Future[User] {.async.} = proc getGraphUserById*(id: string): Future[User] {.async.} =
if id.len == 0 or id.any(c => not c.isDigit): return if id.len == 0 or id.any(c => not c.isDigit): return
let let
url = apiReq(graphUserById, """{"rest_id": "$1"}""" % id) url = apiReq(graphUserById, userByRestIdVars % id)
js = await fetchRaw(url) js = await fetchRaw(url)
result = parseGraphUser(js) result = parseGraphUser(js)

View file

@ -9,7 +9,7 @@ const
graphUser* = "IGgvgiOx4QZndDHuD3x9TQ/UserByScreenName" graphUser* = "IGgvgiOx4QZndDHuD3x9TQ/UserByScreenName"
graphUserV2* = "-ZzAG_Bckx16LMbEvHC3lg/UserResultByScreenNameQuery" graphUserV2* = "-ZzAG_Bckx16LMbEvHC3lg/UserResultByScreenNameQuery"
graphUserById* = "-DAaa9jPxPswYeI2fZ9rug/UserResultByIdQuery" graphUserById* = "xvmVfRLmnr1alc5f2dib0Q/UserByRestId"
graphUserTweetsV2* = "LE3eTyeqhBh2g-fX85O2eQ/UserWithProfileTweetsQueryV2" graphUserTweetsV2* = "LE3eTyeqhBh2g-fX85O2eQ/UserWithProfileTweetsQueryV2"
graphUserTweetsAndRepliesV2* = "AcYHjc_YAx-9_rKWdMsKvA/UserWithProfileTweetsAndRepliesQueryV2" graphUserTweetsAndRepliesV2* = "AcYHjc_YAx-9_rKWdMsKvA/UserWithProfileTweetsAndRepliesQueryV2"
graphUserTweets* = "PNd0vlufvrcIwrAnBYKE9g/UserTweets" graphUserTweets* = "PNd0vlufvrcIwrAnBYKE9g/UserTweets"
@ -174,6 +174,11 @@ const
"withCommunity": false "withCommunity": false
}""".replace(" ", "").replace("\n", "") }""".replace(" ", "").replace("\n", "")
userByRestIdVars* = """{
"userId": "$1",
"withSafetyModeUserFields": true
}""".replace(" ", "").replace("\n", "")
communityTweetsVars* = """{ communityTweetsVars* = """{
"communityId": "$1", $2 "communityId": "$1", $2
"count": 20, "count": 20,

View file

@ -33,6 +33,12 @@ banner_image = [
['mobile_test', 'profile_banners%2F82135242%2F1384108037%2F1500x500'] ['mobile_test', 'profile_banners%2F82135242%2F1384108037%2F1500x500']
] ]
# (user_id, expected_username) — resolving a numeric id to a profile (issue #1433)
id_redirects = [
['12', 'jack'],
['44196397', 'elonmusk']
]
class ProfileTest(BaseTestCase): class ProfileTest(BaseTestCase):
@parameterized.expand(profiles) @parameterized.expand(profiles)
@ -93,3 +99,19 @@ class ProfileTest(BaseTestCase):
self.open_nitter(username) self.open_nitter(username)
banner = self.find_element(Profile.banner + ' img') banner = self.find_element(Profile.banner + ' img')
self.assertIn(url, banner.get_attribute('src')) self.assertIn(url, banner.get_attribute('src'))
class UserIdRedirectTest(BaseTestCase):
@parameterized.expand(id_redirects)
def test_i_user_redirect(self, user_id, username):
"""/i/user/<id> resolves the numeric id and redirects to the profile (issue #1433)"""
self.open_nitter(f'i/user/{user_id}')
self.assert_true(self.get_current_url().rstrip('/').endswith(f'/{username}'))
self.assert_exact_text(f'@{username}', Profile.username)
@parameterized.expand(id_redirects)
def test_intent_user_redirect(self, user_id, username):
"""/intent/user?user_id=<id> redirects to the profile (issue #1433)"""
self.open_nitter(f'intent/user?user_id={user_id}')
self.assert_true(self.get_current_url().rstrip('/').endswith(f'/{username}'))
self.assert_exact_text(f'@{username}', Profile.username)