Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
"verify": [
"vendor/bin/phpcs -p",
"vendor/bin/phpunit --no-coverage --testdox",
"vendor/bin/phpstan --memory-limit=256M analyze -c phpstan.neon"
"vendor/bin/phpstan --memory-limit=256M analyze -c phpstan.neon",
"vendor/bin/phpstan --memory-limit=256M analyze -c phpstan-dev.neon"
],
"tests": [
"vendor/bin/phpunit --no-coverage"
Expand Down
43 changes: 0 additions & 43 deletions phpstan-dev-baseline.neon

This file was deleted.

2 changes: 0 additions & 2 deletions phpstan-dev.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ parameters:
paths:
- tests

includes:
- phpstan-dev-baseline.neon
8 changes: 0 additions & 8 deletions tests/src/Controller/Cas10ControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@
use SimpleSAML\Configuration;
use SimpleSAML\Module\casserver\Cas\Ticket\FileSystemTicketStore;
use SimpleSAML\Module\casserver\Controller\Cas10Controller;
use SimpleSAML\Session;
use Symfony\Component\HttpFoundation\Request;

class Cas10ControllerTest extends TestCase
{
private array $moduleConfig;

private Session $sessionMock;

private array $ticket;

private string $sessionId;
Expand All @@ -37,11 +34,6 @@ protected function setUp(): void
],
];

$this->sessionMock = $this->getMockBuilder(Session::class)
->disableOriginalConstructor()
->onlyMethods(['getSessionId'])
->getMock();

