Skip to content

Commit

Permalink
Fix several issues reported by PHPStan
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Jan 25, 2024
1 parent 0b71cbc commit 50963a9
Show file tree
Hide file tree
Showing 25 changed files with 65 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/SAML2/XML/samlp/StatusDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static function fromXML(DOMElement $xml): static
/**
* Convert this StatusDetail to XML.
*
* @param \DOMElement|null $element The element we are converting to XML.
* @param \DOMElement|null $parent The element we are converting to XML.
* @return \DOMElement The XML element after adding the data corresponding to this StatusDetail.
*/
public function toXML(DOMElement $parent = null): DOMElement
Expand Down
3 changes: 1 addition & 2 deletions src/SAML2/XML/shibmd/KeyAuthority.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ final class KeyAuthority extends AbstractShibmdElement
* Create a KeyAuthority.
*
* @param \SimpleSAML\XMLSecurity\XML\ds\KeyInfo[] $keys
* @param int|null $verifyDepth
* @param int|null $VerifyDepth
* @param list<\SimpleSAML\XML\Attribute> $namespacedAttributes
*/
public function __construct(
Expand Down Expand Up @@ -101,7 +101,6 @@ public static function fromXML(DOMElement $xml): static
*/
public function toXML(DOMElement $parent = null): DOMElement
{
/** @psalm-var \DOMDocument $e->ownerDocument */
$e = $this->instantiateParentElement($parent);

foreach ($this->getAttributesNS() as $attr) {
Expand Down
1 change: 0 additions & 1 deletion src/SAML2/XML/shibmd/Scope.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ public static function fromXML(DOMElement $xml): static
*/
public function toXML(DOMElement $parent = null): DOMElement
{
/** @psalm-var \DOMDocument $e->ownerDocument */
$e = $this->instantiateParentElement($parent);
$e->textContent = $this->getContent();
$e->setAttribute('regexp', $this->isRegexpScope() ? 'true' : 'false');
Expand Down
2 changes: 1 addition & 1 deletion tests/SAML2/Assertion/ProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ final class ProcessorTest extends MockeryTestCase
private static Processor $processor;

/**
* @var m\MockInterface&Decrypter
* @var MockInterface&Decrypter
*/
private static MockInterface $decrypter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ final class NameIdDecryptionTransformerTest extends TestCase
/** @var \SimpleSAML\SAML2\Configuration\Destination */
protected static Destination $destination;

/** @var \SimpleSAML\SAML2\xml\samlp\Response */
/** @var \SimpleSAML\SAML2\XML\samlp\Response */
protected static Response $response;

/** @var string */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ final class AssertionValidatorTest extends TestCase
/** @var \SimpleSAML\SAML2\Configuration\Destination */
protected static Destination $destination;

/** @var \SimpleSAML\SAML2\xml\samlp\Response */
/** @var \SimpleSAML\SAML2\XML\samlp\Response */
protected static Response $response;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ final class SpIsValidAudienceTest extends MockeryTestCase
/** @var \SimpleSAML\SAML2\XML\saml\Conditions */
private static Conditions $conditions;

/** @var \SimpleSAML\SAML2\XML\saml\Isssuer */
/** @var \SimpleSAML\SAML2\XML\saml\Issuer */
private static Issuer $issuer;

/** @var \Mockery\MockInterface */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ final class SubjectConfirmationValidatorTest extends TestCase
/** @var \SimpleSAML\SAML2\Configuration\Destination */
private static Destination $destination;

/** @var \SimpleSAML\SAML2\xml\samlp\Response */
/** @var \SimpleSAML\SAML2\XML\samlp\Response */
private static Response $response;


Expand Down
3 changes: 2 additions & 1 deletion tests/SAML2/BindingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ public function testBindingGuesserPOST(): void
$q = ['AAP' => 'Noot'];
$request = new ServerRequest('POST', 'http://tnyholm.se');
$request = $request->withParsedBody($q);
$this->expectException(UnsupportedBindingException::class, 'Unable to find the current binding.');
$this->expectException(UnsupportedBindingException::class);
$this->expectExceptionMessage('Unable to find the current binding.');
Binding::getCurrentBinding($request);
}

Expand Down
1 change: 1 addition & 0 deletions tests/SAML2/CustomBaseID.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use SimpleSAML\SAML2\XML\saml\Audience;
use SimpleSAML\Test\SAML2\Constants as C;
use SimpleSAML\XML\Exception\InvalidDOMElementException;
use SimpleSAML\XML\Exception\SchemaViolationException;

/**
* Example class to demonstrate how BaseID can be extended.
Expand Down
2 changes: 1 addition & 1 deletion tests/SAML2/CustomRoleDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ final class CustomRoleDescriptor extends AbstractRoleDescriptor
* Defaults to an empty array.
* @param \SimpleSAML\SAML2\XML\md\Organization|null $organization
* The organization running this entity. Defaults to null.
* @param \SimpleSAML\SAML2\XML\md\ContactPerson[] $contacts
* @param \SimpleSAML\SAML2\XML\md\ContactPerson[] $contact
* An array of contacts for this entity. Defaults to an empty array.
* @param list<\SimpleSAML\XML\Attribute> $namespacedAttributes
*/
Expand Down
2 changes: 2 additions & 0 deletions tests/SAML2/UtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public function testXpQuery(): void
$xpCache = XPath::getXPath($xml);
$nameId_after = XPath::xpQuery($xml, './saml_assertion:Subject/saml_assertion:NameID', $xpCache);
$this->assertTrue(count($nameId_after) === 1);

/** @var \DOMNode $nameId_after[0] */
$this->assertEquals('NameIDValue', $nameId_after[0]->textContent);
$this->assertEquals(C::NAMEID_TRANSIENT, $nameId_after[0]->getAttribute("Format"));
$this->assertEquals('OurNameQualifier', $nameId_after[0]->getAttribute("NameQualifier"));
Expand Down
2 changes: 1 addition & 1 deletion tests/SAML2/XML/samlp/MessageFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static function provideMessages(): array

/**
* @param string $file
* @param class-string class
* @param class-string $class
* @dataProvider provideMessages
*/
public function testMessageFactory(string $file, string $class): void
Expand Down
4 changes: 4 additions & 0 deletions tests/bin/authnrequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

require_once(dirname(__FILE__, 3) . '/vendor/autoload.php');

use DateTimeImmutable;
use DateTimeZone;
use SimpleSAML\SAML2\Compat\ContainerSingleton;
use SimpleSAML\SAML2\Compat\MockContainer;
use SimpleSAML\SAML2\XML\saml\EncryptedID;
Expand All @@ -11,6 +13,7 @@
use SimpleSAML\SAML2\XML\saml\Subject;
use SimpleSAML\SAML2\XML\samlp\AuthnRequest;
use SimpleSAML\XMLSecurity\Alg\KeyTransport\KeyTransportAlgorithmFactory;
use SimpleSAML\XMLSecurity\Constants as C;
use SimpleSAML\XMLSecurity\TestUtils\PEMCertificatesMock;

$container = new MockContainer();
Expand All @@ -30,6 +33,7 @@

$authnRequest = new AuthnRequest(
subject: $subject,
issueInstant: new DateTimeImmutable('now', new DateTimeZone('Z')),
issuer: $issuer,
id: '123',
destination: 'https://tiqr.example.org/idp/profile/saml2/Redirect/SSO',
Expand Down
1 change: 1 addition & 0 deletions tests/bin/encryptedassertion.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use SimpleSAML\SAML2\XML\saml\EncryptedAssertion;
use SimpleSAML\XML\DOMDocumentFactory;
use SimpleSAML\XMLSecurity\Alg\KeyTransport\KeyTransportAlgorithmFactory;
use SimpleSAML\XMLSecurity\Constants as C;
use SimpleSAML\XMLSecurity\TestUtils\PEMCertificatesMock;

$container = new MockContainer();
Expand Down
5 changes: 3 additions & 2 deletions tests/bin/encryptedattribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use SimpleSAML\SAML2\XML\saml\AttributeValue;
use SimpleSAML\SAML2\XML\saml\EncryptedAttribute;
use SimpleSAML\XMLSecurity\Alg\KeyTransport\KeyTransportAlgorithmFactory;
use SimpleSAML\XMLSecurity\Constants as C;
use SimpleSAML\XMLSecurity\TestUtils\PEMCertificatesMock;

$container = new MockContainer();
Expand All @@ -20,8 +21,8 @@
PEMCertificatesMock::getPublicKey(PEMCertificatesMock::PUBLIC_KEY)
);
$attribute = new Attribute(
Name: 'urn:encrypted:attribute',
AttributeValues: [new AttributeValue('very secret data')],
name: 'urn:encrypted:attribute',
attributeValue: [new AttributeValue('very secret data')],
);
$encAttribute = new EncryptedAttribute($attribute->encrypt($encryptor));

Expand Down
1 change: 1 addition & 0 deletions tests/bin/encryptedid.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use SimpleSAML\SAML2\XML\saml\EncryptedID;
use SimpleSAML\SAML2\XML\saml\NameID;
use SimpleSAML\XMLSecurity\Alg\KeyTransport\KeyTransportAlgorithmFactory;
use SimpleSAML\XMLSecurity\Constants as C;
use SimpleSAML\XMLSecurity\TestUtils\PEMCertificatesMock;

$container = new MockContainer();
Expand Down
39 changes: 21 additions & 18 deletions tests/bin/entityattributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

namespace SimpleSAML;

use DateTimeImmutable;
use DateTimeZone;
use SimpleSAML\SAML2\Constants as C;
use SimpleSAML\SAML2\XML\mdattr\EntityAttributes;
use SimpleSAML\SAML2\XML\saml\Assertion;
Expand All @@ -27,6 +29,7 @@

$unsignedAssertion = new Assertion(
issuer: new Issuer('testIssuer'),
issueInstant: new DateTimeImmutable('now', new DateTimeZone('Z')),
id: '_93af655219464fb403b34436cfb0c5cb1d9a5502',
subject: new Subject(new NameID(
value: 'some:entity',
Expand All @@ -43,43 +46,43 @@
),
statements: [new AttributeStatement([
new Attribute(
Name: 'urn:mace:dir:attribute-def:uid',
NameFormat: C::NAMEFORMAT_URI,
AttibuteValues: [new AttributeValue('student2')],
name: 'urn:mace:dir:attribute-def:uid',
nameFormat: C::NAMEFORMAT_URI,
attributeValue: [new AttributeValue('student2')],
),
new Attribute(
Name: 'urn:mace:terena.org:attribute-def:schacHomeOrganization',
NameFormat: C::NAMEFORMAT_URI,
AttributesValues: [new AttributeValue('university.example.org'), new AttributeValue('bbb.cc')],
name: 'urn:mace:terena.org:attribute-def:schacHomeOrganization',
nameFormat: C::NAMEFORMAT_URI,
attributeValue: [new AttributeValue('university.example.org'), new AttributeValue('bbb.cc')],
),
new Attribute(
Name: 'urn:schac:attribute-def:schacPersonalUniqueCode',
NameFormat: C::NAMEFORMAT_URI,
AttributeValues: [
name: 'urn:schac:attribute-def:schacPersonalUniqueCode',
nameFormat: C::NAMEFORMAT_URI,
attributeValue: [
new AttributeValue('urn:schac:personalUniqueCode:nl:local:uvt.nl:memberid:524020'),
new AttributeValue('urn:schac:personalUniqueCode:nl:local:surfnet.nl:studentid:12345'),
],
),
new Attribute(
Name: 'urn:mace:dir:attribute-def:eduPersonAffiliation',
NameFormat: C::NAMEFORMAT_URI,
AttributeValues: [new AttributeValue('member'), new AttributeValue('student')],
name: 'urn:mace:dir:attribute-def:eduPersonAffiliation',
nameFormat: C::NAMEFORMAT_URI,
attributeValue: [new AttributeValue('member'), new AttributeValue('student')],
),
])],
);
$unsignedAssertion->sign($signer);
$signedAssertion = Assertion::fromXML($unsignedAssertion->toXML());
$entityAttributes = new EntityAttributes([
new Attribute(
Name: 'attrib1',
NameFormat: C::NAMEFORMAT_URI,
AttributeValues: [new AttributeValue('is'), new AttributeValue('really'), new AttributeValue('cool')],
name: 'attrib1',
nameFormat: C::NAMEFORMAT_URI,
attributeValue: [new AttributeValue('is'), new AttributeValue('really'), new AttributeValue('cool')],
),
$signedAssertion,
new Attribute(
Name: 'foo',
NameFormat: 'urn:simplesamlphp:v1:simplesamlphp',
AttributeValues: [new AttributeValue('is'), new AttributeValue('really'), new AttributeValue('cool')],
name: 'foo',
nameFormat: 'urn:simplesamlphp:v1:simplesamlphp',
attributeValue: [new AttributeValue('is'), new AttributeValue('really'), new AttributeValue('cool')],
),
]);

Expand Down
4 changes: 4 additions & 0 deletions tests/bin/logoutrequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

require_once(dirname(__FILE__, 3) . '/vendor/autoload.php');

use DateTimeImmutable;
use DateTimeZone;
use SimpleSAML\SAML2\Compat\ContainerSingleton;
use SimpleSAML\SAML2\Compat\MockContainer;
use SimpleSAML\SAML2\XML\saml\EncryptedID;
Expand All @@ -11,6 +13,7 @@
use SimpleSAML\SAML2\XML\samlp\LogoutRequest;
use SimpleSAML\SAML2\XML\samlp\SessionIndex;
use SimpleSAML\XMLSecurity\Alg\KeyTransport\KeyTransportAlgorithmFactory;
use SimpleSAML\XMLSecurity\Constants as C;
use SimpleSAML\XMLSecurity\TestUtils\PEMCertificatesMock;

$container = new MockContainer();
Expand All @@ -26,6 +29,7 @@

$logoutRequest = new LogoutRequest(
identifier: $eid,
issueInstant: new DateTimeImmutable('now', new DateTimeZone('Z')),
sessionIndexes: [new SessionIndex('SomeSessionIndex1'), new SessionIndex('SomeSessionIndex2')],
issuer: new Issuer('urn:test:TheIssuer')
);
Expand Down
1 change: 1 addition & 0 deletions tests/bin/signedassertion.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use SimpleSAML\SAML2\XML\saml\Assertion;
use SimpleSAML\XML\DOMDocumentFactory;
use SimpleSAML\XMLSecurity\Alg\Signature\SignatureAlgorithmFactory;
use SimpleSAML\XMLSecurity\Constants as C;
use SimpleSAML\XMLSecurity\TestUtils\PEMCertificatesMock;

$document = DOMDocumentFactory::fromFile(dirname(__FILE__, 2) . '/resources/xml/saml_Assertion.xml');
Expand Down
1 change: 1 addition & 0 deletions tests/bin/signedassertion_tampered.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use SimpleSAML\SAML2\XML\saml\Assertion;
use SimpleSAML\XML\DOMDocumentFactory;
use SimpleSAML\XMLSecurity\Alg\Signature\SignatureAlgorithmFactory;
use SimpleSAML\XMLSecurity\Constants as C;
use SimpleSAML\XMLSecurity\TestUtils\PEMCertificatesMock;

$document = DOMDocumentFactory::fromFile(dirname(__FILE__, 2) . '/resources/xml/saml_Assertion.xml');
Expand Down
1 change: 1 addition & 0 deletions tests/bin/signedassertion_with_comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use SimpleSAML\SAML2\XML\saml\Assertion;
use SimpleSAML\XML\DOMDocumentFactory;
use SimpleSAML\XMLSecurity\Alg\Signature\SignatureAlgorithmFactory;
use SimpleSAML\XMLSecurity\Constants as C;
use SimpleSAML\XMLSecurity\TestUtils\PEMCertificatesMock;

$document = DOMDocumentFactory::fromFile(dirname(__FILE__, 2) . '/resources/xml/saml_Assertion.xml');
Expand Down
6 changes: 5 additions & 1 deletion tests/bin/signedresponse_with_signedassertion.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

require_once(dirname(__FILE__, 3) . '/vendor/autoload.php');

use DateTimeImmutable;
use DateTimeZone;
use SimpleSAML\SAML2\XML\saml\Assertion;
use SimpleSAML\SAML2\XML\saml\Issuer;
use SimpleSAML\SAML2\XML\samlp\Response;
use SimpleSAML\SAML2\XML\samlp\Status;
use SimpleSAML\SAML2\XML\samlp\StatusCode;
Expand All @@ -24,7 +27,8 @@

$unsignedResponse = new Response(
status: new Status(new StatusCode(C::STATUS_SUCCESS)),
issuer: Issuer('https://IdentityProvider.com'),
issuer: new Issuer('https://IdentityProvider.com'),
issueInstant: new DateTimeImmutable('now', new DateTimeZone('Z')),
id: 'abc123',
inResponseTo: 'PHPUnit',
destination: C::ENTITY_OTHER,
Expand Down
4 changes: 4 additions & 0 deletions tests/bin/signedresponse_with_unsignedassertion.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@

require_once(dirname(__FILE__, 3) . '/vendor/autoload.php');

use DateTimeImmutable;
use DateTimeZone;
use SimpleSAML\SAML2\XML\saml\Assertion;
use SimpleSAML\SAML2\XML\saml\Issuer;
use SimpleSAML\SAML2\XML\samlp\Response;
use SimpleSAML\SAML2\XML\samlp\Status;
use SimpleSAML\SAML2\XML\samlp\StatusCode;
use SimpleSAML\Test\SAML2\Constants as C;
use SimpleSAML\XML\DOMDocumentFactory;
use SimpleSAML\XMLSecurity\Alg\Signature\SignatureAlgorithmFactory;
use SimpleSAML\XMLSecurity\TestUtils\PEMCertificatesMock;
Expand All @@ -18,6 +21,7 @@
$unsignedResponse = new Response(
status: new Status(new StatusCode(C::STATUS_SUCCESS)),
issuer: new Issuer('https://IdentityProvider.com'),
issueInstant: new DateTimeImmutable('now', new DateTimeZone('Z')),
id: 'abc123',
inResponseTo: 'PHPUnit',
destination: C::ENTITY_OTHER,
Expand Down
6 changes: 5 additions & 1 deletion tests/bin/unsignedresponse_with_signedassertion.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@

require_once(dirname(__FILE__, 3) . '/vendor/autoload.php');

use DateTimeImmutable;
use DateTimeZone;
use SimpleSAML\SAML2\XML\saml\Assertion;
use SimpleSAML\SAML2\XML\saml\Issuer;
use SimpleSAML\SAML2\XML\samlp\Response;
use SimpleSAML\SAML2\XML\samlp\Status;
use SimpleSAML\SAML2\XML\samlp\StatusCode;
use SimpleSAML\Test\SAML2\Constants as C;
use SimpleSAML\XML\DOMDocumentFactory;
use SimpleSAML\XMLSecurity\Alg\Signature\SignatureAlgorithmFactory;
use SimpleSAML\XMLSecurity\TestUtils\PEMCertificatesMock;
Expand All @@ -24,10 +27,11 @@
$unsignedAssertion->sign($signer);

$unsignedResponse = new Response(
issueInstant: new DateTimeImmutable('now', new DateTimeZone('Z')),
status: new Status(new StatusCode(C::STATUS_SUCCESS)),
issuer: new Issuer('https://IdentityProvider.com'),
id: 'abc123',
inResponseto: 'PHPUnit',
inResponseTo: 'PHPUnit',
destination: C::ENTITY_OTHER,
consent: C::ENTITY_SP,
assertions: [$unsignedAssertion],
Expand Down

0 comments on commit 50963a9

Please sign in to comment.