Loading core/modules/basic_auth/tests/modules/basic_auth_test/src/BasicAuthTestController.php +13 −4 Original line number Diff line number Diff line Loading @@ -4,16 +4,25 @@ namespace Drupal\basic_auth_test; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\PageCache\ResponsePolicyInterface; use Symfony\Component\DependencyInjection\Attribute\Autowire; /** * Provides routes for HTTP Basic Authentication testing. */ class BasicAuthTestController { class BasicAuthTestController extends ControllerBase { public function __construct( #[Autowire(service: 'page_cache_kill_switch')] private ResponsePolicyInterface $pageCacheKillSwitch, ) {} /** * @see \Drupal\basic_auth\Tests\Authentication\BasicAuthTest::testControllerNotCalledBeforeAuth() */ public function modifyState() { \Drupal::state()->set('basic_auth_test.state.controller_executed', TRUE); $this->state()->set('basic_auth_test.state.controller_executed', TRUE); return ['#markup' => 'Done']; } Loading @@ -22,10 +31,10 @@ public function modifyState() { */ public function readState() { // Mark this page as being uncacheable. \Drupal::service('page_cache_kill_switch')->trigger(); $this->pageCacheKillSwitch->trigger(); return [ '#markup' => \Drupal::state()->get('basic_auth_test.state.controller_executed') ? 'yep' : 'nope', '#markup' => $this->state()->get('basic_auth_test.state.controller_executed') ? 'yep' : 'nope', '#cache' => [ 'max-age' => 0, ], Loading core/modules/basic_auth/tests/src/Functional/BasicAuthTest.php +1 −1 Original line number Diff line number Diff line Loading @@ -68,7 +68,7 @@ public function testBasicAuth(): void { // Ensure that the user is prompted to authenticate if they are not yet // authenticated and the route only allows basic auth. $this->drupalGet($url); $this->assertSession()->responseHeaderEquals('WWW-Authenticate', 'Basic realm="' . \Drupal::config('system.site')->get('name') . '"'); $this->assertSession()->responseHeaderEquals('WWW-Authenticate', 'Basic realm="' . $this->config('system.site')->get('name') . '"'); $this->assertSession()->statusCodeEquals(401); // Ensure that a route without basic auth defined doesn't prompt for auth. Loading Loading
core/modules/basic_auth/tests/modules/basic_auth_test/src/BasicAuthTestController.php +13 −4 Original line number Diff line number Diff line Loading @@ -4,16 +4,25 @@ namespace Drupal\basic_auth_test; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\PageCache\ResponsePolicyInterface; use Symfony\Component\DependencyInjection\Attribute\Autowire; /** * Provides routes for HTTP Basic Authentication testing. */ class BasicAuthTestController { class BasicAuthTestController extends ControllerBase { public function __construct( #[Autowire(service: 'page_cache_kill_switch')] private ResponsePolicyInterface $pageCacheKillSwitch, ) {} /** * @see \Drupal\basic_auth\Tests\Authentication\BasicAuthTest::testControllerNotCalledBeforeAuth() */ public function modifyState() { \Drupal::state()->set('basic_auth_test.state.controller_executed', TRUE); $this->state()->set('basic_auth_test.state.controller_executed', TRUE); return ['#markup' => 'Done']; } Loading @@ -22,10 +31,10 @@ public function modifyState() { */ public function readState() { // Mark this page as being uncacheable. \Drupal::service('page_cache_kill_switch')->trigger(); $this->pageCacheKillSwitch->trigger(); return [ '#markup' => \Drupal::state()->get('basic_auth_test.state.controller_executed') ? 'yep' : 'nope', '#markup' => $this->state()->get('basic_auth_test.state.controller_executed') ? 'yep' : 'nope', '#cache' => [ 'max-age' => 0, ], Loading
core/modules/basic_auth/tests/src/Functional/BasicAuthTest.php +1 −1 Original line number Diff line number Diff line Loading @@ -68,7 +68,7 @@ public function testBasicAuth(): void { // Ensure that the user is prompted to authenticate if they are not yet // authenticated and the route only allows basic auth. $this->drupalGet($url); $this->assertSession()->responseHeaderEquals('WWW-Authenticate', 'Basic realm="' . \Drupal::config('system.site')->get('name') . '"'); $this->assertSession()->responseHeaderEquals('WWW-Authenticate', 'Basic realm="' . $this->config('system.site')->get('name') . '"'); $this->assertSession()->statusCodeEquals(401); // Ensure that a route without basic auth defined doesn't prompt for auth. Loading