diff --git a/core/modules/rest/src/Tests/AuthTest.php b/core/modules/rest/src/Tests/AuthTest.php index c8a8e3b..37c830f 100644 --- a/core/modules/rest/src/Tests/AuthTest.php +++ b/core/modules/rest/src/Tests/AuthTest.php @@ -53,18 +53,17 @@ public function testRead() { $account = $this->drupalCreateUser($permissions); $this->drupalLogin($account); - // Try to read the resource with session cookie authentication, which is - // not enabled and should not work. + // Read the resource with session cookie authentication. $this->httpRequest($entity->urlInfo(), 'GET', NULL, $this->defaultMimeType); - $this->assertResponse('401', 'HTTP response code is 401 when the request is authenticated but not authorized.'); + $this->assertResponse('200', 'HTTP response code is 200 for successfully authenticated requests.'); // Ensure that cURL settings/headers aren't carried over to next request. unset($this->curlHandle); // Now read it with the Basic authentication which is enabled and should // work. - $this->basicAuthGet($entity->urlInfo(), $account->getUsername(), $account->pass_raw); - $this->assertResponse('200', 'HTTP response code is 200 for successfully authorized requests.'); + $this->basicAuthGet($entity->urlInfo(), $account->getUsername(), $account->pass_raw, $this->defaultMimeType); + $this->assertResponse('200', 'HTTP response code is 200 for successfully authenticated requests.'); $this->curlClose(); } @@ -84,7 +83,10 @@ public function testRead() { * @return string * Curl output. */ - protected function basicAuthGet(Url $url, $username, $password) { + protected function basicAuthGet(Url $url, $username, $password, $mime_type = NULL) { + if (!isset($mime_type)) { + $mime_type = $this->defaultMimeType; + } $out = $this->curlExec( array( CURLOPT_HTTPGET => TRUE, @@ -92,6 +94,7 @@ protected function basicAuthGet(Url $url, $username, $password) { CURLOPT_NOBODY => FALSE, CURLOPT_HTTPAUTH => CURLAUTH_BASIC, CURLOPT_USERPWD => $username . ':' . $password, + CURLOPT_HTTPHEADER => array('Accept: ' . $mime_type), ) );