@@ -371,6 +371,134 @@ def test_mission_sticker_v3(self):
371371 self .assertEqual (body ["sendPresentMessage" ], False )
372372
373373
374+ class TestLineBotClientAuthorizationHeader (unittest .TestCase ):
375+ """Test that the Authorization header is correctly propagated to all domains."""
376+
377+ def _assert_bearer_token (self , httpserver , uri , method , token ):
378+ """Helper: call an endpoint and verify the Authorization header."""
379+ request , _ = httpserver .log [- 1 ]
380+ self .assertEqual (request .headers .get ("Authorization" ), f"Bearer { token } " )
381+
382+ def test_messaging_api_sends_bearer_token (self ):
383+ with HTTPServer () as httpserver :
384+ httpserver .expect_request (
385+ uri = "/v2/bot/profile/U123" ,
386+ method = "GET" ,
387+ ).respond_with_json (
388+ {"displayName" : "T" , "userId" : "U123" }, status = 200
389+ )
390+
391+ with LineBotClient (
392+ channel_access_token = "my-secret-token" ,
393+ host = httpserver .url_for ("/" )
394+ ) as client :
395+ client .get_profile (user_id = "U123" )
396+
397+ request , _ = httpserver .log [0 ]
398+ self .assertEqual (
399+ request .headers .get ("Authorization" ), "Bearer my-secret-token"
400+ )
401+
402+ def test_insight_api_sends_bearer_token (self ):
403+ with HTTPServer () as httpserver :
404+ httpserver .expect_request (
405+ uri = "/v2/bot/insight/followers" ,
406+ method = "GET" ,
407+ ).respond_with_json (
408+ {"status" : "ready" , "followers" : 0 , "targetedReaches" : 0 , "blocks" : 0 },
409+ status = 200
410+ )
411+
412+ with LineBotClient (
413+ channel_access_token = "insight-token" ,
414+ host = httpserver .url_for ("/" )
415+ ) as client :
416+ client .get_number_of_followers (var_date = "20240101" )
417+
418+ request , _ = httpserver .log [0 ]
419+ self .assertEqual (
420+ request .headers .get ("Authorization" ), "Bearer insight-token"
421+ )
422+
423+ def test_audience_api_sends_bearer_token (self ):
424+ with HTTPServer () as httpserver :
425+ httpserver .expect_request (
426+ uri = "/v2/bot/audienceGroup/99999" ,
427+ method = "DELETE" ,
428+ ).respond_with_json ({}, status = 200 )
429+
430+ with LineBotClient (
431+ channel_access_token = "audience-token" ,
432+ host = httpserver .url_for ("/" )
433+ ) as client :
434+ client .delete_audience_group (audience_group_id = 99999 )
435+
436+ request , _ = httpserver .log [0 ]
437+ self .assertEqual (
438+ request .headers .get ("Authorization" ), "Bearer audience-token"
439+ )
440+
441+ def test_liff_api_sends_bearer_token (self ):
442+ with HTTPServer () as httpserver :
443+ httpserver .expect_request (
444+ uri = "/liff/v1/apps" ,
445+ method = "GET" ,
446+ ).respond_with_json ({"apps" : []}, status = 200 )
447+
448+ with LineBotClient (
449+ channel_access_token = "liff-token" ,
450+ host = httpserver .url_for ("/" )
451+ ) as client :
452+ client .get_all_liff_apps ()
453+
454+ request , _ = httpserver .log [0 ]
455+ self .assertEqual (
456+ request .headers .get ("Authorization" ), "Bearer liff-token"
457+ )
458+
459+ def test_module_api_sends_bearer_token (self ):
460+ with HTTPServer () as httpserver :
461+ httpserver .expect_request (
462+ uri = "/v2/bot/list" ,
463+ method = "GET" ,
464+ ).respond_with_json ({"bots" : []}, status = 200 )
465+
466+ with LineBotClient (
467+ channel_access_token = "module-token" ,
468+ host = httpserver .url_for ("/" )
469+ ) as client :
470+ client .get_modules ()
471+
472+ request , _ = httpserver .log [0 ]
473+ self .assertEqual (
474+ request .headers .get ("Authorization" ), "Bearer module-token"
475+ )
476+
477+ def test_shop_api_sends_bearer_token (self ):
478+ with HTTPServer () as httpserver :
479+ httpserver .expect_request (
480+ uri = "/shop/v3/mission" ,
481+ method = "POST" ,
482+ ).respond_with_json ({}, status = 200 )
483+
484+ with LineBotClient (
485+ channel_access_token = "shop-token" ,
486+ host = httpserver .url_for ("/" )
487+ ) as client :
488+ req = MissionStickerRequest (
489+ to = "U123" ,
490+ productId = "p" ,
491+ productType = "t" ,
492+ sendPresentMessage = False
493+ )
494+ client .mission_sticker_v3 (mission_sticker_request = req )
495+
496+ request , _ = httpserver .log [0 ]
497+ self .assertEqual (
498+ request .headers .get ("Authorization" ), "Bearer shop-token"
499+ )
500+
501+
374502class TestLineBotClientErrors (unittest .TestCase ):
375503 """Test error handling through LineBotClient."""
376504
0 commit comments