aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--.jshintrc28
-rw-r--r--apps/files/index.php6
-rw-r--r--apps/files/js/admin.js12
-rw-r--r--apps/files/js/file-upload.js30
-rw-r--r--apps/files/js/fileactions.js25
-rw-r--r--apps/files/js/filelist.js26
-rw-r--r--apps/files/js/files.js46
-rw-r--r--apps/files/js/upgrade.js11
-rw-r--r--apps/files/js/upload.js11
-rw-r--r--apps/files/lib/helper.php1
-rw-r--r--apps/files/templates/index.php5
-rw-r--r--apps/files/tests/js/fileactionsSpec.js3
-rw-r--r--apps/files/tests/js/filelistSpec.js2
-rw-r--r--apps/files/tests/js/filesSpec.js8
-rw-r--r--apps/files_encryption/hooks/hooks.php64
-rwxr-xr-xapps/files_encryption/lib/helper.php2
-rwxr-xr-xapps/files_encryption/lib/keymanager.php55
-rw-r--r--apps/files_encryption/lib/proxy.php41
-rw-r--r--apps/files_encryption/lib/util.php2
-rw-r--r--apps/files_encryption/tests/hooks.php271
-rw-r--r--apps/files_encryption/tests/keymanager.php20
-rw-r--r--apps/files_encryption/tests/proxy.php50
-rwxr-xr-xapps/files_encryption/tests/share.php44
-rw-r--r--apps/files_sharing/public.php10
-rw-r--r--apps/user_ldap/lib/connection.php2
-rwxr-xr-xautotest-js.sh2
-rwxr-xr-xautotest.sh8
-rwxr-xr-xconfig/config.sample.php7
-rw-r--r--core/js/config.php6
-rw-r--r--core/js/core.json43
-rw-r--r--core/js/js.js53
-rw-r--r--core/js/tests/specHelper.js18
-rw-r--r--core/js/tests/specs/coreSpec.js173
-rw-r--r--core/setup.php73
-rw-r--r--core/setup/controller.php138
-rw-r--r--core/templates/installation.php78
-rw-r--r--lib/base.php3
-rw-r--r--lib/private/connector/sabre/objecttree.php15
-rw-r--r--lib/private/helper.php63
-rw-r--r--lib/private/log/errorhandler.php2
-rw-r--r--lib/private/memcache/apc.php27
-rw-r--r--lib/private/memcache/apcu.php7
-rw-r--r--lib/private/memcache/cache.php2
-rw-r--r--lib/private/memcache/factory.php17
-rw-r--r--lib/private/server.php13
-rwxr-xr-xlib/private/util.php8
-rw-r--r--lib/public/icachefactory.php28
-rw-r--r--lib/public/iservercontainer.php7
-rw-r--r--lib/public/util.php19
-rw-r--r--settings/templates/apps.php4
-rw-r--r--tests/karma.config.js64
-rw-r--r--tests/lib/errorHandler.php62
53 files changed, 1301 insertions, 415 deletions
diff --git a/.gitignore b/.gitignore
index 8c8b61d701b..25cb1b227f9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -88,6 +88,7 @@ nbproject
# Tests - auto-generated files
/data-autotest
/tests/coverage*
+/tests/karma-coverage
/tests/autoconfig*
/tests/autotest*
/tests/data/lorem-copy.txt
diff --git a/.jshintrc b/.jshintrc
new file mode 100644
index 00000000000..f40dd22b5fd
--- /dev/null
+++ b/.jshintrc
@@ -0,0 +1,28 @@
+{
+ "camelCase": true,
+ "eqeqeq": true,
+ "immed": true,
+ "latedef": false,
+ "noarg": true,
+ "nonbsp": true,
+ "undef": true,
+ "unused": true,
+ "trailing": true,
+ "maxparams": 5,
+ "curly": true,
+ "jquery": true,
+ "maxlen": 80,
+ "indent": 4,
+ "browser": true,
+ "globals": {
+ "console": true,
+ "it": true,
+ "itx": true,
+ "expect": true,
+ "describe": true,
+ "beforeEach": true,
+ "afterEach": true,
+ "sinon": true,
+ "fakeServer": true
+ }
+}
diff --git a/apps/files/index.php b/apps/files/index.php
index 2ce8fdb065f..dd63f29bc28 100644
--- a/apps/files/index.php
+++ b/apps/files/index.php
@@ -101,6 +101,8 @@ if ($needUpgrade) {
} else {
// information about storage capacities
$storageInfo=OC_Helper::getStorageInfo($dir);
+ $freeSpace=$storageInfo['free'];
+ $uploadLimit=OCP\Util::uploadLimit();
$maxUploadFilesize=OCP\Util::maxUploadFilesize($dir);
$publicUploadEnabled = \OC_Appconfig::getValue('core', 'shareapi_allow_public_upload', 'yes');
// if the encryption app is disabled, than everything is fine (INIT_SUCCESSFUL status code)
@@ -132,8 +134,10 @@ if ($needUpgrade) {
$tmpl->assign('files', $files);
$tmpl->assign('trash', $trashEnabled);
$tmpl->assign('trashEmpty', $trashEmpty);
- $tmpl->assign('uploadMaxFilesize', $maxUploadFilesize);
+ $tmpl->assign('uploadMaxFilesize', $maxUploadFilesize); // minimium of freeSpace and uploadLimit
$tmpl->assign('uploadMaxHumanFilesize', OCP\Util::humanFileSize($maxUploadFilesize));
+ $tmpl->assign('freeSpace', $freeSpace);
+ $tmpl->assign('uploadLimit', $uploadLimit); // PHP upload limit
$tmpl->assign('allowZipDownload', intval(OCP\Config::getSystemValue('allowZipDownload', true)));
$tmpl->assign('usedSpacePercent', (int)$storageInfo['relative']);
$tmpl->assign('isPublic', false);
diff --git a/apps/files/js/admin.js b/apps/files/js/admin.js
index bfa96670635..f735079fcbe 100644
--- a/apps/files/js/admin.js
+++ b/apps/files/js/admin.js
@@ -1,3 +1,13 @@
+/*
+ * Copyright (c) 2014
+ *
+ * This file is licensed under the Affero General Public License version 3
+ * or later.
+ *
+ * See the COPYING-README file.
+ *
+ */
+
function switchPublicFolder()
{
var publicEnable = $('#publicEnable').is(':checked');
@@ -10,7 +20,7 @@ function switchPublicFolder()
$(document).ready(function(){
switchPublicFolder(); // Execute the function after loading DOM tree
$('#publicEnable').click(function(){
- switchPublicFolder(); // To get rid of onClick()
+ switchPublicFolder(); // To get rid of onClick()
});
$('#allowZipDownload').bind('change', function() {
diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js
index 486273a910c..f962a7044a8 100644
--- a/apps/files/js/file-upload.js
+++ b/apps/files/js/file-upload.js
@@ -1,3 +1,13 @@
+/*
+ * Copyright (c) 2014
+ *
+ * This file is licensed under the Affero General Public License version 3
+ * or later.
+ *
+ * See the COPYING-README file.
+ *
+ */
+
/**
* The file upload code uses several hooks to interact with blueimps jQuery file upload library:
* 1. the core upload handling hooks are added when initializing the plugin,
@@ -8,6 +18,8 @@
* - TODO music upload button
*/
+/* global OC, t, n */
+
/**
* Function that will allow us to know if Ajax uploads are supported
* @link https://github.com/New-Bamboo/example-ajax-upload/blob/master/public/index.html
@@ -241,10 +253,22 @@ $(document).ready(function() {
// add size
selection.totalBytes += file.size;
- //check max upload size
- if (selection.totalBytes > $('#max_upload').val()) {
+ // check PHP upload limit
+ if (selection.totalBytes > $('#upload_limit').val()) {
+ data.textStatus = 'sizeexceedlimit';
+ data.errorThrown = t('files', 'Total file size {size1} exceeds upload limit {size2}', {
+ 'size1': humanFileSize(selection.totalBytes),
+ 'size2': humanFileSize($('#upload_limit').val())
+ });
+ }
+
+ // check free space
+ if (selection.totalBytes > $('#free_space').val()) {
data.textStatus = 'notenoughspace';
- data.errorThrown = t('files', 'Not enough space available');
+ data.errorThrown = t('files', 'Not enough free space, you are uploading {size1} but only {size2} is left', {
+ 'size1': humanFileSize(selection.totalBytes),
+ 'size2': humanFileSize($('#free_space').val())
+ });
}
// end upload for whole selection on error
diff --git a/apps/files/js/fileactions.js b/apps/files/js/fileactions.js
index f36457f01a8..9a69d7b3688 100644
--- a/apps/files/js/fileactions.js
+++ b/apps/files/js/fileactions.js
@@ -1,3 +1,15 @@
+/*
+ * Copyright (c) 2014
+ *
+ * This file is licensed under the Affero General Public License version 3
+ * or later.
+ *
+ * See the COPYING-README file.
+ *
+ */
+
+/* global OC, FileList */
+/* global trashBinApp */
var FileActions = {
actions: {},
defaults: {},
@@ -45,8 +57,9 @@ var FileActions = {
return filteredActions;
},
getDefault: function (mime, type, permissions) {
+ var mimePart;
if (mime) {
- var mimePart = mime.substr(0, mime.indexOf('/'));
+ mimePart = mime.substr(0, mime.indexOf('/'));
}
var name = false;
if (mime && FileActions.defaults[mime]) {
@@ -141,13 +154,14 @@ var FileActions = {
parent.parent().children().last().find('.action.delete').remove();
if (actions['Delete']) {
var img = FileActions.icons['Delete'];
+ var html;
if (img.call) {
img = img(file);
}
if (typeof trashBinApp !== 'undefined' && trashBinApp) {
- var html = '<a href="#" original-title="' + t('files', 'Delete permanently') + '" class="action delete delete-icon" />';
+ html = '<a href="#" original-title="' + t('files', 'Delete permanently') + '" class="action delete delete-icon" />';
} else {
- var html = '<a href="#" class="action delete delete-icon" />';
+ html = '<a href="#" class="action delete delete-icon" />';
}
var element = $(html);
element.data('action', actions['Delete']);
@@ -174,10 +188,11 @@ var FileActions = {
};
$(document).ready(function () {
+ var downloadScope;
if ($('#allowZipDownload').val() == 1) {
- var downloadScope = 'all';
+ downloadScope = 'all';
} else {
- var downloadScope = 'file';
+ downloadScope = 'file';
}
if (typeof disableDownloadActions == 'undefined' || !disableDownloadActions) {
diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js
index 23b31e72467..f538af10362 100644
--- a/apps/files/js/filelist.js
+++ b/apps/files/js/filelist.js
@@ -1,4 +1,16 @@
-var FileList={
+/*
+ * Copyright (c) 2014
+ *
+ * This file is licensed under the Affero General Public License version 3
+ * or later.
+ *
+ * See the COPYING-README file.
+ *
+ */
+
+/* global OC, t, n, FileList, FileActions, Files */
+/* global procesSelection, dragOptions, SVGSupport, replaceSVG */
+window.FileList={
useUndo:true,
postProcessList: function() {
$('#fileList tr').each(function() {
@@ -28,7 +40,8 @@ var FileList={
}
FileList.updateFileSummary();
procesSelection();
-
+
+ $(window).scrollTop(0);
$fileList.trigger(jQuery.Event("updated"));
},
createRow:function(type, name, iconurl, linktarget, size, lastModified, permissions) {
@@ -191,6 +204,7 @@ var FileList={
return OC.linkTo('files', 'index.php')+"?dir="+ encodeURIComponent(dir).replace(/%2F/g, '/');
},
setCurrentDir: function(targetDir, changeUrl) {
+ var url;
$('#dir').val(targetDir);
if (changeUrl !== false) {
if (window.history.pushState && changeUrl !== false) {
@@ -394,7 +408,7 @@ var FileList={
}
return true;
};
-
+
form.submit(function(event) {
event.stopPropagation();
event.preventDefault();
@@ -468,7 +482,7 @@ var FileList={
var basename = newname;
if (newname.indexOf('.') > 0 && tr.data('type') !== 'dir') {
basename = newname.substr(0, newname.lastIndexOf('.'));
- }
+ }
td.find('a.name span.nametext').text(basename);
if (newname.indexOf('.') > 0 && tr.data('type') !== 'dir') {
if ( ! td.find('a.name span.extension').exists() ) {
@@ -834,7 +848,7 @@ $(document).ready(function() {
{name: 'requesttoken', value: oc_requesttoken}
];
};
- }
+ }
});
file_upload_start.on('fileuploadadd', function(e, data) {
@@ -873,7 +887,7 @@ $(document).ready(function() {
*/
file_upload_start.on('fileuploaddone', function(e, data) {
OC.Upload.log('filelist handle fileuploaddone', e, data);
-
+
var response;
if (typeof data.result === 'string') {
response = data.result;
diff --git a/apps/files/js/files.js b/apps/files/js/files.js
index d794a1584de..a535700c1b3 100644
--- a/apps/files/js/files.js
+++ b/apps/files/js/files.js
@@ -1,4 +1,16 @@
-Files={
+/*
+ * Copyright (c) 2014
+ *
+ * This file is licensed under the Affero General Public License version 3
+ * or later.
+ *
+ * See the COPYING-README file.
+ *
+ */
+
+/* global OC, t, n, FileList, FileActions */
+/* global getURLParameter, isPublic */
+var Files = {
// file space size sync
_updateStorageStatistics: function() {
Files._updateStorageStatisticsTimeout = null;
@@ -41,6 +53,7 @@ Files={
}
if (response.data !== undefined && response.data.uploadMaxFilesize !== undefined) {
$('#max_upload').val(response.data.uploadMaxFilesize);
+ $('#free_space').val(response.data.freeSpace);
$('#upload.button').attr('original-title', response.data.maxHumanFilesize);
$('#usedSpacePercent').val(response.data.usedSpacePercent);
Files.displayStorageWarnings();
@@ -67,17 +80,25 @@ Files={
return fileName;
},
- isFileNameValid:function (name) {
- if (name === '.') {
- throw t('files', '\'.\' is an invalid file name.');
- } else if (name.length === 0) {
+ /**
+ * Checks whether the given file name is valid.
+ * @param name file name to check
+ * @return true if the file name is valid.
+ * Throws a string exception with an error message if
+ * the file name is not valid
+ */
+ isFileNameValid: function (name) {
+ var trimmedName = name.trim();
+ if (trimmedName === '.' || trimmedName === '..') {
+ throw t('files', '"{name}" is an invalid file name.', {name: name});
+ } else if (trimmedName.length === 0) {
throw t('files', 'File name cannot be empty.');
}
-
// check for invalid characters
- var invalid_characters = ['\\', '/', '<', '>', ':', '"', '|', '?', '*'];
+ var invalid_characters =
+ ['\\', '/', '<', '>', ':', '"', '|', '?', '*', '\n'];
for (var i = 0; i < invalid_characters.length; i++) {
- if (name.indexOf(invalid_characters[i]) !== -1) {
+ if (trimmedName.indexOf(invalid_characters[i]) !== -1) {
throw t('files', "Invalid name, '\\', '/', '<', '>', ':', '\"', '|', '?' and '*' are not allowed.");
}
}
@@ -654,10 +675,10 @@ function procesSelection() {
var totalSize = 0;
for(var i=0; i<selectedFiles.length; i++) {
totalSize+=selectedFiles[i].size;
- };
+ }
for(var i=0; i<selectedFolders.length; i++) {
totalSize+=selectedFolders[i].size;
- };
+ }
$('#headerSize').text(humanFileSize(totalSize));
var selection = '';
if (selectedFolders.length > 0) {
@@ -769,10 +790,11 @@ Files.lazyLoadPreview = function(path, mime, ready, width, height, etag) {
}
img.src = previewURL;
});
-}
+};
function getUniqueName(name) {
if (FileList.findFileEl(name).exists()) {
+ var numMatch;
var parts=name.split('.');
var extension = "";
if (parts.length > 1) {
@@ -806,7 +828,7 @@ function checkTrashStatus() {
function onClickBreadcrumb(e) {
var $el = $(e.target).closest('.crumb'),
- $targetDir = $el.data('dir');
+ $targetDir = $el.data('dir'),
isPublic = !!$('#isPublic').val();
if ($targetDir !== undefined && !isPublic) {
diff --git a/apps/files/js/upgrade.js b/apps/files/js/upgrade.js
index 02d57fc9e6c..714adf824a1 100644
--- a/apps/files/js/upgrade.js
+++ b/apps/files/js/upgrade.js
@@ -1,3 +1,14 @@
+/*
+ * Copyright (c) 2014
+ *
+ * This file is licensed under the Affero General Public License version 3
+ * or later.
+ *
+ * See the COPYING-README file.
+ *
+ */
+
+/* global OC */
$(document).ready(function () {
var eventSource, total, bar = $('#progressbar');
console.log('start');
diff --git a/apps/files/js/upload.js b/apps/files/js/upload.js
index 9d9f61f600e..617cf4b1c1d 100644
--- a/apps/files/js/upload.js
+++ b/apps/files/js/upload.js
@@ -1,3 +1,14 @@
+/*
+ * Copyright (c) 2014
+ *
+ * This file is licensed under the Affero General Public License version 3
+ * or later.
+ *
+ * See the COPYING-README file.
+ *
+ */
+
+/* global OC */
function Upload(fileSelector) {
if ($.support.xhrFileUpload) {
return new XHRUpload(fileSelector.target.files);
diff --git a/apps/files/lib/helper.php b/apps/files/lib/helper.php
index eaff28178ea..21d1f50e587 100644
--- a/apps/files/lib/helper.php
+++ b/apps/files/lib/helper.php
@@ -15,6 +15,7 @@ class Helper
return array('uploadMaxFilesize' => $maxUploadFilesize,
'maxHumanFilesize' => $maxHumanFilesize,
+ 'freeSpace' => $storageInfo['free'],
'usedSpacePercent' => (int)$storageInfo['relative']);
}
diff --git a/apps/files/templates/index.php b/apps/files/templates/index.php
index ff78f0ca551..939043b2c9f 100644
--- a/apps/files/templates/index.php
+++ b/apps/files/templates/index.php
@@ -17,9 +17,10 @@
<div id="upload" class="button"
title="<?php p($l->t('Upload') . ' max. '.$_['uploadMaxHumanFilesize']) ?>">
<?php if($_['uploadMaxFilesize'] >= 0):?>
- <input type="hidden" name="MAX_FILE_SIZE" id="max_upload"
- value="<?php p($_['uploadMaxFilesize']) ?>">
+ <input type="hidden" id="max_upload" name="MAX_FILE_SIZE" value="<?php p($_['uploadMaxFilesize']) ?>">
<?php endif;?>
+ <input type="hidden" id="upload_limit" value="<?php p($_['uploadLimit']) ?>">
+ <input type="hidden" id="free_space" value="<?php p($_['freeSpace']) ?>">
<?php if(isset($_['dirToken'])):?>
<input type="hidden" id="publicUploadRequestToken" name="requesttoken" value="<?php p($_['requesttoken']) ?>" />
<input type="hidden" id="dirToken" name="dirToken" value="<?php p($_['dirToken']) ?>" />
diff --git a/apps/files/tests/js/fileactionsSpec.js b/apps/files/tests/js/fileactionsSpec.js
index e185cf2f654..8bbc1d3d141 100644
--- a/apps/files/tests/js/fileactionsSpec.js
+++ b/apps/files/tests/js/fileactionsSpec.js
@@ -18,7 +18,10 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
+
+/* global OC, FileActions, FileList */
describe('FileActions tests', function() {
+ var $filesTable;
beforeEach(function() {
// init horrible parameters
var $body = $('body');
diff --git a/apps/files/tests/js/filelistSpec.js b/apps/files/tests/js/filelistSpec.js
index 61e026c0725..c26e65fc4de 100644
--- a/apps/files/tests/js/filelistSpec.js
+++ b/apps/files/tests/js/filelistSpec.js
@@ -18,6 +18,8 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
+
+/* global OC, FileList */
describe('FileList tests', function() {
beforeEach(function() {
// init horrible parameters
diff --git a/apps/files/tests/js/filesSpec.js b/apps/files/tests/js/filesSpec.js
index 9d0a2e4f9d7..018c8ef0f3c 100644
--- a/apps/files/tests/js/filesSpec.js
+++ b/apps/files/tests/js/filesSpec.js
@@ -18,6 +18,8 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
+
+/* global Files */
describe('Files tests', function() {
describe('File name validation', function() {
it('Validates correct file names', function() {
@@ -36,12 +38,14 @@ describe('Files tests', function() {
'und Ümläüte sind auch willkommen'
];
for ( var i = 0; i < fileNames.length; i++ ) {
+ var error = false;
try {
expect(Files.isFileNameValid(fileNames[i])).toEqual(true);
}
catch (e) {
- fail();
+ error = e;
}
+ expect(error).toEqual(false);
}
});
it('Detects invalid file names', function() {
@@ -69,7 +73,7 @@ describe('Files tests', function() {
var threwException = false;
try {
Files.isFileNameValid(fileNames[i]);
- fail();
+ console.error('Invalid file name not detected:', fileNames[i]);
}
catch (e) {
threwException = true;
diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php
index 09d5687e226..4c4b3f2040f 100644
--- a/apps/files_encryption/hooks/hooks.php
+++ b/apps/files_encryption/hooks/hooks.php
@@ -32,6 +32,8 @@ class Hooks {
// file for which we want to rename the keys after the rename operation was successful
private static $renamedFiles = array();
+ // file for which we want to delete the keys after the delete operation was successful
+ private static $deleteFiles = array();
/**
* @brief Startup encryption backend upon user login
@@ -630,4 +632,66 @@ class Hooks {
}
}
+ /**
+ * @brief if the file was really deleted we remove the encryption keys
+ * @param array $params
+ * @return boolean
+ */
+ public static function postDelete($params) {
+
+ if (!isset(self::$deleteFiles[$params[\OC\Files\Filesystem::signal_param_path]])) {
+ return true;
+ }
+
+ $deletedFile = self::$deleteFiles[$params[\OC\Files\Filesystem::signal_param_path]];
+ $path = $deletedFile['path'];
+ $user = $deletedFile['uid'];
+
+ // we don't need to remember the file any longer
+ unset(self::$deleteFiles[$params[\OC\Files\Filesystem::signal_param_path]]);
+
+ $view = new \OC\Files\View('/');
+
+ // return if the file still exists and wasn't deleted correctly
+ if ($view->file_exists('/' . $user . '/files/' . $path)) {
+ return true;
+ }
+
+ // Disable encryption proxy to prevent recursive calls
+ $proxyStatus = \OC_FileProxy::$enabled;
+ \OC_FileProxy::$enabled = false;
+
+ // Delete keyfile & shareKey so it isn't orphaned
+ if (!Keymanager::deleteFileKey($view, $path, $user)) {
+ \OCP\Util::writeLog('Encryption library',
+ 'Keyfile or shareKey could not be deleted for file "' . $user.'/files/'.$path . '"', \OCP\Util::ERROR);
+ }
+
+ Keymanager::delAllShareKeys($view, $user, $path);
+
+ \OC_FileProxy::$enabled = $proxyStatus;
+ }
+
+ /**
+ * @brief remember the file which should be deleted and it's owner
+ * @param array $params
+ * @return boolean
+ */
+ public static function preDelete($params) {
+ $path = $params[\OC\Files\Filesystem::signal_param_path];
+
+ // skip this method if the trash bin is enabled or if we delete a file
+ // outside of /data/user/files
+ if (\OCP\App::isEnabled('files_trashbin')) {
+ return true;
+ }
+
+ $util = new Util(new \OC_FilesystemView('/'), \OCP\USER::getUser());
+ list($owner, $ownerPath) = $util->getUidAndFilename($path);
+
+ self::$deleteFiles[$params[\OC\Files\Filesystem::signal_param_path]] = array(
+ 'uid' => $owner,
+ 'path' => $ownerPath);
+ }
+
}
diff --git a/apps/files_encryption/lib/helper.php b/apps/files_encryption/lib/helper.php
index 5dcb05fa196..bb06a57c714 100755
--- a/apps/files_encryption/lib/helper.php
+++ b/apps/files_encryption/lib/helper.php
@@ -63,6 +63,8 @@ class Helper {
\OCP\Util::connectHook('OC_Filesystem', 'rename', 'OCA\Encryption\Hooks', 'preRename');
\OCP\Util::connectHook('OC_Filesystem', 'post_rename', 'OCA\Encryption\Hooks', 'postRename');
+ \OCP\Util::connectHook('OC_Filesystem', 'post_delete', 'OCA\Encryption\Hooks', 'postDelete');
+ \OCP\Util::connectHook('OC_Filesystem', 'delete', 'OCA\Encryption\Hooks', 'preDelete');
}
/**
diff --git a/apps/files_encryption/lib/keymanager.php b/apps/files_encryption/lib/keymanager.php
index b2c756894b4..7abc565f609 100755
--- a/apps/files_encryption/lib/keymanager.php
+++ b/apps/files_encryption/lib/keymanager.php
@@ -214,15 +214,24 @@ class Keymanager {
*
* @param \OC_FilesystemView $view
* @param string $path path of the file the key belongs to
+ * @param string $userId the user to whom the file belongs
* @return bool Outcome of unlink operation
* @note $path must be relative to data/user/files. e.g. mydoc.txt NOT
* /data/admin/files/mydoc.txt
*/
- public static function deleteFileKey(\OC_FilesystemView $view, $path) {
+ public static function deleteFileKey($view, $path, $userId=null) {
$trimmed = ltrim($path, '/');
- $userId = Helper::getUser($path);
+ if ($trimmed === '') {
+ \OCP\Util::writeLog('Encryption library',
+ 'Can\'t delete file-key empty path given!', \OCP\Util::ERROR);
+ return false;
+ }
+
+ if ($userId === null) {
+ $userId = Helper::getUser($path);
+ }
$util = new Util($view, $userId);
if($util->isSystemWideMountPoint($path)) {
@@ -402,7 +411,15 @@ class Keymanager {
* @param string $userId owner of the file
* @param string $filePath path to the file, relative to the owners file dir
*/
- public static function delAllShareKeys(\OC_FilesystemView $view, $userId, $filePath) {
+ public static function delAllShareKeys($view, $userId, $filePath) {
+
+ $filePath = ltrim($filePath, '/');
+
+ if ($filePath === '') {
+ \OCP\Util::writeLog('Encryption library',
+ 'Can\'t delete share-keys empty path given!', \OCP\Util::ERROR);
+ return false;
+ }
$util = new util($view, $userId);
@@ -413,17 +430,15 @@ class Keymanager {
}
- if ($view->is_dir($userId . '/files/' . $filePath)) {
+ if ($view->is_dir($baseDir . $filePath)) {
$view->unlink($baseDir . $filePath);
} else {
- $localKeyPath = $view->getLocalFile($baseDir . $filePath);
- $escapedPath = Helper::escapeGlobPattern($localKeyPath);
- $matches = glob($escapedPath . '*.shareKey');
- foreach ($matches as $ma) {
- $result = unlink($ma);
- if (!$result) {
- \OCP\Util::writeLog('Encryption library',
- 'Keyfile or shareKey could not be deleted for file "' . $filePath . '"', \OCP\Util::ERROR);
+ $parentDir = dirname($baseDir . $filePath);
+ $filename = pathinfo($filePath, PATHINFO_BASENAME);
+ foreach($view->getDirectoryContent($parentDir) as $content) {
+ $path = $content['path'];
+ if (self::getFilenameFromShareKey($content['name']) === $filename) {
+ $view->unlink('/' . $userId . '/' . $path);
}
}
}
@@ -523,4 +538,20 @@ class Keymanager {
return $targetPath;
}
+
+ /**
+ * @brief extract filename from share key name
+ * @param string $shareKey (filename.userid.sharekey)
+ * @return mixed filename or false
+ */
+ protected static function getFilenameFromShareKey($shareKey) {
+ $parts = explode('.', $shareKey);
+
+ $filename = false;
+ if(count($parts) > 2) {
+ $filename = implode('.', array_slice($parts, 0, count($parts)-2));
+ }
+
+ return $filename;
+ }
}
diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php
index 4e71ab1dd5d..11048005969 100644
--- a/apps/files_encryption/lib/proxy.php
+++ b/apps/files_encryption/lib/proxy.php
@@ -204,47 +204,6 @@ class Proxy extends \OC_FileProxy {
}
/**
- * @brief When a file is deleted, remove its keyfile also
- */
- public function preUnlink($path) {
-
- $relPath = Helper::stripUserFilesPath($path);
-
- // skip this method if the trash bin is enabled or if we delete a file
- // outside of /data/user/files
- if (\OCP\App::isEnabled('files_trashbin') || $relPath === false) {
- return true;
- }
-
- // Disable encryption proxy to prevent recursive calls
- $proxyStatus = \OC_FileProxy::$enabled;
- \OC_FileProxy::$enabled = false;
-
- $view = new \OC_FilesystemView('/');
-
- $userId = \OCP\USER::getUser();
-
- $util = new Util($view, $userId);
-
- list($owner, $ownerPath) = $util->getUidAndFilename($relPath);
-
- // Delete keyfile & shareKey so it isn't orphaned
- if (!Keymanager::deleteFileKey($view, $ownerPath)) {
- \OCP\Util::writeLog('Encryption library',
- 'Keyfile or shareKey could not be deleted for file "' . $ownerPath . '"', \OCP\Util::ERROR);
- }
-
- Keymanager::delAllShareKeys($view, $owner, $ownerPath);
-
- \OC_FileProxy::$enabled = $proxyStatus;
-
- // If we don't return true then file delete will fail; better
- // to leave orphaned keyfiles than to disallow file deletion
- return true;
-
- }
-
- /**
* @param $path
* @return bool
*/
diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php
index 8816d4d649a..ae3e2a2e15a 100644
--- a/apps/files_encryption/lib/util.php
+++ b/apps/files_encryption/lib/util.php
@@ -57,7 +57,7 @@ class Util {
* @param $userId
* @param bool $client
*/
- public function __construct(\OC_FilesystemView $view, $userId, $client = false) {
+ public function __construct($view, $userId, $client = false) {
$this->view = $view;
$this->client = $client;
diff --git a/apps/files_encryption/tests/hooks.php b/apps/files_encryption/tests/hooks.php
new file mode 100644
index 00000000000..c26cba6406d
--- /dev/null
+++ b/apps/files_encryption/tests/hooks.php
@@ -0,0 +1,271 @@
+<?php
+/**
+ * ownCloud
+ *
+ * @author Bjoern Schiessle
+ * @copyright 2014 Bjoern Schiessle <schiessle@owncloud.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+require_once __DIR__ . '/../../../lib/base.php';
+require_once __DIR__ . '/../lib/crypt.php';
+require_once __DIR__ . '/../lib/keymanager.php';
+require_once __DIR__ . '/../lib/stream.php';
+require_once __DIR__ . '/../lib/util.php';
+require_once __DIR__ . '/../appinfo/app.php';
+require_once __DIR__ . '/util.php';
+
+use OCA\Encryption;
+
+/**
+ * Class Test_Encryption_Hooks
+ * @brief this class provide basic hook app tests
+ */
+class Test_Encryption_Hooks extends \PHPUnit_Framework_TestCase {
+
+ const TEST_ENCRYPTION_HOOKS_USER1 = "test-proxy-user1";
+ const TEST_ENCRYPTION_HOOKS_USER2 = "test-proxy-user2";
+
+ /**
+ * @var \OC_FilesystemView
+ */
+ public $user1View; // view on /data/user1/files
+ public $user2View; // view on /data/user2/files
+ public $rootView; // view on /data/user
+ public $data;
+ public $filename;
+
+ public static function setUpBeforeClass() {
+ // reset backend
+ \OC_User::clearBackends();
+ \OC_User::useBackend('database');
+
+ \OC_Hook::clear('OC_Filesystem');
+ \OC_Hook::clear('OC_User');
+
+ // clear share hooks
+ \OC_Hook::clear('OCP\\Share');
+ \OC::registerShareHooks();
+ \OCP\Util::connectHook('OC_Filesystem', 'setup', '\OC\Files\Storage\Shared', 'setup');
+
+ // Filesystem related hooks
+ \OCA\Encryption\Helper::registerFilesystemHooks();
+
+ // Sharing related hooks
+ \OCA\Encryption\Helper::registerShareHooks();
+
+ // clear and register proxies
+ \OC_FileProxy::clearProxies();
+ \OC_FileProxy::register(new OCA\Encryption\Proxy());
+
+ // create test user
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1, true);
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2, true);
+ }
+
+ function setUp() {
+ // set user id
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1);
+ \OC_User::setUserId(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1);
+
+ // init filesystem view
+ $this->user1View = new \OC_FilesystemView('/'. \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1 . '/files');
+ $this->user2View = new \OC_FilesystemView('/'. \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '/files');
+ $this->rootView = new \OC_FilesystemView('/');
+
+ // init short data
+ $this->data = 'hats';
+ $this->filename = 'enc_hooks_tests-' . uniqid() . '.txt';
+
+ }
+
+ public static function tearDownAfterClass() {
+ // cleanup test user
+ \OC_User::deleteUser(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1);
+ \OC_User::deleteUser(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2);
+ }
+
+ function testDeleteHooks() {
+
+ // remember files_trashbin state
+ $stateFilesTrashbin = OC_App::isEnabled('files_trashbin');
+
+ // we want to tests with app files_trashbin disabled
+ \OC_App::disable('files_trashbin');
+
+ // make sure that the trash bin is disabled
+ $this->assertFalse(\OC_APP::isEnabled('files_trashbin'));
+
+ $this->user1View->file_put_contents($this->filename, $this->data);
+
+ // check if all keys are generated
+ $this->assertTrue($this->rootView->file_exists(
+ self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey'));
+ $this->assertTrue($this->rootView->file_exists(
+ self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keyfiles/' . $this->filename . '.key'));
+
+
+ \Test_Encryption_Util::logoutHelper();
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2);
+ \OC_User::setUserId(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2);
+
+
+ $this->user2View->file_put_contents($this->filename, $this->data);
+
+ // check if all keys are generated
+ $this->assertTrue($this->rootView->file_exists(
+ self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey'));
+ $this->assertTrue($this->rootView->file_exists(
+ self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/keyfiles/' . $this->filename . '.key'));
+
+
+ // create a dummy file that we can delete something outside of data/user/files
+ // in this case no share or file keys should be deleted
+ $this->rootView->file_put_contents(self::TEST_ENCRYPTION_HOOKS_USER2 . "/" . $this->filename, $this->data);
+
+ // delete dummy file outside of data/user/files
+ $this->rootView->unlink(self::TEST_ENCRYPTION_HOOKS_USER2 . "/" . $this->filename);
+
+ // all keys should still exist
+ $this->assertTrue($this->rootView->file_exists(
+ self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey'));
+ $this->assertTrue($this->rootView->file_exists(
+ self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/keyfiles/' . $this->filename . '.key'));
+
+
+ // delete the file in data/user/files
+ // now the correspondig share and file keys from user2 should be deleted
+ $this->user2View->unlink($this->filename);
+
+ // check if keys from user2 are really deleted
+ $this->assertFalse($this->rootView->file_exists(
+ self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey'));
+ $this->assertFalse($this->rootView->file_exists(
+ self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/keyfiles/' . $this->filename . '.key'));
+
+ // but user1 keys should still exist
+ $this->assertTrue($this->rootView->file_exists(
+ self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey'));
+ $this->assertTrue($this->rootView->file_exists(
+ self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keyfiles/' . $this->filename . '.key'));
+
+ if ($stateFilesTrashbin) {
+ OC_App::enable('files_trashbin');
+ }
+ else {
+ OC_App::disable('files_trashbin');
+ }
+ }
+
+ function testDeleteHooksForSharedFiles() {
+
+ \Test_Encryption_Util::logoutHelper();
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1);
+ \OC_User::setUserId(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1);
+
+ // remember files_trashbin state
+ $stateFilesTrashbin = OC_App::isEnabled('files_trashbin');
+
+ // we want to tests with app files_trashbin disabled
+ \OC_App::disable('files_trashbin');
+
+ // make sure that the trash bin is disabled
+ $this->assertFalse(\OC_APP::isEnabled('files_trashbin'));
+
+ $this->user1View->file_put_contents($this->filename, $this->data);
+
+ // check if all keys are generated
+ $this->assertTrue($this->rootView->file_exists(
+ self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey'));
+ $this->assertTrue($this->rootView->file_exists(
+ self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keyfiles/' . $this->filename . '.key'));
+
+ // get the file info from previous created file
+ $fileInfo = $this->user1View->getFileInfo($this->filename);
+
+ // check if we have a valid file info
+ $this->assertTrue(is_array($fileInfo));
+
+ // share the file with user2
+ \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_HOOKS_USER2, OCP\PERMISSION_ALL);
+
+ // check if new share key exists
+ $this->assertTrue($this->rootView->file_exists(
+ self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey'));
+
+ \Test_Encryption_Util::logoutHelper();
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2);
+ \OC_User::setUserId(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2);
+
+ // user2 has a local file with the same name
+ $this->user2View->file_put_contents($this->filename, $this->data);
+
+ // check if all keys are generated
+ $this->assertTrue($this->rootView->file_exists(
+ self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey'));
+ $this->assertTrue($this->rootView->file_exists(
+ self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/keyfiles/' . $this->filename . '.key'));
+
+ // delete the Shared file from user1 in data/user2/files/Shared
+ $this->user2View->unlink('/Shared/' . $this->filename);
+
+ // now keys from user1s home should be gone
+ $this->assertFalse($this->rootView->file_exists(
+ self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey'));
+ $this->assertFalse($this->rootView->file_exists(
+ self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey'));
+ $this->assertFalse($this->rootView->file_exists(
+ self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keyfiles/' . $this->filename . '.key'));
+
+ // but user2 keys should still exist
+ $this->assertTrue($this->rootView->file_exists(
+ self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey'));
+ $this->assertTrue($this->rootView->file_exists(
+ self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/keyfiles/' . $this->filename . '.key'));
+
+ // cleanup
+
+ $this->user2View->unlink($this->filename);
+
+ \Test_Encryption_Util::logoutHelper();
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1);
+ \OC_User::setUserId(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1);
+
+ // unshare the file
+ \OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_HOOKS_USER2);
+
+ $this->user1View->unlink($this->filename);
+
+ if ($stateFilesTrashbin) {
+ OC_App::enable('files_trashbin');
+ }
+ else {
+ OC_App::disable('files_trashbin');
+ }
+ }
+
+}
diff --git a/apps/files_encryption/tests/keymanager.php b/apps/files_encryption/tests/keymanager.php
index 58a57ee5af4..6f32c50743c 100644
--- a/apps/files_encryption/tests/keymanager.php
+++ b/apps/files_encryption/tests/keymanager.php
@@ -137,6 +137,17 @@ class Test_Encryption_Keymanager extends \PHPUnit_Framework_TestCase {
}
/**
+ * @small
+ */
+ function testGetFilenameFromShareKey() {
+ $this->assertEquals("file",
+ \TestProtectedKeymanagerMethods::testGetFilenameFromShareKey("file.user.shareKey"));
+ $this->assertEquals("file.name.with.dots",
+ \TestProtectedKeymanagerMethods::testGetFilenameFromShareKey("file.name.with.dots.user.shareKey"));
+ $this->assertFalse(\TestProtectedKeymanagerMethods::testGetFilenameFromShareKey("file.txt"));
+ }
+
+ /**
* @medium
*/
function testSetFileKey() {
@@ -234,3 +245,12 @@ class Test_Encryption_Keymanager extends \PHPUnit_Framework_TestCase {
\OC_FileProxy::$enabled = $proxyStatus;
}
}
+
+/**
+ * dummy class to access protected methods of \OCA\Encryption\Keymanager for testing
+ */
+class TestProtectedKeymanagerMethods extends \OCA\Encryption\Keymanager {
+ public static function testGetFilenameFromShareKey($sharekey) {
+ return self::getFilenameFromShareKey($sharekey);
+ }
+} \ No newline at end of file
diff --git a/apps/files_encryption/tests/proxy.php b/apps/files_encryption/tests/proxy.php
index c3006274d6d..51cc0b795e3 100644
--- a/apps/files_encryption/tests/proxy.php
+++ b/apps/files_encryption/tests/proxy.php
@@ -112,54 +112,4 @@ class Test_Encryption_Proxy extends \PHPUnit_Framework_TestCase {
}
- function testPreUnlinkWithoutTrash() {
-
- // remember files_trashbin state
- $stateFilesTrashbin = OC_App::isEnabled('files_trashbin');
-
- // we want to tests with app files_trashbin enabled
- \OC_App::disable('files_trashbin');
-
- $this->view->file_put_contents($this->filename, $this->data);
-
- // create a dummy file that we can delete something outside of data/user/files
- $this->rootView->file_put_contents("dummy.txt", $this->data);
-
- // check if all keys are generated
- $this->assertTrue($this->rootView->file_exists(
- '/files_encryption/share-keys/'
- . $this->filename . '.' . \Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1 . '.shareKey'));
- $this->assertTrue($this->rootView->file_exists(
- '/files_encryption/keyfiles/' . $this->filename . '.key'));
-
-
- // delete dummy file outside of data/user/files
- $this->rootView->unlink("dummy.txt");
-
- // all keys should still exist
- $this->assertTrue($this->rootView->file_exists(
- '/files_encryption/share-keys/'
- . $this->filename . '.' . \Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1 . '.shareKey'));
- $this->assertTrue($this->rootView->file_exists(
- '/files_encryption/keyfiles/' . $this->filename . '.key'));
-
-
- // delete the file in data/user/files
- $this->view->unlink($this->filename);
-
- // now also the keys should be gone
- $this->assertFalse($this->rootView->file_exists(
- '/files_encryption/share-keys/'
- . $this->filename . '.' . \Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1 . '.shareKey'));
- $this->assertFalse($this->rootView->file_exists(
- '/files_encryption/keyfiles/' . $this->filename . '.key'));
-
- if ($stateFilesTrashbin) {
- OC_App::enable('files_trashbin');
- }
- else {
- OC_App::disable('files_trashbin');
- }
- }
-
}
diff --git a/apps/files_encryption/tests/share.php b/apps/files_encryption/tests/share.php
index e55427620a6..acf408a07f0 100755
--- a/apps/files_encryption/tests/share.php
+++ b/apps/files_encryption/tests/share.php
@@ -194,8 +194,9 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
. $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
// cleanup
- $this->view->unlink(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
+ $this->view->chroot('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/');
+ $this->view->unlink($this->filename);
+ $this->view->chroot('/');
// check if share key not exists
$this->assertFalse($this->view->file_exists(
@@ -265,8 +266,9 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
. $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
// cleanup
- $this->view->unlink(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
+ $this->view->chroot('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/');
+ $this->view->unlink($this->filename);
+ $this->view->chroot('/');
// check if share key not exists
$this->assertFalse($this->view->file_exists(
@@ -352,7 +354,9 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
. $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
// cleanup
- $this->view->unlink('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files' . $this->folder1);
+ $this->view->chroot('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files');
+ $this->view->unlink($this->folder1);
+ $this->view->chroot('/');
// check if share key not exists
$this->assertFalse($this->view->file_exists(
@@ -482,9 +486,9 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
. $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
// cleanup
- $this->view->unlink(
- '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files' . $this->folder1 . $this->subfolder
- . $this->subsubfolder . '/' . $this->filename);
+ $this->view->chroot('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files');
+ $this->view->unlink($this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename);
+ $this->view->chroot('/');
// check if share key not exists
$this->assertFalse($this->view->file_exists(
@@ -559,7 +563,9 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
. $this->filename . '.' . $publicShareKeyId . '.shareKey'));
// cleanup
- $this->view->unlink('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
+ $this->view->chroot('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/');
+ $this->view->unlink($this->filename);
+ $this->view->chroot('/');
// check if share key not exists
$this->assertFalse($this->view->file_exists(
@@ -636,7 +642,9 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
. $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4 . '.shareKey'));
// cleanup
- $this->view->unlink('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
+ $this->view->chroot('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/');
+ $this->view->unlink($this->filename);
+ $this->view->chroot('/');
// check if share key not exists
$this->assertFalse($this->view->file_exists(
@@ -731,8 +739,10 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
. $this->filename . '.' . $recoveryKeyId . '.shareKey'));
// cleanup
- $this->view->unlink('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
- $this->view->unlink('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->folder1);
+ $this->view->chroot('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/');
+ $this->view->unlink($this->filename);
+ $this->view->unlink($this->folder1);
+ $this->view->chroot('/');
// check if share key for recovery not exists
$this->assertFalse($this->view->file_exists(
@@ -828,8 +838,10 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
$this->assertEquals($this->dataShort, $retrievedCryptedFile2);
// cleanup
- $this->view->unlink('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->folder1);
- $this->view->unlink('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->filename);
+ $this->view->chroot('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/');
+ $this->view->unlink($this->folder1);
+ $this->view->unlink($this->filename);
+ $this->view->chroot('/');
// check if share key for user and recovery exists
$this->assertFalse($this->view->file_exists(
@@ -930,7 +942,9 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
. $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey'));
// cleanup
- $this->view->unlink('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
+ $this->view->chroot('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/');
+ $this->view->unlink($this->filename);
+ $this->view->chroot('/');
}
}
diff --git a/apps/files_sharing/public.php b/apps/files_sharing/public.php
index 0ca923fff08..f03ac7205a3 100644
--- a/apps/files_sharing/public.php
+++ b/apps/files_sharing/public.php
@@ -144,15 +144,12 @@ if (isset($path)) {
OCP\Util::addScript('files', 'jquery.fileupload');
$maxUploadFilesize=OCP\Util::maxUploadFilesize($path);
$tmpl = new OCP\Template('files_sharing', 'public', 'base');
- $tmpl->assign('uidOwner', $shareOwner);
$tmpl->assign('displayName', \OCP\User::getDisplayName($shareOwner));
$tmpl->assign('filename', $file);
$tmpl->assign('directory_path', $linkItem['file_target']);
$tmpl->assign('mimetype', \OC\Files\Filesystem::getMimeType($path));
- $tmpl->assign('fileTarget', basename($linkItem['file_target']));
$tmpl->assign('dirToken', $linkItem['token']);
$tmpl->assign('sharingToken', $token);
- $tmpl->assign('disableSharing', true);
$allowPublicUploadEnabled = (bool) ($linkItem['permissions'] & OCP\PERMISSION_CREATE);
if (OC_Appconfig::getValue('core', 'shareapi_allow_public_upload', 'yes') === 'no') {
$allowPublicUploadEnabled = false;
@@ -160,8 +157,6 @@ if (isset($path)) {
if ($linkItem['item_type'] !== 'folder') {
$allowPublicUploadEnabled = false;
}
- $tmpl->assign('uploadMaxFilesize', $maxUploadFilesize);
- $tmpl->assign('uploadMaxHumanFilesize', OCP\Util::humanFileSize($maxUploadFilesize));
$urlLinkIdentifiers= (isset($token)?'&t='.$token:'')
.(isset($_GET['dir'])?'&dir='.$_GET['dir']:'')
@@ -222,6 +217,9 @@ if (isset($path)) {
$maxUploadFilesize=OCP\Util::maxUploadFilesize($path);
$fileHeader = (!isset($files) or count($files) > 0);
$emptyContent = ($allowPublicUploadEnabled and !$fileHeader);
+
+ $freeSpace=OCP\Util::freeSpace($path);
+ $uploadLimit=OCP\Util::uploadLimit();
$folder = new OCP\Template('files', 'index', '');
$folder->assign('fileList', $list->fetchPage());
$folder->assign('breadcrumb', $breadcrumbNav->fetchPage());
@@ -234,6 +232,8 @@ if (isset($path)) {
$folder->assign('files', $files);
$folder->assign('uploadMaxFilesize', $maxUploadFilesize);
$folder->assign('uploadMaxHumanFilesize', OCP\Util::humanFileSize($maxUploadFilesize));
+ $folder->assign('freeSpace', $freeSpace);
+ $folder->assign('uploadLimit', $uploadLimit); // PHP upload limit
$folder->assign('allowZipDownload', intval(OCP\Config::getSystemValue('allowZipDownload', true)));
$folder->assign('usedSpacePercent', 0);
$folder->assign('fileHeader', $fileHeader);
diff --git a/apps/user_ldap/lib/connection.php b/apps/user_ldap/lib/connection.php
index c4e4efd0483..7fbabda7106 100644
--- a/apps/user_ldap/lib/connection.php
+++ b/apps/user_ldap/lib/connection.php
@@ -52,7 +52,7 @@ class Connection extends LDAPUtility {
$this->configID = $configID;
$this->configuration = new Configuration($configPrefix,
!is_null($configID));
- $memcache = new \OC\Memcache\Factory();
+ $memcache = \OC::$server->getMemCacheFactory();
if($memcache->isAvailable()) {
$this->cache = $memcache->create();
} else {
diff --git a/autotest-js.sh b/autotest-js.sh
index 78f4948e7ad..8b9a106b021 100755
--- a/autotest-js.sh
+++ b/autotest-js.sh
@@ -33,5 +33,5 @@ then
exit 2
fi
-KARMA_TESTSUITE="$1" $KARMA start tests/karma.config.js --single-run
+NODE_PATH='build/node_modules' KARMA_TESTSUITE="$1" $KARMA start tests/karma.config.js --single-run
diff --git a/autotest.sh b/autotest.sh
index 94fc692a94d..b88e9cf68b4 100755
--- a/autotest.sh
+++ b/autotest.sh
@@ -185,19 +185,23 @@ EOF
cp $BASEDIR/tests/autoconfig-$1.php $BASEDIR/config/autoconfig.php
# trigger installation
- php -f index.php
+ echo "INDEX"
+ php -f index.php | grep -i -C9999 error && echo "Error during setup" && exit 101
+ echo "END INDEX"
#test execution
echo "Testing with $1 ..."
cd tests
rm -rf coverage-html-$1
mkdir coverage-html-$1
- php -f enable_all.php
+ php -f enable_all.php | grep -i -C9999 error && echo "Error during setup" && exit 101
if [ -z "$NOCOVERAGE" ]; then
$PHPUNIT --configuration phpunit-autotest.xml --log-junit autotest-results-$1.xml --coverage-clover autotest-clover-$1.xml --coverage-html coverage-html-$1 $2 $3
+ RESULT=$?
else
echo "No coverage"
$PHPUNIT --configuration phpunit-autotest.xml --log-junit autotest-results-$1.xml $2 $3
+ RESULT=$?
fi
}
diff --git a/config/config.sample.php b/config/config.sample.php
index 01abc583688..ef5fb7ea5a5 100755
--- a/config/config.sample.php
+++ b/config/config.sample.php
@@ -184,6 +184,13 @@ $CONFIG = array(
/* Life time of a session after inactivity */
"session_lifetime" => 60 * 60 * 24,
+/*
+ * Enable/disable session keep alive when a user is logged in in the Web UI.
+ * This is achieved by sending a "heartbeat" to the server to prevent
+ * the session timing out.
+ */
+"session_keepalive" => true,
+
/* Custom CSP policy, changing this will overwrite the standard policy */
"custom_csp_policy" => "default-src 'self'; script-src 'self' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; frame-src *; img-src *; font-src 'self' data:; media-src *",
diff --git a/core/js/config.php b/core/js/config.php
index dd46f7889d1..517ea1615a8 100644
--- a/core/js/config.php
+++ b/core/js/config.php
@@ -55,6 +55,12 @@ $array = array(
)
),
"firstDay" => json_encode($l->l('firstday', 'firstday')) ,
+ "oc_config" => json_encode(
+ array(
+ 'session_lifetime' => \OCP\Config::getSystemValue('session_lifetime', 60 * 60 * 24),
+ 'session_keepalive' => \OCP\Config::getSystemValue('session_keepalive', true)
+ )
+ )
);
// Echo it
diff --git a/core/js/core.json b/core/js/core.json
index 79cfc42f587..4beab7cf796 100644
--- a/core/js/core.json
+++ b/core/js/core.json
@@ -1,28 +1,23 @@
{
+ "libraries": [
+ "jquery-1.10.0.min.js",
+ "jquery-migrate-1.2.1.min.js",
+ "jquery-ui-1.10.0.custom.js",
+ "jquery-showpassword.js",
+ "jquery.infieldlabel.js",
+ "jquery.placeholder.js",
+ "jquery-tipsy.js"
+ ],
"modules": [
- "jquery-1.10.0.min.js",
- "jquery-migrate-1.2.1.min.js",
- "jquery-ui-1.10.0.custom.js",
- "jquery-showpassword.js",
- "jquery.infieldlabel.js",
- "jquery.placeholder.js",
- "jquery-tipsy.js",
- "compatibility.js",
- "jquery.ocdialog.js",
- "oc-dialogs.js",
- "js.js",
- "octemplate.js",
- "eventsource.js",
- "config.js",
- "multiselect.js",
- "search.js",
- "router.js",
- "oc-requesttoken.js",
- "styles.js",
- "apps.js",
- "fixes.js",
- "jquery-ui-2.10.0.custom.js",
- "jquery-tipsy.js",
- "jquery.ocdialog.js"
+ "compatibility.js",
+ "jquery.ocdialog.js",
+ "oc-dialogs.js",
+ "js.js",
+ "octemplate.js",
+ "eventsource.js",
+ "config.js",
+ "multiselect.js",
+ "router.js",
+ "oc-requesttoken.js"
]
}
diff --git a/core/js/js.js b/core/js/js.js
index 1c7d89ea055..cb177712a3a 100644
--- a/core/js/js.js
+++ b/core/js/js.js
@@ -11,6 +11,8 @@ var oc_webroot;
var oc_current_user = document.getElementsByTagName('head')[0].getAttribute('data-user');
var oc_requesttoken = document.getElementsByTagName('head')[0].getAttribute('data-requesttoken');
+window.oc_config = window.oc_config || {};
+
if (typeof oc_webroot === "undefined") {
oc_webroot = location.pathname;
var pos = oc_webroot.indexOf('/index.php/');
@@ -742,8 +744,39 @@ function fillWindow(selector) {
console.warn("This function is deprecated! Use CSS instead");
}
-$(document).ready(function(){
- sessionHeartBeat();
+/**
+ * Initializes core
+ */
+function initCore() {
+
+ /**
+ * Calls the server periodically to ensure that session doesn't
+ * time out
+ */
+ function initSessionHeartBeat(){
+ // interval in seconds
+ var interval = 900;
+ if (oc_config.session_lifetime) {
+ interval = Math.floor(oc_config.session_lifetime / 2);
+ }
+ // minimum one minute
+ if (interval < 60) {
+ interval = 60;
+ }
+ OC.Router.registerLoadedCallback(function(){
+ var url = OC.Router.generate('heartbeat');
+ setInterval(function(){
+ $.post(url);
+ }, interval * 1000);
+ });
+ }
+
+ // session heartbeat (defaults to enabled)
+ if (typeof(oc_config.session_keepalive) === 'undefined' ||
+ !!oc_config.session_keepalive) {
+
+ initSessionHeartBeat();
+ }
if(!SVGSupport()){ //replace all svg images with png images for browser that dont support svg
replaceSVG();
@@ -856,7 +889,9 @@ $(document).ready(function(){
$('input[type=text]').focus(function(){
this.select();
});
-});
+}
+
+$(document).ready(initCore);
/**
* Filter Jquery selector by attribute value
@@ -986,15 +1021,3 @@ jQuery.fn.exists = function(){
return this.length > 0;
};
-/**
- * Calls the server periodically every 15 mins to ensure that session doesnt
- * time out
- */
-function sessionHeartBeat(){
- OC.Router.registerLoadedCallback(function(){
- var url = OC.Router.generate('heartbeat');
- setInterval(function(){
- $.post(url);
- }, 900000);
- });
-}
diff --git a/core/js/tests/specHelper.js b/core/js/tests/specHelper.js
index 4a30878df51..1848d08354e 100644
--- a/core/js/tests/specHelper.js
+++ b/core/js/tests/specHelper.js
@@ -19,6 +19,8 @@
*
*/
+/* global OC */
+
/**
* Simulate the variables that are normally set by PHP code
*/
@@ -57,10 +59,15 @@ window.oc_webroot = location.href + '/';
window.oc_appswebroots = {
"files": window.oc_webroot + '/apps/files/'
};
+window.oc_config = {
+ session_lifetime: 600 * 1000,
+ session_keepalive: false
+};
// global setup for all tests
(function setupTests() {
- var fakeServer = null;
+ var fakeServer = null,
+ routesRequestStub;
beforeEach(function() {
// enforce fake XHR, tests should not depend on the server and
@@ -78,9 +85,18 @@ window.oc_appswebroots = {
// make it globally available, so that other tests can define
// custom responses
window.fakeServer = fakeServer;
+
+ OC.Router.routes = [];
+ OC.Router.routes_request = {
+ state: sinon.stub().returns('resolved'),
+ done: sinon.stub()
+ };
});
afterEach(function() {
+ OC.Router.routes_request.state.reset();
+ OC.Router.routes_request.done.reset();
+
// uncomment this to log requests
// console.log(window.fakeServer.requests);
fakeServer.restore();
diff --git a/core/js/tests/specs/coreSpec.js b/core/js/tests/specs/coreSpec.js
index 28c20a0642e..478505e9287 100644
--- a/core/js/tests/specs/coreSpec.js
+++ b/core/js/tests/specs/coreSpec.js
@@ -18,6 +18,8 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
+
+/* global OC */
describe('Core base tests', function() {
describe('Base values', function() {
it('Sets webroots', function() {
@@ -25,6 +27,103 @@ describe('Core base tests', function() {
expect(OC.appswebroots).toBeDefined();
});
});
+ describe('basename', function() {
+ it('Returns the nothing if no file name given', function() {
+ expect(OC.basename('')).toEqual('');
+ });
+ it('Returns the nothing if dir is root', function() {
+ expect(OC.basename('/')).toEqual('');
+ });
+ it('Returns the same name if no path given', function() {
+ expect(OC.basename('some name.txt')).toEqual('some name.txt');
+ });
+ it('Returns the base name if root path given', function() {
+ expect(OC.basename('/some name.txt')).toEqual('some name.txt');
+ });
+ it('Returns the base name if double root path given', function() {
+ expect(OC.basename('//some name.txt')).toEqual('some name.txt');
+ });
+ it('Returns the base name if subdir given without root', function() {
+ expect(OC.basename('subdir/some name.txt')).toEqual('some name.txt');
+ });
+ it('Returns the base name if subdir given with root', function() {
+ expect(OC.basename('/subdir/some name.txt')).toEqual('some name.txt');
+ });
+ it('Returns the base name if subdir given with double root', function() {
+ expect(OC.basename('//subdir/some name.txt')).toEqual('some name.txt');
+ });
+ it('Returns the base name if subdir has dot', function() {
+ expect(OC.basename('/subdir.dat/some name.txt')).toEqual('some name.txt');
+ });
+ it('Returns dot if file name is dot', function() {
+ expect(OC.basename('/subdir/.')).toEqual('.');
+ });
+ // TODO: fix the source to make it work like PHP's basename
+ it('Returns the dir itself if no file name given', function() {
+ // TODO: fix the source to make it work like PHP's dirname
+ // expect(OC.basename('subdir/')).toEqual('subdir');
+ expect(OC.basename('subdir/')).toEqual('');
+ });
+ it('Returns the dir itself if no file name given with root', function() {
+ // TODO: fix the source to make it work like PHP's dirname
+ // expect(OC.basename('/subdir/')).toEqual('subdir');
+ expect(OC.basename('/subdir/')).toEqual('');
+ });
+ });
+ describe('dirname', function() {
+ it('Returns the nothing if no file name given', function() {
+ expect(OC.dirname('')).toEqual('');
+ });
+ it('Returns the root if dir is root', function() {
+ // TODO: fix the source to make it work like PHP's dirname
+ // expect(OC.dirname('/')).toEqual('/');
+ expect(OC.dirname('/')).toEqual('');
+ });
+ it('Returns the root if dir is double root', function() {
+ // TODO: fix the source to make it work like PHP's dirname
+ // expect(OC.dirname('//')).toEqual('/');
+ expect(OC.dirname('//')).toEqual('/'); // oh no...
+ });
+ it('Returns dot if dir is dot', function() {
+ expect(OC.dirname('.')).toEqual('.');
+ });
+ it('Returns dot if no root given', function() {
+ // TODO: fix the source to make it work like PHP's dirname
+ // expect(OC.dirname('some dir')).toEqual('.');
+ expect(OC.dirname('some dir')).toEqual('some dir'); // oh no...
+ });
+ it('Returns the dir name if file name and root path given', function() {
+ // TODO: fix the source to make it work like PHP's dirname
+ // expect(OC.dirname('/some name.txt')).toEqual('/');
+ expect(OC.dirname('/some name.txt')).toEqual('');
+ });
+ it('Returns the dir name if double root path given', function() {
+ expect(OC.dirname('//some name.txt')).toEqual('/'); // how lucky...
+ });
+ it('Returns the dir name if subdir given without root', function() {
+ expect(OC.dirname('subdir/some name.txt')).toEqual('subdir');
+ });
+ it('Returns the dir name if subdir given with root', function() {
+ expect(OC.dirname('/subdir/some name.txt')).toEqual('/subdir');
+ });
+ it('Returns the dir name if subdir given with double root', function() {
+ // TODO: fix the source to make it work like PHP's dirname
+ // expect(OC.dirname('//subdir/some name.txt')).toEqual('/subdir');
+ expect(OC.dirname('//subdir/some name.txt')).toEqual('//subdir'); // oh...
+ });
+ it('Returns the dir name if subdir has dot', function() {
+ expect(OC.dirname('/subdir.dat/some name.txt')).toEqual('/subdir.dat');
+ });
+ it('Returns the dir name if file name is dot', function() {
+ expect(OC.dirname('/subdir/.')).toEqual('/subdir');
+ });
+ it('Returns the dir name if no file name given', function() {
+ expect(OC.dirname('subdir/')).toEqual('subdir');
+ });
+ it('Returns the dir name if no file name given with root', function() {
+ expect(OC.dirname('/subdir/')).toEqual('/subdir');
+ });
+ });
describe('Link functions', function() {
var TESTAPP = 'testapp';
var TESTAPP_ROOT = OC.webroot + '/appsx/testapp';
@@ -104,4 +203,78 @@ describe('Core base tests', function() {
})).toEqual('number=123');
});
});
+ describe('Session heartbeat', function() {
+ var clock,
+ oldConfig,
+ loadedStub,
+ routeStub,
+ counter;
+
+ beforeEach(function() {
+ clock = sinon.useFakeTimers();
+ oldConfig = window.oc_config;
+ loadedStub = sinon.stub(OC.Router, 'registerLoadedCallback');
+ routeStub = sinon.stub(OC.Router, 'generate').returns('/heartbeat');
+ counter = 0;
+
+ fakeServer.autoRespond = true;
+ fakeServer.autoRespondAfter = 0;
+ fakeServer.respondWith(/\/heartbeat/, function(xhr) {
+ counter++;
+ xhr.respond(200, {'Content-Type': 'application/json'}, '{}');
+ });
+ });
+ afterEach(function() {
+ clock.restore();
+ window.oc_config = oldConfig;
+ loadedStub.restore();
+ routeStub.restore();
+ });
+ it('sends heartbeat half the session lifetime when heartbeat enabled', function() {
+ window.oc_config = {
+ session_keepalive: true,
+ session_lifetime: 300
+ };
+ window.initCore();
+ expect(loadedStub.calledOnce).toEqual(true);
+ loadedStub.yield();
+ expect(routeStub.calledWith('heartbeat')).toEqual(true);
+
+ expect(counter).toEqual(0);
+
+ // less than half, still nothing
+ clock.tick(100 * 1000);
+ expect(counter).toEqual(0);
+
+ // reach past half (160), one call
+ clock.tick(55 * 1000);
+ expect(counter).toEqual(1);
+
+ // almost there to the next, still one
+ clock.tick(140 * 1000);
+ expect(counter).toEqual(1);
+
+ // past it, second call
+ clock.tick(20 * 1000);
+ expect(counter).toEqual(2);
+ });
+ it('does no send heartbeat when heartbeat disabled', function() {
+ window.oc_config = {
+ session_keepalive: false,
+ session_lifetime: 300
+ };
+ window.initCore();
+ expect(loadedStub.notCalled).toEqual(true);
+ expect(routeStub.notCalled).toEqual(true);
+
+ expect(counter).toEqual(0);
+
+ clock.tick(1000000);
+
+ // still nothing
+ expect(counter).toEqual(0);
+ });
+
+ });
});
+
diff --git a/core/setup.php b/core/setup.php
deleted file mode 100644
index 958376b2cce..00000000000
--- a/core/setup.php
+++ /dev/null
@@ -1,73 +0,0 @@
-<?php
-
-// Check for autosetup:
-$autosetup_file = OC::$SERVERROOT."/config/autoconfig.php";
-if( file_exists( $autosetup_file )) {
- OC_Log::write('core', 'Autoconfig file found, setting up owncloud...', OC_Log::INFO);
- include $autosetup_file;
- $_POST = array_merge ($_POST, $AUTOCONFIG);
- $_REQUEST = array_merge ($_REQUEST, $AUTOCONFIG);
-}
-
-$dbIsSet = isset($_POST['dbtype']);
-$directoryIsSet = isset($_POST['directory']);
-$adminAccountIsSet = isset($_POST['adminlogin']);
-
-if ($dbIsSet AND $directoryIsSet AND $adminAccountIsSet) {
- $_POST['install'] = 'true';
- if( file_exists( $autosetup_file )) {
- unlink($autosetup_file);
- }
-}
-
-OC_Util::addScript( '3rdparty', 'strengthify/jquery.strengthify' );
-OC_Util::addStyle( '3rdparty', 'strengthify/strengthify' );
-OC_Util::addScript('setup');
-
-$hasSQLite = class_exists('SQLite3');
-$hasMySQL = is_callable('mysql_connect');
-$hasPostgreSQL = is_callable('pg_connect');
-$hasOracle = is_callable('oci_connect');
-$hasMSSQL = is_callable('sqlsrv_connect');
-$datadir = OC_Config::getValue('datadirectory', OC::$SERVERROOT.'/data');
-$vulnerableToNullByte = false;
-if(@file_exists(__FILE__."\0Nullbyte")) { // Check if the used PHP version is vulnerable to the NULL Byte attack (CVE-2006-7243)
- $vulnerableToNullByte = true;
-}
-
-// Protect data directory here, so we can test if the protection is working
-OC_Setup::protectDataDirectory();
-
-$opts = array(
- 'hasSQLite' => $hasSQLite,
- 'hasMySQL' => $hasMySQL,
- 'hasPostgreSQL' => $hasPostgreSQL,
- 'hasOracle' => $hasOracle,
- 'hasMSSQL' => $hasMSSQL,
- 'directory' => $datadir,
- 'secureRNG' => OC_Util::secureRNGAvailable(),
- 'htaccessWorking' => OC_Util::isHtAccessWorking(),
- 'vulnerableToNullByte' => $vulnerableToNullByte,
- 'errors' => array(),
- 'dbIsSet' => $dbIsSet,
- 'directoryIsSet' => $directoryIsSet,
-);
-
-if(isset($_POST['install']) AND $_POST['install']=='true') {
- // We have to launch the installation process :
- $e = OC_Setup::install($_POST);
- $errors = array('errors' => $e);
-
- if(count($e) > 0) {
- //OC_Template::printGuestPage("", "error", array("errors" => $errors));
- $options = array_merge($_POST, $opts, $errors);
- OC_Template::printGuestPage("", "installation", $options);
- }
- else {
- header( 'Location: '.OC_Helper::linkToRoute( 'post_setup_check' ));
- exit();
- }
-}
-else {
- OC_Template::printGuestPage("", "installation", $opts);
-}
diff --git a/core/setup/controller.php b/core/setup/controller.php
new file mode 100644
index 00000000000..c628bda609b
--- /dev/null
+++ b/core/setup/controller.php
@@ -0,0 +1,138 @@
+<?php
+/**
+ * Copyright (c) 2013 Bart Visscher <bartv@thisnet.nl>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\Core\Setup;
+
+class Controller {
+ public function run($post) {
+ // Check for autosetup:
+ $post = $this->loadAutoConfig($post);
+ $opts = $this->getSystemInfo();
+
+ if(isset($post['install']) AND $post['install']=='true') {
+ // We have to launch the installation process :
+ $e = \OC_Setup::install($post);
+ $errors = array('errors' => $e);
+
+ if(count($e) > 0) {
+ $options = array_merge($post, $opts, $errors);
+ $this->display($options);
+ }
+ else {
+ $this->finishSetup();
+ }
+ }
+ else {
+ $this->display($opts);
+ }
+ }
+
+ public function display($post) {
+ $defaults = array(
+ 'adminlogin' => '',
+ 'adminpass' => '',
+ 'dbuser' => '',
+ 'dbpass' => '',
+ 'dbname' => '',
+ 'dbtablespace' => '',
+ 'dbhost' => '',
+ );
+ $parameters = array_merge($defaults, $post);
+
+ \OC_Util::addScript( '3rdparty', 'strengthify/jquery.strengthify' );
+ \OC_Util::addStyle( '3rdparty', 'strengthify/strengthify' );
+ \OC_Util::addScript('setup');
+ \OC_Template::printGuestPage('', 'installation', $parameters);
+ }
+
+ public function finishSetup() {
+ header( 'Location: '.\OC_Helper::linkToRoute( 'post_setup_check' ));
+ exit();
+ }
+
+ public function loadAutoConfig($post) {
+ $dbIsSet = isset($post['dbtype']);
+ $directoryIsSet = isset($post['directory']);
+ $adminAccountIsSet = isset($post['adminlogin']);
+
+ $autosetup_file = \OC::$SERVERROOT.'/config/autoconfig.php';
+ if( file_exists( $autosetup_file )) {
+ \OC_Log::write('core', 'Autoconfig file found, setting up owncloud...', \OC_Log::INFO);
+ include $autosetup_file;
+ $post = array_merge ($post, $AUTOCONFIG);
+ }
+
+ if ($dbIsSet AND $directoryIsSet AND $adminAccountIsSet) {
+ $post['install'] = 'true';
+ if( file_exists( $autosetup_file )) {
+ unlink($autosetup_file);
+ }
+ }
+ $post['dbIsSet'] = $dbIsSet;
+ $post['directoryIsSet'] = $directoryIsSet;
+
+ return $post;
+ }
+
+ public function getSystemInfo() {
+ $hasSQLite = class_exists('SQLite3');
+ $hasMySQL = is_callable('mysql_connect');
+ $hasPostgreSQL = is_callable('pg_connect');
+ $hasOracle = is_callable('oci_connect');
+ $hasMSSQL = is_callable('sqlsrv_connect');
+ $databases = array();
+ if ($hasSQLite) {
+ $databases['sqlite'] = 'SQLite';
+ }
+ if ($hasMySQL) {
+ $databases['mysql'] = 'MySQL';
+ }
+ if ($hasPostgreSQL) {
+ $databases['pgsql'] = 'PostgreSQL';
+ }
+ if ($hasOracle) {
+ $databases['oci'] = 'Oracle';
+ }
+ if ($hasMSSQL) {
+ $databases['mssql'] = 'MS SQL';
+ }
+ $datadir = \OC_Config::getValue('datadirectory', \OC::$SERVERROOT.'/data');
+ $vulnerableToNullByte = false;
+ if(@file_exists(__FILE__."\0Nullbyte")) { // Check if the used PHP version is vulnerable to the NULL Byte attack (CVE-2006-7243)
+ $vulnerableToNullByte = true;
+ }
+
+ $errors = array();
+
+ // Protect data directory here, so we can test if the protection is working
+ \OC_Setup::protectDataDirectory();
+ try {
+ $htaccessWorking = \OC_Util::isHtAccessWorking();
+ } catch (\OC\HintException $e) {
+ $errors[] = array(
+ 'error' => $e->getMessage(),
+ 'hint' => $e->getHint()
+ );
+ $htaccessWorking = false;
+ }
+
+ return array(
+ 'hasSQLite' => $hasSQLite,
+ 'hasMySQL' => $hasMySQL,
+ 'hasPostgreSQL' => $hasPostgreSQL,
+ 'hasOracle' => $hasOracle,
+ 'hasMSSQL' => $hasMSSQL,
+ 'databases' => $databases,
+ 'directory' => $datadir,
+ 'secureRNG' => \OC_Util::secureRNGAvailable(),
+ 'htaccessWorking' => $htaccessWorking,
+ 'vulnerableToNullByte' => $vulnerableToNullByte,
+ 'errors' => $errors,
+ );
+ }
+}
diff --git a/core/templates/installation.php b/core/templates/installation.php
index 182fc83a4d4..9670a5e9ee5 100644
--- a/core/templates/installation.php
+++ b/core/templates/installation.php
@@ -48,13 +48,13 @@
<legend><?php print_unescaped($l->t( 'Create an <strong>admin account</strong>' )); ?></legend>
<p class="infield grouptop">
<input type="text" name="adminlogin" id="adminlogin" placeholder=""
- value="<?php p(OC_Helper::init_var('adminlogin')); ?>" autocomplete="off" autofocus required />
+ value="<?php p($_['adminlogin']); ?>" autocomplete="off" autofocus required />
<label for="adminlogin" class="infield"><?php p($l->t( 'Username' )); ?></label>
<img class="svg" src="<?php p(image_path('', 'actions/user.svg')); ?>" alt="" />
</p>
<p class="infield groupbottom">
<input type="password" name="adminpass" data-typetoggle="#show" id="adminpass" placeholder=""
- value="<?php p(OC_Helper::init_var('adminpass')); ?>" required />
+ value="<?php p($_['adminpass']); ?>" required />
<label for="adminpass" class="infield"><?php p($l->t( 'Password' )); ?></label>
<img class="svg" id="adminpass-icon" src="<?php print_unescaped(image_path('', 'actions/password.svg')); ?>" alt="" />
<input type="checkbox" id="show" name="show" />
@@ -75,7 +75,7 @@
<label for="directory"><?php p($l->t( 'Data folder' )); ?></label>
<input type="text" name="directory" id="directory"
placeholder="<?php p(OC::$SERVERROOT."/data"); ?>"
- value="<?php p(OC_Helper::init_var('directory', $_['directory'])); ?>" />
+ value="<?php p($_['directory']); ?>" />
</div>
</fieldset>
<?php endif; ?>
@@ -86,62 +86,16 @@
$hasOtherDB = true; else $hasOtherDB =false; //other than SQLite ?>
<legend><?php p($l->t( 'Configure the database' )); ?></legend>
<div id="selectDbType">
- <?php if($_['hasSQLite']): ?>
- <input type='hidden' id='hasSQLite' value="true" />
- <?php if(!$hasOtherDB): ?>
- <p>SQLite <?php p($l->t( 'will be used' )); ?>.</p>
- <input type="hidden" id="dbtype" name="dbtype" value="sqlite" />
+ <?php foreach($_['databases'] as $type => $label): ?>
+ <?php if(count($_['databases']) === 1): ?>
+ <p class="info"><?php p($label . ' ' . $l->t( 'will be used' )); ?>.</p>
+ <input type="hidden" id="dbtype" name="dbtype" value="<?php p($type) ?>" />
<?php else: ?>
- <input type="radio" name="dbtype" value="sqlite" id="sqlite"
- <?php OC_Helper::init_radio('dbtype', 'sqlite', 'sqlite'); ?>/>
- <label class="sqlite" for="sqlite">SQLite</label>
- <?php endif; ?>
- <?php endif; ?>
-
- <?php if($_['hasMySQL']): ?>
- <input type='hidden' id='hasMySQL' value='true'/>
- <?php if(!$_['hasSQLite'] and !$_['hasPostgreSQL'] and !$_['hasOracle'] and !$_['hasMSSQL']): ?>
- <p>MySQL <?php p($l->t( 'will be used' )); ?>.</p>
- <input type="hidden" id="dbtype" name="dbtype" value="mysql" />
- <?php else: ?>
- <input type="radio" name="dbtype" value="mysql" id="mysql"
- <?php OC_Helper::init_radio('dbtype', 'mysql', 'sqlite'); ?>/>
- <label class="mysql" for="mysql">MySQL</label>
- <?php endif; ?>
- <?php endif; ?>
-
- <?php if($_['hasPostgreSQL']): ?>
- <?php if(!$_['hasSQLite'] and !$_['hasMySQL'] and !$_['hasOracle'] and !$_['hasMSSQL']): ?>
- <p>PostgreSQL <?php p($l->t( 'will be used' )); ?>.</p>
- <input type="hidden" id="dbtype" name="dbtype" value="pgsql" />
- <?php else: ?>
- <label class="pgsql" for="pgsql">PostgreSQL</label>
- <input type="radio" name="dbtype" value='pgsql' id="pgsql"
- <?php OC_Helper::init_radio('dbtype', 'pgsql', 'sqlite'); ?>/>
- <?php endif; ?>
- <?php endif; ?>
-
- <?php if($_['hasOracle']): ?>
- <?php if(!$_['hasSQLite'] and !$_['hasMySQL'] and !$_['hasPostgreSQL'] and !$_['hasMSSQL']): ?>
- <p>Oracle <?php p($l->t( 'will be used' )); ?>.</p>
- <input type="hidden" id="dbtype" name="dbtype" value="oci" />
- <?php else: ?>
- <label class="oci" for="oci">Oracle</label>
- <input type="radio" name="dbtype" value='oci' id="oci"
- <?php OC_Helper::init_radio('dbtype', 'oci', 'sqlite'); ?>/>
- <?php endif; ?>
- <?php endif; ?>
-
- <?php if($_['hasMSSQL']): ?>
- <input type='hidden' id='hasMSSQL' value='true'/>
- <?php if(!$_['hasSQLite'] and !$_['hasMySQL'] and !$_['hasPostgreSQL'] and !$_['hasOracle']): ?>
- <p>MS SQL <?php p($l->t( 'will be used' )); ?>.</p>
- <input type="hidden" id="dbtype" name="dbtype" value="mssql" />
- <?php else: ?>
- <label class="mssql" for="mssql">MS SQL</label>
- <input type="radio" name="dbtype" value='mssql' id="mssql" <?php OC_Helper::init_radio('dbtype', 'mssql', 'sqlite'); ?>/>
- <?php endif; ?>
+ <input type="radio" name="dbtype" value="<?php p($type) ?>" id="<?php p($type) ?>"
+ <?php p($_['dbtype'] === $type ? 'checked="checked" ' : '') ?>/>
+ <label class="<?php p($type) ?>" for="<?php p($type) ?>"><?php p($label) ?></label>
<?php endif; ?>
+ <?php endforeach; ?>
</div>
<?php if($hasOtherDB): ?>
@@ -149,11 +103,11 @@
<p class="infield grouptop">
<label for="dbuser" class="infield"><?php p($l->t( 'Database user' )); ?></label>
<input type="text" name="dbuser" id="dbuser" placeholder=""
- value="<?php p(OC_Helper::init_var('dbuser')); ?>" autocomplete="off" />
+ value="<?php p($_['dbuser']); ?>" autocomplete="off" />
</p>
<p class="infield groupmiddle">
<input type="password" name="dbpass" id="dbpass" placeholder="" data-typetoggle="#dbpassword"
- value="<?php p(OC_Helper::init_var('dbpass')); ?>" />
+ value="<?php p($_['dbpass']); ?>" />
<label for="dbpass" class="infield"><?php p($l->t( 'Database password' )); ?></label>
<input type="checkbox" id="dbpassword" name="dbpassword" />
<label for="dbpassword"></label>
@@ -161,7 +115,7 @@
<p class="infield groupmiddle">
<label for="dbname" class="infield"><?php p($l->t( 'Database name' )); ?></label>
<input type="text" name="dbname" id="dbname" placeholder=""
- value="<?php p(OC_Helper::init_var('dbname')); ?>"
+ value="<?php p($_['dbname']); ?>"
autocomplete="off" pattern="[0-9a-zA-Z$_-]+" />
</p>
<?php if($_['hasOracle']): ?>
@@ -169,14 +123,14 @@
<p class="infield groupmiddle">
<label for="dbtablespace" class="infield"><?php p($l->t( 'Database tablespace' )); ?></label>
<input type="text" name="dbtablespace" id="dbtablespace" placeholder=""
- value="<?php p(OC_Helper::init_var('dbtablespace')); ?>" autocomplete="off" />
+ value="<?php p($_['dbtablespace']); ?>" autocomplete="off" />
</p>
</div>
<?php endif; ?>
<p class="infield groupbottom">
<label for="dbhost" class="infield"><?php p($l->t( 'Database host' )); ?></label>
<input type="text" name="dbhost" id="dbhost" placeholder=""
- value="<?php p(OC_Helper::init_var('dbhost')); ?>" />
+ value="<?php p($_['dbhost']); ?>" />
</p>
</div>
<?php endif; ?>
diff --git a/lib/base.php b/lib/base.php
index b54b2973551..f2d9251294d 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -691,7 +691,8 @@ class OC {
// Check if ownCloud is installed or in maintenance (update) mode
if (!OC_Config::getValue('installed', false)) {
- require_once 'core/setup.php';
+ $controller = new OC\Core\Setup\Controller();
+ $controller->run($_POST);
exit();
}
diff --git a/lib/private/connector/sabre/objecttree.php b/lib/private/connector/sabre/objecttree.php
index cd3f081f7cc..d1e179af2ec 100644
--- a/lib/private/connector/sabre/objecttree.php
+++ b/lib/private/connector/sabre/objecttree.php
@@ -38,7 +38,20 @@ class ObjectTree extends \Sabre_DAV_ObjectTree {
return $this->rootNode;
}
- $info = $this->getFileView()->getFileInfo($path);
+ if (pathinfo($path, PATHINFO_EXTENSION) === 'part') {
+ // read from storage
+ $absPath = $this->getFileView()->getAbsolutePath($path);
+ list($storage, $internalPath) = Filesystem::resolvePath('/' . $absPath);
+ if ($storage) {
+ $scanner = $storage->getScanner($internalPath);
+ // get data directly
+ $info = $scanner->getData($internalPath);
+ }
+ }
+ else {
+ // read from cache
+ $info = $this->getFileView()->getFileInfo($path);
+ }
if (!$info) {
throw new \Sabre_DAV_Exception_NotFound('File with name ' . $path . ' could not be located');
diff --git a/lib/private/helper.php b/lib/private/helper.php
index 58bee9c6300..580f81acc62 100644
--- a/lib/private/helper.php
+++ b/lib/private/helper.php
@@ -448,29 +448,6 @@ class OC_Helper {
*
*/
- //FIXME: should also check for value validation (i.e. the email is an email).
- public static function init_var($s, $d = "") {
- $r = $d;
- if (isset($_REQUEST[$s]) && !empty($_REQUEST[$s])) {
- $r = OC_Util::sanitizeHTML($_REQUEST[$s]);
- }
-
- return $r;
- }
-
- /**
- * returns "checked"-attribute if request contains selected radio element
- * OR if radio element is the default one -- maybe?
- *
- * @param string $s Name of radio-button element name
- * @param string $v Value of current radio-button element
- * @param string $d Value of default radio-button element
- */
- public static function init_radio($s, $v, $d) {
- if ((isset($_REQUEST[$s]) && $_REQUEST[$s] == $v) || (!isset($_REQUEST[$s]) && $v == $d))
- print "checked=\"checked\" ";
- }
-
/**
* detect if a given program is found in the search PATH
*
@@ -831,23 +808,39 @@ class OC_Helper {
* @return number of bytes representing
*/
public static function maxUploadFilesize($dir) {
- $upload_max_filesize = OCP\Util::computerFileSize(ini_get('upload_max_filesize'));
- $post_max_size = OCP\Util::computerFileSize(ini_get('post_max_size'));
- $freeSpace = \OC\Files\Filesystem::free_space($dir);
- if ((int)$upload_max_filesize === 0 and (int)$post_max_size === 0) {
- $maxUploadFilesize = \OC\Files\SPACE_UNLIMITED;
- } elseif ((int)$upload_max_filesize === 0 or (int)$post_max_size === 0) {
- $maxUploadFilesize = max($upload_max_filesize, $post_max_size); //only the non 0 value counts
- } else {
- $maxUploadFilesize = min($upload_max_filesize, $post_max_size);
- }
+ return min(self::freeSpace($dir), self::uploadLimit());
+ }
+ /**
+ * Calculate free space left within user quota
+ *
+ * @param $dir the current folder where the user currently operates
+ * @return number of bytes representing
+ */
+ public static function freeSpace($dir) {
+ $freeSpace = \OC\Files\Filesystem::free_space($dir);
if ($freeSpace !== \OC\Files\SPACE_UNKNOWN) {
$freeSpace = max($freeSpace, 0);
+ return $freeSpace;
+ } else {
+ return INF;
+ }
+ }
- return min($maxUploadFilesize, $freeSpace);
+ /**
+ * Calculate PHP upload limit
+ *
+ * @return PHP upload file size limit
+ */
+ public static function uploadLimit() {
+ $upload_max_filesize = OCP\Util::computerFileSize(ini_get('upload_max_filesize'));
+ $post_max_size = OCP\Util::computerFileSize(ini_get('post_max_size'));
+ if ((int)$upload_max_filesize === 0 and (int)$post_max_size === 0) {
+ return INF;
+ } elseif ((int)$upload_max_filesize === 0 or (int)$post_max_size === 0) {
+ return max($upload_max_filesize, $post_max_size); //only the non 0 value counts
} else {
- return $maxUploadFilesize;
+ return min($upload_max_filesize, $post_max_size);
}
}
diff --git a/lib/private/log/errorhandler.php b/lib/private/log/errorhandler.php
index f6c96ef8218..1dde6b507fc 100644
--- a/lib/private/log/errorhandler.php
+++ b/lib/private/log/errorhandler.php
@@ -19,7 +19,7 @@ class ErrorHandler {
* @param string $msg
* @return string
*/
- private static function removePassword($msg) {
+ protected static function removePassword($msg) {
return preg_replace('/\/\/(.*):(.*)@/', '//xxx:xxx@', $msg);
}
diff --git a/lib/private/memcache/apc.php b/lib/private/memcache/apc.php
index e995cbc526e..332bbfead00 100644
--- a/lib/private/memcache/apc.php
+++ b/lib/private/memcache/apc.php
@@ -9,15 +9,8 @@
namespace OC\Memcache;
class APC extends Cache {
- /**
- * entries in APC gets namespaced to prevent collisions between owncloud instances and users
- */
- protected function getNameSpace() {
- return $this->prefix;
- }
-
public function get($key) {
- $result = apc_fetch($this->getNamespace() . $key, $success);
+ $result = apc_fetch($this->getPrefix() . $key, $success);
if (!$success) {
return null;
}
@@ -25,26 +18,22 @@ class APC extends Cache {
}
public function set($key, $value, $ttl = 0) {
- return apc_store($this->getNamespace() . $key, $value, $ttl);
+ return apc_store($this->getPrefix() . $key, $value, $ttl);
}
public function hasKey($key) {
- return apc_exists($this->getNamespace() . $key);
+ return apc_exists($this->getPrefix() . $key);
}
public function remove($key) {
- return apc_delete($this->getNamespace() . $key);
+ return apc_delete($this->getPrefix() . $key);
}
public function clear($prefix = '') {
- $ns = $this->getNamespace() . $prefix;
- $cache = apc_cache_info('user');
- foreach ($cache['cache_list'] as $entry) {
- if (strpos($entry['info'], $ns) === 0) {
- apc_delete($entry['info']);
- }
- }
- return true;
+ $ns = $this->getPrefix() . $prefix;
+ $ns = preg_quote($ns, '/');
+ $iter = new \APCIterator('user', '/^' . $ns . '/');
+ return apc_delete($iter);
}
static public function isAvailable() {
diff --git a/lib/private/memcache/apcu.php b/lib/private/memcache/apcu.php
index dac0f5f208a..7f780f32718 100644
--- a/lib/private/memcache/apcu.php
+++ b/lib/private/memcache/apcu.php
@@ -9,13 +9,6 @@
namespace OC\Memcache;
class APCu extends APC {
- public function clear($prefix = '') {
- $ns = $this->getNamespace() . $prefix;
- $ns = preg_quote($ns, '/');
- $iter = new \APCIterator('user', '/^'.$ns.'/');
- return apc_delete($iter);
- }
-
static public function isAvailable() {
if (!extension_loaded('apcu')) {
return false;
diff --git a/lib/private/memcache/cache.php b/lib/private/memcache/cache.php
index 0ad1cc7ec03..03671b3f240 100644
--- a/lib/private/memcache/cache.php
+++ b/lib/private/memcache/cache.php
@@ -18,7 +18,7 @@ abstract class Cache implements \ArrayAccess {
* @param string $prefix
*/
public function __construct($prefix = '') {
- $this->prefix = \OC_Util::getInstanceId() . '/' . $prefix;
+ $this->prefix = $prefix;
}
public function getPrefix() {
diff --git a/lib/private/memcache/factory.php b/lib/private/memcache/factory.php
index fde7d947567..334cf9a1f0e 100644
--- a/lib/private/memcache/factory.php
+++ b/lib/private/memcache/factory.php
@@ -8,7 +8,21 @@
namespace OC\Memcache;
-class Factory {
+use \OCP\ICacheFactory;
+
+class Factory implements ICacheFactory {
+ /**
+ * @var string $globalPrefix
+ */
+ private $globalPrefix;
+
+ /**
+ * @param string $globalPrefix
+ */
+ public function __construct($globalPrefix) {
+ $this->globalPrefix = $globalPrefix;
+ }
+
/**
* get a cache instance, will return null if no backend is available
*
@@ -16,6 +30,7 @@ class Factory {
* @return \OC\Memcache\Cache
*/
function create($prefix = '') {
+ $prefix = $this->globalPrefix . '/' . $prefix;
if (XCache::isAvailable()) {
return new XCache($prefix);
} elseif (APCu::isAvailable()) {
diff --git a/lib/private/server.php b/lib/private/server.php
index 2cbd37a97d7..c9e593ec2ed 100644
--- a/lib/private/server.php
+++ b/lib/private/server.php
@@ -138,6 +138,10 @@ class Server extends SimpleContainer implements IServerContainer {
$this->registerService('UserCache', function($c) {
return new UserCache();
});
+ $this->registerService('MemCacheFactory', function ($c) {
+ $instanceId = \OC_Util::getInstanceId();
+ return new \OC\Memcache\Factory($instanceId);
+ });
$this->registerService('ActivityManager', function($c) {
return new ActivityManager();
});
@@ -298,6 +302,15 @@ class Server extends SimpleContainer implements IServerContainer {
}
/**
+ * Returns an \OCP\CacheFactory instance
+ *
+ * @return \OCP\CacheFactory
+ */
+ function getMemCacheFactory() {
+ return $this->query('MemCacheFactory');
+ }
+
+ /**
* Returns the current session
*
* @return \OCP\ISession
diff --git a/lib/private/util.php b/lib/private/util.php
index 8aa7a074d0d..0585749d615 100755
--- a/lib/private/util.php
+++ b/lib/private/util.php
@@ -788,8 +788,12 @@ class OC_Util {
}
$fp = @fopen($testFile, 'w');
- @fwrite($fp, $testContent);
- @fclose($fp);
+ if (!$fp) {
+ throw new OC\HintException('Can\'t create test file to check for working .htaccess file.',
+ 'Make sure it is possible for the webserver to write to '.$testFile);
+ }
+ fwrite($fp, $testContent);
+ fclose($fp);
// accessing the file via http
$url = OC_Helper::makeURLAbsolute(OC::$WEBROOT.'/data'.$fileName);
diff --git a/lib/public/icachefactory.php b/lib/public/icachefactory.php
new file mode 100644
index 00000000000..874f1ec0a59
--- /dev/null
+++ b/lib/public/icachefactory.php
@@ -0,0 +1,28 @@
+<?php
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OCP;
+
+interface ICacheFactory{
+ /**
+ * Get a memory cache instance
+ *
+ * All entries added trough the cache instance will be namespaced by $prefix to prevent collisions between apps
+ *
+ * @param string $prefix
+ * @return \OCP\ICache
+ */
+ public function create($prefix = '');
+
+ /**
+ * Check if any memory cache backend is available
+ *
+ * @return bool
+ */
+ public function isAvailable();
+}
diff --git a/lib/public/iservercontainer.php b/lib/public/iservercontainer.php
index b958d2d03f4..5473f3ee334 100644
--- a/lib/public/iservercontainer.php
+++ b/lib/public/iservercontainer.php
@@ -142,6 +142,13 @@ interface IServerContainer {
function getCache();
/**
+ * Returns an \OCP\CacheFactory instance
+ *
+ * @return \OCP\ICacheFactory
+ */
+ function getMemCacheFactory();
+
+ /**
* Returns the current session
*
* @return \OCP\ISession
diff --git a/lib/public/util.php b/lib/public/util.php
index 26c5a15cff2..d8497e29cfc 100644
--- a/lib/public/util.php
+++ b/lib/public/util.php
@@ -466,4 +466,23 @@ class Util {
public static function maxUploadFilesize($dir) {
return \OC_Helper::maxUploadFilesize($dir);
}
+
+ /**
+ * Calculate free space left within user quota
+ *
+ * @param $dir the current folder where the user currently operates
+ * @return number of bytes representing
+ */
+ public static function freeSpace($dir) {
+ return \OC_Helper::freeSpace($dir);
+ }
+
+ /**
+ * Calculate PHP upload limit
+ *
+ * @return number of bytes representing
+ */
+ public static function uploadLimit() {
+ return \OC_Helper::uploadLimit();
+ }
}
diff --git a/settings/templates/apps.php b/settings/templates/apps.php
index e04815f9b99..4c77c62f511 100644
--- a/settings/templates/apps.php
+++ b/settings/templates/apps.php
@@ -9,9 +9,11 @@
<ul id="leftcontent" class="applist">
+ <?php if(OC_Config::getValue('appstoreenabled', true) === true): ?>
<li>
<a class="app-external" target="_blank" href="http://owncloud.org/dev"><?php p($l->t('Add your App'));?> …</a>
</li>
+ <?php endif; ?>
<?php foreach($_['apps'] as $app):?>
<li <?php if($app['active']) print_unescaped('class="active"')?> data-id="<?php p($app['id']) ?>"
@@ -24,9 +26,11 @@
</li>
<?php endforeach;?>
+ <?php if(OC_Config::getValue('appstoreenabled', true) === true): ?>
<li>
<a class="app-external" target="_blank" href="http://apps.owncloud.com"><?php p($l->t('More Apps'));?> …</a>
</li>
+ <?php endif; ?>
</ul>
<div id="rightcontent">
<div class="appinfo">
diff --git a/tests/karma.config.js b/tests/karma.config.js
index f73ade0f3c6..529bd31338f 100644
--- a/tests/karma.config.js
+++ b/tests/karma.config.js
@@ -29,25 +29,52 @@
* environment variable to the apps name, for example "core" or "files_encryption".
* Multiple apps can be specified by separating them with space.
*
+ * Setting the environment variable NOCOVERAGE to 1 will disable the coverage
+ * preprocessor, which is needed to be able to debug tests properly in a browser.
*/
+
+/* jshint node: true */
module.exports = function(config) {
+ function findApps() {
+ /*
+ var fs = require('fs');
+ var apps = fs.readdirSync('apps');
+ return apps;
+ */
+ // other apps tests don't run yet... needs further research / clean up
+ return ['files'];
+ }
+
+ // respect NOCOVERAGE env variable
+ // it is useful to disable coverage for debugging
+ // because the coverage preprocessor will wrap the JS files somehow
+ var enableCoverage = !parseInt(process.env.NOCOVERAGE, 10);
+ console.log('Coverage preprocessor: ', enableCoverage?'enabled':'disabled');
+
// default apps to test when none is specified (TODO: read from filesystem ?)
- var defaultApps = 'core files';
- var appsToTest = process.env.KARMA_TESTSUITE || defaultApps;
+ var appsToTest = process.env.KARMA_TESTSUITE;
+ if (appsToTest) {
+ appsToTest = appsToTest.split(' ');
+ }
+ else {
+ appsToTest = ['core'].concat(findApps());
+ }
+
+ console.log('Apps to test: ', appsToTest);
// read core files from core.json,
// these are required by all apps so always need to be loaded
// note that the loading order is important that's why they
// are specified in a separate file
var corePath = 'core/js/';
- var coreFiles = require('../' + corePath + 'core.json').modules;
+ var coreModule = require('../' + corePath + 'core.json');
var testCore = false;
var files = [];
var index;
+ var preprocessors = {};
// find out what apps to test from appsToTest
- appsToTest = appsToTest.split(' ');
index = appsToTest.indexOf('core');
if (index > -1) {
appsToTest.splice(index, 1);
@@ -60,11 +87,23 @@ module.exports = function(config) {
// core mocks
files.push(corePath + 'tests/specHelper.js');
- // add core files
- for ( var i = 0; i < coreFiles.length; i++ ) {
- files.push( corePath + coreFiles[i] );
+ // add core library files
+ for ( var i = 0; i < coreModule.libraries.length; i++ ) {
+ var srcFile = corePath + coreModule.libraries[i];
+ files.push(srcFile);
+ }
+
+ // add core modules files
+ for ( var i = 0; i < coreModule.modules.length; i++ ) {
+ var srcFile = corePath + coreModule.modules[i];
+ files.push(srcFile);
+ if (enableCoverage) {
+ preprocessors[srcFile] = 'coverage';
+ }
}
+ // TODO: settings pages
+
// need to test the core app as well ?
if (testCore) {
// core tests
@@ -73,7 +112,11 @@ module.exports = function(config) {
for ( var i = 0; i < appsToTest.length; i++ ) {
// add app JS
- files.push('apps/' + appsToTest[i] + '/js/*.js');
+ var srcFile = 'apps/' + appsToTest[i] + '/js/*.js';
+ files.push(srcFile);
+ if (enableCoverage) {
+ preprocessors[srcFile] = 'coverage';
+ }
// add test specs
files.push('apps/' + appsToTest[i] + '/tests/js/*.js');
}
@@ -83,7 +126,6 @@ module.exports = function(config) {
// base path, that will be used to resolve files and exclude
basePath: '..',
-
// frameworks to use
frameworks: ['jasmine'],
@@ -106,9 +148,7 @@ module.exports = function(config) {
// web server port
port: 9876,
- preprocessors: {
- 'apps/files/js/*.js': 'coverage'
- },
+ preprocessors: preprocessors,
coverageReporter: {
dir:'tests/karma-coverage',
diff --git a/tests/lib/errorHandler.php b/tests/lib/errorHandler.php
new file mode 100644
index 00000000000..68b87deccb6
--- /dev/null
+++ b/tests/lib/errorHandler.php
@@ -0,0 +1,62 @@
+<?php
+/**
+ * ownCloud
+ *
+ * @author Bjoern Schiessle
+ * @copyright 2014 Bjoern Schiessle <schiessle@owncloud.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+class Test_ErrorHandler extends \PHPUnit_Framework_TestCase {
+
+ /**
+ * @brief provide username, password combinations for testRemovePassword
+ * @return array
+ */
+ function passwordProvider() {
+ return array(
+ array('user', 'password'),
+ array('user@owncloud.org', 'password'),
+ array('user', 'pass@word'),
+ array('us:er', 'password'),
+ array('user', 'pass:word'),
+ );
+
+ }
+
+ /**
+ * @dataProvider passwordProvider
+ * @param string $username
+ * @param string $password
+ */
+ function testRemovePassword($username, $password) {
+ $url = 'http://'.$username.':'.$password.'@owncloud.org';
+ $expectedResult = 'http://xxx:xxx@owncloud.org';
+ $result = TestableErrorHandler::testRemovePassword($url);
+
+ $this->assertEquals($expectedResult, $result);
+ }
+
+}
+
+/**
+ * @brief dummy class to access protected methods of \OC\Log\ErrorHandler
+ */
+class TestableErrorHandler extends \OC\Log\ErrorHandler {
+ public static function testRemovePassword($msg) {
+ return self::removePassword($msg);
+ }
+}