@@ -101,6 +101,37 @@ local function test_whoami_lookup_returns_localpart()
101101 assert_equal (calls , 1 , " whoami should be called once" )
102102end
103103
104+ local function test_whoami_lookup_forwards_xff ()
105+ local captured_xff
106+ local request_handle = new_request_handle ({
107+ [" :path" ] = " /_matrix/client/v3/sync" ,
108+ [" :authority" ] = " matrix.example.org" ,
109+ [" authorization" ] = " Bearer xff-token" ,
110+ [" x-forwarded-for" ] = " 203.0.113.1"
111+ }, function (_ , cluster , headers , body , timeout_ms )
112+ captured_xff = headers [" x-forwarded-for" ]
113+ return { [" :status" ] = " 200" }, ' {"user_id":"@carol:example.org"}'
114+ end )
115+
116+ synapse .get_user_identifier_from_request (request_handle , {})
117+ assert_equal (captured_xff , " 203.0.113.1" , " whoami httpCall should forward x-forwarded-for" )
118+ end
119+
120+ local function test_whoami_lookup_without_xff ()
121+ local captured_xff = " sentinel"
122+ local request_handle = new_request_handle ({
123+ [" :path" ] = " /_matrix/client/v3/sync" ,
124+ [" :authority" ] = " matrix.example.org" ,
125+ [" authorization" ] = " Bearer no-xff-token"
126+ }, function (_ , cluster , headers , body , timeout_ms )
127+ captured_xff = headers [" x-forwarded-for" ]
128+ return { [" :status" ] = " 200" }, ' {"user_id":"@dave:example.org"}'
129+ end )
130+
131+ synapse .get_user_identifier_from_request (request_handle , {})
132+ assert_equal (captured_xff , nil , " whoami httpCall should not set x-forwarded-for when absent" )
133+ end
134+
104135local function test_whoami_lookup_is_cached ()
105136 local request_handle = new_request_handle ({
106137 [" :path" ] = " /_matrix/client/v3/sync" ,
@@ -184,6 +215,8 @@ local tests = {
184215 test_access_token_from_authorization_header ,
185216 test_access_token_from_query ,
186217 test_whoami_lookup_returns_localpart ,
218+ test_whoami_lookup_forwards_xff ,
219+ test_whoami_lookup_without_xff ,
187220 test_whoami_lookup_is_cached ,
188221 test_whoami_failure_falls_back_to_token ,
189222 test_missing_token_returns_nil ,
0 commit comments