Skip to content

Commit

Permalink
Merge pull request #254 from silinternational/feature/fix-add-idp-2-n…
Browse files Browse the repository at this point in the history
…ameid

fix the AddIdp2NameId filter
  • Loading branch information
briskt authored Jul 16, 2024
2 parents 3ee5ce9 + 36ea206 commit 3e4c520
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 19 deletions.
2 changes: 1 addition & 1 deletion dockerbuild/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
1 change: 1 addition & 0 deletions dockerbuild/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion modules/sildisco/src/Auth/Process/AddIdp2NameId.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class AddIdp2NameId extends ProcessingFilter
*
* @var string|bool
*/
private sring|bool $spNameQualifier;
private string|bool $spNameQualifier;


/**
Expand Down
37 changes: 21 additions & 16 deletions modules/sildisco/tests/AddIdpTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php


use PHPUnit\Framework\TestCase;
use SAML2\XML\saml\NameID;
use SimpleSAML\Module\sildisco\Auth\Process\AddIdp2NameId;

class AddIdpTest extends PHPUnit_Framework_TestCase
class AddIdpTest extends TestCase
{

private static function getNameID($idp)
Expand All @@ -12,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',
],
Expand Down Expand Up @@ -42,7 +44,7 @@ private static function processAddIdp2NameId(array $config, array $request)
*/
public function testAddIdp2NameId_NoIDPNamespace()
{
$this->setExpectedException('\SimpleSAML\Error\Exception');
$this->expectException('\SimpleSAML\Error\Exception');
$config = ['test' => ['value1', 'value2'],];
$request = self::getNameID('idp-bare');

Expand All @@ -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);
Expand All @@ -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'],
];
Expand All @@ -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);
Expand All @@ -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:2.0:nameid-format:persistent');
$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);

Expand Down
3 changes: 2 additions & 1 deletion modules/sildisco/tests/TagGroupTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

use PHPUnit\Framework\TestCase;
use SimpleSAML\Module\sildisco\Auth\Process\TagGroup;

class TagGroupTest extends PHPUnit_Framework_TestCase
class TagGroupTest extends TestCase
{
/**
* Helper function to run the filter with a given configuration.
Expand Down
2 changes: 2 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sonar.sources=modules,dockerbuild
sonar.exclusions=modules/sildisco/tests/**/*

0 comments on commit 3e4c520

Please sign in to comment.