Skip to content

Commit

Permalink
Make sure that the property exists and is array before merging it. (#2)
Browse files Browse the repository at this point in the history
* Make sure that the property exists and is array before merging it.

* Add tests.
  • Loading branch information
drupol authored Jan 21, 2020
1 parent ccdf289 commit 69feed4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
42 changes: 42 additions & 0 deletions spec/EcPhp/EuLoginBundle/Security/Core/User/EuLoginUserSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,48 @@

class EuLoginUserSpec extends ObjectBehavior
{
public function it_can_get_groups_when_no_groups_are_available()
{
$data = [
'user' => 'user',
'departmentNumber' => 'departmentNumber',
'email' => 'email',
'employeeNumber' => 'employeeNumber',
'employeeType' => 'employeeType',
'firstName' => 'firstName',
'lastName' => 'lastName',
'domain' => 'domain',
'domainUsername' => 'domainUsername',
'telephoneNumber' => 'telephoneNumber',
'locale' => 'locale',
'assuranceLevel' => 'assuranceLevel',
'uid' => 'uid',
'orgId' => 'orgId',
'teleworkingPriority' => 'teleworkingPriority',
'strengths' => [
'bar',
],
'authenticationFactors' => [
'foobar',
],
'loginDate' => 'loginDate',
'sso' => 'sso',
'ticketType' => 'ticketType',
'proxyGrantingProtocol' => 'proxyGrantingProtocol',
'proxyGrantingTicket' => 'proxyGrantingTicket',
'proxies' => [
'proxy1',
],
];

$this
->beConstructedWith($data);

$this
->getGroups()
->shouldReturn([]);
}

public function it_can_get_specific_attribute()
{
$this
Expand Down
5 changes: 4 additions & 1 deletion src/Security/Core/User/EuLoginUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

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

use function array_key_exists;
use function is_array;

/**
* Class EuLoginUser.
*/
Expand Down Expand Up @@ -194,7 +197,7 @@ public function getRoles()
$default = ['ROLE_CAS_AUTHENTICATED'];

if ([] !== $roles = $this->getGroups()) {
if (isset($roles['group'])) {
if (true === array_key_exists('group', $roles) && true === is_array($roles['group'])) {
return array_merge($roles['group'], $default);
}
}
Expand Down

0 comments on commit 69feed4

Please sign in to comment.