Conversation
| "true/punycode": "^2.0 <2.1.1" | ||
| }, | ||
| "replace": { | ||
| "paragonie/random_compat": ">=2", |
There was a problem hiding this comment.
random_compat is bundled in WordPress so this avoids loading via Composer, potentially loading an older version.
The version here is significant as any version below version 2 cannot be installed due to roave/security-advisories, so the constraint must only target versions which could actually be installed. This configuration causes the package not to be installed.
| $client->setPrompt( 'consent' ); | ||
| $client->setRedirectUri( $args['redirect_uri'] ); | ||
| $client->setScopes( (array) $args['required_scopes'] ); | ||
| $client->prepareScopes(); |
There was a problem hiding this comment.
This method didn't actually do anything meaningful as it has no side-effects, it only returns the list of requested scopes as a single string.
scoper.inc.php
Outdated
|
|
||
| // This dependency is a global function which should remain global. | ||
| 'vendor/ralouphie/getallheaders/src/getallheaders.php', | ||
| 'vendor/symfony/polyfill-intl-normalizer/bootstrap.php', |
There was a problem hiding this comment.
There may be others that are needed here, this raised a failure without it so it was the only one added. See the generated third-party/vendor/autoload_files.php for other possible entries here.
There was a problem hiding this comment.
I'm interested to know where the failure was raised, as looking at the resulting third-party/symfony/polyfill-intl-normalizer/bootstrap.php, the generated normalizer_is_normalized() / normalizer_normalize() functions don't work properly as they refer to Symfony\Polyfill\Intl\Normalizer, whereas as can be seen examining third-party/symfony/polyfill-intl-normalizer/Normalizer.php, this Normalizer class is now defined within the Google\Site_Kit_Dependencies\Symfony\Polyfill\Intl\Normalizer namespace.
I think it would be a more correct fix to instead use Scoper to modify the resulting bootstrap.php file to simply avoid adding a namespace statement. I dug into this a bit and was able to test the current generated normalizer_is_normalized() function, which threw a PHP Fatal error: Uncaught Error: Class 'Symfony\\Polyfill\\Intl\\Normalizer\\Normalizer' not found error, whereas a modded version of bootstrap.php as generated without being in the files-whitelist array, but with the namespace line removed, resulted in a working normalizer_is_normalized()...
Given that the normalizer_is_normalized() / normalizer_normalize() functions are called in the WP core remove_accents() function which is in turn called by Tag_Manager::sanitize_container_name(), we need to be a bit careful here...
There was a problem hiding this comment.
Good call, this was the part I think was most likely to introduce problems, but I think removing the namespace from the global bootstrap.php files for polyfills should fix it 👍
I wasn't able to reproduce the initial error that caused me to add the one path to the whitelist initially, but it shouldn't be needed anymore anyways with the more robust solution.
| * @return \Google\Site_Kit_Dependencies\GuzzleHttp\Message\ResponseInterface | ||
| * @return ResponseInterface | ||
| */ | ||
| public function send( RequestInterface $request ) { |
There was a problem hiding this comment.
This class is no longer useful for its intended purpose and needs to be replaced.
| $fake_http_client->set_request_handler( | ||
| function ( Request $request ) use ( $activity_metrics ) { | ||
| if ( 0 !== strpos( $request->getUrl(), 'https://oauth2.googleapis.com/token' ) ) { | ||
| if ( 0 !== strpos( $request->getUri(), 'https://oauth2.googleapis.com/token' ) ) { |
There was a problem hiding this comment.
Naming difference in the new interface.
| $this->authentication->get_oauth_client()->get_client()->setHttpClient( $http_client ); | ||
| $this->analytics->get_owner_oauth_client()->get_client()->setHttpClient( $http_client ); |
There was a problem hiding this comment.
This looks like it was missing initially but may have been working by coincidence. This will need to change going forward as using an alternate HTTP client won't work for this with Guzzle 6.
aaemnnosttv
left a comment
There was a problem hiding this comment.
Note to the reviewer: the diff will be easiest to review with whitespace ignored/hidden as indentation has changed in some chunks but otherwise most of the content has been preserved with minimal changes.
|
|
||
| use Google\Site_Kit\Context; | ||
| use Google\Site_Kit\Core\Modules\Module; | ||
| use Google\Site_Kit\Core\Modules\Module_With_Service_Entity; |
There was a problem hiding this comment.
There are a few instances like this where unused imports were cleaned up as well.
techanvil
left a comment
There was a problem hiding this comment.
Nice work, @aaemnnosttv. I have left a couple of comments, a suggestion and a couple of questions, please take a look.
scoper.inc.php
Outdated
|
|
||
| // This dependency is a global function which should remain global. | ||
| 'vendor/ralouphie/getallheaders/src/getallheaders.php', | ||
| 'vendor/symfony/polyfill-intl-normalizer/bootstrap.php', |
There was a problem hiding this comment.
I'm interested to know where the failure was raised, as looking at the resulting third-party/symfony/polyfill-intl-normalizer/bootstrap.php, the generated normalizer_is_normalized() / normalizer_normalize() functions don't work properly as they refer to Symfony\Polyfill\Intl\Normalizer, whereas as can be seen examining third-party/symfony/polyfill-intl-normalizer/Normalizer.php, this Normalizer class is now defined within the Google\Site_Kit_Dependencies\Symfony\Polyfill\Intl\Normalizer namespace.
I think it would be a more correct fix to instead use Scoper to modify the resulting bootstrap.php file to simply avoid adding a namespace statement. I dug into this a bit and was able to test the current generated normalizer_is_normalized() function, which threw a PHP Fatal error: Uncaught Error: Class 'Symfony\\Polyfill\\Intl\\Normalizer\\Normalizer' not found error, whereas a modded version of bootstrap.php as generated without being in the files-whitelist array, but with the namespace line removed, resulted in a working normalizer_is_normalized()...
Given that the normalizer_is_normalized() / normalizer_normalize() functions are called in the WP core remove_accents() function which is in turn called by Tag_Manager::sanitize_container_name(), we need to be a bit careful here...
| FakeHttp::fake_google_http_handler( | ||
| $this->authentication->get_oauth_client()->get_client(), | ||
| $fake_http_handler | ||
| ); | ||
| FakeHttp::fake_google_http_handler( | ||
| $this->analytics->get_owner_oauth_client()->get_client(), | ||
| $fake_http_handler | ||
| ); |
There was a problem hiding this comment.
This is a slight departure from the existing logic, where just setting the handler for $this->analytics->get_client() as below would be a direct mapping of it. I seem to recall you mentioned something about this, though, where we should have been updating the authentication client as well as the Analytics client. Therefore, I'm pretty confident your update here will be the right thing to do, but would you mind clarifying it for my understanding?
FakeHttp::fake_google_http_handler(
$this->analytics->get_client(),
$fake_http_handler
);There was a problem hiding this comment.
Ah, maybe it was this comment I was thinking of, which I didn't spot at the time of writing the above...
There was a problem hiding this comment.
Yes, I mentioned this above in https://github.com/google/site-kit-wp/pull/6581/files/b58274c240118142014bca49d98ad01c00d754a8#r1103512495.
I thought it was missing the handler set on the module owners client instance since the test uses the data_access_token data provider, which includes the empty token, so I probably assumed the test was intended to run in a sharing context as well, but this one is not so it's all good. I've restored the original form 👍
techanvil
left a comment
There was a problem hiding this comment.
Looks like this needs a bit more attention, as the E2E tests are failing... Please see my separate comment with a bit of detail on this.
techanvil
left a comment
There was a problem hiding this comment.
LGTM, nice one @aaemnnosttv!
Summary
Addresses issue:
Relevant technical choices
Relevant docs
Google\Client)PR Author Checklist
Do not alter or remove anything below. The following sections will be managed by moderators only.
Code Reviewer Checklist
Merge Reviewer Checklist