Skip to content

Commit ec9d873

Browse files
authored
Merge pull request #67 from boesing/feature/test-psr7-uri-userinfo-encoding
Introduce `userInfo` encoding tests
2 parents 3867c50 + 3f8f2dd commit ec9d873

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [1.3.0] - TBD
99

10+
### Added
11+
12+
- Adds `UriIntegrationTest::testSpecialCharsInUserInfo` and `UriIntegrationTest::testAlreadyEncodedUserInfo`.
13+
These validate that usernames and passwords which contain reserved characters (defined by RFC3986) are being encoded
14+
so that the URI does not contain these reserved characters at any time.
15+
1016
## [1.2.0] - 2022-12-01
1117

1218
### Added

src/UriIntegrationTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,4 +281,28 @@ public function testStringRepresentationWithMultipleSlashes(array $test)
281281
{
282282
$this->assertSame($test['expected'], (string) $test['uri']);
283283
}
284+
285+
/**
286+
* Tests that special chars in `userInfo` must always be URL-encoded to pass RFC3986 compliant URIs where characters
287+
* in username and password MUST NOT contain reserved characters.
288+
*
289+
* This test is taken from {@see https://github.com/guzzle/psr7/blob/3cf1b6d4f0c820a2cf8bcaec39fc698f3443b5cf/tests/UriTest.php#L679-L688 guzzlehttp/psr7}.
290+
*
291+
* @see https://www.rfc-editor.org/rfc/rfc3986#appendix-A
292+
*/
293+
public function testSpecialCharsInUserInfo(): void
294+
{
295+
$uri = $this->createUri('/')->withUserInfo('foo@bar.com', 'pass#word');
296+
self::assertSame('foo%40bar.com:pass%23word', $uri->getUserInfo());
297+
}
298+
299+
/**
300+
* Tests that userinfo which is already encoded is not encoded twice.
301+
* This test is taken from {@see https://github.com/guzzle/psr7/blob/3cf1b6d4f0c820a2cf8bcaec39fc698f3443b5cf/tests/UriTest.php#L679-L688 guzzlehttp/psr7}.
302+
*/
303+
public function testAlreadyEncodedUserInfo(): void
304+
{
305+
$uri = $this->createUri('/')->withUserInfo('foo%40bar.com', 'pass%23word');
306+
self::assertSame('foo%40bar.com:pass%23word', $uri->getUserInfo());
307+
}
284308
}

0 commit comments

Comments
 (0)