-
-
Notifications
You must be signed in to change notification settings - Fork 3k
fix: carry the pad deletion token across movePad (#7995) #8089
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
Open
JohnMcLear
wants to merge
2
commits into
develop
Choose a base branch
from
fix/7995-move-pad-deletion-token
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,117 @@ | ||
| 'use strict'; | ||
|
|
||
| import {strict as assert} from 'assert'; | ||
|
|
||
| const common = require('../../common'); | ||
| const padDeletionManager = require('../../../../node/db/PadDeletionManager'); | ||
|
|
||
| let agent: any; | ||
| let apiVersion = 1; | ||
|
|
||
| const endPoint = (p: string) => `/api/${apiVersion}/${p}`; | ||
|
|
||
| const makeId = () => `movetok_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`; | ||
|
|
||
| const callApi = async (point: string, query: Record<string, string> = {}) => { | ||
| const qs = new URLSearchParams(query).toString(); | ||
| const path = qs ? `${endPoint(point)}?${qs}` : endPoint(point); | ||
| return await agent.get(path) | ||
| .set('authorization', await common.generateJWTToken()) | ||
| .expect(200) | ||
| .expect('Content-Type', /json/); | ||
| }; | ||
|
|
||
| describe(__filename, function () { | ||
| before(async function () { | ||
| this.timeout(60000); | ||
| agent = await common.init(); | ||
| const res = await agent.get('/api/').expect(200); | ||
| apiVersion = res.body.currentVersion; | ||
| }); | ||
|
|
||
| it('movePad carries the deletionToken to the destination (issue #7995)', async function () { | ||
| const srcId = makeId(); | ||
| const dstId = `${srcId}_dst`; | ||
| const create = await callApi('createPad', {padID: srcId}); | ||
| const token = create.body.data.deletionToken; | ||
| assert.equal(typeof token, 'string'); | ||
|
|
||
| const move = await callApi('movePad', {sourceID: srcId, destinationID: dstId}); | ||
| assert.equal(move.body.code, 0, JSON.stringify(move.body)); | ||
|
|
||
| const del = await callApi('deletePad', {padID: dstId, deletionToken: token}); | ||
| assert.equal(del.body.code, 0, JSON.stringify(del.body)); | ||
| }); | ||
|
|
||
| it('the moved pad does not offer its creator a second token (issue #7995)', async function () { | ||
| const srcId = makeId(); | ||
| const dstId = `${srcId}_dst`; | ||
| await callApi('createPad', {padID: srcId}); | ||
| await callApi('movePad', {sourceID: srcId, destinationID: dstId}); | ||
|
|
||
| // This is what the creator's next CLIENT_READY does. A non-null result here | ||
| // is exactly the second "save your pad deletion token" modal they reported. | ||
| assert.equal(await padDeletionManager.createDeletionTokenIfAbsent(dstId), null); | ||
|
|
||
| await callApi('deletePad', {padID: dstId}); | ||
| }); | ||
|
|
||
| it('movePad --force replaces the destination pad\'s own token', async function () { | ||
| const srcId = makeId(); | ||
| const dstId = `${srcId}_existing`; | ||
| const src = await callApi('createPad', {padID: srcId}); | ||
| const dst = await callApi('createPad', {padID: dstId}); | ||
| const srcToken = src.body.data.deletionToken; | ||
| const dstToken = dst.body.data.deletionToken; | ||
| assert.notEqual(srcToken, dstToken); | ||
|
|
||
| await callApi('movePad', {sourceID: srcId, destinationID: dstId, force: 'true'}); | ||
|
|
||
| // The overwritten pad's content is gone, so its old token must be too. | ||
| const stale = await callApi('deletePad', {padID: dstId, deletionToken: dstToken}); | ||
| assert.equal(stale.body.code, 1, JSON.stringify(stale.body)); | ||
| const del = await callApi('deletePad', {padID: dstId, deletionToken: srcToken}); | ||
| assert.equal(del.body.code, 0, JSON.stringify(del.body)); | ||
| }); | ||
|
|
||
| it('the transfer never invalidates a token the destination already issued', async function () { | ||
| // Pad.copy() writes the destination records before movePad transfers the | ||
| // token, so the creator can open the new id in between and be shown a | ||
| // freshly minted token. That token has been handed out in plaintext, so the | ||
| // transfer must leave it alone rather than overwrite it. | ||
| const srcId = makeId(); | ||
| const dstId = `${srcId}_raced`; | ||
| const src = await callApi('createPad', {padID: srcId}); | ||
| const srcToken = src.body.data.deletionToken; | ||
| const dstToken = await padDeletionManager.createDeletionTokenIfAbsent(dstId); | ||
|
|
||
| await padDeletionManager.transferDeletionToken(srcId, dstId); | ||
|
|
||
| assert.equal(await padDeletionManager.isValidDeletionToken(dstId, dstToken), true); | ||
| assert.equal(await padDeletionManager.isValidDeletionToken(dstId, srcToken), false); | ||
| // The source token survives the transfer — Pad.remove() drops it when the | ||
| // move completes, so a move that fails midway leaves the source deletable. | ||
| assert.equal(await padDeletionManager.isValidDeletionToken(srcId, srcToken), true); | ||
|
|
||
| await padDeletionManager.removeDeletionToken(dstId); | ||
| await callApi('deletePad', {padID: srcId}); | ||
| }); | ||
|
|
||
| it('copyPad does NOT share the source deletionToken with the copy', async function () { | ||
| const srcId = makeId(); | ||
| const dstId = `${srcId}_copy`; | ||
| const create = await callApi('createPad', {padID: srcId}); | ||
| const token = create.body.data.deletionToken; | ||
|
|
||
| const copy = await callApi('copyPad', {sourceID: srcId, destinationID: dstId}); | ||
| assert.equal(copy.body.code, 0, JSON.stringify(copy.body)); | ||
|
|
||
| const del = await callApi('deletePad', {padID: dstId, deletionToken: token}); | ||
| assert.equal(del.body.code, 1, JSON.stringify(del.body)); | ||
| assert.match(del.body.message, /invalid deletionToken/); | ||
|
|
||
| // cleanup | ||
| await callApi('deletePad', {padID: srcId}); | ||
| await callApi('deletePad', {padID: dstId}); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2. Movepad token race
🐞 Bug≡ CorrectnessAgent Prompt
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools