diff --git a/docs/guide/running-the-site.md b/docs/guide/running-the-site.md index d1c92318..7cec8271 100644 --- a/docs/guide/running-the-site.md +++ b/docs/guide/running-the-site.md @@ -20,7 +20,7 @@ The server's dot shows its state, in the header and next to the site in the side When the server is running, the details list **View site**, **wp-admin** and **Database** under **Server**, with the admin username and password. The header's server menu has **View site** and **wp-admin** too. Each opens in your default browser. -![The site view with the dev server running: in the details, under Server, a Stop button, the View site, wp-admin and Database links, and the admin credentials with the password hidden](/screenshots/dev-server-running.png) +![The site view with the dev server running: in the details, under Server, a Stop button, the View site, wp-admin and Database links, and the admin credentials](/screenshots/dev-server-running.png) **Start** is disabled while a trunk update is running, and while `npm run build` is running, whether you typed it in the terminal or a patch, a pull request or a trunk update started it: the server would serve a `build/` that is still being written. A site set to start its server or watch when opened waits for that build to end. The reverse is no longer true: an update can run with the server up, because it pauses the build watch for the rebuild and leaves the server serving — see [Applying patches and PRs](./applying-patches) and [Staying up to date with trunk](./trunk-updates). @@ -31,7 +31,7 @@ Every site uses the same credentials, shown under **Server** in the details: - Username: `admin` - Password: `password` -The **wp-admin** link opens the dashboard directly. +The **wp-admin** link opens the dashboard already logged in as `admin`. The site itself, and `wp-login.php`, stay logged out until you log in, so you can still test what a visitor sees. ## What the dev server actually runs diff --git a/docs/public/screenshots/dev-server-running.png b/docs/public/screenshots/dev-server-running.png index e0c70cb9..de6ad285 100644 Binary files a/docs/public/screenshots/dev-server-running.png and b/docs/public/screenshots/dev-server-running.png differ diff --git a/src/playground-plan.cjs b/src/playground-plan.cjs index 8ee98560..7fee00b8 100644 --- a/src/playground-plan.cjs +++ b/src/playground-plan.cjs @@ -109,17 +109,23 @@ function planPlaygroundLaunch(config) { // The cost is real and deliberate: DISALLOW_FILE_MODS also blocks installing a // second plugin or theme into the preview. Losing an afternoon of uncommitted // work is worse than restarting a preview you can restart. +// +// Every strategy also turns on Playground's forced auto-login (#743), which +// the app's wp-admin link asks for (site-urls.cjs), so that link opens the +// dashboard logged in. It logs in whoever asks, but the server listens on the +// loopback only, and the admin password is `password` on every site anyway. function planServeConstants(config) { const cfg = config || {}; if (cfg.strategy === 'plugin-mount') { return { WP_ENVIRONMENT_TYPE: 'local', WP_DEVELOPMENT_MODE: 'plugin', + PLAYGROUND_FORCE_AUTO_LOGIN_ENABLED: true, DISALLOW_FILE_MODS: true, DISALLOW_FILE_EDIT: true }; } - return { WP_ENVIRONMENT_TYPE: 'local', WP_DEVELOPMENT_MODE: 'core' }; + return { WP_ENVIRONMENT_TYPE: 'local', WP_DEVELOPMENT_MODE: 'core', PLAYGROUND_FORCE_AUTO_LOGIN_ENABLED: true }; } module.exports = { planPlaygroundLaunch, planServeConstants, WORDPRESS_VFS_ROOT, PLUGINS_VFS_BASE }; diff --git a/src/renderer/components/site-details.jsx b/src/renderer/components/site-details.jsx index 52693f3a..78110fad 100644 --- a/src/renderer/components/site-details.jsx +++ b/src/renderer/components/site-details.jsx @@ -5,8 +5,8 @@ import { __, sprintf } from '@wordpress/i18n'; // given its final export yet, like the segmented control. // eslint-disable-next-line @wordpress/no-unsafe-wp-apis -- see above. import { __experimentalTreeGrid as TreeGrid, __experimentalTreeGridCell as TreeGridCell, __experimentalTreeGridRow as TreeGridRow } from '@wordpress/components'; -import { chevronDown, chevronRight, globe, offline, page, pencil, plus, seen, table, undo, unseen, wordpress } from '@wordpress/icons'; -import { Button, EmptyState, Icon, IconButton, Link, Menu, Notice, Stack, Text, Tooltip, VisuallyHidden } from '@wordpress/ui'; +import { chevronDown, chevronRight, globe, offline, page, pencil, plus, table, undo, wordpress } from '@wordpress/icons'; +import { Button, EmptyState, Icon, Link, Menu, Notice, Stack, Text, Tooltip, VisuallyHidden } from '@wordpress/ui'; import { affectedFileTree, visibleAffectedRows } from '../affected-files.cjs'; import { siteDetailsRows } from '../site-details.cjs'; import { ProcessStatus } from './site-header-actions.jsx'; @@ -73,7 +73,6 @@ const LINK_ICONS = { site: globe, admin: wordpress, database: table }; // and what to log in with. Which of the three things it shows is decided in // site-processes.cjs. function ServerSection({ server }) { - const [showPassword, setShowPassword] = useState(false); const { section } = server; return ( @@ -91,17 +90,7 @@ function ServerSection({ server }) { {__('Username')} {section.credentials.username} {__('Password')} -
- {showPassword ? section.credentials.password : '••••••••'} - setShowPassword((current) => !current)} - /> -
+ {section.credentials.password}
diff --git a/src/renderer/shell.css b/src/renderer/shell.css index ed5a8c3d..27fee189 100644 --- a/src/renderer/shell.css +++ b/src/renderer/shell.css @@ -506,13 +506,6 @@ body { align-items: center; } -.credential-value { - display: flex; - align-items: center; - gap: var(--wpds-dimension-gap-xs); - min-width: 0; -} - /* What a line of text is about, where a notice would be too much: said quietly, something that went well, something to mind, something that went wrong. One class each, for every card and dialog. */ diff --git a/src/renderer/site-processes.cjs b/src/renderer/site-processes.cjs index abd48907..a17a9b3b 100644 --- a/src/renderer/site-processes.cjs +++ b/src/renderer/site-processes.cjs @@ -7,7 +7,7 @@ 'use strict'; const { __, sprintf } = require('@wordpress/i18n'); -const { adminUrl, adminerUrl } = require('./site-urls.cjs'); +const { adminUrl, adminerUrl, ADMIN_USERNAME } = require('./site-urls.cjs'); const { formatElapsed } = require('./dev-server-command.cjs'); /** @@ -172,7 +172,7 @@ function serverLinks({ url = '', running = false } = {}) { } // What the app's server is set up with. Fixed, and the same on every site. -const ADMIN_CREDENTIALS = Object.freeze({ username: 'admin', password: 'password' }); +const ADMIN_CREDENTIALS = Object.freeze({ username: ADMIN_USERNAME, password: 'password' }); /** * What the server's section of the details shows under its heading: where diff --git a/src/renderer/site-urls.cjs b/src/renderer/site-urls.cjs index f473156e..cd00606d 100644 --- a/src/renderer/site-urls.cjs +++ b/src/renderer/site-urls.cjs @@ -36,17 +36,29 @@ function siteUrl(serverUrl, relativePath) { return `${base.replace(/\/+$/, '')}/${rel}`; } +// The admin user every site is set up with. The credentials the details show +// are built from it (site-processes.cjs), so the user the wp-admin link logs +// in as is always the one they name. +const ADMIN_USERNAME = 'admin'; + /** - * The admin dashboard. + * The admin dashboard, already logged in (#743). * * The trailing slash matters: WordPress redirects `/wp-admin` to `/wp-admin/`, * and asking for the canonical form directly saves the round trip. * + * The query is Playground's own: with PLAYGROUND_FORCE_AUTO_LOGIN_ENABLED, + * which every site is served with (playground-plan.cjs), its auto-login + * mu-plugin logs the browser in as the named user on that request. Only this + * link does it: the site's front end and wp-login.php stay logged out until + * the contributor logs in, so a ticket about either can still be tested. + * * @param {string} serverUrl * @return {string} */ function adminUrl(serverUrl) { - return siteUrl(serverUrl, 'wp-admin/'); + const url = siteUrl(serverUrl, 'wp-admin/'); + return url ? `${url}?playground_force_auto_login_as_user=${ADMIN_USERNAME}` : ''; } /** @@ -62,5 +74,6 @@ function adminerUrl(serverUrl) { module.exports = { siteUrl, adminUrl, - adminerUrl + adminerUrl, + ADMIN_USERNAME }; diff --git a/src/server-runner.js b/src/server-runner.js index 021241e0..aa389a24 100644 --- a/src/server-runner.js +++ b/src/server-runner.js @@ -92,10 +92,10 @@ async function main() { 'WP_MAIL_SMTP_SECURE': process.env.WP_MAIL_SMTP_SECURE || '', // '', 'ssl', or 'tls' 'WP_MAIL_SMTP_USER': process.env.WP_MAIL_SMTP_USER || '', 'WP_MAIL_SMTP_PASS': process.env.WP_MAIL_SMTP_PASS || '', - // Last: the environment type and development mode every site - // gets, and, for a strategy that has to protect the host - // directory it mounted, the constants that do, which the shared - // sets above must not override. + // Last: the environment type, development mode and forced + // auto-login every site gets, and, for a strategy that has to + // protect the host directory it mounted, the constants that do, + // which the shared sets above must not override. ...serveConstants } } diff --git a/tests/e2e/journeys/dev-server.spec.js b/tests/e2e/journeys/dev-server.spec.js index 0ef1bd65..72cb2336 100644 --- a/tests/e2e/journeys/dev-server.spec.js +++ b/tests/e2e/journeys/dev-server.spec.js @@ -610,7 +610,7 @@ test( 'the header\'s menu starts and stops the same server, and the server\'s se // INVARIANT — the section says where the site, its admin and its // database are. await expect( link( 'View site' ) ).toHaveAttribute( 'href', URL ); - await expect( link( 'wp-admin' ) ).toHaveAttribute( 'href', `${ URL }wp-admin/` ); + await expect( link( 'wp-admin' ) ).toHaveAttribute( 'href', `${ URL }wp-admin/?playground_force_auto_login_as_user=admin` ); await expect( link( 'Database' ) ).toHaveAttribute( 'href', `${ URL }adminer.php` ); // INVARIANT — a link is opened in the browser, by the main process, and @@ -621,7 +621,7 @@ test( 'the header\'s menu starts and stops the same server, and the server\'s se const windowAddress = () => app.evaluate( ( { BrowserWindow } ) => BrowserWindow.getAllWindows()[ 0 ].webContents.getURL() ); const appAddress = await windowAddress(); await link( 'wp-admin' ).click(); - await expect.poll( async () => ( await server.asked() ).opened ).toEqual( [ URL, `${ URL }wp-admin/` ] ); + await expect.poll( async () => ( await server.asked() ).opened ).toEqual( [ URL, `${ URL }wp-admin/?playground_force_auto_login_as_user=admin` ] ); await server.heard(); await expect( ui.siteHeading( page, 'e2e-site' ) ).toBeVisible(); expect( await windowAddress() ).toBe( appAddress ); @@ -632,19 +632,15 @@ test( 'the header\'s menu starts and stops the same server, and the server\'s se await headerMenu( 'Server running' ).click(); await expect( page.getByRole( 'menuitem' ) ).toHaveText( [ 'View site', 'wp-admin', 'Stop development server' ] ); await page.getByRole( 'menuitem', { name: 'View site', exact: true } ).click(); - await expect.poll( async () => ( await server.asked() ).opened ).toEqual( [ URL, `${ URL }wp-admin/`, URL ] ); + await expect.poll( async () => ( await server.asked() ).opened ).toEqual( [ URL, `${ URL }wp-admin/?playground_force_auto_login_as_user=admin`, URL ] ); await server.heard(); expect( await windowAddress() ).toBe( appAddress ); - // INVARIANT — it says what to log in with, and shows the password only - // when asked to. + // INVARIANT — it says what to log in with, the password included: it is + // `password` on every site, so there is nothing to hide (#743). const credentials = page.getByRole( 'complementary' ).filter( { visible: true } ); await expect( credentials.getByText( 'admin', { exact: true } ) ).toBeVisible(); - await expect( credentials.getByText( 'password', { exact: true } ) ).toHaveCount( 0 ); - await credentials.getByRole( 'button', { name: 'Show password', exact: true } ).click(); await expect( credentials.getByText( 'password', { exact: true } ) ).toBeVisible(); - await credentials.getByRole( 'button', { name: 'Hide password', exact: true } ).click(); - await expect( credentials.getByText( 'password', { exact: true } ) ).toHaveCount( 0 ); // INVARIANT — the header's menu stops it, and both places say so. await headerMenu( 'Server running' ).click(); diff --git a/tests/e2e/journeys/i18n.spec.js b/tests/e2e/journeys/i18n.spec.js index 88a9dbe4..1c563270 100644 --- a/tests/e2e/journeys/i18n.spec.js +++ b/tests/e2e/journeys/i18n.spec.js @@ -317,8 +317,6 @@ test( 'the open site\'s two processes are fully translatable, in the header and await tell( 'playground:url', { sitePath: site.dir, url: URL } ); await expect( details.getByRole( 'link', { name: pseudoLocalize( 'Database' ), exact: true } ) ).toBeVisible(); await expect( menuButton( 'Build watching' ) ).toBeVisible(); - await details.getByRole( 'button', { name: pseudoLocalize( 'Show password' ), exact: true } ).click(); - await expect( details.getByRole( 'button', { name: pseudoLocalize( 'Hide password' ), exact: true } ) ).toBeVisible(); expect( ( await inDetails() ).filter( ( text ) => text !== 'password' ) ).toEqual( [] ); await menuButton( 'Server running' ).click(); await expect( item( 'Stop development server' ) ).toBeVisible(); diff --git a/tests/e2e/journeys/site-links.spec.js b/tests/e2e/journeys/site-links.spec.js index f24d4ae5..038bbd94 100644 --- a/tests/e2e/journeys/site-links.spec.js +++ b/tests/e2e/journeys/site-links.spec.js @@ -61,7 +61,7 @@ test( 'a middle click on a link to the site opens it in the browser, and not in // INVARIANT — a middle click goes to the browser, to the address the link // names. await admin.click( { button: 'middle' } ); - await expect.poll( opened ).toEqual( [ SERVER_URL, `${ SERVER_URL }wp-admin/` ] ); + await expect.poll( opened ).toEqual( [ SERVER_URL, `${ SERVER_URL }wp-admin/?playground_force_auto_login_as_user=admin` ] ); // INVARIANT — and the app opened no window of its own and went nowhere. expect( await app.evaluate( ( { BrowserWindow } ) => BrowserWindow.getAllWindows().length ) ).toBe( 1 ); diff --git a/tests/e2e/real-setup/create-site.spec.js b/tests/e2e/real-setup/create-site.spec.js index 93bafc79..d47addab 100644 --- a/tests/e2e/real-setup/create-site.spec.js +++ b/tests/e2e/real-setup/create-site.spec.js @@ -108,6 +108,15 @@ for ( const target of TARGETS ) { expect( html ).toContain( 'id="loginform"' ); expect( html ).toContain( 'name="log"' ); } ).toPass( { timeout: 60_000, intervals: [ 2_000, 5_000 ] } ); + // INVARIANT: the wp-admin link opens the dashboard logged in (#743), + // which takes the constant the server sets and the query the link + // carries to both be the names Playground's auto-login reads. A + // rename on either side lands on the login form instead. + const dashboard = await request.get( adminUrl.href, { timeout: 15_000 } ); + expect( dashboard.status() ).toBe( 200 ); + const dashboardHtml = await dashboard.text(); + expect( dashboardHtml ).toContain( 'id="wpadminbar"' ); + expect( dashboardHtml ).not.toContain( 'id="loginform"' ); if ( target.servedAsPlugin ) { // INVARIANT: the served WordPress runs the checkout as its active // Gutenberg plugin, and cannot delete it. Read off the Plugins diff --git a/tests/unit/playground-plan.test.cjs b/tests/unit/playground-plan.test.cjs index 590f555e..3f121965 100644 --- a/tests/unit/playground-plan.test.cjs +++ b/tests/unit/playground-plan.test.cjs @@ -81,7 +81,8 @@ test('a plugin-mount slug that is not a plain name is refused before it becomes test('a Core site runs as a local environment in core development mode', () => { assert.deepEqual(planServeConstants({ strategy: 'docroot', docroot: '/sites/wp/build' }), { WP_ENVIRONMENT_TYPE: 'local', - WP_DEVELOPMENT_MODE: 'core' + WP_DEVELOPMENT_MODE: 'core', + PLAYGROUND_FORCE_AUTO_LOGIN_ENABLED: true }); // The default strategy is docroot, so it gets the same. assert.deepEqual(planServeConstants({}), planServeConstants({ strategy: 'docroot' })); @@ -93,6 +94,7 @@ test('a Gutenberg site runs as a local environment in plugin development mode, w assert.deepEqual(planServeConstants({ strategy: 'plugin-mount', pluginDir: '/sites/gutenberg', pluginSlug: 'gutenberg' }), { WP_ENVIRONMENT_TYPE: 'local', WP_DEVELOPMENT_MODE: 'plugin', + PLAYGROUND_FORCE_AUTO_LOGIN_ENABLED: true, DISALLOW_FILE_MODS: true, DISALLOW_FILE_EDIT: true }); diff --git a/tests/unit/site-processes.test.cjs b/tests/unit/site-processes.test.cjs index a9c84c40..5d40f8f9 100644 --- a/tests/unit/site-processes.test.cjs +++ b/tests/unit/site-processes.test.cjs @@ -161,12 +161,19 @@ test('a server with no address has nowhere to send anyone', () => { test('a server with an address offers the site and its admin, and its database once it is running', () => { assert.deepEqual(serverLinks({ url: URL }), [ { id: 'site', label: 'View site', href: URL }, - { id: 'admin', label: 'wp-admin', href: `${URL}wp-admin/` } + { id: 'admin', label: 'wp-admin', href: `${URL}wp-admin/?playground_force_auto_login_as_user=admin` } ]); assert.deepEqual(serverLinks({ url: URL, running: true }).at(-1), { id: 'database', label: 'Database', href: `${URL}adminer.php` }); assert.equal(serverLinks({ url: URL, running: true }).length, 3); }); +// The wp-admin link logs in as a user by name (#743): a link naming a user the +// credentials do not would land on the login screen without a word. +test('the wp-admin link logs in as the user the credentials name', () => { + const admin = serverLinks({ url: URL }).find((link) => link.id === 'admin'); + assert.equal(new globalThis.URL(admin.href).searchParams.get('playground_force_auto_login_as_user'), serverSection({ url: URL }).credentials.username); +}); + test('the section of a server with an address shows where the site is and what to log in with', () => { assert.deepEqual(serverSection({ url: URL, running: true }), { state: 'online', diff --git a/tests/unit/site-urls.test.cjs b/tests/unit/site-urls.test.cjs index c5c93674..42e765ce 100644 --- a/tests/unit/site-urls.test.cjs +++ b/tests/unit/site-urls.test.cjs @@ -7,18 +7,18 @@ const { siteUrl, adminUrl, adminerUrl } = require('../../src/renderer/site-urls. // The shape server-runner.js actually produces: `http://127.0.0.1:${port}/`. const RUNNING = 'http://127.0.0.1:8881/'; -test('adminUrl: the admin of a running site (issue #248)', () => { - assert.strictEqual(adminUrl(RUNNING), 'http://127.0.0.1:8881/wp-admin/'); +test('adminUrl: the admin of a running site, asking Playground to log the browser in (issues #248, #743)', () => { + assert.strictEqual(adminUrl(RUNNING), 'http://127.0.0.1:8881/wp-admin/?playground_force_auto_login_as_user=admin'); }); test('adminUrl: keeps the trailing slash WordPress would redirect to (issue #248)', () => { - assert.ok(adminUrl(RUNNING).endsWith('/wp-admin/')); + assert.strictEqual(new URL(adminUrl(RUNNING)).pathname, '/wp-admin/'); }); // The bug the old inline `.replace(/\/$/, '/')` could not catch: it swapped a // trailing slash for a trailing slash. test('adminUrl: a base without a trailing slash does not run the path together (issue #248)', () => { - assert.strictEqual(adminUrl('http://127.0.0.1:8881'), 'http://127.0.0.1:8881/wp-admin/'); + assert.strictEqual(adminUrl('http://127.0.0.1:8881'), 'http://127.0.0.1:8881/wp-admin/?playground_force_auto_login_as_user=admin'); }); test('adminerUrl: matches what the Open Adminer button produced before (issue #248)', () => {