-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevents files that have been shared via secure view without having a compatible app to view such (or the file type is not supported) from being clicked.
- Loading branch information
1 parent
129f986
commit 9a099fb
Showing
8 changed files
with
137 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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,6 @@ | ||
Bugfix: Secure view default action | ||
|
||
Clicking files that have been shared via secure view without having a compatible app to view such (or the file type is not supported) is no longer possible. This prevents errors and other file actions from falsely registering themselves as default. | ||
|
||
https://github.com/owncloud/web/pull/11139 | ||
https://github.com/owncloud/web/issues/11138 |
This file contains 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 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 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './useCanBeOpenedWithSecureView' | ||
export * from './useGetResourceContext' | ||
export * from './useLoadFileInfoById' | ||
export * from './useResourceContents' |
13 changes: 13 additions & 0 deletions
13
packages/web-pkg/src/composables/resources/useCanBeOpenedWithSecureView.ts
This file contains 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,13 @@ | ||
import { Resource } from '@ownclouders/web-client' | ||
import { useAppsStore } from '../piniaStores' | ||
|
||
export const useCanBeOpenedWithSecureView = () => { | ||
const appsStore = useAppsStore() | ||
|
||
const canBeOpenedWithSecureView = (resource: Resource) => { | ||
const secureViewExtensions = appsStore.fileExtensions.filter(({ secureView }) => secureView) | ||
return secureViewExtensions.some(({ mimeType }) => mimeType === resource.mimeType) | ||
} | ||
|
||
return { canBeOpenedWithSecureView } | ||
} |
This file contains 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 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
70 changes: 70 additions & 0 deletions
70
packages/web-pkg/tests/unit/composables/resources/useCanBeOpenedWithSecureView.spec.ts
This file contains 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,70 @@ | ||
import { getComposableWrapper } from 'web-test-helpers' | ||
import { mock } from 'vitest-mock-extended' | ||
import { Resource } from '@ownclouders/web-client' | ||
import { useCanBeOpenedWithSecureView } from '../../../../src/composables/resources' | ||
import { ApplicationFileExtension } from '../../../../src/apps/types' | ||
|
||
describe('canBeOpenedWithSecureView', () => { | ||
describe('resource', () => { | ||
it('can be opened if a matching file extension with secure view exists', () => { | ||
getWrapper({ | ||
setup: ({ canBeOpenedWithSecureView }) => { | ||
const canBeOpened = canBeOpenedWithSecureView(mock<Resource>({ mimeType: 'text/plain' })) | ||
expect(canBeOpened).toBeTruthy() | ||
}, | ||
fileExtensions: [ | ||
mock<ApplicationFileExtension>({ secureView: true, mimeType: 'text/plain' }) | ||
] | ||
}) | ||
}) | ||
it('can not be opened if no file extension with secure view exists', () => { | ||
getWrapper({ | ||
setup: ({ canBeOpenedWithSecureView }) => { | ||
const canBeOpened = canBeOpenedWithSecureView(mock<Resource>({ mimeType: 'text/plain' })) | ||
expect(canBeOpened).toBeFalsy() | ||
}, | ||
fileExtensions: [ | ||
mock<ApplicationFileExtension>({ secureView: false, mimeType: 'text/plain' }) | ||
] | ||
}) | ||
}) | ||
it('can not be opened if no file extension exists', () => { | ||
getWrapper({ | ||
setup: ({ canBeOpenedWithSecureView }) => { | ||
const canBeOpened = canBeOpenedWithSecureView(mock<Resource>({ mimeType: 'text/plain' })) | ||
expect(canBeOpened).toBeFalsy() | ||
}, | ||
fileExtensions: [] | ||
}) | ||
}) | ||
it("can not be opened if the file extension's mime type doesn't match the one of the resource", () => { | ||
getWrapper({ | ||
setup: ({ canBeOpenedWithSecureView }) => { | ||
const canBeOpened = canBeOpenedWithSecureView(mock<Resource>({ mimeType: 'text/plain' })) | ||
expect(canBeOpened).toBeFalsy() | ||
}, | ||
fileExtensions: [ | ||
mock<ApplicationFileExtension>({ secureView: true, mimeType: 'image/jpg' }) | ||
] | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
||
function getWrapper({ | ||
setup, | ||
fileExtensions = [mock<ApplicationFileExtension>()] | ||
}: { | ||
setup: (instance: ReturnType<typeof useCanBeOpenedWithSecureView>) => void | ||
fileExtensions?: ApplicationFileExtension[] | ||
}) { | ||
return { | ||
wrapper: getComposableWrapper( | ||
() => { | ||
const instance = useCanBeOpenedWithSecureView() | ||
setup(instance) | ||
}, | ||
{ pluginOptions: { piniaOptions: { appsState: { fileExtensions } } } } | ||
) | ||
} | ||
} |