Skip to content

Commit

Permalink
Psalm
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Nov 16, 2019
1 parent d870c1d commit c53489f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
23 changes: 14 additions & 9 deletions lib/Cas/TicketValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@
use SimpleSAML\Error\BadRequest;
use SimpleSAML\Logger;
use SimpleSAML\Module;
use SimpleSAML\Module\casserver\Cas\CasException;
use SimpleSAML\Module\casserver\Cas\Ticket\TicketFactory;
use SimpleSAML\Module\casserver\Cas\Ticket\TicketStore;

class TicketValidator
{
/** @var Configuration */
/** @var \SimpleSAML\Configuration */
private $casconfig;

/** @var TicketStore */
/** @var \SimpleSAML\Module\casserver\Cas\Ticket\TicketStore */
private $ticketStore;

/** @var TicketFactory */
/** @var \SimpleSAML\Module\casserver\Cas\Ticket\TicketFactory */
private $ticketFactory;

/**
Expand All @@ -28,19 +29,23 @@ class TicketValidator

/**
* TicketValidator constructor.
* @param Configuration $casconfig
* @param \SimpleSAML\Configuration $casconfig
*/
public function __construct(Configuration $casconfig)
{
$this->casconfig = $casconfig;
$ticketStoreConfig = $casconfig->getValue('ticketstore', ['class' => 'casserver:FileSystemTicketStore']);
$ticketStoreClass = Module::resolveClass($ticketStoreConfig['class'], 'Cas_Ticket');
/** @var TicketStore $ticketStore */
/** @psalm-suppress InvalidStringClass */
/**
* @psalm-suppress InvalidStringClass
* @var \SimpleSAML\Module\casserver\Cas\Ticket\TicketStore
*/
$this->ticketStore = new $ticketStoreClass($casconfig);
$ticketFactoryClass = Module::resolveClass('casserver:TicketFactory', 'Cas_Ticket');
/** @var $ticketFactory TicketFactory */
/** @psalm-suppress InvalidStringClass */
/**
* @psalm-suppress InvalidStringClass
* @var \SimpleSAML\Module\casserver\Cas\Ticket\TicketFactory
*/
$this->ticketFactory = new $ticketFactoryClass($casconfig);
}

Expand All @@ -49,7 +54,7 @@ public function __construct(Configuration $casconfig)
* @param string $ticket the ticket id to load validate
* @param string $service the service that the ticket was issued to
* @return string|array|null
* @throws CasException Thrown if ticket doesn't exist, expired, service mismatch
* @throws \SimpleSAML\Module\casserver\Cas\CasException Thrown if ticket doesn't exist, expired, service mismatch
* @throws \InvalidArgumentException thrown if $ticket or $service parameter is missing
*/
public function validateAndDeleteTicket($ticket, $service)
Expand Down
8 changes: 8 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

<!-- level 3 issues - slightly lazy code writing, but probably low false-negatives -->
<DeprecatedMethod errorLevel="info" />
<DeprecatedFunction errorLevel="info" />

<MissingClosureReturnType errorLevel="info" />
<MissingReturnType errorLevel="info" />
Expand All @@ -29,5 +30,12 @@
<MissingParamType errorLevel="info" />
<UnusedClass errorLevel="info" />
<PossiblyUnusedMethod errorLevel="info" />

<!-- Suppress PHPunit-issue -->
<InternalMethod>
<errorLevel type="suppress">
<directory name="tests" />
</errorLevel>
</InternalMethod>
</issueHandlers>
</psalm>
1 change: 1 addition & 0 deletions tests/lib/Cas/Protocol/SamlValidateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function testSamlValidatXmlGeneration()
$samlValidate = new SamlValidateResponder();
$xmlString = $samlValidate->convertToSaml($ticket);
$response = new SimpleXMLElement($xmlString);
/** @psalm-suppress PossiblyNullPropertyFetch */
$this->assertEquals($serviceUrl, $response->attributes()->Recipient);
$this->assertEquals('samlp:Success', $response->Status->StatusCode->attributes()->Value);
$this->assertEquals('localhost', $response->Assertion->attributes()->Issuer);
Expand Down
8 changes: 7 additions & 1 deletion tests/www/LoginIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,33 @@
*
* The embedded server is authenticating users user exampleauth::static to automatically log users in.
*
*
* @package Simplesamlphp\Casserver
*/
class LoginIntegrationTest extends \PHPUnit\Framework\TestCase
{
/** @var string $LINK_URL */
private static $LINK_URL = '/module.php/casserver/login.php';

/**
* @var string $SAMLVALIDATE_URL
*/
private static $SAMLVALIDATE_URL = '/module.php/casserver/samlValidate.php';

/**
* @var \SimpleSAML\Test\BuiltInServer
*/
protected $server;

/**
* @var string
*/
protected $server_addr;

/**
* @var int
*/
protected $server_pid;

/**
* @var string
*/
Expand Down Expand Up @@ -379,6 +384,7 @@ private function execAndHandleCurlResponse($ch)
throw new \Exception('curl error: ' . curl_error($ch));
}
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
/** @psalm-var string $resp */
list($header, $body) = explode("\r\n\r\n", $resp, 2);
$raw_headers = explode("\r\n", $header);
array_shift($raw_headers);
Expand Down

0 comments on commit c53489f

Please sign in to comment.