Skip to content
Open
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
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"pimple/pimple": "^3.6",
"ramsey/uuid": "^4.9.1",
"robrichards/xmlseclibs": "^3.1.3",
"simplesamlphp/assert": "^1.9.1",
"simplesamlphp/saml2": "^4.19",
"symfony/asset": "^7.4",
"symfony/console": "^7.4",
Expand Down
61 changes: 60 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion library/EngineBlock/Attributes/Validator/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
* limitations under the License.
*/

use SimpleSAML\Assert\Assert;
use SimpleSAML\Assert\AssertionFailedException;

class EngineBlock_Attributes_Validator_Type extends EngineBlock_Attributes_Validator_Abstract
{
const ERROR_ATTRIBUTE_VALIDATOR_URI = 'error_attribute_validator_type_uri';
Expand Down Expand Up @@ -75,7 +78,9 @@ public function validate(array $attributes)

case 'URL':
foreach ($attributeValues as $attributeValue) {
if (filter_var($attributeValue, FILTER_VALIDATE_URL) === false) {
try {
Assert::validURL($attributeValue);
} catch (AssertionFailedException $e) {
$this->_messages[] = array(
self::ERROR_ATTRIBUTE_VALIDATOR_URL,
$this->_attributeName,
Expand Down
18 changes: 13 additions & 5 deletions library/EngineBlock/Validator/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
* limitations under the License.
*/

use SimpleSAML\Assert\Assert;
use SimpleSAML\Assert\AssertionFailedException;

/**
* Validate URIs according to RFC-3986.
*
* See: http://www.rfc-editor.org/errata_search.php?rfc=3986
* Validate URIs using simplesamlphp/assert.
*
* Note that this is a VERY permissive regex
* The legacy regex is kept for the unused parse() helper so existing debug
* output shape remains available if it is ever reintroduced.
*/
class EngineBlock_Validator_Uri
{
Expand All @@ -33,7 +35,13 @@ class EngineBlock_Validator_Uri
*/
public function validate($uri)
{
return (bool) preg_match(self::REGEX, $uri);
try {
Assert::validURI($uri);
} catch (AssertionFailedException $e) {
return false;
}

return true;
}

/**
Expand Down
31 changes: 29 additions & 2 deletions tests/library/EngineBlock/Test/Attributes/Validator/TypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* limitations under the License.
*/

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

class EngineBlock_Test_TypeTest extends TestCase
Expand All @@ -26,13 +27,22 @@ class EngineBlock_Test_TypeTest extends TestCase
* @param $options
* @param $attributes
*/
#[\PHPUnit\Framework\Attributes\DataProvider('validAttributesProvider')]
#[DataProvider('validAttributesProvider')]
public function testAttributeValidates($attributeName, $options, $attributes)
{
$validator = new EngineBlock_Attributes_Validator_Type($attributeName, $options);
$this->assertTrue($validator->validate($attributes));
}

#[DataProvider('invalidAttributesProvider')]
public function testAttributeValidationFails($attributeName, $options, $attributes, $expectedMessage)
{
$validator = new EngineBlock_Attributes_Validator_Type($attributeName, $options);

$this->assertFalse($validator->validate($attributes));
$this->assertSame([$expectedMessage, $attributeName, $options, $attributes[$attributeName][0]], $validator->getMessages()[0]);
}

public static function validAttributesProvider()
{
return array(
Expand All @@ -59,7 +69,8 @@ public static function validAttributesProvider()
'options' => 'URI',
'attributes' => array(
'foo' => array(
'?'
'?',
'urn:mace:dir:entitlement:common-lib-terms',
)
)
),
Expand All @@ -78,4 +89,20 @@ public static function validAttributesProvider()
)
);
}

public static function invalidAttributesProvider()
{
return array(
array(
'attributeName' => 'foo',
'options' => 'URL',
'attributes' => array(
'foo' => array(
'mailto:test@example.org',
)
),
'expectedMessage' => EngineBlock_Attributes_Validator_Type::ERROR_ATTRIBUTE_VALIDATOR_URL,
),
);
}
}
6 changes: 2 additions & 4 deletions tests/library/EngineBlock/Test/Validator/UriTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
use PHPUnit\Framework\TestCase;

/**
* @todo write test which tests failing...this validator is so permissive it is VERY hard to let it fail
*/
class EngineBlock_Test_Validator_UriTest extends TestCase
{
use MockeryPHPUnitIntegration;
Expand All @@ -46,7 +43,8 @@ public static function validUriProvider()
{
return array(
array('http://example.com'), // Pretty standard http url
array('urn:mace:dir:entitlement:common-lib-terms') // Saml entitlement
array('urn:mace:dir:entitlement:common-lib-terms'), // Saml entitlement
array('?'),
);
}
}