1 | <?php |
||
2 | |||
3 | /** |
||
4 | * Copyright © 2016-present Spryker Systems GmbH. All rights reserved. |
||
5 | * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. |
||
6 | */ |
||
7 | |||
8 | namespace SprykerTest\Yves\Application\Expander; |
||
9 | |||
10 | use Codeception\Test\Unit; |
||
11 | use Spryker\Shared\EventDispatcher\EventDispatcherInterface; |
||
12 | use Spryker\Yves\Application\ApplicationConfig; |
||
13 | use Spryker\Yves\Application\Expander\SecurityHeaderExpander; |
||
14 | |||
15 | /** |
||
16 | * Auto-generated group annotations |
||
17 | * |
||
18 | * @group SprykerTest |
||
19 | * @group Yves |
||
20 | * @group Application |
||
21 | * @group Expander |
||
22 | * @group SecurityHeaderExpanderTest |
||
23 | * Add your own group annotations below this line |
||
24 | */ |
||
25 | class SecurityHeaderExpanderTest extends Unit |
||
26 | { |
||
27 | /** |
||
28 | * @var string |
||
29 | */ |
||
30 | protected const HEADER_CONTENT_SECURITY_POLICY = 'Content-Security-Policy'; |
||
31 | |||
32 | /** |
||
33 | * @return void |
||
34 | */ |
||
35 | public function testExpandReturnExpandedHeadersWhenRequestIsCorrect(): void |
||
36 | { |
||
37 | // Arrange |
||
38 | $eventDispatcherMock = $this->createMock(EventDispatcherInterface::class); |
||
39 | $applicationConfigMock = $this->createMock(ApplicationConfig::class); |
||
40 | $applicationConfigMock->method('getSecurityHeaders')->willReturn([ |
||
41 | static::HEADER_CONTENT_SECURITY_POLICY => 'form-action self', |
||
42 | ]); |
||
43 | $applicationConfigMock->method('getDomainWhitelist')->willReturn([ |
||
44 | 'test.domain', |
||
45 | 'test.domain', |
||
46 | ]); |
||
47 | $securityHeaderExpanderMock = $this->getSecurityHeaderExpanderMock($applicationConfigMock); |
||
48 | |||
49 | //Assert |
||
50 | $securityHeaderExpanderMock->method('executeSecurityHeaderExpanderPlugins') |
||
0 ignored issues
–
show
|
|||
51 | ->with([ |
||
52 | static::HEADER_CONTENT_SECURITY_POLICY => 'form-action test.domain self', |
||
53 | ]); |
||
54 | |||
55 | //Act |
||
56 | $securityHeaderExpanderMock->expand($eventDispatcherMock); |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * @return void |
||
61 | */ |
||
62 | public function testExpandReturnInitialHeadersWhenRequestDoesntHaveCSPHeader(): void |
||
63 | { |
||
64 | // Arrange |
||
65 | $eventDispatcherMock = $this->createMock(EventDispatcherInterface::class); |
||
66 | $applicationConfigMock = $this->createMock(ApplicationConfig::class); |
||
67 | $applicationConfigMock->method('getSecurityHeaders')->willReturn([ |
||
68 | 'test' => 'test', |
||
69 | ]); |
||
70 | $securityHeaderExpanderMock = $this->getSecurityHeaderExpanderMock($applicationConfigMock); |
||
71 | |||
72 | //Assert |
||
73 | $securityHeaderExpanderMock->method('executeSecurityHeaderExpanderPlugins') |
||
74 | ->with([ |
||
75 | 'test' => 'test', |
||
76 | ]); |
||
77 | |||
78 | //Act |
||
79 | $securityHeaderExpanderMock->expand($eventDispatcherMock); |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * @return void |
||
84 | */ |
||
85 | public function testExpandReturnInitialHeadersWhenRequestDoesntHaveWhitelistedDomains(): void |
||
86 | { |
||
87 | // Arrange |
||
88 | $eventDispatcherMock = $this->createMock(EventDispatcherInterface::class); |
||
89 | $applicationConfigMock = $this->createMock(ApplicationConfig::class); |
||
90 | $applicationConfigMock->method('getSecurityHeaders')->willReturn([ |
||
91 | static::HEADER_CONTENT_SECURITY_POLICY => 'form-action self', |
||
92 | ]); |
||
93 | $securityHeaderExpanderMock = $this->getSecurityHeaderExpanderMock($applicationConfigMock); |
||
94 | |||
95 | //Assert |
||
96 | $securityHeaderExpanderMock->method('executeSecurityHeaderExpanderPlugins') |
||
97 | ->with([ |
||
98 | static::HEADER_CONTENT_SECURITY_POLICY => 'form-action self', |
||
99 | ]); |
||
100 | |||
101 | //Act |
||
102 | $securityHeaderExpanderMock->expand($eventDispatcherMock); |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * @param \Spryker\Yves\Application\ApplicationConfig $applicationConfigMock |
||
107 | * |
||
108 | * @return \Spryker\Yves\Application\Expander\SecurityHeaderExpander|\PHPUnit\Framework\MockObject\MockObject |
||
109 | */ |
||
110 | protected function getSecurityHeaderExpanderMock(ApplicationConfig $applicationConfigMock): SecurityHeaderExpander |
||
111 | { |
||
112 | return $this->getMockBuilder(SecurityHeaderExpander::class) |
||
113 | ->setConstructorArgs([$applicationConfigMock, []]) |
||
114 | ->disableOriginalClone() |
||
115 | ->disableArgumentCloning() |
||
116 | ->disallowMockingUnknownTypes() |
||
117 | ->setMethods(['executeSecurityHeaderExpanderPlugins']) |
||
118 | ->getMock(); |
||
119 | } |
||
120 | } |
||
121 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.