-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add assertion to validate a distinguished name
- Loading branch information
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\Test\Assert; | ||
|
||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use PHPUnit\Framework\TestCase; | ||
use SimpleSAML\Assert\Assert; | ||
use SimpleSAML\Assert\AssertionFailedException; | ||
|
||
/** | ||
* Class \SimpleSAML\Assert\DistinguishedNameTest | ||
* | ||
* @package simplesamlphp/assert | ||
*/ | ||
#[CoversClass(Assert::class)] | ||
final class DistinguishedNameTest extends TestCase | ||
{ | ||
/** | ||
* @param boolean $shouldPass | ||
* @param string $name | ||
*/ | ||
#[DataProvider('provideDistinguishedName')] | ||
public function testValidDistinguishedName(bool $shouldPass, string $name): void | ||
{ | ||
try { | ||
Assert::validDistinguishedName($name); | ||
$this->assertTrue($shouldPass); | ||
} catch (AssertionFailedException $e) { | ||
$this->assertFalse($shouldPass); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* @return array<int, array{0: bool, 1: string}> | ||
*/ | ||
public static function provideDistinguishedName(): array | ||
{ | ||
return [ | ||
[true, 'CN=Dijen\, Tim van,OU=Accounts,DC=simplesamlphp,DC=org'], | ||
[false, 'Test'], | ||
[false, '_Test'], | ||
[false, '_5425e58e-e799-4884-92cc-ca64ecede32f'], // prefixed v4 UUID | ||
[false, 'Te*st'], | ||
[false, '1Test'], | ||
[false, 'Te:st'], | ||
]; | ||
} | ||
} |