From b9fb1805893ffa0f7060de8213dcd86586b6e706 Mon Sep 17 00:00:00 2001 From: Eric Doughty-Papassideris Date: Mon, 27 May 2024 20:58:29 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20Add=20trash=20of=20anonymous=20file?= =?UTF-8?q?=20e2e=20tests=20=20(#433)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/node/test/e2e/common/user-api.ts | 7 ++ .../node/test/e2e/documents/trash.spec.ts | 66 ++++++++++++++----- 2 files changed, 55 insertions(+), 18 deletions(-) diff --git a/tdrive/backend/node/test/e2e/common/user-api.ts b/tdrive/backend/node/test/e2e/common/user-api.ts index e0baac94..e31347c4 100644 --- a/tdrive/backend/node/test/e2e/common/user-api.ts +++ b/tdrive/backend/node/test/e2e/common/user-api.ts @@ -245,6 +245,13 @@ export default class UserApi { return result; } + /** Gets the public link access token then `impersonateWithJWT` as an anonymous user with that link */ + async impersonatePublicLinkAccessOf(item: Partial & { id: string }, cb: () => Promise): Promise { + const publicToken = await this.getPublicLinkAccessToken(item); + expect(publicToken?.value?.length ?? "").toBeGreaterThan(0); + return this.impersonateWithJWT(publicToken?.value, cb); + } + async createDocument( item: Partial, version: Partial diff --git a/tdrive/backend/node/test/e2e/documents/trash.spec.ts b/tdrive/backend/node/test/e2e/documents/trash.spec.ts index 683e1ae0..fd3decf6 100644 --- a/tdrive/backend/node/test/e2e/documents/trash.spec.ts +++ b/tdrive/backend/node/test/e2e/documents/trash.spec.ts @@ -73,7 +73,7 @@ describe("the Drive's documents' trash feature", () => { }); describe("deleting a file uploaded by an anonymous user should go to the sharers trash", () => { - async function getTrashContentIds() { + async function getCurrentUsersTrashContentIds() { const listTrashResponse = await currentUser.getDocument("trash"); expect(listTrashResponse.statusCode).toBe(200); const listTrashResult = deserialize( @@ -83,26 +83,61 @@ describe("the Drive's documents' trash feature", () => { return listTrashResult.children.map(({id}) => id); } - async function uploadFileAsAnonymousUser(destinationSharedFolder: DriveFile) { - const publicToken = await currentUser.getPublicLinkAccessToken(destinationSharedFolder); - expect(publicToken?.value?.length ?? "").toBeGreaterThan(0); - return await currentUser.impersonateWithJWT(publicToken.value, () => - currentUser.createDefaultDocument({ - parent_id: destinationSharedFolder.id, - })); - } - it("finds the owner from the immediate parent folder", async () => { const publiclyWriteableFolder = await currentUser.createDirectory(); const setPublicWriteableResponse = await currentUser.shareWithPublicLink(publiclyWriteableFolder, "write"); expect(setPublicWriteableResponse.statusCode).toBe(200); - const anonymouslyUploadedDoc = await uploadFileAsAnonymousUser(publiclyWriteableFolder); + const anonymouslyUploadedDoc = await currentUser.impersonatePublicLinkAccessOf(publiclyWriteableFolder, () => + currentUser.createDefaultDocument({ + parent_id: publiclyWriteableFolder.id, + })); + expect(publiclyWriteableFolder.creator).toEqual(currentUser.user.id); + expect(anonymouslyUploadedDoc.creator).not.toEqual(currentUser.user.id); const deletionToTrashResponse = await currentUser.delete(anonymouslyUploadedDoc.id); expect(deletionToTrashResponse.statusCode).toBe(200); - expect((await getTrashContentIds())).toContain(anonymouslyUploadedDoc.id); + expect((await getCurrentUsersTrashContentIds())).toContain(anonymouslyUploadedDoc.id); + }); + + it("finds the owner from the indirect parent folder", async () => { + const publiclyWriteableFolder = await currentUser.createDirectory(); + const setPublicWriteableResponse = await currentUser.shareWithPublicLink(publiclyWriteableFolder, "write"); + expect(setPublicWriteableResponse.statusCode).toBe(200); + + const anonymouslyUploadedDoc = await currentUser.impersonatePublicLinkAccessOf(publiclyWriteableFolder, async () => { + const anonymouslyCreatedFolder = await currentUser.createDirectory(publiclyWriteableFolder.id); + expect(anonymouslyCreatedFolder.creator).not.toEqual(currentUser.user.id); + return currentUser.createDefaultDocument({ + parent_id: anonymouslyCreatedFolder.id, + }) + }); + expect(publiclyWriteableFolder.creator).toEqual(currentUser.user.id); + expect(anonymouslyUploadedDoc.creator).not.toEqual(currentUser.user.id); + + const deletionToTrashResponse = await currentUser.delete(anonymouslyUploadedDoc.id); + expect(deletionToTrashResponse.statusCode).toBe(200); + + expect((await getCurrentUsersTrashContentIds())).toContain(anonymouslyUploadedDoc.id); + }); + + it.only("goes into the sharers trash even if another user deletes the file", async () => { + const publiclyWriteableFolder = await currentUser.createDirectory(); + const setPublicWriteableResponse = await currentUser.shareWithPublicLink(publiclyWriteableFolder, "write"); + expect(setPublicWriteableResponse.statusCode).toBe(200); + + const anonymouslyUploadedDoc = await currentUser.impersonatePublicLinkAccessOf(publiclyWriteableFolder, () => + currentUser.createDefaultDocument({ + parent_id: publiclyWriteableFolder.id, + })); + + const secondaryUser = await UserApi.getInstance(platform!); + + const deletionToTrashResponse = await secondaryUser.delete(anonymouslyUploadedDoc.id); + expect(deletionToTrashResponse.statusCode).toBe(200); + + expect((await getCurrentUsersTrashContentIds())).toContain(anonymouslyUploadedDoc.id); }); it("If anonymous user deletes the files in should be in the users trash", async () => { @@ -118,12 +153,7 @@ describe("the Drive's documents' trash feature", () => { const deletionToTrashResponse = await anonymousUser.delete(anonymouslyUploadedDoc.id); expect(deletionToTrashResponse.statusCode).toBe(200); - expect((await getTrashContentIds())).toContain(anonymouslyUploadedDoc.id); + expect((await getCurrentUsersTrashContentIds())).toContain(anonymouslyUploadedDoc.id); }); - - it("if another user deletes the files it should be in the users trash", async () => { - //TODO - }); - }); }); \ No newline at end of file