@@ -69,6 +69,12 @@ protected function setUp(): void
6969 ['backend ' => [], 'custom-backend ' => [], 'default ' => [], 'custom ' => [],]
7070 );
7171
72+ $ reflectionProperty = $ this ->middlewareReflection ->getProperty ('policies ' );
73+ $ reflectionProperty ->setValue (
74+ $ this ->middleware ,
75+ ['backend ' => ['matchUris ' => ['^/neos ' ]], 'custom-backend ' => ['matchUris ' => []]]
76+ );
77+
7278 $ this ->requestHandlerMock ->expects ($ this ->once ())->method ('handle ' )->willReturn ($ this ->responseMock );
7379 }
7480
@@ -112,4 +118,52 @@ public function testProcessShouldAddHeadersToResponseAndReplaceBody(): void
112118
113119 $ this ->middleware ->process ($ this ->requestMock , $ this ->requestHandlerMock );
114120 }
121+
122+ public function testProcessShouldUseBackendPolicyForCustomMatchUri (): void
123+ {
124+ $ reflectionProperty = $ this ->middlewareReflection ->getProperty ('policies ' );
125+ $ reflectionProperty ->setValue (
126+ $ this ->middleware ,
127+ ['backend ' => ['matchUris ' => ['^/neos ' ]], 'custom-backend ' => ['matchUris ' => ['^/monocle(/.*)?$ ' ]]]
128+ );
129+
130+ $ this ->requestMock ->expects ($ this ->once ())->method ('getUri ' )->willReturn ($ this ->uriMock );
131+ $ this ->uriMock ->expects ($ this ->once ())->method ('getPath ' )->willReturn ('/monocle/dashboard ' );
132+
133+ $ this ->policyFactoryMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ this ->policyMock );
134+ $ this ->policyMock ->expects ($ this ->once ())->method ('hasNonceDirectiveValue ' )->willReturn (false );
135+ $ this ->responseMock ->expects ($ this ->once ())->method ('withAddedHeader ' )->willReturnSelf ();
136+
137+ $ this ->middleware ->process ($ this ->requestMock , $ this ->requestHandlerMock );
138+ }
139+
140+ public function testProcessShouldUseDefaultPolicyWhenNoMatchUriMatches (): void
141+ {
142+ $ this ->requestMock ->expects ($ this ->once ())->method ('getUri ' )->willReturn ($ this ->uriMock );
143+ $ this ->uriMock ->expects ($ this ->once ())->method ('getPath ' )->willReturn ('/monocle/dashboard ' );
144+
145+ $ this ->policyFactoryMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ this ->policyMock );
146+ $ this ->policyMock ->expects ($ this ->once ())->method ('hasNonceDirectiveValue ' )->willReturn (false );
147+ $ this ->responseMock ->expects ($ this ->once ())->method ('withAddedHeader ' )->willReturnSelf ();
148+
149+ $ this ->middleware ->process ($ this ->requestMock , $ this ->requestHandlerMock );
150+ }
151+
152+ public function testProcessShouldNotMatchNeosWhenBackendMatchUrisOverridden (): void
153+ {
154+ $ reflectionProperty = $ this ->middlewareReflection ->getProperty ('policies ' );
155+ $ reflectionProperty ->setValue (
156+ $ this ->middleware ,
157+ ['backend ' => ['matchUris ' => ['^/other ' ]], 'custom-backend ' => ['matchUris ' => []]]
158+ );
159+
160+ $ this ->requestMock ->expects ($ this ->once ())->method ('getUri ' )->willReturn ($ this ->uriMock );
161+ $ this ->uriMock ->expects ($ this ->once ())->method ('getPath ' )->willReturn ('/neos ' );
162+
163+ $ this ->policyFactoryMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ this ->policyMock );
164+ $ this ->policyMock ->expects ($ this ->once ())->method ('hasNonceDirectiveValue ' )->willReturn (false );
165+ $ this ->responseMock ->expects ($ this ->once ())->method ('withAddedHeader ' )->willReturnSelf ();
166+
167+ $ this ->middleware ->process ($ this ->requestMock , $ this ->requestHandlerMock );
168+ }
115169}
0 commit comments