From 5597a92799e8b3d5491b19015a3cbfab007ef6f8 Mon Sep 17 00:00:00 2001 From: briskt <3172830+briskt@users.noreply.github.com> Date: Mon, 15 Jul 2024 19:43:24 -0600 Subject: [PATCH 1/3] fix the AddIdp2NameId filter --- dockerbuild/config/config.php | 2 +- dockerbuild/run-tests.sh | 1 + .../src/Auth/Process/AddIdp2NameId.php | 2 +- modules/sildisco/tests/AddIdpTest.php | 35 +++++++++++-------- modules/sildisco/tests/TagGroupTest.php | 3 +- 5 files changed, 25 insertions(+), 18 deletions(-) diff --git a/dockerbuild/config/config.php b/dockerbuild/config/config.php index 2ceed2f..e6e2ef7 100644 --- a/dockerbuild/config/config.php +++ b/dockerbuild/config/config.php @@ -1456,5 +1456,5 @@ if ($HUB_MODE) { // prefix the 'member' (urn:oid:2.5.4.31) attribute elements with idp.idp_name. $config['authproc.idp'][48] = 'sildisco:TagGroup'; -// $config['authproc.idp'][49] = 'sildisco:AddIdp2NameId'; + $config['authproc.idp'][49] = 'sildisco:AddIdp2NameId'; } diff --git a/dockerbuild/run-tests.sh b/dockerbuild/run-tests.sh index 77f9735..b4ec773 100755 --- a/dockerbuild/run-tests.sh +++ b/dockerbuild/run-tests.sh @@ -9,5 +9,6 @@ set -e /data/run-metadata-tests.sh ./vendor/bin/phpunit -v tests/AnnouncementTest.php +./vendor/bin/phpunit -v vendor/simplesamlphp/simplesamlphp/modules/sildisco/tests/ /data/run-integration-tests.sh diff --git a/modules/sildisco/src/Auth/Process/AddIdp2NameId.php b/modules/sildisco/src/Auth/Process/AddIdp2NameId.php index 0a29cb9..1ec9232 100644 --- a/modules/sildisco/src/Auth/Process/AddIdp2NameId.php +++ b/modules/sildisco/src/Auth/Process/AddIdp2NameId.php @@ -59,7 +59,7 @@ class AddIdp2NameId extends ProcessingFilter * * @var string|bool */ - private sring|bool $spNameQualifier; + private string|bool $spNameQualifier; /** diff --git a/modules/sildisco/tests/AddIdpTest.php b/modules/sildisco/tests/AddIdpTest.php index fa8930c..7883e6e 100644 --- a/modules/sildisco/tests/AddIdpTest.php +++ b/modules/sildisco/tests/AddIdpTest.php @@ -1,9 +1,11 @@ setExpectedException('\SimpleSAML\Error\Exception'); + $this->expectException('\SimpleSAML\Error\Exception'); $config = ['test' => ['value1', 'value2'],]; $request = self::getNameID('idp-bare'); @@ -56,7 +58,7 @@ public function testAddIdp2NameId_NoIDPNamespace() */ public function testAddIdp2NameId_EmptyIDPNamespace() { - $this->setExpectedException('\SimpleSAML\Error\Exception'); + $this->expectException('\SimpleSAML\Error\Exception'); $config = ['test' => ['value1', 'value2'],]; $request = self::getNameID('idp-empty'); self::processAddIdp2NameId($config, $request); @@ -68,7 +70,7 @@ public function testAddIdp2NameId_EmptyIDPNamespace() */ public function testAddIdp2NameId_BadIDPNamespace() { - $this->setExpectedException('\SimpleSAML\Error\Exception'); + $this->expectException('\SimpleSAML\Error\Exception'); $config = [ 'test' => ['value1', 'value2'], ]; @@ -82,19 +84,21 @@ public function testAddIdp2NameId_BadIDPNamespace() */ public function testAddIdp2NameId_GoodString() { + $nameID = new NameID(); + $nameID->setValue('Tester1_SmithA'); $config = ['test' => ['value1', 'value2']]; $state = [ 'saml:sp:IdP' => 'idp-good', - 'saml:sp:NameID' => 'Tester1_SmithA', + 'saml:sp:NameID' => $nameID, 'Attributes' => [], 'metadataPath' => __DIR__ . '/fixtures/metadata/', ]; - $newNameID = $state['saml:sp:NameID']; - $newNameID = 'Tester1_SmithA@idpGood'; + $newNameID = new NameID(); + $newNameID->setValue('Tester1_SmithA@idpGood'); $expected = $state; - $expected['saml:NameID']['urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified'] = $newNameID; + $expected['saml:NameID']['urn:oasis:names:tc:SAML:2.0:nameid-format:persistent'] = $newNameID; $results = self::processAddIdp2NameId($config, $state); $this->assertEquals($expected, $results); @@ -105,23 +109,24 @@ public function testAddIdp2NameId_GoodString() */ public function testAddIdp2NameId_GoodArray() { + $nameID = new NameID(); + $nameID->setValue('Tester1_SmithA'); + $nameID->setFormat('urn:oasis:names:tc:SAML:1.1:nameid-format:transient'); + $nameID->setSPNameQualifier('http://ssp-sp1.local'); + $config = ['test' => ['value1', 'value2']]; $state = [ 'saml:sp:IdP' => 'idp-good', - 'saml:sp:NameID' => [ - 'Format' => 'urn:oasis:names:tc:SAML:1.1:nameid-format:transient', - 'Value' => 'Tester1_SmithA', - 'SPNameQualifier' => 'http://ssp-sp1.local', - ], + 'saml:sp:NameID' => $nameID, 'Attributes' => [], 'metadataPath' => __DIR__ . '/fixtures/metadata/', ]; $newNameID = $state['saml:sp:NameID']; - $newNameID['Value'] = 'Tester1_SmithA@idpGood'; + $newNameID->setValue('Tester1_SmithA@idpGood'); $expected = $state; - $expected['saml:NameID']['urn:oasis:names:tc:SAML:1.1:nameid-format:transient'] = $newNameID; + $expected['saml:NameID']['urn:oasis:names:tc:SAML:2.0:nameid-format:persistent'] = $newNameID; $results = self::processAddIdp2NameId($config, $state); diff --git a/modules/sildisco/tests/TagGroupTest.php b/modules/sildisco/tests/TagGroupTest.php index 89bab5c..c54b8c0 100644 --- a/modules/sildisco/tests/TagGroupTest.php +++ b/modules/sildisco/tests/TagGroupTest.php @@ -1,8 +1,9 @@ Date: Tue, 16 Jul 2024 08:57:39 -0600 Subject: [PATCH 2/3] change NameID format to "SAML:2.0" "persistent" throughout the unit test --- modules/sildisco/tests/AddIdpTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/sildisco/tests/AddIdpTest.php b/modules/sildisco/tests/AddIdpTest.php index 7883e6e..686eb07 100644 --- a/modules/sildisco/tests/AddIdpTest.php +++ b/modules/sildisco/tests/AddIdpTest.php @@ -14,7 +14,7 @@ private static function getNameID($idp) 'saml:sp:IdP' => $idp, 'saml:sp:NameID' => [ [ - 'Format' => 'urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified', + 'Format' => 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent', 'Value' => 'Tester1_Smith', 'SPNameQualifier' => 'http://ssp-sp1.local', ], @@ -111,7 +111,7 @@ public function testAddIdp2NameId_GoodArray() { $nameID = new NameID(); $nameID->setValue('Tester1_SmithA'); - $nameID->setFormat('urn:oasis:names:tc:SAML:1.1:nameid-format:transient'); + $nameID->setFormat('urn:oasis:names:tc:SAML:2.0:nameid-format:persistent'); $nameID->setSPNameQualifier('http://ssp-sp1.local'); $config = ['test' => ['value1', 'value2']]; From 36ea206b44d4c092c32d3d7fd799967315c647f8 Mon Sep 17 00:00:00 2001 From: briskt <3172830+briskt@users.noreply.github.com> Date: Tue, 16 Jul 2024 10:08:36 -0600 Subject: [PATCH 3/3] add sonar-project.properties --- sonar-project.properties | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 sonar-project.properties diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 0000000..782160d --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,2 @@ +sonar.sources=modules,dockerbuild +sonar.exclusions=modules/sildisco/tests/**/*