Skip to content
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

phpMyAdmin hosting card: migrate data getter to direct wpcom.req.post #60806

Merged
merged 2 commits into from
Feb 7, 2022

Conversation

jsnajdr
Copy link
Member

@jsnajdr jsnajdr commented Feb 3, 2022

For an Atomic site, there is a /hosting-config/:site page available (accessible also from Settings > Hosting Configuration in sidebar) and it contains a card for opening phpMyAdmin:

Screenshot 2022-02-03 at 10 28 35

How the "Open phpMyAdmin" button works is that it first issues a POST request to public-api to retrieve a token, and then opens a wordpress.com/pma-login?token URL in a new window.

It's the POST request this PR is migrating from a data getter to a simple wpcom.req.post request.

How to test:
Verify that the flow I describe above works for an Atomic site: clicking the button should retrieve a token and open a phpMyAdmin for the site in a new tab.

@jsnajdr jsnajdr requested a review from a team February 3, 2022 09:47
@jsnajdr jsnajdr self-assigned this Feb 3, 2022
@matticbot matticbot added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Feb 3, 2022
@github-actions
Copy link

github-actions bot commented Feb 3, 2022

@matticbot
Copy link
Contributor

matticbot commented Feb 3, 2022

Here is how your PR affects size of JS and CSS bundles shipped to the user's browser:

App Entrypoints (~35 bytes added 📈 [gzipped])

name        parsed_size           gzip_size
entry-main       -201 B  (-0.0%)      +35 B  (+0.0%)

Common code that is always downloaded and parsed every time the app is loaded, no matter which route is used.

Sections (~163 bytes removed 📉 [gzipped])

name     parsed_size           gzip_size
hosting       -274 B  (-0.1%)     -163 B  (-0.1%)

Sections contain code specific for a given set of routes. Is downloaded and parsed only when a particular route is navigated to.

Legend

What is parsed and gzip size?

Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory.
Gzip Size: Compressed size of the JS and CSS files. This much data needs to be downloaded over network.

Generated by performance advisor bot at iscalypsofastyet.com.

Copy link
Member

@tyxla tyxla left a comment

Choose a reason for hiding this comment

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

This looks good to me! Great cleanup! 🚀

I'd only add an error notice in the failure scenario. 🔔

Noting that this can't be fully tested due to the fact that it only works on wordpress.com domain (it's a limitation of the endpoint by design, with security purposes). Let's keep an eye and re-test once it's on staging!

window.open( `https://wordpress.com/pma-login?token=${ token }` );
}
} catch {
// ignore errors
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be useful if we can just dispatch an error notice in this scenario.

Copy link
Member Author

Choose a reason for hiding this comment

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

Notice added 👍 It's a very generic "could not open please try again" message because there's nothing that could be comprehensible or actionable for the user. The main goal is to say something instead of failing silently.

@jsnajdr
Copy link
Member Author

jsnajdr commented Feb 7, 2022

this can't be fully tested due to the fact that it only works on wordpress.com domain

Does it really? I was able to test the feature completely on an Atomic site, even in development Calypso. It fetches a token from the REST endpoint and opens wordpress.com/pma-login?token=... in a new window. The /pma-login page is not server by Calypso, it's a PHP-powered wpcom route.

@tyxla
Copy link
Member

tyxla commented Feb 7, 2022

this can't be fully tested due to the fact that it only works on wordpress.com domain

Does it really? I was able to test the feature completely on an Atomic site, even in development Calypso. It fetches a token from the REST endpoint and opens wordpress.com/pma-login?token=... in a new window. The /pma-login page is not server by Calypso, it's a PHP-powered wpcom route.

It's weird how you managed to test it! Looking at request_phpmyadmin_login() it seems like we are validating the HTTP_HOST on top of the other validations. And when I test with calypso.live on this branch, it doesn't work (it fails silently because of the catch).

@jsnajdr
Copy link
Member Author

jsnajdr commented Feb 7, 2022

It's weird how you managed to test it!

Now I see what's wrong: the server endpoint checks if the origin is in an approved list (A8C\Atomic\Hosting\Utils\validate_api_request function) and the list includes:

http://calypso.localhost:3000
https://calypso.live

I was testing only in local dev server which is OK. But calypso.live containers run on a random subdomain and the origin doesn't match.

When doing a similar origin check at other places (e.g., OAuth code), we "normalize" the calypso.live urls with:

preg_replace( '#^https://[a-z0-9-]+\.calypso\.live(/|$)#', 'https://calypso.live$1', $redirect_uri )

before checking. The validate_api_request function would deserve to have this step, too.

@jsnajdr jsnajdr merged commit de10be0 into trunk Feb 7, 2022
@jsnajdr jsnajdr deleted the querify/php-my-admin-token branch February 7, 2022 12:30
@github-actions github-actions bot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Feb 7, 2022
@a8ci18n
Copy link

a8ci18n commented Feb 7, 2022

This Pull Request is now available for translation here: https://translate.wordpress.com/deliverables/7128962

Thank you @jsnajdr for including a screenshot in the description! This is really helpful for our translators.

@a8ci18n
Copy link

a8ci18n commented Feb 18, 2022

Translation for this Pull Request has now been finished.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants