Skip to content

Commit dd3a67f

Browse files
authored
[Website] Prevent Query API defaults from overriding login info provided by the Blueprint (#2871)
## Motivation for the change, related issues As reported in #2872 the Playground website will override the `login` step and shorthand when applying Query API overrides. The default behavior of the Query API is to set the `login` shorthand to `true`, but the override doesn't check if the Blueprint already provides a `login` step or shorthand. This behavior results in the user being unable to use the `login` step and shorthand on the Playground website, except if they explicitly set `?login=no` in the Query API. ## Implementation details This PR addresses the issue by prepending the default login step to the steps array instead of appending it to the end. By prepending it, the login steps provided by the user will override the default login step. The login step only defines the `PLAYGROUND_AUTO_LOGIN_AS_USER` const, we can have multiple, because each step overrides the definition of the previous step. ([login step code](https://github.com/WordPress/wordpress-playground/blob/15e5181600d6e93db3f3bb73f37b86ead15f51a3/packages/playground/blueprints/src/lib/steps/login.ts#L43)). On the first page load, a mu-plugin detects the const and logs in the user defined in that const ([login code)](https://github.com/WordPress/wordpress-playground/blob/cae150a060f2c6067797186b62140b719cd32e63/packages/playground/wordpress/src/index.ts#L103). Because of that, it doesn't matter how many times we call the login step, login will be executed once. ## Testing Instructions (or ideally a Blueprint) - CI ### Manual testing - Checkout this branch - [Open this Playground website link](http://127.0.0.1:5400/website-server/?blueprint-url=https%3A%2F%2Fraw.githubusercontent.com%2Fyookoala%2Fuser-profile-tabs%2F23cc90db58bf16e656a07503aa95514a27a2a2e3%2F.wordpress-org%2Fblueprints%2Fblueprint.json) - Once Playground loads you should be logged in as the `Demo User`
1 parent 43ea776 commit dd3a67f

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

packages/playground/blueprints/src/lib/v1/compile.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,12 @@ function compileBlueprintJson(
230230
})) as StepDefinition[];
231231
blueprint.steps!.unshift(...steps);
232232
}
233+
234+
/**
235+
* Prepend a login step to enable Blueprints to override the default login step.
236+
*/
233237
if (blueprint.login) {
234-
blueprint.steps!.push({
238+
blueprint.steps!.unshift({
235239
step: 'login',
236240
...(blueprint.login === true
237241
? { username: 'admin' }

packages/playground/website/playwright/e2e/blueprints.spec.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,34 @@ test('should login the user in if a login step is provided', async ({
597597
await expect(wordpress.locator('body')).toContainText('Dashboard');
598598
});
599599

600+
test('should login a non-admin user if a login step with a non-admin username is provided', async ({
601+
website,
602+
wordpress,
603+
}) => {
604+
const blueprint: Blueprint = {
605+
landingPage: '/wp-admin/profile.php',
606+
extraLibraries: ['wp-cli'],
607+
steps: [
608+
{
609+
step: 'wp-cli',
610+
command:
611+
"wp user create user user@example.com --user_pass='password'",
612+
},
613+
{
614+
step: 'login',
615+
username: 'user',
616+
password: 'password',
617+
},
618+
],
619+
};
620+
621+
const encodedBlueprint = JSON.stringify(blueprint);
622+
await website.goto(`./#${encodedBlueprint}`);
623+
await expect(wordpress.locator('#profile-page #email')).toHaveValue(
624+
'user@example.com'
625+
);
626+
});
627+
600628
['/wp-admin/', '/wp-admin/post.php?post=1&action=edit'].forEach((path) => {
601629
test(`should correctly redirect encoded wp-admin url to ${path}`, async ({
602630
website,

0 commit comments

Comments
 (0)