|
1 | 1 | <?php |
2 | 2 |
|
3 | | -test('manager global tabs refresh persisted csrf tokens before restoring urls', function () { |
| 3 | +test('manager global tabs delegate token-free storage and audited restoration to the shared helper', function () { |
4 | 4 | $frame = file_get_contents(dirname(__DIR__, 4) . '/manager/views/frame/1.blade.php'); |
5 | 5 |
|
6 | 6 | expect($frame) |
7 | | - ->toContain('csrf_token: @js(csrf_token())'); |
| 7 | + ->toMatch('~<meta\s+name="csrf-token"\s+content="\{\{ csrf_token\(\) \}\}"\s*/?>~') |
| 8 | + ->toContain("config('cms.manager_tab_restore.modules'") |
| 9 | + ->toContain('tab_restore_user:'); |
8 | 10 |
|
9 | 11 | $script = file_get_contents(dirname(__DIR__, 4) . '/manager/media/style/default/js/evo.js'); |
10 | 12 |
|
11 | 13 | expect($script) |
12 | | - ->toContain("tabsCsrfPlaceholder: '__EVO_CSRF_TOKEN__'") |
| 14 | + ->not->toContain('__EVO_CSRF_TOKEN__') |
13 | 15 | ->toContain('tabUrlForStorage: function (url)') |
14 | 16 | ->toContain('tabUrlForRestore: function (url)') |
| 17 | + ->toContain('w.evoManagerTabState.storage(url, evo.tabsRestoreOptions())') |
| 18 | + ->toContain('w.evoManagerTabState.restore(url, evo.tabsRestoreOptions())') |
15 | 19 | ->toContain('url: evo.tabUrlForStorage(url)') |
16 | 20 | ->toContain('active: evo.tabUrlForStorage(activeUrl)') |
17 | | - ->toContain('url: evo.tabUrlForRestore(tab.url)') |
18 | | - ->toContain('url: evo.tabUrlForRestore(data.active)') |
19 | | - ->toContain('evo.tabUrlForRestore(href)') |
| 21 | + ->toContain('var tabUrl = evo.tabUrlForRestore(tab.url)') |
| 22 | + ->toContain('var activeUrl = evo.tabUrlForRestore(data.active)') |
| 23 | + ->toContain('startupUrl = evo.tabUrlForRestore(w.location.href)') |
| 24 | + ->toContain('token: evo.tabsCsrfToken()') |
| 25 | + ->toContain('modules: evo.config.tab_restore_modules') |
| 26 | + ->toContain("'EVO_Tabs:' + encodeURIComponent(evo.EVO_MANAGER_URL) + ':' + evo.config.tab_restore_user") |
20 | 27 | ->toContain("localStorage.setItem('page_url', evo.tabUrlForStorage(b))"); |
| 28 | + |
| 29 | + // Runtime URL validation and stale-token cases live in manager-tab-state.test.js. |
| 30 | + $helper = file_get_contents(dirname(__DIR__, 4) . '/manager/media/script/manager-tab-state.js'); |
| 31 | + expect($helper) |
| 32 | + ->toContain("target.searchParams.delete('_token')") |
| 33 | + ->toContain("target.searchParams.set('_token', options.token)") |
| 34 | + ->toContain('var target = read(url, options)') |
| 35 | + ->toContain("if (!target || !options.token) return ''"); |
21 | 36 | }); |
0 commit comments