-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from rediris-es/tests
Added more tests
- Loading branch information
Showing
8 changed files
with
659 additions
and
2 deletions.
There are no files selected for viewing
127 changes: 127 additions & 0 deletions
127
spec/Controller/OpenIdConnectInstallerControllerSpec.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the simplesamlphp-module-oidc. | ||
* | ||
* Copyright (C) 2018 by the Spanish Research and Academic Network. | ||
* | ||
* This code was developed by Universidad de Córdoba (UCO https://www.uco.es) | ||
* for the RedIRIS SIR service (SIR: http://www.rediris.es/sir) | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace spec\SimpleSAML\Modules\OpenIDConnect\Controller; | ||
|
||
use PhpSpec\ObjectBehavior; | ||
use SimpleSAML\Modules\OpenIDConnect\Controller\OpenIdConnectInstallerController; | ||
use SimpleSAML\Modules\OpenIDConnect\Factories\TemplateFactory; | ||
use SimpleSAML\Modules\OpenIDConnect\Services\DatabaseLegacyOAuth2Import; | ||
use SimpleSAML\Modules\OpenIDConnect\Services\DatabaseMigration; | ||
use SimpleSAML\Modules\OpenIDConnect\Services\SessionMessagesService; | ||
use Zend\Diactoros\Response\RedirectResponse; | ||
use Zend\Diactoros\ServerRequest; | ||
|
||
class OpenIdConnectInstallerControllerSpec extends ObjectBehavior | ||
{ | ||
public function let( | ||
TemplateFactory $templateFactory, | ||
SessionMessagesService $messages, | ||
DatabaseMigration $databaseMigration, | ||
DatabaseLegacyOAuth2Import $databaseLegacyOAuth2Import | ||
) { | ||
$databaseMigration->isUpdated()->willReturn(false); | ||
|
||
$this->beConstructedWith( | ||
$templateFactory, | ||
$messages, | ||
$databaseMigration, | ||
$databaseLegacyOAuth2Import | ||
); | ||
} | ||
|
||
public function it_is_initializable() | ||
{ | ||
$this->shouldHaveType(OpenIdConnectInstallerController::class); | ||
} | ||
|
||
public function it_returns_to_main_page_if_already_updated( | ||
DatabaseMigration $databaseMigration, | ||
ServerRequest $request | ||
) { | ||
$databaseMigration->isUpdated()->shouldBeCalled()->willReturn(true); | ||
|
||
$this->__invoke($request)->shouldBeAnInstanceOf(RedirectResponse::class); | ||
} | ||
|
||
public function it_shows_information_page( | ||
ServerRequest $request, | ||
TemplateFactory $templateFactory, | ||
\SimpleSAML_XHTML_Template $template | ||
) { | ||
$request->getParsedBody()->shouldBeCalled(); | ||
$request->getMethod()->shouldBeCalled()->willReturn('GET'); | ||
|
||
$templateFactory->render('oidc:install.twig', [ | ||
'oauth2_enabled' => false, | ||
])->shouldBeCalled()->willReturn($template); | ||
|
||
$this->__invoke($request)->shouldBeLike($template); | ||
} | ||
|
||
public function it_requires_confirmation_before_install_schema( | ||
DatabaseMigration $databaseMigration, | ||
ServerRequest $request, | ||
TemplateFactory $templateFactory, | ||
\SimpleSAML_XHTML_Template $template | ||
) { | ||
$request->getParsedBody()->shouldBeCalled(); | ||
$request->getMethod()->shouldBeCalled()->willReturn('POST'); | ||
$databaseMigration->migrate()->shouldNotBeCalled(); | ||
|
||
$templateFactory->render('oidc:install.twig', [ | ||
'oauth2_enabled' => false, | ||
])->shouldBeCalled()->willReturn($template); | ||
|
||
$this->__invoke($request)->shouldBeLike($template); | ||
} | ||
|
||
public function it_creates_schema( | ||
DatabaseMigration $databaseMigration, | ||
DatabaseLegacyOAuth2Import $databaseLegacyOAuth2Import, | ||
ServerRequest $request, | ||
SessionMessagesService $messages | ||
) { | ||
$request->getParsedBody()->shouldBeCalled()->willReturn([ | ||
'migrate' => true, | ||
]); | ||
$request->getMethod()->shouldBeCalled()->willReturn('POST'); | ||
|
||
$databaseMigration->migrate()->shouldBeCalled(); | ||
$databaseLegacyOAuth2Import->import()->shouldNotBeCalled(); | ||
$messages->addMessage('{oidc:install:finished}')->shouldBeCalled(); | ||
|
||
$this->__invoke($request)->shouldBeAnInstanceOf(RedirectResponse::class); | ||
} | ||
|
||
public function it_imports_data_from_oauth2_module( | ||
DatabaseMigration $databaseMigration, | ||
DatabaseLegacyOAuth2Import $databaseLegacyOAuth2Import, | ||
ServerRequest $request, | ||
SessionMessagesService $messages | ||
) { | ||
$request->getParsedBody()->shouldBeCalled()->willReturn([ | ||
'migrate' => true, | ||
'oauth2_migrate' => true, | ||
]); | ||
$request->getMethod()->shouldBeCalled()->willReturn('POST'); | ||
|
||
$databaseMigration->migrate()->shouldBeCalled(); | ||
$databaseLegacyOAuth2Import->import()->shouldBeCalled(); | ||
$messages->addMessage('{oidc:install:finished}')->shouldBeCalled(); | ||
$messages->addMessage('{oidc:import:finished}')->shouldBeCalled(); | ||
|
||
$this->__invoke($request)->shouldBeAnInstanceOf(RedirectResponse::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the simplesamlphp-module-oidc. | ||
* | ||
* Copyright (C) 2018 by the Spanish Research and Academic Network. | ||
* | ||
* This code was developed by Universidad de Córdoba (UCO https://www.uco.es) | ||
* for the RedIRIS SIR service (SIR: http://www.rediris.es/sir) | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace spec\SimpleSAML\Modules\OpenIDConnect\Entity; | ||
|
||
use League\OAuth2\Server\Entities\ClientEntityInterface; | ||
use PhpSpec\ObjectBehavior; | ||
use SimpleSAML\Modules\OpenIDConnect\Entity\AccessTokenEntity; | ||
use SimpleSAML\Modules\OpenIDConnect\Entity\Interfaces\MementoInterface; | ||
|
||
class AccessTokenEntitySpec extends ObjectBehavior | ||
{ | ||
public function let(ClientEntityInterface $clientEntity) | ||
{ | ||
$clientEntity->getIdentifier()->willReturn('client_id'); | ||
|
||
$this->beConstructedThrough('fromState', [ | ||
[ | ||
'id' => 'id', | ||
'scopes' => json_encode([]), | ||
'expires_at' => '1970-01-01 00:00:00', | ||
'user_id' => 'user_id', | ||
'client' => $clientEntity, | ||
'is_revoked' => false, | ||
], | ||
]); | ||
} | ||
|
||
public function it_is_initializable() | ||
{ | ||
$this->shouldHaveType(AccessTokenEntity::class); | ||
} | ||
|
||
public function it_implements_memento_interface() | ||
{ | ||
$this->shouldHaveType(MementoInterface::class); | ||
} | ||
|
||
public function it_has_an_id() | ||
{ | ||
$this->getIdentifier()->shouldBeEqualTo('id'); | ||
} | ||
|
||
public function it_has_scopes() | ||
{ | ||
$this->getScopes()->shouldBeEqualTo([]); | ||
} | ||
|
||
public function it_has_expiry_date_time() | ||
{ | ||
$this->getExpiryDateTime()->format('Y-m-d H:i:s')->shouldBeLike('1970-01-01 00:00:00'); | ||
} | ||
|
||
public function it_has_an_user_id() | ||
{ | ||
$this->getUserIdentifier()->shouldBeEqualTo('user_id'); | ||
} | ||
|
||
public function it_has_a_client(ClientEntityInterface $clientEntity) | ||
{ | ||
$this->getClient()->shouldBe($clientEntity); | ||
} | ||
|
||
public function it_can_be_revoked() | ||
{ | ||
$this->isRevoked()->shouldBeEqualTo(false); | ||
} | ||
|
||
public function it_can_return_state() | ||
{ | ||
$this->getState()->shouldBeLike([ | ||
'id' => 'id', | ||
'scopes' => json_encode([]), | ||
'expires_at' => '1970-01-01 00:00:00', | ||
'user_id' => 'user_id', | ||
'client_id' => 'client_id', | ||
'is_revoked' => false, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the simplesamlphp-module-oidc. | ||
* | ||
* Copyright (C) 2018 by the Spanish Research and Academic Network. | ||
* | ||
* This code was developed by Universidad de Córdoba (UCO https://www.uco.es) | ||
* for the RedIRIS SIR service (SIR: http://www.rediris.es/sir) | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace spec\SimpleSAML\Modules\OpenIDConnect\Entity; | ||
|
||
use League\OAuth2\Server\Entities\ClientEntityInterface; | ||
use PhpSpec\ObjectBehavior; | ||
use SimpleSAML\Modules\OpenIDConnect\Entity\AuthCodeEntity; | ||
use SimpleSAML\Modules\OpenIDConnect\Entity\Interfaces\MementoInterface; | ||
|
||
class AuthCodeEntitySpec extends ObjectBehavior | ||
{ | ||
public function let(ClientEntityInterface $clientEntity) | ||
{ | ||
$clientEntity->getIdentifier()->willReturn('client_id'); | ||
|
||
$this->beConstructedThrough('fromState', [ | ||
[ | ||
'id' => 'id', | ||
'scopes' => json_encode([]), | ||
'expires_at' => '1970-01-01 00:00:00', | ||
'user_id' => 'user_id', | ||
'client' => $clientEntity, | ||
'is_revoked' => false, | ||
'redirect_uri' => 'https://localhost/redirect', | ||
], | ||
]); | ||
} | ||
|
||
public function it_is_initializable() | ||
{ | ||
$this->shouldHaveType(AuthCodeEntity::class); | ||
} | ||
|
||
public function it_implements_memento_interface() | ||
{ | ||
$this->shouldHaveType(MementoInterface::class); | ||
} | ||
|
||
public function it_has_an_id() | ||
{ | ||
$this->getIdentifier()->shouldBeEqualTo('id'); | ||
} | ||
|
||
public function it_has_scopes() | ||
{ | ||
$this->getScopes()->shouldBeEqualTo([]); | ||
} | ||
|
||
public function it_has_expiry_date_time() | ||
{ | ||
$this->getExpiryDateTime()->format('Y-m-d H:i:s')->shouldBeLike('1970-01-01 00:00:00'); | ||
} | ||
|
||
public function it_has_an_user_id() | ||
{ | ||
$this->getUserIdentifier()->shouldBeEqualTo('user_id'); | ||
} | ||
|
||
public function it_has_a_client(ClientEntityInterface $clientEntity) | ||
{ | ||
$this->getClient()->shouldBe($clientEntity); | ||
} | ||
|
||
public function it_can_be_revoked() | ||
{ | ||
$this->isRevoked()->shouldBeEqualTo(false); | ||
} | ||
|
||
public function it_has_a_redirect_uri() | ||
{ | ||
$this->getRedirectUri()->shouldBeEqualTo('https://localhost/redirect'); | ||
} | ||
|
||
public function it_can_return_state() | ||
{ | ||
$this->getState()->shouldBeLike([ | ||
'id' => 'id', | ||
'scopes' => json_encode([]), | ||
'expires_at' => '1970-01-01 00:00:00', | ||
'user_id' => 'user_id', | ||
'client_id' => 'client_id', | ||
'is_revoked' => false, | ||
'redirect_uri' => 'https://localhost/redirect', | ||
]); | ||
} | ||
} |
Oops, something went wrong.