Skip to content

Commit

Permalink
test(nextcloud): Add checks to ensure that all available props are pa…
Browse files Browse the repository at this point in the history
…rsed

Signed-off-by: provokateurin <[email protected]>
  • Loading branch information
provokateurin committed Oct 9, 2024
1 parent 5fa38db commit 548176b
Show file tree
Hide file tree
Showing 3 changed files with 190 additions and 9 deletions.
171 changes: 164 additions & 7 deletions packages/nextcloud/test/api/webdav/webdav_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import 'dart:convert';
import 'dart:math';
import 'dart:typed_data';

import 'package:http/http.dart';
import 'package:collection/collection.dart';
import 'package:http/http.dart' as http;
import 'package:http/testing.dart';
import 'package:mocktail/mocktail.dart';
import 'package:nextcloud/core.dart' as core;
Expand All @@ -15,6 +16,7 @@ import 'package:nextcloud_test/nextcloud_test.dart';
import 'package:test/test.dart';
import 'package:universal_io/io.dart';
import 'package:version/version.dart';
import 'package:xml/xml.dart';

class MockCallbackFunction extends Mock {
void progressCallback(double progress);
Expand All @@ -24,6 +26,35 @@ class _FileMock extends Mock implements File {}

class _FileStatMock extends Mock implements FileStat {}

List<String> _getMultistatusPropNames(XmlElement root) {
return root.firstElementChild!.childElements
.singleWhere(
(node) =>
node.name.local == 'propstat' &&
node.childElements.singleWhere((node) => node.name.local == 'status').innerText.contains('200 OK'),
)
.childElements
.singleWhere((node) => node.name.local == 'prop')
.childElements
.map((el) => '{${el.name.namespaceUri}}${el.name.local}')
.toList()
.sorted();
}

Future<void> _expectAllPropsAreParsed(NextcloudTester tester, WebDavMultistatus result, PathUri uri) async {
final parsedProps = _getMultistatusPropNames(result.toXmlElement(namespaces: namespaces));
expect(parsedProps, isNotEmpty);

final streamedResponse = await tester.client.webdav.httpClient.send(tester.client.webdav.propfind_Request(uri));
expect(streamedResponse.statusCode, 207);
final rawResponse = await http.Response.fromStream(streamedResponse);

final expectedProps = _getMultistatusPropNames(XmlDocument.parse(rawResponse.body).rootElement);
expect(expectedProps, isNotEmpty);

expect(parsedProps, expectedProps);
}

void main() {
test('Chunked responses', () async {
await HttpServer.bind('127.0.0.1', 0).then((server) async {
Expand Down Expand Up @@ -82,10 +113,10 @@ void main() {
late FileStat fileStat;

setUpAll(() {
registerFallbackValue(Request('get', Uri()) as BaseRequest);
registerFallbackValue(http.Request('get', Uri()) as http.BaseRequest);

final mockClient = MockClient((request) async {
return Response('', 400);
return http.Response('', 400);
});

client = WebDavClient(
Expand Down Expand Up @@ -162,7 +193,7 @@ void main() {
final file = File('test/files/test.png');
await tester.client.webdav.putFile(file, file.statSync(), PathUri.parse('test/test.png'));

final response = await tester.client.webdav.propfind(
var response = await tester.client.webdav.propfind(
PathUri.parse('test/test.png'),
prop: const WebDavPropWithoutValues.fromBools(
davCreationdate: true,
Expand Down Expand Up @@ -226,7 +257,7 @@ void main() {
),
);

final props = response.responses.first.propstats.first.prop;
var props = response.responses.first.propstats.first.prop;
expect(props.davCreationdate!.isBefore(DateTime.timestamp()), isTrue);
expect(props.davDisplayname, 'test.png');
expect(props.davGetcontentlanguage, isNull);
Expand Down Expand Up @@ -284,14 +315,77 @@ void main() {
expect(props.ocTags!.tags, isNull);
expect(json.decode(props.ocmSharePermissions!), ['share', 'read', 'write']);
expect(props.ocsSharePermissions, 19);

response = await tester.client.webdav.propfind(PathUri.parse('test/test.png'));

props = response.responses.first.propstats.first.prop;
expect(props.davCreationdate, isNull);
expect(props.davDisplayname, isNull);
expect(props.davGetcontentlanguage, isNull);
expect(props.davGetcontentlength, 8650);
expect(props.davGetcontenttype, 'image/png');
expect(props.davGetetag, isNotEmpty);
expect(props.davGetlastmodified!.isBefore(DateTime.timestamp()), isTrue);
expect(props.davQuotaAvailableBytes, isNull);
expect(props.davQuotaUsedBytes, isNull);
expect(props.davResourcetype!.collection, isNull);
expect(props.ncCreationTime, isNull);
expect(props.ncAclCanManage, isNull);
expect(props.ncAclEnabled, isNull);
expect(props.ncAclList, isNull);
expect(props.ncContainedFileCount, isNull);
expect(props.ncContainedFolderCount, isNull);
expect(props.ncDataFingerprint, isNull);
expect(props.ncGroupFolderId, isNull);
expect(props.ncHasPreview, isNull);
expect(props.ncHidden, isNull);
expect(props.ncInheritedAclList, isNull);
expect(props.ncIsEncrypted, isNull);
expect(props.ncIsMountRoot, isNull);
expect(props.ncLock, isNull);
expect(props.ncLockOwner, isNull);
expect(props.ncLockOwnerDisplayname, isNull);
expect(props.ncLockOwnerType, isNull);
expect(props.ncLockTime, isNull);
expect(props.ncLockTimeout, isNull);
expect(props.ncLockToken, isNull);
expect(props.ncMountType, isNull);
expect(props.ncNote, isNull);
expect(props.ncReminderDueDate, isNull);
expect(props.ncRichWorkspace, isNull);
expect(props.ncRichWorkspaceFile, isNull);
expect(props.ncShareAttributes, isNull);
expect(props.ncSharees, isNull);
expect(props.ncUploadTime, isNull);
expect(props.ncVersionAuthor, isNull);
expect(props.ncVersionLabel, isNull);
expect(props.ncMetadataBlurhash, isNull);
expect(props.ocChecksums, isNull);
expect(props.ocCommentsCount, isNull);
expect(props.ocCommentsHref, isNull);
expect(props.ocCommentsUnread, isNull);
expect(props.ocDownloadURL, isNull);
expect(props.ocFavorite, isNull);
expect(props.ocFileid, isNull);
expect(props.ocId, isNull);
expect(props.ocOwnerDisplayName, isNull);
expect(props.ocOwnerId, isNull);
expect(props.ocPermissions, isNull);
expect(props.ocShareTypes, isNull);
expect(props.ocSize, isNull);
expect(props.ocTags, isNull);
expect(props.ocmSharePermissions, isNull);
expect(props.ocsSharePermissions, isNull);

await _expectAllPropsAreParsed(tester, response, PathUri.parse('test/test.png'));
});

test('Get directory props', () async {
await tester.client.webdav.mkcol(PathUri.parse('test/dir-props'));
final file = File('test/files/test.png');
await tester.client.webdav.putFile(file, file.statSync(), PathUri.parse('test/dir-props/test.png'));

final response = await tester.client.webdav.propfind(
var response = await tester.client.webdav.propfind(
PathUri.parse('test/dir-props'),
prop: const WebDavPropWithoutValues.fromBools(
davCreationdate: true,
Expand Down Expand Up @@ -356,7 +450,7 @@ void main() {
depth: WebDavDepth.zero,
);

final props = response.responses.first.propstats.first.prop;
var props = response.responses.first.propstats.first.prop;
expect(props.davCreationdate!.isBefore(DateTime.timestamp()), isTrue);
expect(props.davDisplayname, 'dir-props');
expect(props.davGetcontentlanguage, isNull);
Expand Down Expand Up @@ -414,6 +508,69 @@ void main() {
expect(props.ocTags!.tags, isNull);
expect(json.decode(props.ocmSharePermissions!), ['share', 'read', 'write']);
expect(props.ocsSharePermissions, 31);

response = await tester.client.webdav.propfind(PathUri.parse('test/dir-props'));

props = response.responses.first.propstats.first.prop;
expect(props.davCreationdate, isNull);
expect(props.davDisplayname, isNull);
expect(props.davGetcontentlanguage, isNull);
expect(props.davGetcontentlength, isNull);
expect(props.davGetcontenttype, isNull);
expect(props.davGetetag, isNotEmpty);
expect(props.davGetlastmodified!.isBefore(DateTime.timestamp()), isTrue);
expect(props.davQuotaAvailableBytes, -3);
expect(props.davQuotaUsedBytes, 8650);
expect(props.davResourcetype!.collection, <dynamic>[]);
expect(props.ncCreationTime, isNull);
expect(props.ncAclCanManage, isNull);
expect(props.ncAclEnabled, isNull);
expect(props.ncAclList, isNull);
expect(props.ncContainedFileCount, isNull);
expect(props.ncContainedFolderCount, isNull);
expect(props.ncDataFingerprint, isNull);
expect(props.ncGroupFolderId, isNull);
expect(props.ncHasPreview, isNull);
expect(props.ncHidden, isNull);
expect(props.ncInheritedAclList, isNull);
expect(props.ncIsEncrypted, isNull);
expect(props.ncIsMountRoot, isNull);
expect(props.ncLock, isNull);
expect(props.ncLockOwner, isNull);
expect(props.ncLockOwnerDisplayname, isNull);
expect(props.ncLockOwnerType, isNull);
expect(props.ncLockTime, isNull);
expect(props.ncLockTimeout, isNull);
expect(props.ncLockToken, isNull);
expect(props.ncMountType, isNull);
expect(props.ncNote, isNull);
expect(props.ncReminderDueDate, isNull);
expect(props.ncRichWorkspace, isNull);
expect(props.ncRichWorkspaceFile, isNull);
expect(props.ncShareAttributes, isNull);
expect(props.ncSharees, isNull);
expect(props.ncUploadTime, isNull);
expect(props.ncVersionAuthor, isNull);
expect(props.ncVersionLabel, isNull);
expect(props.ncMetadataBlurhash, isNull);
expect(props.ocChecksums, isNull);
expect(props.ocCommentsCount, isNull);
expect(props.ocCommentsHref, isNull);
expect(props.ocCommentsUnread, isNull);
expect(props.ocDownloadURL, isNull);
expect(props.ocFavorite, isNull);
expect(props.ocFileid, isNull);
expect(props.ocId, isNull);
expect(props.ocOwnerDisplayName, isNull);
expect(props.ocOwnerId, isNull);
expect(props.ocPermissions, isNull);
expect(props.ocShareTypes, isNull);
expect(props.ocSize, isNull);
expect(props.ocTags, isNull);
expect(props.ocmSharePermissions, isNull);
expect(props.ocsSharePermissions, isNull);

await _expectAllPropsAreParsed(tester, response, PathUri.parse('test/dir-props'));
});

test('Create share', () async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,16 @@ content-type: application/xml
depth: 0
ocs-apirequest: true
requesttoken: token
<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>
<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>
PROPFIND http://localhost/remote\.php/webdav/test/dir-props
authorization: Bearer mock
content-type: application/xml
ocs-apirequest: true
requesttoken: token
<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:propfind>
PROPFIND http://localhost/remote\.php/webdav/test/dir-props
authorization: Bearer mock
content-type: application/xml
ocs-apirequest: true
requesttoken: token
<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:propfind>
14 changes: 13 additions & 1 deletion packages/nextcloud/test/fixtures/webdav/get_file_props.regexp
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,16 @@ authorization: Bearer mock
content-type: application/xml
ocs-apirequest: true
requesttoken: token
<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>
<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>
PROPFIND http://localhost/remote\.php/webdav/test/test\.png
authorization: Bearer mock
content-type: application/xml
ocs-apirequest: true
requesttoken: token
<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:propfind>
PROPFIND http://localhost/remote\.php/webdav/test/test\.png
authorization: Bearer mock
content-type: application/xml
ocs-apirequest: true
requesttoken: token
<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:propfind>

0 comments on commit 548176b

Please sign in to comment.