Skip to content

Commit

Permalink
Show error message when accessing space via publik link that is disab…
Browse files Browse the repository at this point in the history
…led (#11725)

* Show error message when accessing space via publik link that is disabled
  • Loading branch information
AlexAndBear authored Oct 7, 2024
1 parent 8af6c71 commit e4da1e3
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Bugfix: Accessing disabled password-protected space does not show error

We've fixed a bug where accessing a disabled password-protected space did not show an error message.
Now, users will see an error message when trying to access a disabled password-protected space.

https://github.com/owncloud/web/pull/11725
https://github.com/owncloud/web/issues/11721
21 changes: 13 additions & 8 deletions packages/web-runtime/src/pages/resolvePublicLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ export default defineComponent({
} catch (e) {
authStore.clearPublicLinkContext()
console.error(e, e.resource)
return
throw e
}
}
Expand Down Expand Up @@ -275,14 +275,19 @@ export default defineComponent({
})
onMounted(async () => {
if (unref(isOcmLink)) {
await resolvePublicLinkTask.perform(false)
return
}
try {
if (unref(isOcmLink)) {
await resolvePublicLinkTask.perform(false)
return
}
await loadPublicSpaceTask.perform()
await loadPublicSpaceTask.perform()
if (!unref(isPasswordRequired)) {
await resolvePublicLinkTask.perform(false)
if (!unref(isPasswordRequired)) {
await resolvePublicLinkTask.perform(false)
}
} catch (e) {
console.error(e)
}
})
Expand Down
44 changes: 41 additions & 3 deletions packages/web-runtime/tests/unit/pages/resolvePublicLink.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { CapabilityStore, ClientService, useRouteParam, useRouteQuery } from '@o
import { DavHttpError, SpaceResource } from '@ownclouders/web-client'
import { authService } from '../../../src/services/auth'
import { ref } from 'vue'
import { DavErrorCode } from '@ownclouders/web-client/webdav'

vi.mock('../../../src/services/auth')

Expand Down Expand Up @@ -67,6 +68,31 @@ describe('resolvePublicLink', () => {
})
})
})
describe('error message', () => {
it('should display an error message if the space cannot be resolved', async () => {
const { wrapper, mocks } = getWrapper({ getFileInfoErrorStatusCode: 404 })

try {
await wrapper.vm.loadPublicSpaceTask.last
} catch {}

expect(wrapper.find('.oc-link-resolve-error-message').text()).toContain(
'The resource could not be located, it may not exist anymore.'
)
})
it('should display an error message if the space cannot be resolved after entering password', async () => {
const { wrapper, mocks } = getWrapper({
passwordRequired: true,
getFileInfoErrorStatusCode: 404
})
await wrapper.vm.loadPublicSpaceTask.last
await expect(wrapper.vm.resolvePublicLinkTask.perform(true)).rejects.toThrow()

expect(wrapper.find('.oc-link-resolve-error-message').text()).toContain(
'The resource could not be located, it may not exist anymore.'
)
})
})
describe('internal link', () => {
it('redirects the user to the login page', async () => {
const { wrapper, mocks } = getWrapper({ isInternalLink: true })
Expand All @@ -82,8 +108,13 @@ describe('resolvePublicLink', () => {

function getWrapper({
passwordRequired = false,
isInternalLink = false
}: { passwordRequired?: boolean; isInternalLink?: boolean } = {}) {
isInternalLink = false,
getFileInfoErrorStatusCode = null
}: {
passwordRequired?: boolean
isInternalLink?: boolean
getFileInfoErrorStatusCode?: number
} = {}) {
const $clientService = mockDeep<ClientService>()
const spaceResource = mockDeep<SpaceResource>({ driveType: 'public' })

Expand All @@ -98,7 +129,14 @@ function getWrapper({
)
}

$clientService.webdav.getFileInfo.mockResolvedValueOnce(spaceResource)
if (getFileInfoErrorStatusCode) {
$clientService.webdav.getFileInfo.mockRejectedValueOnce(
new DavHttpError('', 'ERR_UNKNOWN' as DavErrorCode, undefined, getFileInfoErrorStatusCode)
)
} else {
$clientService.webdav.getFileInfo.mockResolvedValueOnce(spaceResource)
}

const mocks = { ...defaultComponentMocks(), $clientService }

const capabilities = {
Expand Down

0 comments on commit e4da1e3

Please sign in to comment.