SecureSiteBasicGuestUnsetTest.php in Secure Site 8
File
src/Tests/BasicAuth/SecureSiteBasicGuestUnsetTest.php
View source
<?php
namespace Drupal\securesite\Tests\BasicAuth;
use Drupal\simpletest\WebTestBase;
class SecureSiteBasicGuestUnsetTest extends WebTestBase {
public static $modules = array(
'securesite',
);
public static function getInfo() {
return array(
'name' => t('Basic authentication: Guest credentials unset'),
'description' => t('Test HTTP basic authentication with guest credentials unset.'),
'group' => t('Secure Site'),
);
}
function setUp() {
parent::setUp();
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array(
'access secured pages',
));
\Drupal::config('securesite.settings')
->set('securesite_type', array(
SECURESITE_FORM,
SECURESITE_BASIC,
SECURESITE_DIGEST,
))
->save();
$this->curl_options[CURLOPT_USERPWD] = ':';
}
function testSecureSiteTypeBasicGuestUnsetEmptyNoAccess() {
user_role_revoke_permissions(DRUPAL_ANONYMOUS_RID, array(
'access secured pages',
));
$this
->drupalGet(NULL);
$this
->assertResponse(403, t('Requesting home page with empty credentials and guest access disabled.'));
$this
->drupalHead(NULL);
$this
->assertResponse(401, t('Trying to clear credentials by repeating request.'));
}
function testSecureSiteTypeBasicGuestUnsetEmptyAccess() {
$this
->drupalHead(NULL);
$this
->assertResponse(200, t('Requesting home page with empty credentials and guest access enabled.'));
}
function testSecureSiteTypeBasicGuestUnsetRandomNoAccess() {
user_role_revoke_permissions(DRUPAL_ANONYMOUS_RID, array(
'access secured pages',
));
$this->curl_options[CURLOPT_USERPWD] = $this
->randomName() . ':' . user_password();
$this
->drupalGet(NULL);
$this
->assertResponse(401, t('Requesting home page with random credentials and guest access disabled.'));
}
function testSecureSiteTypeBasicGuestUnsetRandomAccess() {
$this->curl_options[CURLOPT_USERPWD] = $this
->randomName() . ':' . user_password();
$this
->drupalGet(NULL);
$this
->assertResponse(200, t('Requesting home page with random credentials and guest access enabled.'));
}
function testSecureSiteTypeBasicGuestUnsetChange() {
$user = $this
->drupalCreateUser();
$this
->drupalHead(NULL);
$this->curl_options[CURLOPT_USERPWD] = "{$user->name}:{$user->pass_raw}";
$this
->drupalHead(NULL);
$this
->assertResponse(403, t('Requesting home page with new user credentials.'));
}
function tearDown() {
$this->curl_options = array();
parent::tearDown();
}
}