@@ -351,7 +351,6 @@ public function it_prepares_mapped_headers_with_defaults_and_default_prefetch_he
351351 /* ASSERT */
352352 $ this ->assertSame (
353353 [
354- HttpHeaderType::AUTHORIZATION ->value => 'Bearer token ' ,
355354 HttpHeaderType::ACCEPT ->value => 'application/json ' ,
356355 HttpHeaderType::ACCEPT_LANGUAGE ->value => 'en-US ' ,
357356 config ('demon-dextral-horn.defaults.prefetch_header ' ) => PrefetchType::AUTO ->value ,
@@ -388,6 +387,92 @@ public function it_applies_header_overrides(): void
388387 $ this ->assertSame ($ acceptValue , Arr::get ($ headers , HttpHeaderType::ACCEPT ->value ));
389388 }
390389
390+ #[Test]
391+ public function it_applies_authorization_header_override (): void
392+ {
393+ /* SETUP */
394+ $ headersData = new HeadersData (
395+ authorization: null ,
396+ accept: 'application/json ' ,
397+ acceptLanguage: 'en-US '
398+ );
399+ $ requestData = new RequestData (
400+ uri: '/sample_route ' ,
401+ method: Request::METHOD_GET ,
402+ headers: $ headersData ,
403+ routeName: 'sample.route ' ,
404+ );
405+ $ authValue = 'Bearer overridden_token ' ;
406+ $ overrides = [
407+ HttpHeaderType::AUTHORIZATION ->value => $ authValue ,
408+ ];
409+
410+ /* EXECUTE */
411+ $ headers = $ this ->anonymousClass ->callPrepareMappedHeaders ($ requestData , $ overrides );
412+
413+ /* ASSERT */
414+ $ this ->assertArrayHasKey (HttpHeaderType::AUTHORIZATION ->value , $ headers );
415+ $ this ->assertSame ($ authValue , Arr::get ($ headers , HttpHeaderType::AUTHORIZATION ->value ));
416+ }
417+
418+ #[Test]
419+ public function it_forwards_authorization_header_for_route_with_auth_middleware (): void
420+ {
421+ /* SETUP */
422+ $ token = 'Bearer sample_token ' ;
423+ $ acceptValue = 'application/json ' ;
424+ $ languageValue = 'en-US ' ;
425+ $ headersData = new HeadersData (
426+ authorization: $ token ,
427+ accept: $ acceptValue ,
428+ acceptLanguage: $ languageValue
429+ );
430+ $ requestData = new RequestData (
431+ uri: '/auth-protected-route ' ,
432+ method: Request::METHOD_GET ,
433+ headers: $ headersData ,
434+ routeName: 'auth.protected.route ' ,
435+ );
436+
437+ /* EXECUTE */
438+ $ headers = $ this ->anonymousClass ->callPrepareMappedHeaders ($ requestData );
439+
440+ /* ASSERT */
441+ $ this ->assertArrayHasKey (HttpHeaderType::AUTHORIZATION ->value , $ headers );
442+ $ this ->assertSame ($ token , $ headers [HttpHeaderType::AUTHORIZATION ->value ]);
443+ $ this ->assertSame ($ acceptValue , $ headers [HttpHeaderType::ACCEPT ->value ]);
444+ $ this ->assertSame ($ languageValue , $ headers [HttpHeaderType::ACCEPT_LANGUAGE ->value ]);
445+ $ this ->assertArrayHasKey (config ('demon-dextral-horn.defaults.prefetch_header ' ), $ headers );
446+ }
447+
448+ #[Test]
449+ public function it_does_not_forward_authorization_header_for_public_named_route (): void
450+ {
451+ /* SETUP */
452+ $ acceptValue = 'application/json ' ;
453+ $ languageValue = 'en-US ' ;
454+ $ headersData = new HeadersData (
455+ authorization: 'Bearer token ' ,
456+ accept: $ acceptValue ,
457+ acceptLanguage: $ languageValue
458+ );
459+ $ requestData = new RequestData (
460+ uri: '/public-route-no-auth ' ,
461+ method: Request::METHOD_GET ,
462+ headers: $ headersData ,
463+ routeName: 'public.route.no.auth ' ,
464+ );
465+
466+ /* EXECUTE */
467+ $ headers = $ this ->anonymousClass ->callPrepareMappedHeaders ($ requestData );
468+
469+ /* ASSERT */
470+ $ this ->assertArrayNotHasKey (HttpHeaderType::AUTHORIZATION ->value , $ headers );
471+ $ this ->assertSame ($ acceptValue , $ headers [HttpHeaderType::ACCEPT ->value ]);
472+ $ this ->assertSame ($ languageValue , $ headers [HttpHeaderType::ACCEPT_LANGUAGE ->value ]);
473+ $ this ->assertArrayHasKey (config ('demon-dextral-horn.defaults.prefetch_header ' ), $ headers );
474+ }
475+
391476 #[Test]
392477 public function it_filters_out_null_header_values (): void
393478 {
0 commit comments