Skip to content

Commit 80194ee

Browse files
committed
Add unit test for redirect_uri validation
1 parent 78d7687 commit 80194ee

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/Forms/ClientForm.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class ClientForm extends Form
3434

3535
/**
3636
* RFC3986. AppendixB. Parsing a URI Reference with a Regular Expression.
37+
* From v6.*, the regex was modified to allow URI without host, to support adding entries like
38+
* `openid-credential-offer://`
3739
*/
3840
final public const REGEX_URI = '/^[^:]+:\/\/?([^\s\/$.?#].[^\s]*)?$/';
3941

tests/unit/src/Forms/ClientFormTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,36 @@ public function testSetDefaultsUnsetsAuthSourceIfNotValid(): void
171171

172172
$this->assertNull($sut->getValues()['auth_source']);
173173
}
174+
175+
public static function redirectUriProvider(): array
176+
{
177+
return [
178+
['https', false],
179+
['https:', false],
180+
['example', false],
181+
['example.com', false],
182+
['example.com/?foo=bar', false],
183+
['www.example.com/?foo=bar', false],
184+
['https://example', true],
185+
['https://example.com', true],
186+
['https://example.com/', true],
187+
['https://example.com/foo', true],
188+
['https://example.com/foo?bar=1', true],
189+
190+
// To support OID4VCI
191+
['openid-credential-offer://', true],
192+
['foo://', true],
193+
['https://', true],
194+
];
195+
}
196+
197+
#[DataProvider('redirectUriProvider')]
198+
public function testCanValidateRedirectUri(string $url, bool $isValid): void
199+
{
200+
$sut = $this->sut();
201+
$sut->setValues(['redirect_uri' => $url]);
202+
$sut->validateRedirectUri($sut);
203+
204+
$this->assertEquals(!$isValid, $sut->hasErrors(), $url);
205+
}
174206
}

0 commit comments

Comments
 (0)