From ccdb87d28b18b6b63cd2809233f1ec08cfc56d81 Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Fri, 28 Apr 2023 06:38:26 +0200 Subject: [PATCH 1/2] make workspaceKeyBox mandator --- apps/app/components/page/Page.tsx | 2 +- apps/app/components/sidebarFolder/SidebarFolder.tsx | 12 ++++++------ apps/app/components/sidebarPage/SidebarPage.tsx | 2 +- apps/app/generated/graphql.ts | 10 +++++----- .../createNewSnapshotKey/createNewSnapshotKey.ts | 2 +- .../deriveExistingSnapshotKey.ts | 2 +- apps/app/utils/document/documentPathStore.ts | 2 +- apps/app/utils/document/updateDocumentName.ts | 1 - apps/app/utils/folder/folderKeyStore.ts | 2 +- apps/backend/src/graphql/types/workspace.ts | 2 +- 10 files changed, 18 insertions(+), 19 deletions(-) diff --git a/apps/app/components/page/Page.tsx b/apps/app/components/page/Page.tsx index 380207076..781b1a902 100644 --- a/apps/app/components/page/Page.tsx +++ b/apps/app/components/page/Page.tsx @@ -137,7 +137,7 @@ export default function Page({ snapshot: { keyDerivationTrace: snapshotKeyData.keyDerivationTrace, }, - workspaceKeyBox: workspace.currentWorkspaceKey.workspaceKeyBox!, + workspaceKeyBox: workspace.currentWorkspaceKey.workspaceKeyBox, }); return { diff --git a/apps/app/components/sidebarFolder/SidebarFolder.tsx b/apps/app/components/sidebarFolder/SidebarFolder.tsx index f684c31de..b034bfe4f 100644 --- a/apps/app/components/sidebarFolder/SidebarFolder.tsx +++ b/apps/app/components/sidebarFolder/SidebarFolder.tsx @@ -147,7 +147,7 @@ export default function SidebarFolder(props: Props) { try { const parentKeyChainData = deriveKeysFromKeyDerivationTrace({ keyDerivationTrace: props.keyDerivationTrace, - workspaceKeyBox: folderWorkspaceKey.workspaceKeyBox!, + workspaceKeyBox: folderWorkspaceKey.workspaceKeyBox, activeDevice: { signingPublicKey: activeDevice.signingPublicKey, signingPrivateKey: activeDevice.signingPrivateKey!, @@ -201,7 +201,7 @@ export default function SidebarFolder(props: Props) { encryptionPublicKeySignature: activeDevice.encryptionPublicKeySignature!, }, - workspaceKeyBox: workspace.currentWorkspaceKey.workspaceKeyBox!, + workspaceKeyBox: workspace.currentWorkspaceKey.workspaceKeyBox, }); const parentChainItem = parentFolderKeyChainData.trace[parentFolderKeyChainData.trace.length - 1]; @@ -270,7 +270,7 @@ export default function SidebarFolder(props: Props) { } const folderKeyTrace = deriveKeysFromKeyDerivationTrace({ keyDerivationTrace: props.keyDerivationTrace, - workspaceKeyBox: workspace.currentWorkspaceKey.workspaceKeyBox!, + workspaceKeyBox: workspace.currentWorkspaceKey.workspaceKeyBox, activeDevice: { signingPublicKey: activeDevice.signingPublicKey, signingPrivateKey: activeDevice.signingPrivateKey!, @@ -327,7 +327,7 @@ export default function SidebarFolder(props: Props) { snapshot: { keyDerivationTrace: snapshot.publicData.keyDerivationTrace, }, - workspaceKeyBox: workspace.currentWorkspaceKey.workspaceKeyBox!, + workspaceKeyBox: workspace.currentWorkspaceKey.workspaceKeyBox, }); const result = await runCreateDocumentMutation( { @@ -399,7 +399,7 @@ export default function SidebarFolder(props: Props) { if (!workspace) { throw new Error("Workspace not found"); } - if (!workspace.currentWorkspaceKey!.workspaceKeyBox) { + if (!workspace.currentWorkspaceKey?.workspaceKeyBox) { throw new Error("no workspace key boxes for this workspace"); } const workspaceKeyData = await deriveWorkspaceKey({ @@ -418,7 +418,7 @@ export default function SidebarFolder(props: Props) { encryptionPublicKeySignature: activeDevice.encryptionPublicKeySignature!, }, - workspaceKeyBox: workspace.currentWorkspaceKey!.workspaceKeyBox!, + workspaceKeyBox: workspace.currentWorkspaceKey.workspaceKeyBox, }); // ignore the last chain item as it's the key for the old folder name let parentKey = workspaceKey; diff --git a/apps/app/components/sidebarPage/SidebarPage.tsx b/apps/app/components/sidebarPage/SidebarPage.tsx index 94ec99d19..ed801eb8f 100644 --- a/apps/app/components/sidebarPage/SidebarPage.tsx +++ b/apps/app/components/sidebarPage/SidebarPage.tsx @@ -104,7 +104,7 @@ export default function SidebarPage(props: Props) { snapshot: { keyDerivationTrace: snapshot.keyDerivationTrace, }, - workspaceKeyBox: documentWorkspaceKey.workspaceKeyBox!, + workspaceKeyBox: documentWorkspaceKey.workspaceKeyBox, }); setDocumentTitle(documentTitle); documentTitleStore.updateDocumentTitle({ diff --git a/apps/app/generated/graphql.ts b/apps/app/generated/graphql.ts index 95665ea08..aedd7cb7d 100644 --- a/apps/app/generated/graphql.ts +++ b/apps/app/generated/graphql.ts @@ -1300,7 +1300,7 @@ export type WorkspaceKey = { generation: Scalars['Int']; id: Scalars['String']; workspaceId: Scalars['String']; - workspaceKeyBox?: Maybe; + workspaceKeyBox: WorkspaceKeyBox; workspaceKeyBoxes?: Maybe>; }; @@ -1387,7 +1387,7 @@ export type AttachDeviceToWorkspacesMutationVariables = Exact<{ }>; -export type AttachDeviceToWorkspacesMutation = { __typename?: 'Mutation', attachDeviceToWorkspaces?: { __typename?: 'AttachDeviceToWorkspacesResult', workspaceKeys: Array<{ __typename?: 'WorkspaceKey', id: string, generation: number, workspaceId: string, workspaceKeyBox?: { __typename?: 'WorkspaceKeyBox', id: string, deviceSigningPublicKey: string, creatorDeviceSigningPublicKey: string, ciphertext: string, nonce: string, creatorDevice: { __typename?: 'CreatorDevice', signingPublicKey: string, encryptionPublicKey: string } } | null }> } | null }; +export type AttachDeviceToWorkspacesMutation = { __typename?: 'Mutation', attachDeviceToWorkspaces?: { __typename?: 'AttachDeviceToWorkspacesResult', workspaceKeys: Array<{ __typename?: 'WorkspaceKey', id: string, generation: number, workspaceId: string, workspaceKeyBox: { __typename?: 'WorkspaceKeyBox', id: string, deviceSigningPublicKey: string, creatorDeviceSigningPublicKey: string, ciphertext: string, nonce: string, creatorDevice: { __typename?: 'CreatorDevice', signingPublicKey: string, encryptionPublicKey: string } } }> } | null }; export type AttachDevicesToWorkspacesMutationVariables = Exact<{ input: AttachDevicesToWorkspacesInput; @@ -1436,7 +1436,7 @@ export type CreateInitialWorkspaceStructureMutationVariables = Exact<{ }>; -export type CreateInitialWorkspaceStructureMutation = { __typename?: 'Mutation', createInitialWorkspaceStructure?: { __typename?: 'CreateInitialWorkspaceStructureResult', workspace?: { __typename?: 'Workspace', id: string, name?: string | null, members?: Array<{ __typename?: 'WorkspaceMember', userId: string, role: Role }> | null, currentWorkspaceKey?: { __typename?: 'WorkspaceKey', id: string, workspaceId: string, generation: number, workspaceKeyBox?: { __typename?: 'WorkspaceKeyBox', id: string, workspaceKeyId: string, deviceSigningPublicKey: string, ciphertext: string, creatorDevice: { __typename?: 'CreatorDevice', signingPublicKey: string, encryptionPublicKey: string } } | null } | null } | null, folder?: { __typename?: 'Folder', id: string, nameCiphertext: string, nameNonce: string, parentFolderId?: string | null, rootFolderId?: string | null, workspaceId?: string | null, keyDerivationTrace: { __typename?: 'KeyDerivationTrace', workspaceKeyId: string, trace: Array<{ __typename?: 'KeyDerivationTraceEntry', entryId: string, subkeyId: number, parentId?: string | null, context: string }> } } | null, document?: { __typename?: 'Document', id: string } | null, snapshot?: { __typename?: 'Snapshot', id: string, latestVersion: number, data: string, documentId: string, keyDerivationTrace: { __typename?: 'KeyDerivationTrace', workspaceKeyId: string, trace: Array<{ __typename?: 'KeyDerivationTraceEntry', entryId: string, subkeyId: number, parentId?: string | null, context: string }> } } | null } | null }; +export type CreateInitialWorkspaceStructureMutation = { __typename?: 'Mutation', createInitialWorkspaceStructure?: { __typename?: 'CreateInitialWorkspaceStructureResult', workspace?: { __typename?: 'Workspace', id: string, name?: string | null, members?: Array<{ __typename?: 'WorkspaceMember', userId: string, role: Role }> | null, currentWorkspaceKey?: { __typename?: 'WorkspaceKey', id: string, workspaceId: string, generation: number, workspaceKeyBox: { __typename?: 'WorkspaceKeyBox', id: string, workspaceKeyId: string, deviceSigningPublicKey: string, ciphertext: string, creatorDevice: { __typename?: 'CreatorDevice', signingPublicKey: string, encryptionPublicKey: string } } } | null } | null, folder?: { __typename?: 'Folder', id: string, nameCiphertext: string, nameNonce: string, parentFolderId?: string | null, rootFolderId?: string | null, workspaceId?: string | null, keyDerivationTrace: { __typename?: 'KeyDerivationTrace', workspaceKeyId: string, trace: Array<{ __typename?: 'KeyDerivationTraceEntry', entryId: string, subkeyId: number, parentId?: string | null, context: string }> } } | null, document?: { __typename?: 'Document', id: string } | null, snapshot?: { __typename?: 'Snapshot', id: string, latestVersion: number, data: string, documentId: string, keyDerivationTrace: { __typename?: 'KeyDerivationTrace', workspaceKeyId: string, trace: Array<{ __typename?: 'KeyDerivationTraceEntry', entryId: string, subkeyId: number, parentId?: string | null, context: string }> } } | null } | null }; export type CreateWorkspaceInvitationMutationVariables = Exact<{ input: CreateWorkspaceInvitationInput; @@ -1752,7 +1752,7 @@ export type WorkspaceQueryVariables = Exact<{ }>; -export type WorkspaceQuery = { __typename?: 'Query', workspace?: { __typename?: 'Workspace', id: string, name?: string | null, members?: Array<{ __typename?: 'WorkspaceMember', userId: string, username?: string | null, role: Role, devices?: Array<{ __typename?: 'MinimalDevice', signingPublicKey: string, encryptionPublicKey: string, encryptionPublicKeySignature: string }> | null }> | null, currentWorkspaceKey?: { __typename?: 'WorkspaceKey', id: string, workspaceId: string, workspaceKeyBox?: { __typename?: 'WorkspaceKeyBox', id: string, workspaceKeyId: string, deviceSigningPublicKey: string, ciphertext: string, nonce: string, creatorDevice: { __typename?: 'CreatorDevice', signingPublicKey: string, encryptionPublicKey: string } } | null } | null, workspaceKeys?: Array<{ __typename?: 'WorkspaceKey', id: string, workspaceId: string, generation: number, workspaceKeyBox?: { __typename?: 'WorkspaceKeyBox', id: string, workspaceKeyId: string, deviceSigningPublicKey: string, ciphertext: string, nonce: string, creatorDevice: { __typename?: 'CreatorDevice', signingPublicKey: string, encryptionPublicKey: string } } | null }> | null } | null }; +export type WorkspaceQuery = { __typename?: 'Query', workspace?: { __typename?: 'Workspace', id: string, name?: string | null, members?: Array<{ __typename?: 'WorkspaceMember', userId: string, username?: string | null, role: Role, devices?: Array<{ __typename?: 'MinimalDevice', signingPublicKey: string, encryptionPublicKey: string, encryptionPublicKeySignature: string }> | null }> | null, currentWorkspaceKey?: { __typename?: 'WorkspaceKey', id: string, workspaceId: string, workspaceKeyBox: { __typename?: 'WorkspaceKeyBox', id: string, workspaceKeyId: string, deviceSigningPublicKey: string, ciphertext: string, nonce: string, creatorDevice: { __typename?: 'CreatorDevice', signingPublicKey: string, encryptionPublicKey: string } } } | null, workspaceKeys?: Array<{ __typename?: 'WorkspaceKey', id: string, workspaceId: string, generation: number, workspaceKeyBox: { __typename?: 'WorkspaceKeyBox', id: string, workspaceKeyId: string, deviceSigningPublicKey: string, ciphertext: string, nonce: string, creatorDevice: { __typename?: 'CreatorDevice', signingPublicKey: string, encryptionPublicKey: string } } }> | null } | null }; export type WorkspaceDevicesQueryVariables = Exact<{ workspaceId: Scalars['ID']; @@ -1780,7 +1780,7 @@ export type WorkspacesQueryVariables = Exact<{ }>; -export type WorkspacesQuery = { __typename?: 'Query', workspaces?: { __typename?: 'WorkspaceConnection', nodes?: Array<{ __typename?: 'Workspace', id: string, name?: string | null, members?: Array<{ __typename?: 'WorkspaceMember', userId: string, role: Role }> | null, currentWorkspaceKey?: { __typename?: 'WorkspaceKey', id: string, workspaceId: string, generation: number, workspaceKeyBox?: { __typename?: 'WorkspaceKeyBox', id: string, workspaceKeyId: string, deviceSigningPublicKey: string, ciphertext: string, nonce: string, creatorDevice: { __typename?: 'CreatorDevice', signingPublicKey: string, encryptionPublicKey: string } } | null } | null, workspaceKeys?: Array<{ __typename?: 'WorkspaceKey', id: string, workspaceId: string, generation: number, workspaceKeyBox?: { __typename?: 'WorkspaceKeyBox', id: string, workspaceKeyId: string, deviceSigningPublicKey: string, ciphertext: string, nonce: string, creatorDevice: { __typename?: 'CreatorDevice', signingPublicKey: string, encryptionPublicKey: string } } | null }> | null } | null> | null } | null }; +export type WorkspacesQuery = { __typename?: 'Query', workspaces?: { __typename?: 'WorkspaceConnection', nodes?: Array<{ __typename?: 'Workspace', id: string, name?: string | null, members?: Array<{ __typename?: 'WorkspaceMember', userId: string, role: Role }> | null, currentWorkspaceKey?: { __typename?: 'WorkspaceKey', id: string, workspaceId: string, generation: number, workspaceKeyBox: { __typename?: 'WorkspaceKeyBox', id: string, workspaceKeyId: string, deviceSigningPublicKey: string, ciphertext: string, nonce: string, creatorDevice: { __typename?: 'CreatorDevice', signingPublicKey: string, encryptionPublicKey: string } } } | null, workspaceKeys?: Array<{ __typename?: 'WorkspaceKey', id: string, workspaceId: string, generation: number, workspaceKeyBox: { __typename?: 'WorkspaceKeyBox', id: string, workspaceKeyId: string, deviceSigningPublicKey: string, ciphertext: string, nonce: string, creatorDevice: { __typename?: 'CreatorDevice', signingPublicKey: string, encryptionPublicKey: string } } }> | null } | null> | null } | null }; export const AcceptWorkspaceInvitationDocument = gql` diff --git a/apps/app/utils/createNewSnapshotKey/createNewSnapshotKey.ts b/apps/app/utils/createNewSnapshotKey/createNewSnapshotKey.ts index ea0c2967a..51db80245 100644 --- a/apps/app/utils/createNewSnapshotKey/createNewSnapshotKey.ts +++ b/apps/app/utils/createNewSnapshotKey/createNewSnapshotKey.ts @@ -41,7 +41,7 @@ export const createNewSnapshotKey = async ({ encryptionPrivateKey: activeDevice.encryptionPrivateKey!, encryptionPublicKeySignature: activeDevice.encryptionPublicKeySignature!, }, - workspaceKeyBox: workspace.currentWorkspaceKey.workspaceKeyBox!, + workspaceKeyBox: workspace.currentWorkspaceKey.workspaceKeyBox, }); const parentFolderChainItem = diff --git a/apps/app/utils/deriveExistingSnapshotKey/deriveExistingSnapshotKey.ts b/apps/app/utils/deriveExistingSnapshotKey/deriveExistingSnapshotKey.ts index d1ddc4559..360208a7b 100644 --- a/apps/app/utils/deriveExistingSnapshotKey/deriveExistingSnapshotKey.ts +++ b/apps/app/utils/deriveExistingSnapshotKey/deriveExistingSnapshotKey.ts @@ -31,7 +31,7 @@ export const deriveExistingSnapshotKey = async ( encryptionPrivateKey: activeDevice.encryptionPrivateKey!, encryptionPublicKeySignature: activeDevice.encryptionPublicKeySignature!, }, - workspaceKeyBox: workspace?.currentWorkspaceKey.workspaceKeyBox!, + workspaceKeyBox: workspace.currentWorkspaceKey.workspaceKeyBox, }); const folderChainItem = folderKeyChainData.trace[folderKeyChainData.trace.length - 2]; diff --git a/apps/app/utils/document/documentPathStore.ts b/apps/app/utils/document/documentPathStore.ts index 03d502784..8c900e270 100644 --- a/apps/app/utils/document/documentPathStore.ts +++ b/apps/app/utils/document/documentPathStore.ts @@ -87,7 +87,7 @@ export const useDocumentPathStore = create((set, get) => ({ encryptionPublicKeySignature: activeDevice.encryptionPublicKeySignature!, }, - workspaceKeyBox: folderWorkspaceKey.workspaceKeyBox!, + workspaceKeyBox: folderWorkspaceKey.workspaceKeyBox, }); // since decryptFolderName also derives the folder subkey, // we can pass the parentKeyTrace's parent key to it diff --git a/apps/app/utils/document/updateDocumentName.ts b/apps/app/utils/document/updateDocumentName.ts index e5c405865..00fd356dd 100644 --- a/apps/app/utils/document/updateDocumentName.ts +++ b/apps/app/utils/document/updateDocumentName.ts @@ -35,7 +35,6 @@ export const updateDocumentName = async ({ const encryptedDocumentTitle = encryptDocumentTitle({ title: name, activeDevice, - // @ts-expect-error workspaceKeyBox: workspace.currentWorkspaceKey.workspaceKeyBox, snapshot: snapshotResult.data.snapshot, }); diff --git a/apps/app/utils/folder/folderKeyStore.ts b/apps/app/utils/folder/folderKeyStore.ts index 7a87d8f77..7d3b21202 100644 --- a/apps/app/utils/folder/folderKeyStore.ts +++ b/apps/app/utils/folder/folderKeyStore.ts @@ -125,7 +125,7 @@ export const useFolderKeyStore = create((set, get) => ({ encryptionPublicKeySignature: activeDevice.encryptionPublicKeySignature!, }, - workspaceKeyBox: workspace!.currentWorkspaceKey.workspaceKeyBox!, + workspaceKeyBox: workspace.currentWorkspaceKey.workspaceKeyBox, }); folderKey = derivedFolderKeyData.trace[derivedFolderKeyData.trace.length - 1].key; diff --git a/apps/backend/src/graphql/types/workspace.ts b/apps/backend/src/graphql/types/workspace.ts index e4e8e00ce..fddf0de6c 100644 --- a/apps/backend/src/graphql/types/workspace.ts +++ b/apps/backend/src/graphql/types/workspace.ts @@ -36,7 +36,7 @@ export const WorkspaceKey = objectType({ t.nonNull.string("id"); t.nonNull.string("workspaceId"); t.nonNull.int("generation"); - t.field("workspaceKeyBox", { + t.nonNull.field("workspaceKeyBox", { type: WorkspaceKeyBox, }); t.list.nonNull.field("workspaceKeyBoxes", { From 8d99946d2df99295ebc4cd3bc2eed08ebe7c0d7d Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Fri, 28 Apr 2023 14:47:04 +0200 Subject: [PATCH 2/2] fix tests --- .../database/workspace/rotateWorkspaceKey.ts | 10 +++--- ...removeMembersAndRotateWorkspaceKey.test.ts | 36 +++++++++++++------ .../document/workspaceKeyByDocumentId.test.ts | 22 ++++++------ apps/backend/src/types/workspace.ts | 4 +-- 4 files changed, 42 insertions(+), 30 deletions(-) diff --git a/apps/backend/src/database/workspace/rotateWorkspaceKey.ts b/apps/backend/src/database/workspace/rotateWorkspaceKey.ts index 458eb68a0..01fd72811 100644 --- a/apps/backend/src/database/workspace/rotateWorkspaceKey.ts +++ b/apps/backend/src/database/workspace/rotateWorkspaceKey.ts @@ -26,7 +26,7 @@ export const rotateWorkspaceKey = async ({ if (!user) { throw new ForbiddenError("Unauthorized"); } - const verifedUserWorkspace = await prisma.usersToWorkspaces.findMany({ + const verifiedUserWorkspace = await prisma.usersToWorkspaces.findMany({ where: { userId, role: Role.ADMIN, @@ -35,7 +35,7 @@ export const rotateWorkspaceKey = async ({ }, select: { workspaceId: true }, }); - if (!verifedUserWorkspace) { + if (!verifiedUserWorkspace) { throw new ForbiddenError("Unauthorized"); } @@ -92,7 +92,7 @@ export const rotateWorkspaceKey = async ({ const createdWorkspaceKeyBoxes = await prisma.workspaceKeyBox.findMany({ where: { workspaceKeyId: newWorkspaceKey.id }, }); - const returnedWorskpaceKey: WorkspaceKey = newWorkspaceKey; - returnedWorskpaceKey.workspaceKeyBoxes = createdWorkspaceKeyBoxes; - return returnedWorskpaceKey; + const returnedWorkspaceKey: WorkspaceKey = newWorkspaceKey; + returnedWorkspaceKey.workspaceKeyBoxes = createdWorkspaceKeyBoxes; + return returnedWorkspaceKey; }; diff --git a/apps/backend/src/graphql/mutations/workspace/removeMembersAndRotateWorkspaceKey.test.ts b/apps/backend/src/graphql/mutations/workspace/removeMembersAndRotateWorkspaceKey.test.ts index 870b508f9..af1afa9c8 100644 --- a/apps/backend/src/graphql/mutations/workspace/removeMembersAndRotateWorkspaceKey.test.ts +++ b/apps/backend/src/graphql/mutations/workspace/removeMembersAndRotateWorkspaceKey.test.ts @@ -356,21 +356,35 @@ test("user can rotate key for multiple devices", async () => { workspaceInvitationResult.invitationSigningPrivateKey, authorizationHeader: userData2.sessionKey, }); - const user2DeviceKeyBox = encryptWorkspaceKeyForDevice({ - receiverDeviceEncryptionPublicKey: userData1.device.signingPublicKey, - creatorDeviceEncryptionPrivateKey: userData1.deviceEncryptionPrivateKey, - workspaceKey, + + const workspaceResult2 = await getWorkspace({ + graphql, + workspaceId: userData1.workspace.id, + deviceSigningPublicKey: userData1.webDevice.signingPublicKey, + authorizationHeader: userData1.sessionKey, }); + + const workspace2 = workspaceResult2.workspace; + const workspaceKeyDevicePairs = workspace2.workspaceKeys.map( + (workspaceKeyData) => { + const user2DeviceKeyBox = encryptWorkspaceKeyForDevice({ + receiverDeviceEncryptionPublicKey: userData2.device.encryptionPublicKey, + creatorDeviceEncryptionPrivateKey: userData1.deviceEncryptionPrivateKey, + // TODO this is not correct, we should put the correct workspaceKey her based on the workspaceKeyData + workspaceKey, + }); + return { + workspaceKeyId: workspaceKeyData.id, + nonce: user2DeviceKeyBox.nonce, + ciphertext: user2DeviceKeyBox.ciphertext, + }; + } + ); + const user2DeviceKeyBoxes = [ { workspaceId: userData1.workspace.id, - workspaceKeyDevicePairs: [ - { - workspaceKeyId: userData1.workspace.currentWorkspaceKey.id, - nonce: user2DeviceKeyBox.nonce, - ciphertext: user2DeviceKeyBox.nonce, - }, - ], + workspaceKeyDevicePairs, }, ]; await attachDeviceToWorkspaces({ diff --git a/apps/backend/src/graphql/queries/document/workspaceKeyByDocumentId.test.ts b/apps/backend/src/graphql/queries/document/workspaceKeyByDocumentId.test.ts index 2518c4a7e..3bbe58dd8 100644 --- a/apps/backend/src/graphql/queries/document/workspaceKeyByDocumentId.test.ts +++ b/apps/backend/src/graphql/queries/document/workspaceKeyByDocumentId.test.ts @@ -73,7 +73,7 @@ test("key for main workspace, main device", async () => { expect(workspaceKey.workspaceId).toBe(userData1.workspace.id); }); -test("empty keys on incomplete workspace share", async () => { +test("throws error on incomplete workspace share", async () => { // create new user const userData2 = await createUserWithWorkspace({ id: generateId(), @@ -100,17 +100,15 @@ test("empty keys on incomplete workspace share", async () => { inviteeMainDevice: userData2.mainDevice, authorizationHeader: userData2.sessionKey, }); - const workspaceKeyResult = await getWorkspaceKeyByDocumentId({ - graphql, - documentId: userData1.document.id, - deviceSigningPublicKey: userData2.webDevice.signingPublicKey, - authorizationHeader: userData2.sessionKey, - }); - const workspaceKey = - workspaceKeyResult.workspaceKeyByDocumentId.nameWorkspaceKey; - expect(workspaceKey.generation).toBe(0); - expect(workspaceKey.workspaceKeyBox).toBe(null); - expect(workspaceKey.workspaceId).toBe(userData1.workspace.id); + await expect( + (async () => + await getWorkspaceKeyByDocumentId({ + graphql, + documentId: userData1.document.id, + deviceSigningPublicKey: userData2.webDevice.signingPublicKey, + authorizationHeader: userData2.sessionKey, + }))() + ).rejects.toThrowError(/Internal server error/); }); test("key for shared workspace", async () => { diff --git a/apps/backend/src/types/workspace.ts b/apps/backend/src/types/workspace.ts index 282f9fb77..455e86a4a 100644 --- a/apps/backend/src/types/workspace.ts +++ b/apps/backend/src/types/workspace.ts @@ -1,10 +1,10 @@ import { CreatorDevice as PrismaCreatorDevice, - Role, - UsersToWorkspaces, Workspace as PrismaWorkspace, WorkspaceKey as PrismaWorkspaceKey, WorkspaceKeyBox as PrismaWorkspaceKeyBox, + Role, + UsersToWorkspaces, } from "../../prisma/generated/output"; import { CreatorDevice, Device, MinimalDevice } from "./device";