From 7edf2f267cf4807a74cf03df2f68e519e3b567b2 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Mon, 5 Oct 2020 10:54:58 +0200 Subject: [PATCH] refactor: Get rid of mock, use real objects. --- .../Security/Core/User/EuLoginUserSpec.php | 279 ++++++++---------- 1 file changed, 129 insertions(+), 150 deletions(-) diff --git a/spec/EcPhp/EuLoginBundle/Security/Core/User/EuLoginUserSpec.php b/spec/EcPhp/EuLoginBundle/Security/Core/User/EuLoginUserSpec.php index 63e32be..095db1d 100644 --- a/spec/EcPhp/EuLoginBundle/Security/Core/User/EuLoginUserSpec.php +++ b/spec/EcPhp/EuLoginBundle/Security/Core/User/EuLoginUserSpec.php @@ -57,7 +57,14 @@ public function it_can_get_specific_attribute() $this ->getAuthenticationFactors() - ->shouldReturn(['ecphp@ec.europa.eu']); + ->shouldReturn([ + 'moniker' => [ + '@value' => 'ecphp@ec.europa.eu', + '@attributes' => [ + 'number' => '1', + ], + ], + ]); $this ->getDepartmentNumber() @@ -116,7 +123,7 @@ public function it_can_get_specific_attribute() $this ->getStrengths() - ->shouldReturn(['bar']); + ->shouldReturn(['strength1']); $this ->getTelephoneNumber() @@ -137,6 +144,18 @@ public function it_can_get_specific_attribute() $this ->getAttributes() ->shouldReturn($this->getAttributesData()); + + $this + ->getUserManager() + ->shouldReturn('userManager'); + + $this + ->getTimeZone() + ->shouldReturn('timeZone'); + + $this + ->getProxyGrantingProtocol() + ->shouldReturn('proxyGrantingProtocol'); } public function it_can_get_the_attributes_only(CasUserInterface $user) @@ -162,10 +181,6 @@ public function it_is_initializable() ->getSalt() ->shouldBeNull(); - $this - ->getAttribute('user') - ->shouldReturn('username'); - $this ->getUser() ->shouldReturn('username'); @@ -179,7 +194,7 @@ public function it_is_initializable() ->shouldBeNull(); } - public function let(CasUserInterface $user) + public function let() { $body = <<<'EOF' @@ -193,12 +208,72 @@ public function let(CasUserInterface $user) proxyGrantingTicket + + departmentNumber + + + domain + + + domainUsername + + + email + + + employeeNumber + + + employeeType + + + firstName + + + lastName + + + locale + + + loginDate + + + orgId + + + sso + + + strength1 + + + telephoneNumber + + + teleworkingPriority + + + ticketType + + + uid + ecphp@ec.europa.eu 40 + + proxyGrantingProtocol + + + userManager + + + timeZone + group1 group2 @@ -217,134 +292,7 @@ public function let(CasUserInterface $user) $response = new Response(200, ['Content-Type' => 'application/xml'], $body); $data = (new Introspector())->parse($response)['serviceResponse']['authenticationSuccess']; - $user - ->beConstructedWith($data); - - $user - ->getAttribute('extendedAttributes', []) - ->willReturn([ - 'extendedAttribute' => [ - 'attributeValue' => [ - 'value1', - 'value2', - ], - '@attributes' => [ - 'name' => 'attr1', - ], - ], - ]); - - $user - ->get('foo', 'bar') - ->willReturn('bar'); - - $user - ->getUsername() - ->willReturn('username'); - - $user - ->getAttribute('user', null) - ->willReturn('username'); - - $user - ->getPgt() - ->willReturn('proxyGrantingTicket'); - - $user - ->getAttribute('assuranceLevel') - ->willReturn($data['attributes']['assuranceLevel']); - - $user - ->getAttribute('authenticationFactors', []) - ->willReturn([ - 'ecphp@ec.europa.eu', - ]); - - $user - ->getAttribute('departmentNumber') - ->willReturn('departmentNumber'); - - $user - ->getAttribute('domain') - ->willReturn('domain'); - - $user - ->getAttribute('domainUsername') - ->willReturn('domainUsername'); - - $user - ->getAttribute('email') - ->willReturn('email'); - - $user - ->getAttribute('employeeNumber') - ->willReturn('employeeNumber'); - - $user - ->getAttribute('employeeType') - ->willReturn('employeeType'); - - $user - ->getAttribute('firstName') - ->willReturn('firstName'); - - $user - ->getAttribute('groups', ['group' => []]) - ->willReturn([ - 'group' => [ - 'group1', - 'group2', - ], - '@attributes' => [ - 'number' => 2, - ], - ]); - - $user - ->getAttribute('lastName') - ->willReturn('lastName'); - - $user - ->getAttribute('locale') - ->willReturn('locale'); - - $user - ->getAttribute('loginDate') - ->willReturn('loginDate'); - - $user - ->getAttribute('orgId') - ->willReturn('orgId'); - - $user - ->getAttribute('sso') - ->willReturn('sso'); - - $user - ->getAttribute('strengths', []) - ->willReturn([ - 'bar', - ]); - - $user - ->getAttribute('telephoneNumber') - ->willReturn('telephoneNumber'); - - $user - ->getAttribute('teleworkingPriority') - ->willReturn('teleworkingPriority'); - - $user - ->getAttribute('ticketType') - ->willReturn('ticketType'); - - $user - ->getAttribute('uid') - ->willReturn('uid'); - - $user - ->getAttributes() - ->willReturn($this->getAttributesData()); + $user = new CasUser($data); $this ->beConstructedWith($user); @@ -354,26 +302,47 @@ private function getAttributesData(): array { return [ 'departmentNumber' => 'departmentNumber', + 'domain' => 'domain', + 'domainUsername' => 'domainUsername', 'email' => 'email', 'employeeNumber' => 'employeeNumber', 'employeeType' => 'employeeType', - 'extendedAttributes' => [ - 'extendedAttribute' => [ - [ - 'attr1' => [ - 'value1', - 'value2', - ], + 'firstName' => 'firstName', + 'lastName' => 'lastName', + 'locale' => 'locale', + 'loginDate' => 'loginDate', + 'orgId' => 'orgId', + 'sso' => 'sso', + 'strengths' => [ + 'strength' => [ + 'strength1', + ], + '@attributes' => [ + 'number' => '1', + ], + ], + 'telephoneNumber' => 'telephoneNumber', + 'teleworkingPriority' => 'teleworkingPriority', + 'ticketType' => 'ticketType', + 'uid' => 'uid', + 'authenticationFactors' => [ + 'moniker' => [ + '@value' => 'ecphp@ec.europa.eu', + '@attributes' => [ + 'number' => '1', ], ], ], + 'assuranceLevel' => '40', + 'proxyGrantingProtocol' => 'proxyGrantingProcotol', + 'userManager' => 'userManager', + 'timeZone' => 'timeZone', 'firstName' => 'firstName', 'lastName' => 'lastName', 'domain' => 'domain', 'domainUsername' => 'domainUsername', 'telephoneNumber' => 'telephoneNumber', 'locale' => 'locale', - 'assuranceLevel' => '40', 'uid' => 'uid', 'orgId' => 'orgId', 'teleworkingPriority' => 'teleworkingPriority', @@ -382,19 +351,29 @@ private function getAttributesData(): array 'group1', 'group2', ], - ], - 'strengths' => [ - 'strength' => [ - 'bar', + '@attributes' => [ + 'number' => '2', ], ], - 'authenticationFactors' => [ - 'ecphp@ec.europa.eu', + 'extendedAttributes' => [ + 'extendedAttribute' => [ + [ + 'attributeValue' => [ + 'rex', + 'snoopy', + ], + '@attributes' => [ + 'name' => 'http://stork.eu/motherInLawDogName', + ], + ], + ], ], - 'loginDate' => 'loginDate', 'sso' => 'sso', 'ticketType' => 'ticketType', + 'assuranceLevel' => '40', 'proxyGrantingProtocol' => 'proxyGrantingProtocol', + 'timeZone' => 'timeZone', + 'userManager' => 'userManager', ]; } }