Skip to content

Commit

Permalink
Merge pull request #10143 from owncloud/fix-sharejail-private-link-again
Browse files Browse the repository at this point in the history
fix: resolve share jail private link in both formats
  • Loading branch information
kulmann authored Dec 12, 2023
2 parents 8a5b55a + 2fd7a88 commit a57ce4b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 19 deletions.
7 changes: 6 additions & 1 deletion packages/web-runtime/src/pages/resolvePrivateLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ export default defineComponent({
const resolvePrivateLinkTask = useTask(function* (signal, id) {
try {
if (id === `${SHARE_JAIL_ID}$${SHARE_JAIL_ID}!${SHARE_JAIL_ID}`) {
if (
[
`${SHARE_JAIL_ID}$${SHARE_JAIL_ID}!${SHARE_JAIL_ID}`,
`${SHARE_JAIL_ID}$${SHARE_JAIL_ID}`
].includes(id)
) {
return router.push(createLocationShares('files-shares-with-me'))
}
Expand Down
58 changes: 40 additions & 18 deletions packages/web-runtime/tests/unit/pages/resolvePrivateLink.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ import {
useGetResourceContext
} from '@ownclouders/web-pkg'
import { Resource, SpaceResource } from '@ownclouders/web-client'
import { SHARE_JAIL_ID } from '@ownclouders/web-client/src/helpers'

jest.mock('@ownclouders/web-pkg', () => ({
...jest.requireActual('@ownclouders/web-pkg'),
useRouteQuery: jest.fn(),
useRouteParam: jest.fn(),
useRouteQuery: jest.fn((str) => str),
useRouteParam: jest.fn((str) => str),
queryItemAsString: jest.fn(),
useGetResourceContext: jest.fn(),
useConfigurationManager: jest.fn()
Expand Down Expand Up @@ -48,21 +49,33 @@ describe('resolvePrivateLink', () => {
})
)
})
it('resolves to "files-shares-with-me" for received single file shares', async () => {
const fileId = '1'
const driveAliasAndItem = 'shares/someShare'
const space = mock<SpaceResource>({
driveType: 'share',
getDriveAliasAndItem: () => driveAliasAndItem
describe('resolves to "files-shares-with-me"', () => {
it('resolves for single file shares', async () => {
const fileId = '1'
const driveAliasAndItem = 'shares/someShare'
const space = mock<SpaceResource>({
driveType: 'share',
getDriveAliasAndItem: () => driveAliasAndItem
})
const resource = mock<Resource>({ fileId, type: 'file' })
const { wrapper, mocks } = getWrapper({ space, resource, fileId, path: '/' })
await wrapper.vm.resolvePrivateLinkTask.last
expect(mocks.$router.push).toHaveBeenCalledWith(
expect.objectContaining({ name: 'files-shares-with-me' })
)
})
it.each([
`${SHARE_JAIL_ID}$${SHARE_JAIL_ID}`,
`${SHARE_JAIL_ID}$${SHARE_JAIL_ID}!${SHARE_JAIL_ID}`
])('resolves for the share jail id', async (fileId) => {
const { wrapper, mocks } = getWrapper({ fileId })
await wrapper.vm.resolvePrivateLinkTask.last
expect(mocks.$router.push).toHaveBeenCalledWith(
expect.objectContaining({ name: 'files-shares-with-me' })
)
})
const resource = mock<Resource>({ fileId, type: 'file' })
const { wrapper, mocks } = getWrapper({ space, resource, fileId, path: '/' })
await wrapper.vm.resolvePrivateLinkTask.last
expect(mocks.$router.push).toHaveBeenCalledWith(
expect.objectContaining({ name: 'files-shares-with-me' })
)
})
it('passes the details query paramif given via query', async () => {
it('passes the details query param if given via query', async () => {
const details = 'sharing'
const { wrapper, mocks } = getWrapper({ details })
await wrapper.vm.resolvePrivateLinkTask.last
Expand Down Expand Up @@ -117,9 +130,18 @@ function getWrapper({
openWithDefaultAppQuery = 'true',
openLinksWithDefaultApp = true
} = {}) {
jest.mocked(queryItemAsString).mockReturnValueOnce(fileId)
jest.mocked(queryItemAsString).mockReturnValueOnce(openWithDefaultAppQuery)
jest.mocked(queryItemAsString).mockReturnValueOnce(details)
jest.mocked(queryItemAsString).mockImplementation((str: string) => {
if (str === 'fileId') {
return fileId
}
if (str === 'openWithDefaultApp') {
return openWithDefaultAppQuery
}
if (str === 'details') {
return details
}
return str
})

jest.mocked(useGetResourceContext).mockReturnValue({
getResourceContext: jest.fn().mockResolvedValue({ space, resource, path })
Expand Down

0 comments on commit a57ce4b

Please sign in to comment.