Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Use a WHATWG URL spec compliant URL parser - see https://url.spec.wha… #229

Merged
merged 1 commit into from
Nov 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .drone.starlark
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ config = {
'master'
],

'appInstallCommand': 'make vendor',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indent


'codestyle': {
'ordinary' : {
'phpVersions': [
Expand Down
77 changes: 77 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ steps:
exclude: apps/oauth2
version: daily-master-qa

- name: install-app-oauth2
pull: always
image: owncloudci/php:7.0
commands:
- cd /var/www/owncloud/server/apps/oauth2
- make vendor

- name: setup-server-oauth2
pull: always
image: owncloudci/php:7.0
Expand Down Expand Up @@ -195,6 +202,13 @@ steps:
exclude: apps/oauth2
version: daily-master-qa

- name: install-app-oauth2
pull: always
image: owncloudci/php:7.0
commands:
- cd /var/www/owncloud/server/apps/oauth2
- make vendor

- name: setup-server-oauth2
pull: always
image: owncloudci/php:7.0
Expand Down Expand Up @@ -271,6 +285,13 @@ steps:
exclude: apps/oauth2
version: daily-master-qa

- name: install-app-oauth2
pull: always
image: owncloudci/php:7.0
commands:
- cd /var/www/owncloud/server/apps/oauth2
- make vendor

- name: setup-server-oauth2
pull: always
image: owncloudci/php:7.0
Expand Down Expand Up @@ -347,6 +368,13 @@ steps:
exclude: apps/oauth2
version: daily-master-qa

- name: install-app-oauth2
pull: always
image: owncloudci/php:7.0
commands:
- cd /var/www/owncloud/server/apps/oauth2
- make vendor

- name: setup-server-oauth2
pull: always
image: owncloudci/php:7.0
Expand Down Expand Up @@ -423,6 +451,13 @@ steps:
exclude: apps/oauth2
version: daily-master-qa

- name: install-app-oauth2
pull: always
image: owncloudci/php:7.0
commands:
- cd /var/www/owncloud/server/apps/oauth2
- make vendor

- name: setup-server-oauth2
pull: always
image: owncloudci/php:7.0
Expand Down Expand Up @@ -498,6 +533,13 @@ steps:
exclude: apps/oauth2
version: daily-master-qa

- name: install-app-oauth2
pull: always
image: owncloudci/php:7.0
commands:
- cd /var/www/owncloud/server/apps/oauth2
- make vendor

- name: setup-server-oauth2
pull: always
image: owncloudci/php:7.0
Expand Down Expand Up @@ -574,6 +616,13 @@ steps:
exclude: apps/oauth2
version: daily-master-qa

- name: install-app-oauth2
pull: always
image: owncloudci/php:7.1
commands:
- cd /var/www/owncloud/server/apps/oauth2
- make vendor

- name: setup-server-oauth2
pull: always
image: owncloudci/php:7.1
Expand Down Expand Up @@ -641,6 +690,13 @@ steps:
exclude: apps/oauth2
version: daily-master-qa

- name: install-app-oauth2
pull: always
image: owncloudci/php:7.2
commands:
- cd /var/www/owncloud/server/apps/oauth2
- make vendor

- name: setup-server-oauth2
pull: always
image: owncloudci/php:7.2
Expand Down Expand Up @@ -708,6 +764,13 @@ steps:
exclude: apps/oauth2
version: daily-master-qa

- name: install-app-oauth2
pull: always
image: owncloudci/php:7.3
commands:
- cd /var/www/owncloud/server/apps/oauth2
- make vendor

- name: setup-server-oauth2
pull: always
image: owncloudci/php:7.3
Expand Down Expand Up @@ -786,6 +849,13 @@ steps:
- cd /var/www/owncloud/testrunner
- make install-composer-deps vendor-bin-deps

- name: install-app-oauth2
pull: always
image: owncloudci/php:7.0
commands:
- cd /var/www/owncloud/server/apps/oauth2
- make vendor

- name: setup-server-oauth2
pull: always
image: owncloudci/php:7.0
Expand Down Expand Up @@ -904,6 +974,13 @@ steps:
- cd /var/www/owncloud/testrunner
- make install-composer-deps vendor-bin-deps

- name: install-app-oauth2
pull: always
image: owncloudci/php:7.0
commands:
- cd /var/www/owncloud/server/apps/oauth2
- make vendor

- name: setup-server-oauth2
pull: always
image: owncloudci/php:7.0
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ dist_dir=$(build_dir)/dist
# internal aliases
composer_deps=vendor
composer_dev_deps=
acceptance_test_deps=vendor-bin/behat/vendor
acceptance_test_deps=vendor-bin/behat/vendor $(composer_deps)
nodejs_deps=
bower_deps=

Expand Down Expand Up @@ -122,12 +122,12 @@ clean-deps: clean-composer-deps
##------------------------
.PHONY: test-php-unit
test-php-unit: ## Run php unit tests
test-php-unit:
test-php-unit: $(composer_deps)
$(PHPUNIT) --configuration ./phpunit.xml --testsuite unit

.PHONY: test-php-unit-dbg
test-php-unit-dbg: ## Run php unit tests using phpdbg
test-php-unit-dbg:
test-php-unit-dbg: $(composer_deps)
$(PHPUNITDBG) --configuration ./phpunit.xml --testsuite unit

.PHONY: test-php-style
Expand Down
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
"php": "7.0.8"
}
},
"require": {},
"require": {
"rowbot/url": "^1.1"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.2"
},
Expand All @@ -21,4 +23,4 @@
"bin-links": false
}
}
}
}
60 changes: 57 additions & 3 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 28 additions & 24 deletions lib/Utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@

