diff --git a/core/modules/system/src/Tests/Session/SessionAuthenticationTest.php b/core/modules/system/src/Tests/Session/SessionAuthenticationTest.php index 1a67266809c012ab74c072179c8a82c418756343..ed3f6e84ce9473a8638fd7bb696740cd2d255827 100644 --- a/core/modules/system/src/Tests/Session/SessionAuthenticationTest.php +++ b/core/modules/system/src/Tests/Session/SessionAuthenticationTest.php @@ -110,4 +110,28 @@ protected function assertSessionData($response, $expected) { $this->assertEqual($this->user->id(), $response['user'], 'The correct user is logged in.'); } + /** + * Tests that a session is not started automatically by basic authentication. + */ + public function testBasicAuthNoSession() { + // A route that is authorized through basic_auth only, not cookie. + $no_cookie_url = Url::fromRoute('session_test.get_session_basic_auth'); + + // A route that is authorized with standard cookie authentication. + $cookie_url = ''; + + // If we authenticate with a third party authentication system then no + // session cookie should be set, the third party system is responsible for + // sustaining the session. + $this->basicAuthGet($no_cookie_url, $this->user->getUsername(), $this->user->pass_raw); + $this->assertResponse(200, 'The user is successfully authenticated using basic authentication.'); + $this->assertFalse($this->drupalGetHeader('set-cookie', TRUE), 'No cookie is set on a route protected with basic authentication.'); + + // On the other hand, authenticating using Cookie sets a cookie. + $edit = ['name' => $this->user->getUsername(), 'pass' => $this->user->pass_raw]; + $this->drupalPostForm($cookie_url, $edit, t('Log in')); + $this->assertResponse(200, 'The user is successfully authenticated using cookie authentication.'); + $this->assertTrue($this->drupalGetHeader('set-cookie', TRUE), 'A cookie is set on a route protected with cookie authentication.'); + } + }