forked from BookStackApp/BookStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSecurityHeaderTest.php
More file actions
69 lines (59 loc) · 2.36 KB
/
Copy pathSecurityHeaderTest.php
File metadata and controls
69 lines (59 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
namespace Tests;
use Illuminate\Support\Str;
class SecurityHeaderTest extends TestCase
{
public function test_cookies_samesite_lax_by_default()
{
$resp = $this->get('/');
foreach ($resp->headers->getCookies() as $cookie) {
$this->assertEquals('lax', $cookie->getSameSite());
}
}
public function test_cookies_samesite_none_when_iframe_hosts_set()
{
$this->runWithEnv('ALLOWED_IFRAME_HOSTS', 'http://example.com', function () {
$resp = $this->get('/');
foreach ($resp->headers->getCookies() as $cookie) {
$this->assertEquals('none', $cookie->getSameSite());
}
});
}
public function test_secure_cookies_controlled_by_app_url()
{
$this->runWithEnv('APP_URL', 'http://example.com', function () {
$resp = $this->get('/');
foreach ($resp->headers->getCookies() as $cookie) {
$this->assertFalse($cookie->isSecure());
}
});
$this->runWithEnv('APP_URL', 'https://example.com', function () {
$resp = $this->get('/');
foreach ($resp->headers->getCookies() as $cookie) {
$this->assertTrue($cookie->isSecure());
}
});
}
public function test_iframe_csp_self_only_by_default()
{
$resp = $this->get('/');
$cspHeaders = collect($resp->headers->get('Content-Security-Policy'));
$frameHeaders = $cspHeaders->filter(function ($val) {
return Str::startsWith($val, 'frame-ancestors');
});
$this->assertTrue($frameHeaders->count() === 1);
$this->assertEquals('frame-ancestors \'self\'', $frameHeaders->first());
}
public function test_iframe_csp_includes_extra_hosts_if_configured()
{
$this->runWithEnv('ALLOWED_IFRAME_HOSTS', 'https://a.example.com https://b.example.com', function () {
$resp = $this->get('/');
$cspHeaders = collect($resp->headers->get('Content-Security-Policy'));
$frameHeaders = $cspHeaders->filter(function ($val) {
return Str::startsWith($val, 'frame-ancestors');
});
$this->assertTrue($frameHeaders->count() === 1);
$this->assertEquals('frame-ancestors \'self\' https://a.example.com https://b.example.com', $frameHeaders->first());
});
}
}