-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a test to ensure referrerpolicy is set
- Loading branch information
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace Drupal\Tests\turnstile_protect\Functional; | ||
|
||
use Drupal\Tests\BrowserTestBase; | ||
|
||
/** | ||
* Tests redirection from /node/1 to /challenge. | ||
* | ||
* @group turnstile_protect | ||
*/ | ||
class NoReferrerTest extends BrowserTestBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected static $modules = [ | ||
'node', | ||
'captcha', | ||
'turnstile', | ||
'turnstile_protect', | ||
]; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected $defaultTheme = 'claro'; | ||
|
||
/** | ||
* Sets up the test environment. | ||
*/ | ||
protected function setUp(): void { | ||
parent::setUp(); | ||
|
||
// Always pass the turnstile | ||
// https://developers.cloudflare.com/turnstile/troubleshooting/testing/ | ||
$this->config('turnstile.settings') | ||
->set('site_key', '1x00000000000000000000AA') | ||
->set('secret_key', '1x0000000000000000000000000000000AA') | ||
->save(); | ||
} | ||
|
||
/** | ||
* Tests referrerpolicy is set on cloudflare <script>. | ||
*/ | ||
public function testReferrer() { | ||
$cloudFlareSrc = \Drupal::config('turnstile.settings')->get('turnstile_src'); | ||
$this->drupalGet('/challenge'); | ||
$page = $this->getSession()->getPage(); | ||
$script = $page->find('css', "script[src='$cloudFlareSrc']"); | ||
$this->assertNotNull($script, "Cloudflare script could not be found on page"); | ||
$attribute = 'referrerpolicy'; | ||
$this->assertTrue($script->hasAttribute($attribute) && $script->getAttribute($attribute) === 'no-referrer', "referrerpolicy not correct"); | ||
} | ||
|
||
} |