Skip to content

Commit 5fa38db

Browse files
committed
test(nextcloud): Improve PROPFIND props tests
Signed-off-by: provokateurin <[email protected]>
1 parent fc49ae4 commit 5fa38db

File tree

3 files changed

+181
-105
lines changed

3 files changed

+181
-105
lines changed

.cspell/nextcloud.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ requesttoken
5050
reshares
5151
resharing
5252
rgdnvw
53+
rgdnvck
5354
roomid
5455
rowocs
5556
setsip

packages/nextcloud/test/api/webdav/webdav_test.dart

Lines changed: 176 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import 'package:nextcloud/webdav.dart';
1414
import 'package:nextcloud_test/nextcloud_test.dart';
1515
import 'package:test/test.dart';
1616
import 'package:universal_io/io.dart';
17+
import 'package:version/version.dart';
1718

1819
class MockCallbackFunction extends Mock {
1920
void progressCallback(double progress);
@@ -161,7 +162,7 @@ void main() {
161162
final file = File('test/files/test.png');
162163
await tester.client.webdav.putFile(file, file.statSync(), PathUri.parse('test/test.png'));
163164

164-
final result = await tester.client.webdav.propfind(
165+
final response = await tester.client.webdav.propfind(
165166
PathUri.parse('test/test.png'),
166167
prop: const WebDavPropWithoutValues.fromBools(
167168
davCreationdate: true,
@@ -224,121 +225,195 @@ void main() {
224225
ocsSharePermissions: true,
225226
),
226227
);
227-
final response = result.toWebDavFiles().single;
228-
229-
expect(response.path, PathUri.parse('test/test.png'));
230-
expect(response.id, isNotEmpty);
231-
expect(response.fileId, greaterThan(0));
232-
expect(response.isCollection, isFalse);
233-
expect(response.mimeType, 'image/png');
234-
expect(response.etag, isNotEmpty);
235-
expect(response.size, 8650);
236-
expect(response.ownerId, 'user1');
237-
expect(response.ownerDisplay, 'User One');
238-
expect(response.lastModified!.isBefore(DateTime.timestamp()), isTrue);
239-
expect(response.isDirectory, isFalse);
240-
expect(response.uploadedDate!.isBefore(DateTime.timestamp()), isTrue);
241-
expect(response.createdDate!.isBefore(DateTime.timestamp()), isTrue);
242-
expect(response.favorite, isFalse);
243-
expect(response.hasPreview, isTrue);
244-
expect(response.name, 'test.png');
245-
expect(response.isDirectory, isFalse);
246-
247-
expect(response.props.davCreationdate!.isBefore(DateTime.timestamp()), isTrue);
248-
expect(response.props.davDisplayname, 'test.png');
249-
expect(response.props.davGetcontentlanguage, isNull);
250-
expect(response.props.davGetcontentlength, 8650);
251-
expect(response.props.davGetcontenttype, 'image/png');
252-
expect(response.props.davGetetag, isNotEmpty);
253-
expect(response.props.davGetlastmodified!.isBefore(DateTime.timestamp()), isTrue);
254-
expect(response.props.davQuotaAvailableBytes, isNull);
255-
expect(response.props.davQuotaUsedBytes, isNull);
256-
expect(response.props.davResourcetype!.collection, isNull);
257-
expect(response.props.ncCreationTime!.isBefore(DateTime.timestamp()), isTrue);
258-
expect(response.props.ncAclCanManage, isNull);
259-
expect(response.props.ncAclEnabled, isNull);
260-
expect(response.props.ncAclList, isNull);
261-
expect(response.props.ncContainedFileCount, isNull);
262-
expect(response.props.ncContainedFolderCount, isNull);
263-
expect(response.props.ncDataFingerprint, isNull);
264-
expect(response.props.ncGroupFolderId, isNull);
265-
expect(response.props.ncHasPreview, isTrue);
266-
expect(response.props.ncHidden, isFalse);
267-
expect(response.props.ncInheritedAclList, isNull);
268-
expect(response.props.ncIsEncrypted, isNull);
269-
expect(response.props.ncIsMountRoot, isFalse);
270-
expect(response.props.ncLock, isNull);
271-
expect(response.props.ncLockOwner, isNull);
272-
expect(response.props.ncLockOwnerDisplayname, isNull);
273-
expect(response.props.ncLockOwnerType, isNull);
274-
expect(response.props.ncLockTime, isNull);
275-
expect(response.props.ncLockTimeout, isNull);
276-
expect(response.props.ncLockToken, isNull);
277-
expect(response.props.ncMountType, isNull);
278-
expect(response.props.ncNote, isNull);
279-
expect(response.props.ncReminderDueDate, isNull);
280-
expect(response.props.ncRichWorkspace, isNull);
281-
expect(response.props.ncRichWorkspaceFile, isNull);
282-
expect(json.decode(response.props.ncShareAttributes!), <String>[]);
283-
expect(response.props.ncSharees!.sharees, isNull);
284-
expect(response.props.ncUploadTime!.isBefore(DateTime.timestamp()), isTrue);
285-
expect(response.props.ncVersionAuthor, isNull);
286-
expect(response.props.ncVersionLabel, isNull);
287-
expect(response.props.ncMetadataBlurhash, isNull);
288-
expect(response.props.ocChecksums, isNull);
289-
expect(response.props.ocCommentsCount, 0);
290-
expect(response.props.ocCommentsHref, isNotEmpty);
291-
expect(response.props.ocCommentsUnread, 0);
292-
expect(response.props.ocDownloadURL, isNull);
293-
expect(response.props.ocFavorite, false);
294-
expect(response.props.ocFileid, greaterThan(0));
295-
expect(response.props.ocId, isNotEmpty);
296-
expect(response.props.ocOwnerDisplayName, 'User One');
297-
expect(response.props.ocOwnerId, 'user1');
298-
expect(response.props.ocPermissions, 'RGDNVW');
299-
expect(response.props.ocShareTypes!.shareTypes, isNull);
300-
expect(response.props.ocSize, 8650);
301-
expect(response.props.ocTags!.tags, isNull);
302-
expect(json.decode(response.props.ocmSharePermissions!), ['share', 'read', 'write']);
303-
expect(response.props.ocsSharePermissions, 19);
228+
229+
final props = response.responses.first.propstats.first.prop;
230+
expect(props.davCreationdate!.isBefore(DateTime.timestamp()), isTrue);
231+
expect(props.davDisplayname, 'test.png');
232+
expect(props.davGetcontentlanguage, isNull);
233+
expect(props.davGetcontentlength, 8650);
234+
expect(props.davGetcontenttype, 'image/png');
235+
expect(props.davGetetag, isNotEmpty);
236+
expect(props.davGetlastmodified!.isBefore(DateTime.timestamp()), isTrue);
237+
expect(props.davQuotaAvailableBytes, isNull);
238+
expect(props.davQuotaUsedBytes, isNull);
239+
expect(props.davResourcetype!.collection, isNull);
240+
expect(props.ncCreationTime!.isBefore(DateTime.timestamp()), isTrue);
241+
expect(props.ncAclCanManage, isNull);
242+
expect(props.ncAclEnabled, isNull);
243+
expect(props.ncAclList, isNull);
244+
expect(props.ncContainedFileCount, isNull);
245+
expect(props.ncContainedFolderCount, isNull);
246+
expect(props.ncDataFingerprint, isNull);
247+
expect(props.ncGroupFolderId, isNull);
248+
expect(props.ncHasPreview, isTrue);
249+
expect(props.ncHidden, isFalse);
250+
expect(props.ncInheritedAclList, isNull);
251+
expect(props.ncIsEncrypted, isNull);
252+
expect(props.ncIsMountRoot, isFalse);
253+
expect(props.ncLock, isNull);
254+
expect(props.ncLockOwner, isNull);
255+
expect(props.ncLockOwnerDisplayname, isNull);
256+
expect(props.ncLockOwnerType, isNull);
257+
expect(props.ncLockTime, isNull);
258+
expect(props.ncLockTimeout, isNull);
259+
expect(props.ncLockToken, isNull);
260+
expect(props.ncMountType, isNull);
261+
expect(props.ncNote, isNull);
262+
expect(props.ncReminderDueDate, isNull);
263+
expect(props.ncRichWorkspace, isNull);
264+
expect(props.ncRichWorkspaceFile, isNull);
265+
expect(json.decode(props.ncShareAttributes!), <String>[]);
266+
expect(props.ncSharees!.sharees, isNull);
267+
expect(props.ncUploadTime!.isBefore(DateTime.timestamp()), isTrue);
268+
expect(props.ncVersionAuthor, isNull);
269+
expect(props.ncVersionLabel, isNull);
270+
expect(props.ncMetadataBlurhash, isNull);
271+
expect(props.ocChecksums, isNull);
272+
expect(props.ocCommentsCount, 0);
273+
expect(props.ocCommentsHref, isNotEmpty);
274+
expect(props.ocCommentsUnread, 0);
275+
expect(props.ocDownloadURL, isNull);
276+
expect(props.ocFavorite, false);
277+
expect(props.ocFileid, greaterThan(0));
278+
expect(props.ocId, isNotEmpty);
279+
expect(props.ocOwnerDisplayName, 'User One');
280+
expect(props.ocOwnerId, 'user1');
281+
expect(props.ocPermissions, 'RGDNVW');
282+
expect(props.ocShareTypes!.shareTypes, isNull);
283+
expect(props.ocSize, 8650);
284+
expect(props.ocTags!.tags, isNull);
285+
expect(json.decode(props.ocmSharePermissions!), ['share', 'read', 'write']);
286+
expect(props.ocsSharePermissions, 19);
304287
});
305288

306289
test('Get directory props', () async {
307-
final data = utf8.encode('test');
308290
await tester.client.webdav.mkcol(PathUri.parse('test/dir-props'));
309-
await tester.client.webdav.put(data, PathUri.parse('test/dir-props/test.txt'));
291+
final file = File('test/files/test.png');
292+
await tester.client.webdav.putFile(file, file.statSync(), PathUri.parse('test/dir-props/test.png'));
310293

311-
final response = (await tester.client.webdav.propfind(
294+
final response = await tester.client.webdav.propfind(
312295
PathUri.parse('test/dir-props'),
313296
prop: const WebDavPropWithoutValues.fromBools(
297+
davCreationdate: true,
298+
davDisplayname: true,
299+
davGetcontentlanguage: true,
300+
davGetcontentlength: true,
314301
davGetcontenttype: true,
302+
davGetetag: true,
315303
davGetlastmodified: true,
304+
davQuotaAvailableBytes: true,
305+
davQuotaUsedBytes: true,
316306
davResourcetype: true,
307+
ncAclCanManage: true,
308+
ncAclEnabled: true,
309+
ncAclList: true,
310+
ncContainedFileCount: true,
311+
ncContainedFolderCount: true,
312+
ncCreationTime: true,
313+
ncDataFingerprint: true,
314+
ncGroupFolderId: true,
315+
ncHasPreview: true,
316+
ncHidden: true,
317+
ncInheritedAclList: true,
318+
ncIsEncrypted: true,
319+
ncIsMountRoot: true,
320+
ncLock: true,
321+
ncLockOwner: true,
322+
ncLockOwnerDisplayname: true,
323+
ncLockOwnerEditor: true,
324+
ncLockOwnerType: true,
325+
ncLockTime: true,
326+
ncLockTimeout: true,
327+
ncLockToken: true,
328+
ncMountType: true,
329+
ncNote: true,
330+
ncReminderDueDate: true,
331+
ncRichWorkspace: true,
332+
ncRichWorkspaceFile: true,
333+
ncShareAttributes: true,
334+
ncSharees: true,
335+
ncUploadTime: true,
336+
ncVersionAuthor: true,
337+
ncVersionLabel: true,
338+
ncMetadataBlurhash: true,
339+
ocChecksums: true,
340+
ocCommentsCount: true,
341+
ocCommentsHref: true,
342+
ocCommentsUnread: true,
343+
ocDownloadURL: true,
344+
ocFavorite: true,
345+
ocFileid: true,
346+
ocId: true,
347+
ocOwnerDisplayName: true,
348+
ocOwnerId: true,
349+
ocPermissions: true,
350+
ocShareTypes: true,
317351
ocSize: true,
352+
ocTags: true,
353+
ocmSharePermissions: true,
354+
ocsSharePermissions: true,
318355
),
319356
depth: WebDavDepth.zero,
320-
))
321-
.toWebDavFiles()
322-
.single;
323-
324-
expect(response.path, PathUri.parse('test/dir-props/'));
325-
expect(response.isCollection, isTrue);
326-
expect(response.mimeType, isNull);
327-
expect(response.size, data.lengthInBytes);
328-
expect(
329-
response.lastModified!.secondsSinceEpoch,
330-
closeTo(DateTime.timestamp().secondsSinceEpoch, 10),
331357
);
332-
expect(response.name, 'dir-props');
333-
expect(response.isDirectory, isTrue);
334358

335-
expect(response.props.davGetcontenttype, isNull);
336-
expect(
337-
response.props.davGetlastmodified!.secondsSinceEpoch,
338-
closeTo(DateTime.timestamp().secondsSinceEpoch, 10),
339-
);
340-
expect(response.props.davResourcetype!.collection, isNotNull);
341-
expect(response.props.ocSize, data.lengthInBytes);
359+
final props = response.responses.first.propstats.first.prop;
360+
expect(props.davCreationdate!.isBefore(DateTime.timestamp()), isTrue);
361+
expect(props.davDisplayname, 'dir-props');
362+
expect(props.davGetcontentlanguage, isNull);
363+
expect(props.davGetcontentlength, isNull);
364+
expect(props.davGetcontenttype, isNull);
365+
expect(props.davGetetag, isNotEmpty);
366+
expect(props.davGetlastmodified!.isBefore(DateTime.timestamp()), isTrue);
367+
expect(props.davQuotaAvailableBytes, -3);
368+
expect(props.davQuotaUsedBytes, 8650);
369+
expect(props.davResourcetype!.collection, <dynamic>[]);
370+
expect(props.ncCreationTime!.isBefore(DateTime.timestamp()), isTrue);
371+
expect(props.ncAclCanManage, isNull);
372+
expect(props.ncAclEnabled, isNull);
373+
expect(props.ncAclList, isNull);
374+
expect(props.ncContainedFileCount, 1);
375+
expect(props.ncContainedFolderCount, 0);
376+
expect(props.ncDataFingerprint, isNull);
377+
expect(props.ncGroupFolderId, isNull);
378+
expect(props.ncHasPreview, isFalse);
379+
expect(props.ncHidden, isFalse);
380+
expect(props.ncInheritedAclList, isNull);
381+
expect(props.ncIsEncrypted, tester.version < Version(30, 0, 0) ? isFalse : isNull);
382+
expect(props.ncIsMountRoot, isFalse);
383+
expect(props.ncLock, isNull);
384+
expect(props.ncLockOwner, isNull);
385+
expect(props.ncLockOwnerDisplayname, isNull);
386+
expect(props.ncLockOwnerType, isNull);
387+
expect(props.ncLockTime, isNull);
388+
expect(props.ncLockTimeout, isNull);
389+
expect(props.ncLockToken, isNull);
390+
expect(props.ncMountType, isNull);
391+
expect(props.ncNote, isNull);
392+
expect(props.ncReminderDueDate, isNull);
393+
expect(props.ncRichWorkspace, isNull);
394+
expect(props.ncRichWorkspaceFile, isNull);
395+
expect(json.decode(props.ncShareAttributes!), <String>[]);
396+
expect(props.ncSharees!.sharees, isNull);
397+
expect(props.ncUploadTime, isNull);
398+
expect(props.ncVersionAuthor, isNull);
399+
expect(props.ncVersionLabel, isNull);
400+
expect(props.ncMetadataBlurhash, isNull);
401+
expect(props.ocChecksums, isNull);
402+
expect(props.ocCommentsCount, 0);
403+
expect(props.ocCommentsHref, isNotEmpty);
404+
expect(props.ocCommentsUnread, 0);
405+
expect(props.ocDownloadURL, isNull);
406+
expect(props.ocFavorite, false);
407+
expect(props.ocFileid, greaterThan(0));
408+
expect(props.ocId, isNotEmpty);
409+
expect(props.ocOwnerDisplayName, 'User One');
410+
expect(props.ocOwnerId, 'user1');
411+
expect(props.ocPermissions, 'RGDNVCK');
412+
expect(props.ocShareTypes!.shareTypes, isNull);
413+
expect(props.ocSize, 8650);
414+
expect(props.ocTags!.tags, isNull);
415+
expect(json.decode(props.ocmSharePermissions!), ['share', 'read', 'write']);
416+
expect(props.ocsSharePermissions, 31);
342417
});
343418

344419
test('Create share', () async {

packages/nextcloud/test/fixtures/webdav/get_directory_props.regexp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ authorization: Bearer mock
33
content-type: application/xml
44
ocs-apirequest: true
55
requesttoken: token
6-
PUT http://localhost/remote\.php/webdav/test/dir-props/test\.txt
6+
PUT http://localhost/remote\.php/webdav/test/dir-props/test\.png
77
authorization: Bearer mock
8-
content-length: 4
8+
content-length: 8650
99
content-type: application/xml
1010
ocs-apirequest: true
1111
requesttoken: token
12-
test
12+
.+
1313
PROPFIND http://localhost/remote\.php/webdav/test/dir-props
1414
authorization: Bearer mock
1515
content-type: application/xml
1616
depth: 0
1717
ocs-apirequest: true
1818
requesttoken: token
19-
<d:propfind xmlns:d="DAV:" xmlns:oc="http://owncloud\.org/ns" xmlns:nc="http://nextcloud\.org/ns" xmlns:ocs="http://open-collaboration-services\.org/ns" xmlns:ocm="http://open-cloud-mesh\.org/ns"><d:prop><d:getcontenttype/><d:getlastmodified/><d:resourcetype/><oc:size/></d:prop></d:propfind>
19+
<d:propfind xmlns:d="DAV:" xmlns:oc="http://owncloud\.org/ns" xmlns:nc="http://nextcloud\.org/ns" xmlns:ocs="http://open-collaboration-services\.org/ns" xmlns:ocm="http://open-cloud-mesh\.org/ns"><d:prop><d:creationdate/><d:displayname/><d:getcontentlanguage/><d:getcontentlength/><d:getcontenttype/><d:getetag/><d:getlastmodified/><d:quota-available-bytes/><d:quota-used-bytes/><d:resourcetype/><nc:acl-can-manage/><nc:acl-enabled/><nc:acl-list/><nc:contained-file-count/><nc:contained-folder-count/><nc:creation_time/><nc:data-fingerprint/><nc:group-folder-id/><nc:has-preview/><nc:hidden/><nc:inherited-acl-list/><nc:is-encrypted/><nc:is-mount-root/><nc:lock/><nc:lock-owner/><nc:lock-owner-displayname/><nc:lock-owner-editor/><nc:lock-owner-type/><nc:lock-time/><nc:lock-timeout/><nc:lock-token/><nc:mount-type/><nc:note/><nc:reminder-due-date/><nc:rich-workspace/><nc:rich-workspace-file/><nc:share-attributes/><nc:sharees/><nc:upload_time/><nc:version-author/><nc:version-label/><nc:metadata-blurhash/><oc:checksums/><oc:comments-count/><oc:comments-href/><oc:comments-unread/><oc:downloadURL/><oc:favorite/><oc:fileid/><oc:id/><oc:owner-display-name/><oc:owner-id/><oc:permissions/><oc:share-types/><oc:size/><oc:tags/><ocm:share-permissions/><ocs:share-permissions/></d:prop></d:propfind>

0 commit comments

Comments
 (0)