Skip to content

Commit 51b887d

Browse files
committed
Merge branch '7.4' into 8.0
* 7.4: (40 commits) [PropertyInfo] treat mixed[] the same as array when getting types from docblocks treat `mixed[]` the same as `array` when getting types from docblocks install ext-zstd on PHP 8.5 as well fix merge [Console] Fix profile invokable command sync ControllerHelper docblock with latest AbstractController changes fix: Typehint for `createForm` in abstractController [Notifier][Mercure] Add support for Mercure 0.7 register attribute loader arguments in a forward-compatible way ensure compatibility with RelayCluster 0.20.0 mark test using a Redis connection as an integration test ensure compatibility with Relay extension 0.20.0 [FrameworkBundle] Allow backed enum to be used in initial_marking workflow configuration [DependencyInjection] Fix `query_string` env processor for URLs without query string [HttpFoundation] Fix Expires response header for EventStream Bump Symfony version to 7.4.1 Update VERSION for 7.4.0 Update CHANGELOG for 7.4.0 - [DependencyInjection] Fix state corruption in PhpFileLoader during recursive imports ...
2 parents bea6dc7 + 92f9cc6 commit 51b887d

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

Authenticator/Passport/Badge/UserBadge.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,8 @@ public function __construct(
5454
private ?array $attributes = null,
5555
?\Closure $identifierNormalizer = null,
5656
) {
57-
if ('' === $userIdentifier) {
58-
throw new BadCredentialsException('Empty user identifier.');
59-
}
57+
$this->validateUserIdentifier($userIdentifier);
6058

61-
if (\strlen($userIdentifier) > self::MAX_USERNAME_LENGTH) {
62-
throw new BadCredentialsException('Username too long.');
63-
}
6459
if ($identifierNormalizer) {
6560
$this->identifierNormalizer = static fn () => $identifierNormalizer($userIdentifier);
6661
}
@@ -73,6 +68,8 @@ public function getUserIdentifier(): string
7368
if (isset($this->identifierNormalizer)) {
7469
$this->userIdentifier = ($this->identifierNormalizer)();
7570
$this->identifierNormalizer = null;
71+
72+
$this->validateUserIdentifier($this->userIdentifier);
7673
}
7774

7875
return $this->userIdentifier;
@@ -131,4 +128,15 @@ public function isResolved(): bool
131128
{
132129
return true;
133130
}
131+
132+
private function validateUserIdentifier(string $userIdentifier): void
133+
{
134+
if ('' === $userIdentifier) {
135+
throw new BadCredentialsException('Empty user identifier.');
136+
}
137+
138+
if (\strlen($userIdentifier) > self::MAX_USERNAME_LENGTH) {
139+
throw new BadCredentialsException('Username too long.');
140+
}
141+
}
134142
}

Tests/Authenticator/Passport/Badge/UserBadgeTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,14 @@ public static function provideUserIdentifierNormalizationData(): iterable
6262
yield 'Greek to ASCII' => ['ΝιΚόΛΑος', 'NIKOLAOS', $upperAndAscii];
6363
yield 'Katakana to ASCII' => ['たなかそういち', 'TANAKASOUICHI', $upperAndAscii];
6464
}
65+
66+
public function testUserIdentifierNormalizationEnforcesMaxLength()
67+
{
68+
$badge = new UserBadge('valid_input', null, null, fn () => str_repeat('a', UserBadge::MAX_USERNAME_LENGTH + 1));
69+
70+
$this->expectException(BadCredentialsException::class);
71+
$this->expectExceptionMessage('Username too long.');
72+
73+
$badge->getUserIdentifier();
74+
}
6575
}

0 commit comments

Comments
 (0)