-
Notifications
You must be signed in to change notification settings - Fork 8.1k
ext/uri: Increases test coverage #23342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
NickSdot
wants to merge
1
commit into
php:master
Choose a base branch
from
NickSdot:hardening/ext-uri-coverage
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,221
−12
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,14 @@ | ||
| --TEST-- | ||
| Test HTTP stream URI parsing - error - invalid URI | ||
| --INI-- | ||
| allow_url_fopen=1 | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| // hits ext/uri parsing and fails | ||
| // before connection is attempted | ||
| var_dump(@fopen("http://", "r")); | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| bool(false) |
This file contains hidden or 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,23 @@ | ||
| --TEST-- | ||
| Test phpinfo() - URI module information | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| ob_start(); | ||
| phpinfo(INFO_MODULES); | ||
| $info = ob_get_clean(); | ||
|
|
||
| var_dump(str_contains($info, "URI support => active")); | ||
| var_dump( | ||
| str_contains($info, "uriparser bundled version") || | ||
| ( | ||
| str_contains($info, "uriparser compiled version") | ||
| && | ||
| str_contains($info, "uriparser loaded version") | ||
| ) | ||
| ); | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| bool(true) | ||
| bool(true) | ||
19 changes: 19 additions & 0 deletions
19
ext/uri/tests/rfc3986/builder/build_error_invalid_internal_fragment.phpt
This file contains hidden or 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,19 @@ | ||
| --TEST-- | ||
| Test Uri\Rfc3986\UriBuilder::build() - error - invalid internal fragment | ||
| --EXTENSIONS-- | ||
| reflection | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| $builder = new Uri\Rfc3986\UriBuilder(); | ||
| new ReflectionProperty($builder, 'fragment')->setValue($builder, '<'); | ||
|
|
||
| try { | ||
| $builder->build(); | ||
| } catch (Throwable $e) { | ||
| echo $e::class, ': ', $e->getMessage(), "\n"; | ||
| } | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| Uri\InvalidUriException: The specified fragment is malformed |
19 changes: 19 additions & 0 deletions
19
ext/uri/tests/rfc3986/builder/build_error_invalid_internal_host.phpt
This file contains hidden or 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,19 @@ | ||
| --TEST-- | ||
| Test Uri\Rfc3986\UriBuilder::build() - error - invalid internal host | ||
| --EXTENSIONS-- | ||
| reflection | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| $builder = new Uri\Rfc3986\UriBuilder(); | ||
| new ReflectionProperty($builder, 'host')->setValue($builder, '['); | ||
|
|
||
| try { | ||
| $builder->build(); | ||
| } catch (Throwable $e) { | ||
| echo $e::class, ': ', $e->getMessage(), "\n"; | ||
| } | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| Uri\InvalidUriException: The specified host is malformed |
19 changes: 19 additions & 0 deletions
19
ext/uri/tests/rfc3986/builder/build_error_invalid_internal_query.phpt
This file contains hidden or 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,19 @@ | ||
| --TEST-- | ||
| Test Uri\Rfc3986\UriBuilder::build() - error - invalid internal query | ||
| --EXTENSIONS-- | ||
| reflection | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| $builder = new Uri\Rfc3986\UriBuilder(); | ||
| new ReflectionProperty($builder, 'query')->setValue($builder, '<'); | ||
|
|
||
| try { | ||
| $builder->build(); | ||
| } catch (Throwable $e) { | ||
| echo $e::class, ': ', $e->getMessage(), "\n"; | ||
| } | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| Uri\InvalidUriException: The specified query is malformed |
19 changes: 19 additions & 0 deletions
19
ext/uri/tests/rfc3986/builder/build_error_invalid_internal_scheme.phpt
This file contains hidden or 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,19 @@ | ||
| --TEST-- | ||
| Test Uri\Rfc3986\UriBuilder::build() - error - invalid internal scheme | ||
| --EXTENSIONS-- | ||
| reflection | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| $builder = new Uri\Rfc3986\UriBuilder(); | ||
| new ReflectionProperty($builder, 'scheme')->setValue($builder, ':'); | ||
|
|
||
| try { | ||
| $builder->build(); | ||
| } catch (Throwable $e) { | ||
| echo $e::class, ': ', $e->getMessage(), "\n"; | ||
| } | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| Uri\InvalidUriException: The specified scheme is malformed |
62 changes: 62 additions & 0 deletions
62
ext/uri/tests/rfc3986/builder/build_success_referenced_component.phpt
This file contains hidden or 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,62 @@ | ||
| --TEST-- | ||
| Test Uri\Rfc3986\UriBuilder::build() - success - referenced component | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| $scope = "\0Uri\\Rfc3986\\UriBuilder\0"; | ||
|
|
||
| $serialised = serialize(new Uri\Rfc3986\UriBuilder()); | ||
|
|
||
| $serialised = str_replace( | ||
| "s:30:\"{$scope}scheme\";N;", | ||
| "s:30:\"{$scope}scheme\";s:5:\"https\";", | ||
| $serialised, | ||
| ); | ||
|
|
||
| $serialised = str_replace( | ||
| "s:28:\"{$scope}host\";N;", | ||
| "s:28:\"{$scope}host\";s:11:\"example.com\";", | ||
| $serialised, | ||
| ); | ||
|
|
||
| $serialised = str_replace( | ||
| "s:28:\"{$scope}path\";s:0:\"\";", | ||
| "s:28:\"{$scope}path\";s:5:\"/path\";", | ||
| $serialised, | ||
| ); | ||
|
|
||
| // make fragment share path value | ||
| $serialised = str_replace( | ||
| "s:32:\"{$scope}fragment\";N;", | ||
| "s:32:\"{$scope}fragment\";R:6;", | ||
| $serialised, | ||
| ); | ||
|
|
||
| $uri = unserialize($serialised)->build(); | ||
|
|
||
| var_dump($uri->toRawString()); | ||
| var_dump($uri); | ||
| var_dump($uri->equals(new Uri\Rfc3986\Uri($uri->toRawString()))); | ||
|
|
||
| ?> | ||
| --EXPECTF-- | ||
| string(30) "https://example.com/path#/path" | ||
| object(Uri\Rfc3986\Uri)#%d (%d) { | ||
| ["scheme"]=> | ||
| string(5) "https" | ||
| ["username"]=> | ||
| NULL | ||
| ["password"]=> | ||
| NULL | ||
| ["host"]=> | ||
| string(11) "example.com" | ||
| ["port"]=> | ||
| NULL | ||
| ["path"]=> | ||
| string(5) "/path" | ||
| ["query"]=> | ||
| NULL | ||
| ["fragment"]=> | ||
| string(5) "/path" | ||
| } | ||
| bool(true) |
This file contains hidden or 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,35 @@ | ||
| --TEST-- | ||
| Test Uri\Rfc3986\UriBuilder::setHost() - success - empty string | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| $builder = new Uri\Rfc3986\UriBuilder(); | ||
| $builder->setHost(''); | ||
| $uri = $builder->build(); | ||
|
|
||
| var_dump($uri->toRawString()); | ||
| var_dump($uri); | ||
| var_dump($uri->equals(new Uri\Rfc3986\Uri($uri->toRawString()))); | ||
|
|
||
| ?> | ||
| --EXPECTF-- | ||
| string(2) "//" | ||
| object(Uri\Rfc3986\Uri)#%d (%d) { | ||
| ["scheme"]=> | ||
| NULL | ||
| ["username"]=> | ||
| NULL | ||
| ["password"]=> | ||
| NULL | ||
| ["host"]=> | ||
| string(0) "" | ||
| ["port"]=> | ||
| NULL | ||
| ["path"]=> | ||
| string(0) "" | ||
| ["query"]=> | ||
| NULL | ||
| ["fragment"]=> | ||
| NULL | ||
| } | ||
| bool(true) |
16 changes: 16 additions & 0 deletions
16
ext/uri/tests/rfc3986/getters/userinfo_success_without_password_separator.phpt
This file contains hidden or 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,16 @@ | ||
| --TEST-- | ||
| Test Uri\Rfc3986\Uri component retrieval - userinfo - without password separator | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| $uri = new Uri\Rfc3986\Uri('https://user@example.com'); | ||
|
|
||
| var_dump($uri->getUserInfo()); | ||
| var_dump($uri->getUsername()); | ||
| var_dump($uri->getPassword()); | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| string(4) "user" | ||
| string(4) "user" | ||
| string(0) "" |
16 changes: 16 additions & 0 deletions
16
ext/uri/tests/rfc3986/modification/host_error_unset_with_port.phpt
This file contains hidden or 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,16 @@ | ||
| --TEST-- | ||
| Test Uri\Rfc3986\Uri::withHost() - error - unsetting with port | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| $uri = new Uri\Rfc3986\Uri('https://example.com:8080'); | ||
|
|
||
| try { | ||
| $uri->withHost(null); | ||
| } catch (Throwable $e) { | ||
| echo $e::class, ': ', $e->getMessage(), "\n"; | ||
| } | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| Uri\InvalidUriException: Cannot remove the host from a URI that has a port |
14 changes: 14 additions & 0 deletions
14
ext/uri/tests/rfc3986/parsing/port_error_excessive_digits.phpt
This file contains hidden or 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,14 @@ | ||
| --TEST-- | ||
| Test Uri\Rfc3986\Uri parsing - port - excessive number of digits | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| try { | ||
| new \Uri\Rfc3986\Uri('https://example.com:4242424269424242426942424242694242424269'); | ||
| } catch (Throwable $e) { | ||
| echo $e::class, ': ', $e->getMessage(), "\n"; | ||
| } | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| Uri\InvalidUriException: The port is out of range |
This file contains hidden or 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
19 changes: 19 additions & 0 deletions
19
ext/uri/tests/rfc3986/parsing/port_success_maximum_integer.phpt
This file contains hidden or 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,19 @@ | ||
| --TEST-- | ||
| Test Uri\Rfc3986\Uri parsing - port - maximum integer | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| if (PHP_INT_SIZE == 8) { | ||
| $uri = new \Uri\Rfc3986\Uri('https://example.com:9223372036854775807'); | ||
| echo $uri->getPort(), "\n"; | ||
| echo "2147483647", "\n"; | ||
| } else { | ||
| $uri = new \Uri\Rfc3986\Uri('https://example.com:2147483647'); | ||
| echo "9223372036854775807", "\n"; | ||
| echo $uri->getPort(), "\n"; | ||
| } | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| 9223372036854775807 | ||
| 2147483647 |
51 changes: 51 additions & 0 deletions
51
ext/uri/tests/whatwg/builder/build_success_multiple_validation_warnings.phpt
This file contains hidden or 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,51 @@ | ||
| --TEST-- | ||
| Test Uri\WhatWg\UrlBuilder::build() - success - multiple validation warnings | ||
| --EXTENSIONS-- | ||
| reflection | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| $builder = new Uri\WhatWg\UrlBuilder(); | ||
|
|
||
| foreach ([ | ||
| "scheme" => "https", | ||
| "host" => "127.0.0.1.", | ||
| "path" => "\\foo", | ||
| ] as $property => $value) { | ||
| new ReflectionProperty($builder, $property)->setValue($builder, $value); | ||
| } | ||
|
|
||
| $url = $builder->build(errors: $errors); | ||
|
|
||
| var_dump($url->toAsciiString()); | ||
| var_dump($url); | ||
| foreach ($errors as $error) { | ||
| echo $error->type->name, ': ', $error->context, ': '; | ||
| var_dump($error->failure); | ||
| } | ||
| var_dump($url->equals(new Uri\WhatWg\Url($url->toAsciiString()))); | ||
|
|
||
| ?> | ||
| --EXPECTF-- | ||
| string(21) "https://127.0.0.1/foo" | ||
| object(Uri\WhatWg\Url)#%d (%d) { | ||
| ["scheme"]=> | ||
| string(5) "https" | ||
| ["username"]=> | ||
| NULL | ||
| ["password"]=> | ||
| NULL | ||
| ["host"]=> | ||
| string(9) "127.0.0.1" | ||
| ["port"]=> | ||
| NULL | ||
| ["path"]=> | ||
| string(4) "/foo" | ||
| ["query"]=> | ||
| NULL | ||
| ["fragment"]=> | ||
| NULL | ||
| } | ||
| Ipv4EmptyPart: : bool(false) | ||
| InvalidReverseSoldius: \foo: bool(false) | ||
| bool(true) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debatable if this is worth testing. Thoughts?