2021-04-23 12:25:14 +02:00
|
|
|
import 'package:nc_photos/entity/file.dart';
|
|
|
|
import 'package:nc_photos/entity/webdav_response_parser.dart';
|
|
|
|
import 'package:test/test.dart';
|
|
|
|
import 'package:xml/xml.dart';
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
group("WebdavFileParser", () {
|
|
|
|
test("file", () {
|
|
|
|
final xml = XmlDocument.parse("""
|
|
|
|
<?xml version="1.0"?>
|
|
|
|
<d:multistatus xmlns:d="DAV:"
|
|
|
|
xmlns:s="http://sabredav.org/ns"
|
|
|
|
xmlns:oc="http://owncloud.org/ns"
|
|
|
|
xmlns:nc="http://nextcloud.org/ns">
|
|
|
|
<d:response>
|
|
|
|
<d:href>/remote.php/dav/files/admin/Nextcloud%20intro.mp4</d:href>
|
|
|
|
<d:propstat>
|
|
|
|
<d:prop>
|
|
|
|
<d:getlastmodified>Fri, 01 Jan 2021 02:03:04 GMT</d:getlastmodified>
|
|
|
|
<d:getetag>"1324f58d4d5c8d81bed6e4ed9d5ea862"</d:getetag>
|
|
|
|
<d:getcontenttype>video/mp4</d:getcontenttype>
|
|
|
|
<d:resourcetype/>
|
|
|
|
<d:getcontentlength>3963036</d:getcontentlength>
|
|
|
|
<nc:has-preview>false</nc:has-preview>
|
|
|
|
</d:prop>
|
|
|
|
<d:status>HTTP/1.1 200 OK</d:status>
|
|
|
|
</d:propstat>
|
|
|
|
</d:response>
|
|
|
|
</d:multistatus>
|
|
|
|
""");
|
|
|
|
final results = WebdavFileParser()(xml);
|
|
|
|
expect(results, [
|
|
|
|
File(
|
|
|
|
path: "remote.php/dav/files/admin/Nextcloud intro.mp4",
|
|
|
|
contentLength: 3963036,
|
|
|
|
contentType: "video/mp4",
|
|
|
|
etag: "1324f58d4d5c8d81bed6e4ed9d5ea862",
|
|
|
|
lastModified: DateTime.utc(2021, 1, 1, 2, 3, 4),
|
|
|
|
hasPreview: false,
|
|
|
|
isCollection: false,
|
|
|
|
),
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("file w/ 404 properties", () {
|
|
|
|
final xml = XmlDocument.parse("""
|
|
|
|
<?xml version="1.0"?>
|
|
|
|
<d:multistatus xmlns:d="DAV:"
|
|
|
|
xmlns:s="http://sabredav.org/ns"
|
|
|
|
xmlns:oc="http://owncloud.org/ns"
|
|
|
|
xmlns:nc="http://nextcloud.org/ns">
|
|
|
|
<d:response>
|
|
|
|
<d:href>/remote.php/dav/files/admin/Nextcloud%20intro.mp4</d:href>
|
|
|
|
<d:propstat>
|
|
|
|
<d:prop>
|
|
|
|
<d:getlastmodified>Fri, 01 Jan 2021 02:03:04 GMT</d:getlastmodified>
|
|
|
|
<d:getetag>"1324f58d4d5c8d81bed6e4ed9d5ea862"</d:getetag>
|
|
|
|
<d:getcontenttype>video/mp4</d:getcontenttype>
|
|
|
|
<d:resourcetype/>
|
|
|
|
<d:getcontentlength>3963036</d:getcontentlength>
|
|
|
|
<nc:has-preview>false</nc:has-preview>
|
|
|
|
</d:prop>
|
|
|
|
<d:status>HTTP/1.1 200 OK</d:status>
|
|
|
|
</d:propstat>
|
|
|
|
<d:propstat>
|
|
|
|
<d:prop>
|
|
|
|
<d:quota-used-bytes/>
|
|
|
|
<d:quota-available-bytes/>
|
|
|
|
</d:prop>
|
|
|
|
<d:status>HTTP/1.1 404 Not Found</d:status>
|
|
|
|
</d:propstat>
|
|
|
|
</d:response>
|
|
|
|
</d:multistatus>
|
|
|
|
""");
|
|
|
|
final results = WebdavFileParser()(xml);
|
|
|
|
expect(results, [
|
|
|
|
File(
|
|
|
|
path: "remote.php/dav/files/admin/Nextcloud intro.mp4",
|
|
|
|
contentLength: 3963036,
|
|
|
|
contentType: "video/mp4",
|
|
|
|
etag: "1324f58d4d5c8d81bed6e4ed9d5ea862",
|
|
|
|
lastModified: DateTime.utc(2021, 1, 1, 2, 3, 4),
|
|
|
|
hasPreview: false,
|
|
|
|
isCollection: false,
|
|
|
|
),
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("file w/ metadata", () {
|
|
|
|
final xml = XmlDocument.parse("""
|
|
|
|
<?xml version="1.0"?>
|
|
|
|
<d:multistatus xmlns:d="DAV:"
|
|
|
|
xmlns:s="http://sabredav.org/ns"
|
|
|
|
xmlns:oc="http://owncloud.org/ns"
|
|
|
|
xmlns:nc="http://nextcloud.org/ns">
|
|
|
|
<d:response>
|
|
|
|
<d:href>/remote.php/dav/files/admin/Photos/Nextcloud%20community.jpg</d:href>
|
|
|
|
<d:propstat>
|
|
|
|
<d:prop>
|
|
|
|
<d:getlastmodified>Fri, 01 Jan 2021 02:03:04 GMT</d:getlastmodified>
|
|
|
|
<d:getetag>"8950e39a034e369237d9285e2d815a50"</d:getetag>
|
|
|
|
<d:getcontenttype>image/jpeg</d:getcontenttype>
|
|
|
|
<d:resourcetype/>
|
|
|
|
<d:getcontentlength>797325</d:getcontentlength>
|
|
|
|
<nc:has-preview>true</nc:has-preview>
|
|
|
|
<x1:metadata xmlns:x1="com.nkming.nc_photos">{"version":2,"lastUpdated":"2021-01-02T03:04:05.678Z","fileEtag":"8950e39a034e369237d9285e2d815a50","imageWidth":3000,"imageHeight":2000}</x1:metadata>
|
|
|
|
</d:prop>
|
|
|
|
<d:status>HTTP/1.1 200 OK</d:status>
|
|
|
|
</d:propstat>
|
|
|
|
</d:response>
|
|
|
|
</d:multistatus>
|
|
|
|
""");
|
|
|
|
final results = WebdavFileParser()(xml);
|
|
|
|
expect(results, [
|
|
|
|
File(
|
|
|
|
path: "remote.php/dav/files/admin/Photos/Nextcloud community.jpg",
|
|
|
|
contentLength: 797325,
|
|
|
|
contentType: "image/jpeg",
|
|
|
|
etag: "8950e39a034e369237d9285e2d815a50",
|
|
|
|
lastModified: DateTime.utc(2021, 1, 1, 2, 3, 4),
|
|
|
|
hasPreview: true,
|
|
|
|
isCollection: false,
|
|
|
|
metadata: Metadata(
|
|
|
|
lastUpdated: DateTime.utc(2021, 1, 2, 3, 4, 5, 678),
|
|
|
|
fileEtag: "8950e39a034e369237d9285e2d815a50",
|
|
|
|
imageWidth: 3000,
|
|
|
|
imageHeight: 2000,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("multiple files", () {
|
|
|
|
final xml = XmlDocument.parse("""
|
|
|
|
<?xml version="1.0"?>
|
|
|
|
<d:multistatus xmlns:d="DAV:"
|
|
|
|
xmlns:s="http://sabredav.org/ns"
|
|
|
|
xmlns:oc="http://owncloud.org/ns"
|
|
|
|
xmlns:nc="http://nextcloud.org/ns">
|
|
|
|
<d:response>
|
|
|
|
<d:href>/remote.php/dav/files/admin/Nextcloud%20intro.mp4</d:href>
|
|
|
|
<d:propstat>
|
|
|
|
<d:prop>
|
|
|
|
<d:getlastmodified>Fri, 01 Jan 2021 02:03:04 GMT</d:getlastmodified>
|
|
|
|
<d:getetag>"1324f58d4d5c8d81bed6e4ed9d5ea862"</d:getetag>
|
|
|
|
<d:getcontenttype>video/mp4</d:getcontenttype>
|
|
|
|
<d:resourcetype/>
|
|
|
|
<d:getcontentlength>3963036</d:getcontentlength>
|
|
|
|
<nc:has-preview>false</nc:has-preview>
|
|
|
|
</d:prop>
|
|
|
|
<d:status>HTTP/1.1 200 OK</d:status>
|
|
|
|
</d:propstat>
|
|
|
|
</d:response>
|
|
|
|
<d:response>
|
|
|
|
<d:href>/remote.php/dav/files/admin/Nextcloud.png</d:href>
|
|
|
|
<d:propstat>
|
|
|
|
<d:prop>
|
|
|
|
<d:getlastmodified>Sat, 02 Jan 2021 03:04:05 GMT</d:getlastmodified>
|
|
|
|
<d:getetag>"48689d5b17c449d9db492ffe8f7ab8a6"</d:getetag>
|
|
|
|
<d:getcontenttype>image/png</d:getcontenttype>
|
|
|
|
<d:resourcetype/>
|
|
|
|
<d:getcontentlength>50598</d:getcontentlength>
|
|
|
|
<nc:has-preview>true</nc:has-preview>
|
|
|
|
<x1:metadata xmlns:x1="com.nkming.nc_photos">{"version":2,"lastUpdated":"2021-01-02T03:04:05.678000Z","fileEtag":"48689d5b17c449d9db492ffe8f7ab8a6","imageWidth":500,"imageHeight":500}</x1:metadata>
|
|
|
|
</d:prop>
|
|
|
|
<d:status>HTTP/1.1 200 OK</d:status>
|
|
|
|
</d:propstat>
|
|
|
|
</d:response>
|
|
|
|
</d:multistatus>
|
|
|
|
""");
|
|
|
|
final results = WebdavFileParser()(xml);
|
|
|
|
expect(results, [
|
|
|
|
File(
|
|
|
|
path: "remote.php/dav/files/admin/Nextcloud intro.mp4",
|
|
|
|
contentLength: 3963036,
|
|
|
|
contentType: "video/mp4",
|
|
|
|
etag: "1324f58d4d5c8d81bed6e4ed9d5ea862",
|
|
|
|
lastModified: DateTime.utc(2021, 1, 1, 2, 3, 4),
|
|
|
|
hasPreview: false,
|
|
|
|
isCollection: false,
|
|
|
|
),
|
|
|
|
File(
|
|
|
|
path: "remote.php/dav/files/admin/Nextcloud.png",
|
|
|
|
contentLength: 50598,
|
|
|
|
contentType: "image/png",
|
|
|
|
etag: "48689d5b17c449d9db492ffe8f7ab8a6",
|
|
|
|
lastModified: DateTime.utc(2021, 1, 2, 3, 4, 5),
|
|
|
|
hasPreview: true,
|
|
|
|
isCollection: false,
|
|
|
|
metadata: Metadata(
|
|
|
|
fileEtag: "48689d5b17c449d9db492ffe8f7ab8a6",
|
|
|
|
imageWidth: 500,
|
|
|
|
imageHeight: 500,
|
|
|
|
lastUpdated: DateTime.utc(2021, 1, 2, 3, 4, 5, 678),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("directory", () {
|
|
|
|
final xml = XmlDocument.parse("""
|
|
|
|
<?xml version="1.0"?>
|
|
|
|
<d:multistatus xmlns:d="DAV:"
|
|
|
|
xmlns:s="http://sabredav.org/ns"
|
|
|
|
xmlns:oc="http://owncloud.org/ns"
|
|
|
|
xmlns:nc="http://nextcloud.org/ns">
|
|
|
|
<d:response>
|
|
|
|
<d:href>/remote.php/dav/files/admin/Photos/</d:href>
|
|
|
|
<d:propstat>
|
|
|
|
<d:prop>
|
|
|
|
<d:getlastmodified>Fri, 01 Jan 2021 02:03:04 GMT</d:getlastmodified>
|
|
|
|
<d:getetag>"123456789abcd"</d:getetag>
|
|
|
|
<d:resourcetype>
|
|
|
|
<d:collection/>
|
|
|
|
</d:resourcetype>
|
|
|
|
<nc:has-preview>false</nc:has-preview>
|
|
|
|
</d:prop>
|
|
|
|
<d:status>HTTP/1.1 200 OK</d:status>
|
|
|
|
</d:propstat>
|
|
|
|
<d:propstat>
|
|
|
|
<d:prop>
|
|
|
|
<d:getcontenttype/>
|
|
|
|
<d:getcontentlength/>
|
|
|
|
<x1:metadata xmlns:x1="com.nkming.nc_photos"/>
|
|
|
|
</d:prop>
|
|
|
|
<d:status>HTTP/1.1 404 Not Found</d:status>
|
|
|
|
</d:propstat>
|
|
|
|
</d:response>
|
|
|
|
</d:multistatus>
|
|
|
|
""");
|
|
|
|
final results = WebdavFileParser()(xml);
|
|
|
|
expect(results, [
|
|
|
|
File(
|
|
|
|
path: "remote.php/dav/files/admin/Photos",
|
|
|
|
etag: "123456789abcd",
|
|
|
|
lastModified: DateTime.utc(2021, 1, 1, 2, 3, 4),
|
|
|
|
isCollection: true,
|
|
|
|
hasPreview: false,
|
|
|
|
),
|
|
|
|
]);
|
|
|
|
});
|
2021-05-06 22:29:29 +02:00
|
|
|
|
|
|
|
test("nextcloud hosed in subdir", () {
|
|
|
|
final xml = XmlDocument.parse("""
|
|
|
|
<?xml version="1.0"?>
|
|
|
|
<d:multistatus xmlns:d="DAV:"
|
|
|
|
xmlns:s="http://sabredav.org/ns"
|
|
|
|
xmlns:oc="http://owncloud.org/ns"
|
|
|
|
xmlns:nc="http://nextcloud.org/ns">
|
|
|
|
<d:response>
|
|
|
|
<d:href>/nextcloud/remote.php/dav/files/admin/Nextcloud%20intro.mp4</d:href>
|
|
|
|
<d:propstat>
|
|
|
|
<d:prop>
|
|
|
|
<d:getlastmodified>Fri, 01 Jan 2021 02:03:04 GMT</d:getlastmodified>
|
|
|
|
<d:getetag>"1324f58d4d5c8d81bed6e4ed9d5ea862"</d:getetag>
|
|
|
|
<d:getcontenttype>video/mp4</d:getcontenttype>
|
|
|
|
<d:resourcetype/>
|
|
|
|
<d:getcontentlength>3963036</d:getcontentlength>
|
|
|
|
<nc:has-preview>false</nc:has-preview>
|
|
|
|
</d:prop>
|
|
|
|
<d:status>HTTP/1.1 200 OK</d:status>
|
|
|
|
</d:propstat>
|
|
|
|
</d:response>
|
|
|
|
</d:multistatus>
|
|
|
|
""");
|
|
|
|
final results = WebdavFileParser()(xml);
|
|
|
|
expect(results, [
|
|
|
|
File(
|
|
|
|
path: "remote.php/dav/files/admin/Nextcloud intro.mp4",
|
|
|
|
contentLength: 3963036,
|
|
|
|
contentType: "video/mp4",
|
|
|
|
etag: "1324f58d4d5c8d81bed6e4ed9d5ea862",
|
|
|
|
lastModified: DateTime.utc(2021, 1, 1, 2, 3, 4),
|
|
|
|
hasPreview: false,
|
|
|
|
isCollection: false,
|
|
|
|
),
|
|
|
|
]);
|
|
|
|
});
|
2021-04-23 12:25:14 +02:00
|
|
|
});
|
|
|
|
}
|