3939use PHPUnit \Framework \TestCase ;
4040use TRegx \PhpUnit \DataProviders \DataProvider as TRegxDataProvider ;
4141
42- $ _SERVER ["HTTP_HOST " ] = "phpunit " ; // used for config override
42+ $ _SERVER ["SERVER_NAME " ] = "phpunit " ; // used for config override
4343require_once __DIR__ . "/../resources/config.php " ;
4444
4545global $ HTTP_HEADER_TEST_INPUTS ;
@@ -82,7 +82,7 @@ function executeWorker(
8282): array {
8383 global $ LDAP ;
8484 $ command = sprintf (
85- "HTTP_HOST =phpunit %s %s %s 2>&1 " ,
85+ "SERVER_NAME =phpunit %s %s %s 2>&1 " ,
8686 escapeshellarg (PHP_BINARY ),
8787 escapeshellarg (__DIR__ . "/../workers/ " . $ basename ),
8888 $ args ,
@@ -513,7 +513,7 @@ function switchUser(
513513 // session_start will be called on the first post()
514514 $ _SERVER ["REMOTE_USER " ] = $ eppn ;
515515 $ _SERVER ["REMOTE_ADDR " ] = "127.0.0.1 " ;
516- $ _SERVER ["HTTP_HOST " ] = "phpunit " ; // used for config override
516+ $ _SERVER ["SERVER_NAME " ] = "phpunit " ; // used for config override
517517 $ _SERVER ["eppn " ] = $ eppn ;
518518 $ _SERVER ["givenName " ] = $ given_name ;
519519 $ _SERVER ["sn " ] = $ sn ;
@@ -559,9 +559,10 @@ function assertNoWarningErrorMessages()
559559 function http_post (
560560 string $ phpfile ,
561561 array $ post_data ,
562- array $ query_parameters = [],
562+ array $ query_params = [],
563563 bool $ do_generate_csrf_token = true ,
564564 bool $ do_validate_messages = true ,
565+ ?string $ bearer_token = null ,
565566 ): string {
566567 global $ LDAP ,
567568 $ SQL ,
@@ -580,11 +581,14 @@ function http_post(
580581 $ _SERVER ["REQUEST_METHOD " ] = "POST " ;
581582 $ _SERVER ["PHP_SELF " ] = _preg_replace ("/.*webroot\// " , "/ " , $ phpfile );
582583 $ _SERVER ["REQUEST_URI " ] = _preg_replace ("/.*webroot\// " , "/ " , $ phpfile ); // Slightly imprecise because it doesn't include get parameters
584+ if ($ bearer_token !== null ) {
585+ $ _SERVER ["HTTP_AUTHORIZATION " ] = "Bearer $ bearer_token " ;
586+ }
583587 if (!array_key_exists ("csrf_token " , $ post_data ) && $ do_generate_csrf_token ) {
584588 $ post_data ["csrf_token " ] = CSRFToken::generate ();
585589 }
586590 $ _POST = $ post_data ;
587- $ _GET = $ query_parameters ;
591+ $ _GET = $ query_params ;
588592 ob_start ();
589593 try {
590594 $ post_did_redirect_or_die = false ;
@@ -609,8 +613,9 @@ function http_post(
609613
610614 function http_get (
611615 string $ phpfile ,
612- array $ get_data = [],
616+ array $ query_params = [],
613617 bool $ ignore_die = false ,
618+ ?string $ bearer_token = null ,
614619 $ do_validate_messages = true ,
615620 ): string {
616621 global $ LDAP ,
@@ -630,7 +635,10 @@ function http_get(
630635 $ _SERVER ["REQUEST_METHOD " ] = "GET " ;
631636 $ _SERVER ["PHP_SELF " ] = _preg_replace ("/.*webroot\// " , "/ " , $ phpfile );
632637 $ _SERVER ["REQUEST_URI " ] = _preg_replace ("/.*webroot\// " , "/ " , $ phpfile ); // Slightly imprecise because it doesn't include get parameters
633- $ _GET = $ get_data ;
638+ if ($ bearer_token !== null ) {
639+ $ _SERVER ["HTTP_AUTHORIZATION " ] = "Bearer $ bearer_token " ;
640+ }
641+ $ _GET = $ query_params ;
634642 ob_start ();
635643 try {
636644 include $ phpfile ;
0 commit comments