namespace OCA\OAuth2;

require_once __DIR__ . '/../vendor/autoload.php';

use Rowbot\URL\Exception\TypeError;
use Rowbot\URL\URL;

class Utilities {

/**
* Generates a random string with 64 characters.
*
* @return string The random string.
*/
public static function generateRandom() {
public static function generateRandom(): string {
return \OC::$server->getSecureRandom()->generate(64,
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789');
}
Expand All @@ -46,43 +51,42 @@ public static function validateRedirectUri($expected, $actual, $allowSubdomains)
$expected = 'http://localhost' . \substr($expected, 18);
$validatePort = false;
}
if (\strcmp(\parse_url($expected, PHP_URL_SCHEME), \parse_url($actual, PHP_URL_SCHEME)) !== 0) {
return false;
}

$expectedHost = \parse_url($expected, PHP_URL_HOST);
$actualHost = \parse_url($actual, PHP_URL_HOST);
try {
$expectedUrl = new URL($expected);
$actualUrl = new URL($actual);
if (\strcmp($expectedUrl->protocol, $actualUrl->protocol) !== 0) {
return false;
}

if ($allowSubdomains) {
if (\strcmp($expectedHost, $actualHost) !== 0
&& \strcmp($expectedHost, \str_replace(\explode('.', $actualHost)[0] . '.', '', $actualHost)) !== 0
) {
if ($allowSubdomains) {
if (\strcmp($expectedUrl->hostname, $actualUrl->hostname) !== 0
&& \strcmp($expectedUrl->hostname, \str_replace(\explode('.', $actualUrl->hostname)[0] . '.', '', $actualUrl->hostname)) !== 0
) {
return false;
}
} elseif (\strcmp($expectedUrl->hostname, $actualUrl->hostname) !== 0) {
return false;
}
} else {
if (\strcmp($expectedHost, $actualHost) !== 0) {

if ($validatePort && $expectedUrl->port !== $actualUrl->port) {
return false;
}
}

if ($validatePort) {
if (\strcmp(\parse_url($expected, PHP_URL_PORT), \parse_url($actual, PHP_URL_PORT)) !== 0) {
if ($expectedUrl->pathname !== $actualUrl->pathname) {
return false;
}
}

if (\strcmp(\parse_url($expected, PHP_URL_PATH), \parse_url($actual, PHP_URL_PATH)) !== 0) {
return false;
}
if ($expectedUrl->search !== $actualUrl->search) {
return false;
}

if (\strcmp(\parse_url($expected, PHP_URL_QUERY), \parse_url($actual, PHP_URL_QUERY)) !== 0) {
return true;
} catch (TypeError $ex) {
return false;
}

return true;
}

public static function isValidUrl($redirectUri) {
public static function isValidUrl($redirectUri): bool {
if (\strpos($redirectUri, 'http://localhost:*') === 0) {
$redirectUri = 'http://localhost' . \substr($redirectUri, 18);
}
Expand Down
Loading