Skip to content

Commit 69feed4

Browse files
authored
Make sure that the property exists and is array before merging it. (#2)
* Make sure that the property exists and is array before merging it. * Add tests.
1 parent ccdf289 commit 69feed4

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

spec/EcPhp/EuLoginBundle/Security/Core/User/EuLoginUserSpec.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,48 @@
99

1010
class EuLoginUserSpec extends ObjectBehavior
1111
{
12+
public function it_can_get_groups_when_no_groups_are_available()
13+
{
14+
$data = [
15+
'user' => 'user',
16+
'departmentNumber' => 'departmentNumber',
17+
'email' => 'email',
18+
'employeeNumber' => 'employeeNumber',
19+
'employeeType' => 'employeeType',
20+
'firstName' => 'firstName',
21+
'lastName' => 'lastName',
22+
'domain' => 'domain',
23+
'domainUsername' => 'domainUsername',
24+
'telephoneNumber' => 'telephoneNumber',
25+
'locale' => 'locale',
26+
'assuranceLevel' => 'assuranceLevel',
27+
'uid' => 'uid',
28+
'orgId' => 'orgId',
29+
'teleworkingPriority' => 'teleworkingPriority',
30+
'strengths' => [
31+
'bar',
32+
],
33+
'authenticationFactors' => [
34+
'foobar',
35+
],
36+
'loginDate' => 'loginDate',
37+
'sso' => 'sso',
38+
'ticketType' => 'ticketType',
39+
'proxyGrantingProtocol' => 'proxyGrantingProtocol',
40+
'proxyGrantingTicket' => 'proxyGrantingTicket',
41+
'proxies' => [
42+
'proxy1',
43+
],
44+
];
45+
46+
$this
47+
->beConstructedWith($data);
48+
49+
$this
50+
->getGroups()
51+
->shouldReturn([]);
52+
}
53+
1254
public function it_can_get_specific_attribute()
1355
{
1456
$this

src/Security/Core/User/EuLoginUser.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
use EcPhp\CasBundle\Security\Core\User\CasUser;
88

9+
use function array_key_exists;
10+
use function is_array;
11+
912
/**
1013
* Class EuLoginUser.
1114
*/
@@ -194,7 +197,7 @@ public function getRoles()
194197
$default = ['ROLE_CAS_AUTHENTICATED'];
195198

196199
if ([] !== $roles = $this->getGroups()) {
197-
if (isset($roles['group'])) {
200+
if (true === array_key_exists('group', $roles) && true === is_array($roles['group'])) {
198201
return array_merge($roles['group'], $default);
199202
}
200203
}

0 commit comments

Comments
 (0)