-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Make
davRootPath
and davRemoteURL
support public shares
Signed-off-by: Ferdinand Thiessen <[email protected]>
- Loading branch information
Showing
8 changed files
with
144 additions
and
136 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
import type { ArgumentsType } from 'vitest' | ||
import type { FileStat } from 'webdav' | ||
import type { davResultToNode } from '../../lib/dav/dav' | ||
import { beforeEach, describe, expect, test, vi } from 'vitest' | ||
|
||
const auth = vi.hoisted(() => ({ getCurrentUser: vi.fn() })) | ||
const router = vi.hoisted(() => ({ generateRemoteUrl: vi.fn() })) | ||
const sharing = vi.hoisted(() => ({ isPublicShare: vi.fn(), getSharingToken: vi.fn() })) | ||
|
||
vi.mock('@nextcloud/auth', () => auth) | ||
vi.mock('@nextcloud/router', () => router) | ||
vi.mock('@nextcloud/sharing/public', () => sharing) | ||
|
||
const restoreMocks = () => { | ||
vi.resetAllMocks() | ||
router.generateRemoteUrl.mockImplementation((service) => `https://example.com/remote.php/${service}`) | ||
} | ||
|
||
const mockPublicShare = () => { | ||
auth.getCurrentUser.mockImplementationOnce(() => null) | ||
sharing.isPublicShare.mockImplementation(() => true) | ||
sharing.getSharingToken.mockImplementation(() => 'token-1234') | ||
} | ||
|
||
describe('DAV path functions', () => { | ||
|
||
beforeEach(() => { | ||
vi.resetModules() | ||
restoreMocks() | ||
}) | ||
|
||
test('root path is correct on public shares', async () => { | ||
mockPublicShare() | ||
|
||
const { davGetRootPath } = await import('../../lib/dav/dav') | ||
expect(davGetRootPath()).toBe('/files/token-1234') | ||
}) | ||
|
||
test('remote URL is correct on public shares', async () => { | ||
mockPublicShare() | ||
|
||
const { davGetRemoteURL } = await import('../../lib/dav/dav') | ||
expect(davGetRemoteURL()).toBe('https://example.com/public.php/dav') | ||
}) | ||
}) | ||
|
||
describe('on public shares', () => { | ||
beforeEach(() => { | ||
vi.resetAllMocks() | ||
vi.resetModules() | ||
}) | ||
|
||
// Wrapper function as we can not static import the function to allow mocking the modules | ||
const resultToNode = async (...rest: ArgumentsType<typeof davResultToNode>) => { | ||
const { davResultToNode } = await import('../../lib/dav/dav') | ||
return davResultToNode(...rest) | ||
} | ||
|
||
/* | ||
* Result of: | ||
* davGetClient().getDirectoryContents(`${davRootPath}${path}`, { details: true }) | ||
*/ | ||
const result: FileStat = { | ||
filename: '/files/test/New folder/Neue Textdatei.md', | ||
basename: 'Neue Textdatei.md', | ||
lastmod: 'Tue, 25 Jul 2023 12:29:34 GMT', | ||
size: 123, | ||
type: 'file', | ||
etag: '7a27142de0a62ed27a7293dbc16e93bc', | ||
mime: 'text/markdown', | ||
props: { | ||
resourcetype: { collection: false }, | ||
displayname: 'New File', | ||
getcontentlength: '123', | ||
getcontenttype: 'text/markdown', | ||
getetag: '"7a27142de0a62ed27a7293dbc16e93bc"', | ||
getlastmodified: 'Tue, 25 Jul 2023 12:29:34 GMT', | ||
}, | ||
} | ||
|
||
describe('davResultToNode', () => { | ||
beforeEach(() => { | ||
vi.resetModules() | ||
restoreMocks() | ||
}) | ||
|
||
test('has correct owner set on public shares', async () => { | ||
mockPublicShare() | ||
|
||
const remoteResult = { ...result, filename: '/root/New folder/Neue Textdatei.md' } | ||
const node = await resultToNode(remoteResult, '/root', 'http://example.com/remote.php/dav') | ||
|
||
expect(node.isDavRessource).toBe(true) | ||
expect(node.owner).toBe('anonymous') | ||
}) | ||
}) | ||
}) |
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 was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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