-
Notifications
You must be signed in to change notification settings - Fork 0
fix(handlers): offer encrypted files only to handlers that read them over dav #38
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| /*! | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
| import { getFileActions } from '@nextcloud/files' | ||
| import { describe, expect, it, vi } from 'vitest' | ||
| import { canView, isHandlerEnabled, registerHandler } from '../lib/handlers.ts' | ||
| import { getHandlerForFile } from '../lib/helpers/handlerHelper.ts' | ||
| import { makeFile, makeHandler } from './factories.ts' | ||
|
|
||
| /** | ||
| * An end-to-end encrypted file is decrypted when fetched from its WebDAV | ||
| * endpoint. A handler fetching through an endpoint of its own would show | ||
| * ciphertext, so it is never offered such a file. | ||
| */ | ||
| describe('an end-to-end encrypted file', () => { | ||
| const encrypted = makeFile({ mime: 'text/markdown', attributes: { 'e2ee-is-encrypted': true } }) | ||
| const plain = makeFile({ mime: 'text/markdown', attributes: { 'e2ee-is-encrypted': false } }) | ||
| const unmarked = makeFile({ mime: 'text/markdown' }) | ||
|
|
||
| const custom = makeHandler({ id: 'custom', tagname: 'oca-viewer-custom' }) | ||
| const dav = makeHandler({ id: 'dav', tagname: 'oca-viewer-dav', supportsEndToEndEncryption: true }) | ||
|
|
||
| it('is refused by a handler that has not opted in, without asking it', () => { | ||
| const enabled = vi.fn(() => true) | ||
|
|
||
| expect(isHandlerEnabled(makeHandler({ enabled }), [encrypted])).toBe(false) | ||
| expect(enabled).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it('goes to a handler that reads it over dav', () => { | ||
| expect(isHandlerEnabled(dav, [encrypted])).toBe(true) | ||
| }) | ||
|
|
||
| it('taints a set: one encrypted file refuses the whole set', () => { | ||
| expect(isHandlerEnabled(custom, [plain, encrypted])).toBe(false) | ||
| expect(isHandlerEnabled(dav, [plain, encrypted])).toBe(true) | ||
| }) | ||
|
|
||
| it('changes nothing for a file the attribute marks as not encrypted, or does not mark', () => { | ||
| expect(isHandlerEnabled(custom, [plain])).toBe(true) | ||
| expect(isHandlerEnabled(custom, [unmarked])).toBe(true) | ||
| }) | ||
|
|
||
| it('is not viewable when only handlers without the flag take its mime', () => { | ||
| registerHandler(custom) | ||
|
|
||
| expect(canView(plain)).toBe(true) | ||
| expect(canView(encrypted)).toBe(false) | ||
| expect(getHandlerForFile(encrypted)).toBeUndefined() | ||
| }) | ||
|
|
||
| it('skips to the handler that can read it', () => { | ||
| registerHandler(custom) | ||
| registerHandler(dav) | ||
|
|
||
| expect(getHandlerForFile(plain)?.id).toBe('custom') | ||
| expect(getHandlerForFile(encrypted)?.id).toBe('dav') | ||
| }) | ||
|
|
||
| it('hides the "Open with" entry of a handler that cannot read it', () => { | ||
| registerHandler(custom) | ||
| registerHandler(dav) | ||
| const ctx = { view: {} as never, folder: {} as never, contents: [] } | ||
| const actionIds = (file: typeof encrypted) => getFileActions() | ||
| .filter((action) => ['viewer-open', 'viewer-open-with-custom', 'viewer-open-with-dav'].includes(action.id)) | ||
| .filter((action) => action.enabled?.({ ...ctx, nodes: [file] })) | ||
| .map((action) => action.id) | ||
| .sort() | ||
|
|
||
| expect(actionIds(plain)).toEqual(['viewer-open', 'viewer-open-with-custom', 'viewer-open-with-dav']) | ||
| expect(actionIds(encrypted)).toEqual(['viewer-open', 'viewer-open-with-dav']) | ||
| }) | ||
| }) | ||
|
|
||
| describe('the default handlers', () => { | ||
| it('all read the file over dav, so they take encrypted files', async () => { | ||
| const { registerDefaultHandlers } = await import('../lib/defaults.ts') | ||
| const { getHandlers } = await import('../lib/handlers.ts') | ||
| registerDefaultHandlers() | ||
|
|
||
| for (const id of ['images', 'videos', 'audios']) { | ||
| expect(getHandlers().get(id)?.supportsEndToEndEncryption, id).toBe(true) | ||
| } | ||
| }) | ||
| }) |
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
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.
Uh oh!
There was an error while loading. Please reload this page.