SecureSiteDigestUserStoredTest.php in Secure Site 8
File
src/Tests/DigestAuth/SecureSiteDigestUserStoredTest.php
View source
<?php
namespace Drupal\securesite\Tests\DigestAuth;
use Drupal\simpletest\WebTestBase;
class SecureSiteDigestUserStoredTest extends WebTestBase {
public static $modules = array(
'securesite',
);
protected $user;
public static function getInfo() {
return array(
'name' => t('Digest authentication: User credentials stored'),
'description' => t('Test HTTP digest authentication with stored user credentials. Digest scripts must be configured on the live site before these tests can be run.'),
'group' => t('Secure Site'),
);
}
function setUp() {
parent::setUp();
_securesite_copy_script_config($this);
$config = \Drupal::config('securesite.settings');
$config
->set('securesite_enabled', SECURESITE_ALWAYS);
$config
->set('securesite_type', array(
SECURESITE_FORM,
SECURESITE_BASIC,
SECURESITE_DIGEST,
));
$config
->save();
$this->user = $this
->drupalCreateUser(array(
'access secured pages',
));
$this->curl_options[CURLOPT_HTTPAUTH] = CURLAUTH_DIGEST;
}
function testSecureSiteTypeDigestUserStoredWrong() {
$this->curl_options[CURLOPT_USERPWD] = $this->user->name . ':' . $this->user->pass;
$this
->drupalHead(NULL);
$this
->assertResponse(401, t('Requesting home page with wrong password.'));
}
function testSecureSiteTypeDigestUserStoredCorrect() {
$this->curl_options[CURLOPT_USERPWD] = $this->user->name . ':' . $this->user->pass_raw;
$this
->drupalHead(NULL);
$this
->assertResponse(200, t('Requesting home page with correct password.'));
module_load_include('inc', 'securesite');
$directives = _securesite_parse_directives($this
->drupalGetHeader('Authentication-Info'));
$this
->assertTrue(isset($directives['rspauth']), t('Checking correct password authentication info.'));
$this
->drupalHead('user/logout');
$this
->assertResponse(401, t('Requesting log-out page'));
}
function tearDown() {
user_cancel(array(), $this->user->uid, $method = 'user_cancel_delete');
parent::tearDown();
}
}