-
-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathHttpExtension.cookieSecure.phpt
More file actions
77 lines (54 loc) · 2.43 KB
/
HttpExtension.cookieSecure.phpt
File metadata and controls
77 lines (54 loc) · 2.43 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
70
71
72
73
74
75
76
77
<?php
declare(strict_types=1);
use Nette\Bridges\HttpDI\HttpExtension;
use Nette\Bridges\HttpDI\SessionExtension;
use Nette\DI;
use Tester\Assert;
require __DIR__ . '/../bootstrap.php';
test('cookie secure flag disabled', function () {
$compiler = new DI\Compiler;
$compiler->addExtension('http', new HttpExtension);
$compiler->addExtension('session', new SessionExtension(false, PHP_SAPI === 'cli'));
$loader = new DI\Config\Loader;
$config = $loader->load(Tester\FileMock::create('
http:
cookieSecure: no
', 'neon'));
eval($compiler->addConfig($config)->setClassName('ContainerNo')->compile());
$container = new ContainerNo;
Assert::false($container->getService('http.response')->cookieSecure);
Assert::false($container->getService('session.session')->getOptions()['cookie_secure']);
});
test('cookie secure flag enabled', function () {
$compiler = new DI\Compiler;
$compiler->addExtension('http', new HttpExtension);
$compiler->addExtension('session', new SessionExtension(false, PHP_SAPI === 'cli'));
$loader = new DI\Config\Loader;
$config = $loader->load(Tester\FileMock::create('
http:
cookieSecure: yes
', 'neon'));
eval($compiler->addConfig($config)->setClassName('ContainerYes')->compile());
$container = new ContainerYes;
Assert::true($container->getService('http.response')->cookieSecure);
Assert::true($container->getService('session.session')->getOptions()['cookie_secure']);
});
test('auto cookie secure flag based on HTTPS', function () {
$compiler = new DI\Compiler;
$compiler->addExtension('http', new HttpExtension);
$compiler->addExtension('session', new SessionExtension(false, PHP_SAPI === 'cli'));
$loader = new DI\Config\Loader;
$config = $loader->load(Tester\FileMock::create('
http:
cookieSecure: auto
', 'neon'));
eval($compiler->addConfig($config)->setClassName('ContainerAuto')->compile());
$container = new ContainerAuto;
$container->addService('http.request', new Nette\Http\Request(new Nette\Http\UrlScript('http://localhost')));
Assert::false($container->getService('http.response')->cookieSecure);
Assert::false($container->getService('session.session')->getOptions()['cookie_secure']);
$container = new ContainerAuto;
$container->addService('http.request', new Nette\Http\Request(new Nette\Http\UrlScript('https://localhost')));
Assert::true($container->getService('http.response')->cookieSecure);
Assert::true($container->getService('session.session')->getOptions()['cookie_secure']);
});