File tree Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Original file line number Diff line number Diff line change 8
8
use League \OAuth2 \Server \AuthorizationServer ;
9
9
use Psr \Container \ContainerInterface ;
10
10
11
+ use function is_int ;
11
12
use function is_string ;
12
13
use function sprintf ;
13
14
@@ -78,7 +79,7 @@ private function addListeners(
78
79
foreach ($ listeners as $ idx => $ listenerConfig ) {
79
80
$ event = $ listenerConfig [0 ];
80
81
$ listener = $ listenerConfig [1 ];
81
- $ priority = $ listenerConfig [2 ] ?? null ;
82
+ $ priority = $ listenerConfig [2 ] ?? 0 ;
82
83
if (is_string ($ listener )) {
83
84
if (! $ container ->has ($ listener )) {
84
85
throw new Exception \InvalidConfigException (sprintf (
@@ -92,6 +93,14 @@ private function addListeners(
92
93
}
93
94
$ listener = $ container ->get ($ listener );
94
95
}
96
+ if (! is_int ($ priority )) {
97
+ throw new Exception \InvalidConfigException (sprintf (
98
+ 'The third element of event_listeners config at index "%s" (priority) '
99
+ . 'is expected to be an integer, received "%s" ' ,
100
+ $ idx ,
101
+ $ priority
102
+ ));
103
+ }
95
104
$ authServer ->getEmitter ()
96
105
->addListener ($ event , $ listener , $ priority );
97
106
}
Original file line number Diff line number Diff line change @@ -140,6 +140,39 @@ static function (RequestEvent $event): void {
140
140
$ result ->getEmitter ()->emit (new RequestEvent (RequestEvent::CLIENT_AUTHENTICATION_FAILED , $ request ));
141
141
}
142
142
143
+ public function testInvokeWithListenerConfigFailsIfPriorityIsNotAnInteger (): void
144
+ {
145
+ $ mockContainer = $ this ->getContainerMock ();
146
+ $ mockListener = $ this ->createMock (ListenerInterface::class);
147
+ $ mockContainer ->set (ListenerInterface::class, $ mockListener );
148
+
149
+ $ config = [
150
+ 'authentication ' => [
151
+ 'private_key ' => __DIR__ . '/TestAsset/private.key ' ,
152
+ 'encryption_key ' => 'iALlwJ1sH77dmFCJFo+pMdM6Af4bF/hCca1EDDx7MwE= ' ,
153
+ 'access_token_expire ' => 'P1D ' ,
154
+ 'grants ' => [
155
+ ClientCredentialsGrant::class => ClientCredentialsGrant::class,
156
+ ],
157
+ 'event_listeners ' => [
158
+ [
159
+ RequestEvent::CLIENT_AUTHENTICATION_FAILED ,
160
+ ListenerInterface::class,
161
+ 'one ' ,
162
+ ],
163
+ ],
164
+ ],
165
+ ];
166
+
167
+ $ mockContainer ->set ('config ' , $ config );
168
+
169
+ $ factory = new AuthorizationServerFactory ();
170
+
171
+ $ this ->expectException (InvalidConfigException::class);
172
+
173
+ $ factory ($ mockContainer );
174
+ }
175
+
143
176
public function testInvokeWithListenerConfigMissingServiceThrowsException (): void
144
177
{
145
178
$ mockContainer = $ this ->getContainerMock ();
You can’t perform that action at this time.
0 commit comments