$this->ticket = [
'id' => 'ST-' . $this->sessionId,
'validBefore' => 1731111111,
Expand Down
36 changes: 9 additions & 27 deletions tests/src/Controller/Cas20ControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@
namespace SimpleSAML\Module\casserver\Tests\Controller;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use SimpleSAML\CAS\Constants as C;
use SimpleSAML\Configuration;
use SimpleSAML\Module;
use SimpleSAML\Module\casserver\Cas\Factories\TicketFactory;
use SimpleSAML\Module\casserver\Cas\Ticket\FileSystemTicketStore;
use SimpleSAML\Module\casserver\Cas\TicketValidator;
use SimpleSAML\Module\casserver\Controller\Cas20Controller;
use SimpleSAML\Session;
use SimpleSAML\Utils;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand All @@ -23,8 +20,6 @@ class Cas20ControllerTest extends TestCase
{
private array $moduleConfig;

private Session $sessionMock;

private Request $samlValidateRequest;

private string $sessionId;
Expand All @@ -33,10 +28,6 @@ class Cas20ControllerTest extends TestCase

private FileSystemTicketStore $ticketStore;

private TicketValidator $ticketValidatorMock;

private Utils\HTTP|MockObject $utilsHttpMock;

private array $ticket;

private array $proxyTicket;
Expand All @@ -59,21 +50,6 @@ protected function setUp(): void
// Hard code the ticket store
$this->ticketStore = new FileSystemTicketStore(Configuration::loadFromArray($this->moduleConfig));

$this->ticketValidatorMock = $this->getMockBuilder(TicketValidator::class)
->setConstructorArgs([Configuration::loadFromArray($this->moduleConfig)])
->onlyMethods(['validateAndDeleteTicket'])
->getMock();

$this->sessionMock = $this->getMockBuilder(Session::class)
->disableOriginalConstructor()
->onlyMethods(['getSessionId'])
->getMock();

$this->utilsHttpMock = $this->getMockBuilder(Utils\HTTP::class)
->disableOriginalConstructor()
->onlyMethods(['fetch'])
->getMock();

$this->ticket = [
'id' => 'ST-' . $this->sessionId,
'validBefore' => 1731111111,
Expand Down Expand Up @@ -152,6 +128,7 @@ public function testProxyValidatePassesTheCorrectMethodToValidate(string $prefix
$controllerMock->expects($this->once())
->method('validate')
->with($request, $method, false, null, $prefix . $this->sessionId, 'https://myservice.com/abcd', null);

$controllerMock->$method($request, ...$requestParameters);
}

Expand Down Expand Up @@ -355,7 +332,7 @@ public function testProxyReturnsProxyTicket(): void
$xml->registerXPathNamespace('cas', 'serviceResponse');
$this->assertEquals('serviceResponse', $xml->getName());
$this->assertNotNull($xml->xpath('//cas:proxySuccess'));
$ticketId = (string)$xml->xpath('//cas:proxyTicket')[0];
$ticketId = (string) $xml->xpath('//cas:proxyTicket')[0];
$proxyTicket = $this->ticketStore->getTicket($ticketId);
$this->assertTrue(filter_var($ticketFactory->isProxyTicket($proxyTicket), FILTER_VALIDATE_BOOLEAN));
}
Expand Down Expand Up @@ -748,14 +725,19 @@ public function testThrowOnProxyServiceIdentityFail(): void
parameters: $params,
);

$this->utilsHttpMock->expects($this->once())
$httpUtilsMock = $this->getMockBuilder(Utils\HTTP::class)
->disableOriginalConstructor()
->onlyMethods(['fetch'])
->getMock();

$httpUtilsMock->expects($this->once())
->method('fetch')
->willThrowException(new \Exception());

$cas20Controller = new Cas20Controller(
sspConfig: $this->sspConfig,
casConfig: $config,
httpUtils: $this->utilsHttpMock,
httpUtils: $httpUtilsMock,
);
$ticketStore = $cas20Controller->getTicketStore();
$ticketStore->addTicket($this->ticket);
Expand Down
33 changes: 14 additions & 19 deletions tests/src/Controller/Cas30ControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@
use SimpleSAML\Module\casserver\Cas\Ticket\FileSystemTicketStore;
use SimpleSAML\Module\casserver\Cas\TicketValidator;
use SimpleSAML\Module\casserver\Controller\Cas30Controller;
use SimpleSAML\Session;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class Cas30ControllerTest extends TestCase
{
private array $moduleConfig;

private Session $sessionMock;

private Request $samlValidateRequest;

private string $sessionId;
Expand All @@ -29,8 +26,6 @@ class Cas30ControllerTest extends TestCase

private FileSystemTicketStore $ticketStore;

private TicketValidator $ticketValidatorMock;

private array $ticket;


Expand All @@ -51,16 +46,6 @@ protected function setUp(): void
// Hard code the ticket store
$this->ticketStore = new FileSystemTicketStore(Configuration::loadFromArray($this->moduleConfig));

$this->ticketValidatorMock = $this->getMockBuilder(TicketValidator::class)
->setConstructorArgs([Configuration::loadFromArray($this->moduleConfig)])
->onlyMethods(['validateAndDeleteTicket'])
->getMock();

$this->sessionMock = $this->getMockBuilder(Session::class)
->disableOriginalConstructor()
->onlyMethods(['getSessionId'])
->getMock();

$this->ticket = [
'id' => 'ST-' . $this->sessionId,
'validBefore' => 9999999999,
Expand Down Expand Up @@ -236,15 +221,20 @@ public function testCasValidateAndDeleteTicketThrowsException(): void
content: $samlRequest,
);

$this->ticketValidatorMock
$ticketValidatorMock = $this->getMockBuilder(TicketValidator::class)
->setConstructorArgs([Configuration::loadFromArray($this->moduleConfig)])
->onlyMethods(['validateAndDeleteTicket'])
->getMock();

$ticketValidatorMock
->expects($this->once())
->method('validateAndDeleteTicket')
->willThrowException(new \RuntimeException('Cas validateAndDeleteTicket failed'));

$cas30Controller = new Cas30Controller(
$this->sspConfig,
$casconfig,
$this->ticketValidatorMock,
$ticketValidatorMock,
);

// Exception expected
Expand Down Expand Up @@ -289,15 +279,20 @@ public function testUnableToLoadTicket(): void
content: $samlRequest,
);

$this->ticketValidatorMock
$ticketValidatorMock = $this->getMockBuilder(TicketValidator::class)
->setConstructorArgs([Configuration::loadFromArray($this->moduleConfig)])
->onlyMethods(['validateAndDeleteTicket'])
->getMock();

$ticketValidatorMock
->expects($this->once())
->method('validateAndDeleteTicket')
->willReturn('i am a string');

$cas30Controller = new Cas30Controller(
$this->sspConfig,
$casconfig,
$this->ticketValidatorMock,
$ticketValidatorMock,
);

// Exception expected
Expand Down
Loading
Loading