Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle encryption state in web interface #6670

Merged
merged 4 commits into from
Dec 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions apps/files/js/filelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,8 @@
type: $el.attr('data-type'),
etag: $el.attr('data-etag'),
permissions: parseInt($el.attr('data-permissions'), 10),
hasPreview: $el.attr('data-has-preview') === 'true'
hasPreview: $el.attr('data-has-preview') === 'true',
isEncrypted: $el.attr('data-e2eencrypted') === 'true'
};
var size = $el.attr('data-size');
if (size) {
Expand Down Expand Up @@ -1155,7 +1156,10 @@
if (type === 'dir') {
mime = mime || 'httpd/unix-directory';

if (fileData.mountType && fileData.mountType.indexOf('external') === 0) {
if (fileData.isEncrypted) {
icon = OC.MimeType.getIconUrl('dir-encrypted');
dataIcon = icon;
} else if (fileData.mountType && fileData.mountType.indexOf('external') === 0) {
icon = OC.MimeType.getIconUrl('dir-external');
dataIcon = icon;
}
Expand All @@ -1176,7 +1180,8 @@
"data-mtime": mtime,
"data-etag": fileData.etag,
"data-permissions": permissions,
"data-has-preview": fileData.hasPreview !== false
"data-has-preview": fileData.hasPreview !== false,
"data-e2eencrypted": fileData.isEncrypted === true
});

if (dataIcon) {
Expand Down Expand Up @@ -1447,7 +1452,9 @@
path = fileData.path || this.getCurrentDirectory(),
permissions = parseInt(fileData.permissions, 10) || 0;

if (fileData.isShareMountPoint) {
var isEndToEndEncrypted = (type === 'dir' && fileData.isEncrypted);

if (!isEndToEndEncrypted && fileData.isShareMountPoint) {
permissions = permissions | OC.PERMISSION_UPDATE;
}

Expand Down
64 changes: 59 additions & 5 deletions apps/files/tests/js/filelistSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ describe('OCA.Files.FileList tests', function() {
expect($tr.attr('data-permissions')).toEqual('31');
expect($tr.attr('data-mime')).toEqual('text/plain');
expect($tr.attr('data-mtime')).toEqual('123456');
expect($tr.attr('data-e2eencrypted')).toEqual('false');
expect($tr.find('a.name').attr('href'))
.toEqual(OC.webroot + '/remote.php/webdav/subdir/testName.txt');
expect($tr.find('.nametext').text().trim()).toEqual('testName.txt');
Expand Down Expand Up @@ -246,6 +247,7 @@ describe('OCA.Files.FileList tests', function() {
expect($tr.attr('data-permissions')).toEqual('31');
expect($tr.attr('data-mime')).toEqual('httpd/unix-directory');
expect($tr.attr('data-mtime')).toEqual('123456');
expect($tr.attr('data-e2eencrypted')).toEqual('false');

expect($tr.find('.filesize').text()).toEqual('1 KB');
expect($tr.find('.date').text()).not.toEqual('?');
Expand All @@ -271,6 +273,7 @@ describe('OCA.Files.FileList tests', function() {
expect($tr.attr('data-permissions')).toEqual('31');
expect($tr.attr('data-mime')).toBeUndefined();
expect($tr.attr('data-mtime')).toEqual('123456');
expect($tr.attr('data-e2eencrypted')).toEqual('false');

expect($tr.find('.filesize').text()).toEqual('Pending');
expect($tr.find('.date').text()).not.toEqual('?');
Expand All @@ -293,10 +296,20 @@ describe('OCA.Files.FileList tests', function() {
expect($tr.attr('data-permissions')).toEqual('31');
expect($tr.attr('data-mime')).toEqual('httpd/unix-directory');
expect($tr.attr('data-mtime')).toEqual('123456');
expect($tr.attr('data-e2eencrypted')).toEqual('false');

expect($tr.find('.filesize').text()).toEqual('Pending');
expect($tr.find('.date').text()).not.toEqual('?');
});
it('generates dir element with true e2eencrypted attribute when calling add() with minimal data including isEncrypted', function() {
var fileData = {
type: 'dir',
name: 'testFolder',
isEncrypted: true
};
var $tr = fileList.add(fileData);
expect($tr.attr('data-e2eencrypted')).toEqual('true');
});
it('generates file element with no permissions when permissions are explicitly none', function() {
var fileData = {
type: 'dir',
Expand Down Expand Up @@ -1442,6 +1455,32 @@ describe('OCA.Files.FileList tests', function() {
expect(OC.TestUtil.getImageUrl($td.find('.thumbnail'))).toEqual(OC.webroot + '/core/img/filetypes/folder.svg');
expect(previewLoadStub.notCalled).toEqual(true);
});
it('render encrypted folder icon for encrypted root', function() {
var fileData = {
type: 'dir',
mimetype: 'httpd/unix-directory',
name: 'test dir',
isEncrypted: true
};
var $tr = fileList.add(fileData);
var $td = $tr.find('td.filename');
expect(OC.TestUtil.getImageUrl($td.find('.thumbnail'))).toEqual(OC.webroot + '/core/img/filetypes/folder-encrypted.svg');
expect(previewLoadStub.notCalled).toEqual(true);
});
it('render encrypted folder icon for encrypted subdir', function() {
var fileData = {
type: 'dir',
mimetype: 'httpd/unix-directory',
name: 'test dir',
isEncrypted: true
};
var $tr = fileList.add(fileData);
var $td = $tr.find('td.filename');
expect(OC.TestUtil.getImageUrl($td.find('.thumbnail'))).toEqual(OC.webroot + '/core/img/filetypes/folder-encrypted.svg');
expect(previewLoadStub.notCalled).toEqual(true);
// default icon override
expect($tr.attr('data-icon')).toEqual(OC.webroot + '/core/img/filetypes/folder-encrypted.svg');
});
it('render external storage icon for external storage root', function() {
var fileData = {
type: 'dir',
Expand Down Expand Up @@ -2086,7 +2125,8 @@ describe('OCA.Files.FileList tests', function() {
size: 12,
etag: 'abc',
permissions: OC.PERMISSION_ALL,
hasPreview: true
hasPreview: true,
isEncrypted: false
});
expect(files[1]).toEqual({
id: 3,
Expand All @@ -2097,7 +2137,8 @@ describe('OCA.Files.FileList tests', function() {
size: 58009,
etag: '123',
permissions: OC.PERMISSION_ALL,
hasPreview: true
hasPreview: true,
isEncrypted: false
});
expect(files[2]).toEqual({
id: 4,
Expand All @@ -2108,7 +2149,8 @@ describe('OCA.Files.FileList tests', function() {
size: 250,
etag: '456',
permissions: OC.PERMISSION_ALL,
hasPreview: true
hasPreview: true,
isEncrypted: false
});
expect(files[0].id).toEqual(1);
expect(files[0].name).toEqual('One.txt');
Expand All @@ -2130,7 +2172,8 @@ describe('OCA.Files.FileList tests', function() {
size: 12,
etag: 'abc',
permissions: OC.PERMISSION_ALL,
hasPreview: true
hasPreview: true,
isEncrypted: false
});
expect(files[1]).toEqual({
id: 4,
Expand All @@ -2141,7 +2184,8 @@ describe('OCA.Files.FileList tests', function() {
size: 250,
etag: '456',
permissions: OC.PERMISSION_ALL,
hasPreview: true
hasPreview: true,
isEncrypted: false
});
});
describe('Download', function() {
Expand Down Expand Up @@ -3231,6 +3275,16 @@ describe('OCA.Files.FileList tests', function() {
expect(fileInfo.mimetype).toEqual('text/plain');
expect(fileInfo.type).toEqual('file');
expect(fileInfo.path).not.toBeDefined();
expect(fileInfo.isEncrypted).toEqual(false);
});
it('sets isEncrypted attribute if data includes true e2eencrypted', function() {
testFiles[3].isEncrypted = true;

fileList.setFiles(testFiles);
$tr = fileList.findFileEl('somedir');

var fileInfo = fileList.elementToFile($tr);
expect(fileInfo.isEncrypted).toEqual(true);
});
it('adds path attribute if available', function() {
$tr.attr('data-path', '/subdir');
Expand Down
1 change: 1 addition & 0 deletions core/img/filetypes/folder-encrypted.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions core/js/files/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
Client.PROPERTY_PERMISSIONS = '{' + Client.NS_OWNCLOUD + '}permissions';
Client.PROPERTY_SIZE = '{' + Client.NS_OWNCLOUD + '}size';
Client.PROPERTY_GETCONTENTLENGTH = '{' + Client.NS_DAV + '}getcontentlength';
Client.PROPERTY_ISENCRYPTED = '{' + Client.NS_DAV + '}is-encrypted';

Client.PROTOCOL_HTTP = 'http';
Client.PROTOCOL_HTTPS = 'https';
Expand Down Expand Up @@ -120,6 +121,10 @@
* Mount type
*/
[Client.NS_NEXTCLOUD, 'mount-type'],
/**
* Encryption state
*/
[Client.NS_NEXTCLOUD, 'is-encrypted'],
];

/**
Expand Down Expand Up @@ -305,6 +310,13 @@
data.hasPreview = true;
}

var isEncryptedProp = props['{' + Client.NS_NEXTCLOUD + '}is-encrypted'];
if (!_.isUndefined(isEncryptedProp)) {
data.isEncrypted = isEncryptedProp === '1';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be sure, the server is guaranteed to always return '1', never 1, true or 'true', right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, that's what's stored in the file cache table

} else {
data.isEncrypted = false;
}

var contentType = props[Client.PROPERTY_GETCONTENTTYPE];
if (!_.isUndefined(contentType)) {
data.mimetype = contentType;
Expand Down
2 changes: 2 additions & 0 deletions core/js/mimetype.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ OC.MimeType = {
// Generate path
if (mimeType === 'dir' && $.inArray('folder', files) !== -1) {
return 'folder';
} else if (mimeType === 'dir-encrypted' && $.inArray('folder-encrypted', files) !== -1) {
return 'folder-encrypted';
} else if (mimeType === 'dir-shared' && $.inArray('folder-shared', files) !== -1) {
return 'folder-shared';
} else if (mimeType === 'dir-public' && $.inArray('folder-public', files) !== -1) {
Expand Down
1 change: 1 addition & 0 deletions core/js/mimetypelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ OC.MimeTypeList={
"file",
"folder",
"folder-drag-accept",
"folder-encrypted",
"folder-external",
"folder-public",
"folder-shared",
Expand Down
6 changes: 5 additions & 1 deletion core/js/share.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,14 @@ OC.Share = _.extend(OC.Share || {}, {
$tr.find('.filename .thumbnail').css('background-image', 'url(' + shareFolderIcon + ')');
$tr.attr('data-icon', shareFolderIcon);
} else if (type === 'dir') {
var isEncrypted = $tr.attr('data-e2eencrypted');
var mountType = $tr.attr('data-mounttype');
// FIXME: duplicate of FileList._createRow logic for external folder,
// need to refactor the icon logic into a single code path eventually
if (mountType && mountType.indexOf('external') === 0) {
if (isEncrypted === 'true') {
shareFolderIcon = OC.MimeType.getIconUrl('dir-encrypted');
$tr.attr('data-icon', shareFolderIcon);
} else if (mountType && mountType.indexOf('external') === 0) {
shareFolderIcon = OC.MimeType.getIconUrl('dir-external');
$tr.attr('data-icon', shareFolderIcon);
} else {
Expand Down
13 changes: 11 additions & 2 deletions core/js/tests/specs/files/clientSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ describe('OC.Files.Client tests', function() {
expect(props).toContain('{http://owncloud.org/ns}fileid');
expect(props).toContain('{http://owncloud.org/ns}size');
expect(props).toContain('{http://owncloud.org/ns}permissions');
expect(props).toContain('{http://nextcloud.org/ns}is-encrypted');
});
it('sends PROPFIND to base url when empty path given', function() {
client.getFolderContents('');
Expand Down Expand Up @@ -262,6 +263,7 @@ describe('OC.Files.Client tests', function() {
expect(info.mtime).toEqual(1436535485000);
expect(info.mimetype).toEqual('text/plain');
expect(info.etag).toEqual('559fcabd79a38');
expect(info.isEncrypted).toEqual(false);

// sub entry
info = response[1];
Expand All @@ -274,6 +276,7 @@ describe('OC.Files.Client tests', function() {
expect(info.mtime).toEqual(1436536800000);
expect(info.mimetype).toEqual('httpd/unix-directory');
expect(info.etag).toEqual('66cfcabd79abb');
expect(info.isEncrypted).toEqual(false);
});
});
it('returns parent node in result if specified', function() {
Expand Down Expand Up @@ -303,6 +306,7 @@ describe('OC.Files.Client tests', function() {
expect(info.mtime).toEqual(1436522405000);
expect(info.mimetype).toEqual('httpd/unix-directory');
expect(info.etag).toEqual('56cfcabd79abb');
expect(info.isEncrypted).toEqual(false);

// the two other entries follow
expect(response[1].id).toEqual(51);
Expand Down Expand Up @@ -422,6 +426,7 @@ describe('OC.Files.Client tests', function() {
expect(props).toContain('{http://owncloud.org/ns}fileid');
expect(props).toContain('{http://owncloud.org/ns}size');
expect(props).toContain('{http://owncloud.org/ns}permissions');
expect(props).toContain('{http://nextcloud.org/ns}is-encrypted');
});
it('parses the result list into a FileInfo array', function() {
var promise = client.getFilteredFiles({
Expand Down Expand Up @@ -473,7 +478,7 @@ describe('OC.Files.Client tests', function() {
describe('file info', function() {
var responseXml = dav.Client.prototype.parseMultiStatus(
'<?xml version="1.0" encoding="utf-8"?>' +
'<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:oc="http://owncloud.org/ns">' +
'<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:oc="http://owncloud.org/ns" xmlns:nc="http://nextcloud.org/ns">' +
makeResponseBlock(
'/owncloud/remote.php/webdav/path/to%20space/%E6%96%87%E4%BB%B6%E5%A4%B9/',
{
Expand All @@ -483,7 +488,8 @@ describe('OC.Files.Client tests', function() {
'oc:id': '00000011oc2d13a6a068',
'oc:fileid': '11',
'oc:permissions': 'GRDNVCK',
'oc:size': '120'
'oc:size': '120',
'nc:is-encrypted': '1'
},
[
'd:getcontenttype',
Expand All @@ -510,6 +516,7 @@ describe('OC.Files.Client tests', function() {
expect(props).toContain('{http://owncloud.org/ns}fileid');
expect(props).toContain('{http://owncloud.org/ns}size');
expect(props).toContain('{http://owncloud.org/ns}permissions');
expect(props).toContain('{http://nextcloud.org/ns}is-encrypted');
});
it('parses the result into a FileInfo', function() {
var promise = client.getFileInfo('path/to space/文件夹');
Expand All @@ -535,6 +542,7 @@ describe('OC.Files.Client tests', function() {
expect(info.mtime).toEqual(1436522405000);
expect(info.mimetype).toEqual('httpd/unix-directory');
expect(info.etag).toEqual('56cfcabd79abb');
expect(info.isEncrypted).toEqual(true);
});
});
it('properly parses entry inside root', function() {
Expand Down Expand Up @@ -583,6 +591,7 @@ describe('OC.Files.Client tests', function() {
expect(info.mtime).toEqual(1436522405000);
expect(info.mimetype).toEqual('httpd/unix-directory');
expect(info.etag).toEqual('56cfcabd79abb');
expect(info.isEncrypted).toEqual(false);
});
});
it('rejects promise when an error occurred', function() {
Expand Down
7 changes: 7 additions & 0 deletions core/js/tests/specs/shareSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ describe('OC.Share tests', function() {

checkIcon('filetypes/folder-external');
});
it('shows encrypted icon if encrypted folder', function() {
$file.attr('data-type', 'dir');
$file.attr('data-e2eencrypted', true);
OC.Share.markFileAsShared($file, false, false);

checkIcon('filetypes/folder-encrypted');
});
});

describe('displaying the recipients', function() {
Expand Down