-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API Fetch: refresh nonces as soon as they expired, then fetch again (#…
…16683) * API Fetch: refresh nonces as soon as they expired, then fetch again * Use exit() * Fix PHP linting errors
- Loading branch information
Showing
5 changed files
with
93 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
/** | ||
* Plugin Name: Gutenberg Test Plugin, Nonce | ||
* Plugin URI: https://github.com/WordPress/gutenberg | ||
* Author: Gutenberg Team | ||
* | ||
* @package gutenberg-test-plugin-nonce | ||
*/ | ||
|
||
/** | ||
* Returns the nonce life time. | ||
*/ | ||
function gutenberg_test_plugin_nonce_life() { | ||
return 5; | ||
} | ||
add_filter( 'nonce_life', 'gutenberg_test_plugin_nonce_life' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
activatePlugin, | ||
createNewPost, | ||
deactivatePlugin, | ||
saveDraft, | ||
} from '@wordpress/e2e-test-utils'; | ||
|
||
describe( 'Nonce', () => { | ||
beforeAll( async () => { | ||
await activatePlugin( 'gutenberg-test-plugin-nonce' ); | ||
} ); | ||
|
||
afterAll( async () => { | ||
await deactivatePlugin( 'gutenberg-test-plugin-nonce' ); | ||
} ); | ||
|
||
beforeEach( async () => { | ||
await createNewPost(); | ||
} ); | ||
|
||
it( 'should refresh when expired', async () => { | ||
await page.keyboard.press( 'Enter' ); | ||
// eslint-disable-next-line no-restricted-syntax | ||
await page.waitFor( 5000 ); | ||
await page.keyboard.type( 'test' ); | ||
// `saveDraft` waits for saving to be successful, so this test would | ||
// timeout if it's not. | ||
await saveDraft(); | ||
// We expect a 403 status once. | ||
expect( console ).toHaveErrored(); | ||
} ); | ||
} ); |
Is it possible to include this behavior in the nonce middleware instead? Ideally, the raw apiFetch doesn't have any specific thing like that.