summaryrefslogtreecommitdiffstats
path: root/l10n/mn/files_external.po
blob: 2f8626fe51503381310557f3a06fc23efa76f271 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# 
# Translators:
msgid ""
msgstr ""
"Project-Id-Version: ownCloud\n"
"Report-Msgid-Bugs-To: translations@owncloud.org\n"
"POT-Creation-Date: 2014-06-29 01:54-0400\n"
"PO-Revision-Date: 2014-06-29 05:54+0000\n"
"Last-Translator: I Robot\n"
"Language-Team: Mongolian (http://www.transifex.com/projects/p/owncloud/language/mn/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: mn\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

#: ajax/dropbox.php:27
msgid ""
"Fetching request tokens failed. Verify that your Dropbox app key and secret "
"are correct."
msgstr ""

#: ajax/dropbox.php:40
msgid ""
"Fetching access tokens failed. Verify that your Dropbox app key and secret "
"are correct."
msgstr ""

#: ajax/dropbox.php:48 js/dropbox.js:102
msgid "Please provide a valid Dropbox app key and secret."
msgstr ""

#: ajax/google.php:27
#, php-format
msgid "Step 1 failed. Exception: %s"
msgstr ""

#: ajax/google.php:38
#, php-format
msgid "Step 2 failed. Exception: %s"
msgstr ""

#: appinfo/app.php:35 js/app.js:32 templates/settings.php:9
msgid "External storage"
msgstr ""

#: appinfo/app.php:44
msgid "Local"
msgstr ""

#: appinfo/app.php:47
msgid "Location"
msgstr ""

#: appinfo/app.php:50
msgid "Amazon S3"
msgstr ""

#: appinfo/app.php:53
msgid "Key"
msgstr ""

#: appinfo/app.php:54
msgid "Secret"
msgstr ""

#: appinfo/app.php:55 appinfo/app.php:64
msgid "Bucket"
msgstr ""

#: appinfo/app.php:59
msgid "Amazon S3 and compliant"
msgstr ""

#: appinfo/app.php:62
msgid "Access Key"
msgstr ""

#: appinfo/app.php:63
msgid "Secret Key"
msgstr ""

#: appinfo/app.php:65
msgid "Hostname (optional)"
msgstr ""

#: appinfo/app.php:66
msgid "Port (optional)"
msgstr ""

#: appinfo/app.php:67
msgid "Region (optional)"
msgstr ""

#: appinfo/app.php:68
msgid "Enable SSL"
msgstr ""

#: appinfo/app.php:69
msgid "Enable Path Style"
msgstr ""

#: appinfo/app.php:77
msgid "App key"
msgstr ""

#: appinfo/app.php:78
msgid "App secret"
msgstr ""

#: appinfo/app.php:88 appinfo/app.php:129 appinfo/app.php:140
#: appinfo/app.php:173
msgid "Host"
msgstr ""

#: appinfo/app.php:89 appinfo/app.php:130 appinfo/app.php:152
#: appinfo/app.php:163 appinfo/app.php:174
msgid "Username"
msgstr ""

#: appinfo/app.php:90 appinfo/app.php:131 appinfo/app.php:153
#: appinfo/app.php:164 appinfo/app.php:175
msgid "Password"
msgstr ""

#: appinfo/app.php:91 appinfo/app.php:133 appinfo/app.php:143
#: appinfo/app.php:154 appinfo/app.php:176
msgid "Root"
msgstr ""

#: appinfo/app.php:92
msgid "Secure ftps://"
msgstr ""

#: appinfo/app.php:100
msgid "Client ID"
msgstr ""

#: appinfo/app.php:101
msgid "Client secret"
msgstr ""

#: appinfo/app.php:108
msgid "OpenStack Object Storage"
msgstr ""

#: appinfo/app.php:111
msgid "Username (required)"
msgstr ""

#: appinfo/app.php:112
msgid "Bucket (required)"
msgstr ""

#: appinfo/app.php:113
msgid "Region (optional for OpenStack Object Storage)"
msgstr ""

#: appinfo/app.php:114
msgid "API Key (required for Rackspace Cloud Files)"
msgstr ""

#: appinfo/app.php:115
msgid "Tenantname (required for OpenStack Object Storage)"
msgstr ""

#: appinfo/app.php:116
msgid "Password (required for OpenStack Object Storage)"
msgstr ""

#: appinfo/app.php:117
msgid "Service Name (required for OpenStack Object Storage)"
msgstr ""

#: appinfo/app.php:118
msgid "URL of identity endpoint (required for OpenStack Object Storage)"
msgstr ""

#: appinfo/app.php:119
msgid "Timeout of HTTP requests in seconds (optional)"
msgstr ""

#: appinfo/app.php:132 appinfo/app.php:142
msgid "Share"
msgstr ""

#: appinfo/app.php:137
msgid "SMB / CIFS using OC login"
msgstr ""

#: appinfo/app.php:141
msgid "Username as share"
msgstr ""

#: appinfo/app.php:151 appinfo/app.php:162
msgid "URL"
msgstr ""

#: appinfo/app.php:155 appinfo/app.php:166
msgid "Secure https://"
msgstr ""

#: appinfo/app.php:165
msgid "Remote subfolder"
msgstr ""

#: js/dropbox.js:7 js/dropbox.js:29 js/google.js:8 js/google.js:40
msgid "Access granted"
msgstr ""

#: js/dropbox.js:33 js/dropbox.js:97 js/dropbox.js:103
msgid "Error configuring Dropbox storage"
msgstr ""

#: js/dropbox.js:68 js/google.js:89
msgid "Grant access"
msgstr ""

#: js/google.js:45 js/google.js:122
msgid "Error configuring Google Drive storage"
msgstr ""

#: js/mountsfilelist.js:34
msgid "Personal"
msgstr ""

#: js/mountsfilelist.js:36
msgid "System"
msgstr ""

#: js/settings.js:320 js/settings.js:327
msgid "Saved"
msgstr ""

#: lib/config.php:707
msgid "<b>Note:</b> "
msgstr ""

#: lib/config.php:717
msgid " and "
msgstr ""

#: lib/config.php:739
#, php-format
msgid ""
"<b>Note:</b> The cURL support in PHP is not enabled or installed. Mounting "
"of %s is not possible. Please ask your system administrator to install it."
msgstr ""

#: lib/config.php:741
#, php-format
msgid ""
"<b>Note:</b> The FTP support in PHP is not enabled or installed. Mounting of"
" %s is not possible. Please ask your system administrator to install it."
msgstr ""

#: lib/config.php:743
#, php-format
msgid ""
"<b>Note:</b> \"%s\" is not installed. Mounting of %s is not possible. Please"
" ask your system administrator to install it."
msgstr ""

#: templates/list.php:7
msgid "You don't have any external storages"
msgstr ""

#: templates/list.php:16
msgid "Name"
msgstr ""

#: templates/list.php:20
msgid "Storage type"
msgstr ""

#: templates/list.php:23
msgid "Scope"
msgstr ""

#: templates/settings.php:2
msgid "External Storage"
msgstr ""

#: templates/settings.php:8 templates/settings.php:27
msgid "Folder name"
msgstr ""

#: templates/settings.php:10
msgid "Configuration"
msgstr ""

#: templates/settings.php:11
msgid "Options"
msgstr ""

#: templates/settings.php:12
msgid "Available for"
msgstr ""

#: templates/settings.php:32
msgid "Add storage"
msgstr ""

#: templates/settings.php:92
msgid "No user or group"
msgstr ""

#: templates/settings.php:95
msgid "All Users"
msgstr ""

#: templates/settings.php:97
msgid "Groups"
msgstr ""

#: templates/settings.php:105
msgid "Users"
msgstr ""

#: templates/settings.php:118 templates/settings.php:119
#: templates/settings.php:158 templates/settings.php:159
msgid "Delete"
msgstr ""

#: templates/settings.php:132
msgid "Enable User External Storage"
msgstr ""

#: templates/settings.php:135
msgid "Allow users to mount the following external storage"
msgstr ""

#: templates/settings.php:150
msgid "SSL root certificates"
msgstr ""

#: templates/settings.php:168
msgid "Import Root Certificate"
msgstr ""
50 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387
<?php
/**
 * ownCloud
 *
 * @author Florin Peter
 * @copyright 2013 Florin Peter <owncloud@florin-peter.de>
 *
 * 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/>.
 *
 */

namespace OCA\Files_Encryption\Tests;

/**
 * Class Share
 */
class Share extends TestCase {

	const TEST_ENCRYPTION_SHARE_USER1 = "test-share-user1";
	const TEST_ENCRYPTION_SHARE_USER2 = "test-share-user2";
	const TEST_ENCRYPTION_SHARE_USER3 = "test-share-user3";
	const TEST_ENCRYPTION_SHARE_USER4 = "test-share-user4";
	const TEST_ENCRYPTION_SHARE_GROUP1 = "test-share-group1";

	public $stateFilesTrashbin;
	public $filename;
	public $dataShort;
	/**
	 * @var \OC\Files\View
	 */
	public $view;
	public $folder1;
	public $subfolder;
	public $subsubfolder;

	public static function setUpBeforeClass() {
		parent::setUpBeforeClass();

		// enable resharing
		\OC::$server->getAppConfig()->setValue('core', 'shareapi_allow_resharing', 'yes');

		// register share hooks
		\OC::registerShareHooks();
		\OCA\Files_Sharing\Helper::registerHooks();

		// clear and register hooks
		\OC_FileProxy::register(new \OCA\Files\Share\Proxy());

		// create users
		self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1, true);
		self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER2, true);
		self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER3, true);
		self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER4, true);

		// create group and assign users
		\OC_Group::createGroup(self::TEST_ENCRYPTION_SHARE_GROUP1);
		\OC_Group::addToGroup(self::TEST_ENCRYPTION_SHARE_USER3, self::TEST_ENCRYPTION_SHARE_GROUP1);
		\OC_Group::addToGroup(self::TEST_ENCRYPTION_SHARE_USER4, self::TEST_ENCRYPTION_SHARE_GROUP1);
	}

	protected function setUp() {
		parent::setUp();

		$this->dataShort = 'hats';
		$this->view = new \OC\Files\View('/');

		$this->folder1 = '/folder1';
		$this->subfolder = '/subfolder1';
		$this->subsubfolder = '/subsubfolder1';

		$this->filename = 'share-tmp.test';

		// remember files_trashbin state
		$this->stateFilesTrashbin = \OC_App::isEnabled('files_trashbin');

		// we don't want to tests with app files_trashbin enabled
		\OC_App::disable('files_trashbin');

		// login as first user
		self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);

		$this->createMocks();
	}

	protected function tearDown() {
		// reset app files_trashbin
		if ($this->stateFilesTrashbin) {
			\OC_App::enable('files_trashbin');
		} else {
			\OC_App::disable('files_trashbin');
		}

		$this->restoreHttpHelper();

		parent::tearDown();
	}

	public static function tearDownAfterClass() {
		// clean group
		\OC_Group::deleteGroup(self::TEST_ENCRYPTION_SHARE_GROUP1);

		// cleanup users
		\OC_User::deleteUser(self::TEST_ENCRYPTION_SHARE_USER1);
		\OC_User::deleteUser(self::TEST_ENCRYPTION_SHARE_USER2);
		\OC_User::deleteUser(self::TEST_ENCRYPTION_SHARE_USER3);
		\OC_User::deleteUser(self::TEST_ENCRYPTION_SHARE_USER4);

		parent::tearDownAfterClass();
	}

	private function createMocks() {
		$config = $this->getMockBuilder('\OCP\IConfig')
				->disableOriginalConstructor()->getMock();
		$certificateManager = $this->getMock('\OCP\ICertificateManager');
		$httpHelperMock = $this->getMockBuilder('\OC\HTTPHelper')
				->setConstructorArgs(array($config, $certificateManager))
				->getMock();
		$httpHelperMock->expects($this->any())->method('post')->with($this->anything())->will($this->returnValue(array('success' => true, 'result' => "{'ocs' : { 'meta' : { 'statuscode' : 100 }}}")));

		$this->registerHttpHelper($httpHelperMock);
	}

	/**
	 * Register an http helper mock for testing purposes.
	 * @param $httpHelper http helper mock
	 */
	private function registerHttpHelper($httpHelper) {
		$this->oldHttpHelper = \OC::$server->query('HTTPHelper');
		\OC::$server->registerService('HTTPHelper', function ($c) use ($httpHelper) {
			return $httpHelper;
		});
	}

	/**
	 * Restore the original http helper
	 */
	private function restoreHttpHelper() {
		$oldHttpHelper = $this->oldHttpHelper;
		\OC::$server->registerService('HTTPHelper', function ($c) use ($oldHttpHelper) {
			return $oldHttpHelper;
		});
	}

	/**
	 * @medium
	 */
	function testDeclineServer2ServerShare() {

		self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);

		// save file with content
		$cryptedFile = file_put_contents('crypt:///' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/'  . $this->filename, $this->dataShort);

		// test that data was successfully written
		$this->assertInternalType('int', $cryptedFile);

		// get the file info from previous created file
		$fileInfo = $this->view->getFileInfo(
			'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);


		// share the file
		$token = \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_LINK, '', \OCP\Constants::PERMISSION_ALL);
		$this->assertTrue(is_string($token));

		$publicShareKeyId = \OC::$server->getConfig()->getAppValue('files_encryption', 'publicShareKeyId');

		// check if share key for public exists
		$this->assertTrue($this->view->file_exists(
			'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
			. $this->filename . '/' . $publicShareKeyId . '.shareKey'));

		// manipulate share
		$query = \OC::$server->getDatabaseConnection()->prepare('UPDATE `*PREFIX*share` SET `share_type` = ?, `share_with` = ? WHERE `token`=?');
		$this->assertTrue($query->execute(array(\OCP\Share::SHARE_TYPE_REMOTE, 'foo@bar', $token)));

		// check if share key not exists
		$this->assertTrue($this->view->file_exists(
			'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
			. $this->filename . '/' . $publicShareKeyId . '.shareKey'));


		$query = \OC::$server->getDatabaseConnection()->prepare('SELECT * FROM `*PREFIX*share` WHERE `token`=?');
		$query->execute(array($token));

		$share = $query->fetch();

		$_POST['token'] = $token;
		$s2s = new \OCA\Files_Sharing\API\Server2Server();
		$s2s->declineShare(array('id' => $share['id']));

		$this->assertFalse($this->view->file_exists(
			'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
			. $this->filename . '/' . $publicShareKeyId . '.shareKey'));

	}

	/**
	 * @medium
	 * @param bool $withTeardown
	 */
	function testShareFile($withTeardown = true) {
		// login as admin
		self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);

		// save file with content
		$cryptedFile = file_put_contents('crypt:///' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename, $this->dataShort);

		// test that data was successfully written
		$this->assertInternalType('int', $cryptedFile);

		// disable encryption proxy to prevent recursive calls
		$proxyStatus = \OC_FileProxy::$enabled;
		\OC_FileProxy::$enabled = false;

		// get the file info from previous created file
		$fileInfo = $this->view->getFileInfo(
			'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);

		// check if we have a valid file info
		$this->assertInstanceOf('\OC\Files\FileInfo', $fileInfo);

		// check if the unencrypted file size is stored
		$this->assertGreaterThan(0, $fileInfo['unencrypted_size']);

		// re-enable the file proxy
		\OC_FileProxy::$enabled = $proxyStatus;

		// share the file
		\OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_SHARE_USER2, \OCP\Constants::PERMISSION_ALL);

		// login as admin
		self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);

		// check if share key for user1 exists
		$this->assertTrue($this->view->file_exists(
			'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
			. $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));

		// login as user1
		self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER2);

		// get file contents
		$retrievedCryptedFile = $this->view->file_get_contents(
			'/' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->filename);

		// check if data is the same as we previously written
		$this->assertEquals($this->dataShort, $retrievedCryptedFile);

		// cleanup
		if ($withTeardown) {

			// login as admin
			self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);

			// unshare the file
			\OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_SHARE_USER2);

			// check if share key not exists
			$this->assertFalse($this->view->file_exists(
				'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
				. $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));

			// cleanup
			$this->view->chroot('/' . self::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(
				'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
				. $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
		}
	}

	function testDownloadVersions() {
		// login as admin
		self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);

		$rootView = new \OC\Files\View();

		// save file twice to create a new version
		\OC\Files\Filesystem::file_put_contents($this->filename, "revision1");
		\OCA\Files_Versions\Storage::store($this->filename);
		\OC\Files\Filesystem::file_put_contents($this->filename, "revision2");

		// check if the owner can retrieve the correct version
		$versions = \OCA\Files_Versions\Storage::getVersions(self::TEST_ENCRYPTION_SHARE_USER1, $this->filename);
		$this->assertSame(1, count($versions));
		$version = reset($versions);
		$versionUser1 = $rootView->file_get_contents('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_versions/' . $this->filename . '.v' . $version['version']);
		$this->assertSame('revision1', $versionUser1);

		// share the file
		$fileInfo = \OC\Files\Filesystem::getFileInfo($this->filename);
		$this->assertInstanceOf('\OC\Files\FileInfo', $fileInfo);
		$this->assertTrue(\OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_SHARE_USER2, \OCP\Constants::PERMISSION_ALL));

		// try to download the version as user2
		self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER2);
		$versionUser2 = $rootView->file_get_contents('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_versions/' . $this->filename . '.v' . $version['version']);
		$this->assertSame('revision1', $versionUser2);

		//cleanup
		self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);
		\OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_SHARE_USER2);
		\OC\Files\Filesystem::unlink($this->filename);
	}

	/**
	 * @medium
	 * @param bool $withTeardown
	 */
	function testReShareFile($withTeardown = true) {
		$this->testShareFile(false);

		// login as user2
		self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER2);

		// get the file info
		$fileInfo = $this->view->getFileInfo(
			'/' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->filename);

		// share the file with user3
		\OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_SHARE_USER3, \OCP\Constants::PERMISSION_ALL);

		// login as admin
		self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);

		// check if share key for user2 exists
		$this->assertTrue($this->view->file_exists(
			'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
			. $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey'));

		// login as user2
		self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER3);

		// get file contents
		$retrievedCryptedFile = $this->view->file_get_contents(
			'/' . self::TEST_ENCRYPTION_SHARE_USER3 . '/files/' . $this->filename);

		// check if data is the same as previously written
		$this->assertEquals($this->dataShort, $retrievedCryptedFile);

		// cleanup
		if ($withTeardown) {

			// login as user1
			self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER2);

			// unshare the file with user2
			\OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_SHARE_USER3);

			// login as admin
			self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);

			// check if share key not exists
			$this->assertFalse($this->view->file_exists(
				'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
				. $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey'));

			// unshare the file with user1
			\OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_SHARE_USER2);

			// check if share key not exists
			$this->assertFalse($this->view->file_exists(
				'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
				. $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));

			// cleanup
			$this->view->chroot('/' . self::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(
				'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
				. $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
		}
	}

	/**
	 * @medium
	 * @param bool $withTeardown
	 * @return array
	 */
	function testShareFolder($withTeardown = true) {
		// login as admin
		self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);

		// create folder structure
		$this->view->mkdir('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files' . $this->folder1);
		$this->view->mkdir(
			'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files' . $this->folder1 . $this->subfolder);
		$this->view->mkdir(
			'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files' . $this->folder1 . $this->subfolder
			. $this->subsubfolder);

		// save file with content
		$cryptedFile = file_put_contents('crypt:///' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/'  . $this->folder1 . $this->subfolder . $this->subsubfolder . '/'
			. $this->filename, $this->dataShort);

		// test that data was successfully written
		$this->assertInternalType('int', $cryptedFile);

		// disable encryption proxy to prevent recursive calls
		$proxyStatus = \OC_FileProxy::$enabled;
		\OC_FileProxy::$enabled = false;

		// get the file info from previous created folder
		$fileInfo = $this->view->getFileInfo(
			'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files' . $this->folder1);

		// check if we have a valid file info
		$this->assertInstanceOf('\OC\Files\FileInfo', $fileInfo);

		// re-enable the file proxy
		\OC_FileProxy::$enabled = $proxyStatus;

		// share the folder with user1
		\OCP\Share::shareItem('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_SHARE_USER2, \OCP\Constants::PERMISSION_ALL);

		// login as admin
		self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);

		// check if share key for user1 exists
		$this->assertTrue($this->view->file_exists(
			'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys' . $this->folder1
			. $this->subfolder . $this->subsubfolder . '/'
			. $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));

		// login as user1
		self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER2);

		// get file contents
		$retrievedCryptedFile = $this->view->file_get_contents(
			'/' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->folder1
			. $this->subfolder . $this->subsubfolder . '/' . $this->filename);

		// check if data is the same
		$this->assertEquals($this->dataShort, $retrievedCryptedFile);

		// cleanup
		if ($withTeardown) {

			// login as admin
			self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);

			// unshare the folder with user1
			\OCP\Share::unshare('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_SHARE_USER2);

			// check if share key not exists
			$this->assertFalse($this->view->file_exists(
				'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys'
				. $this->folder1 . $this->subfolder . $this->subsubfolder . '/'
				. $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));

			// cleanup
			$this->view->chroot('/' . self::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(
				'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys'
				. $this->folder1 . $this->subfolder . $this->subsubfolder . '/'
				. $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
		}

		return $fileInfo;
	}

	/**
	 * @medium
	 * @param bool $withTeardown
	 */
	function testReShareFolder($withTeardown = true) {
		$fileInfoFolder1 = $this->testShareFolder(false);

		// login as user2
		self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER2);

		// disable encryption proxy to prevent recursive calls
		$proxyStatus = \OC_FileProxy::$enabled;
		\OC_FileProxy::$enabled = false;

		// get the file info from previous created folder
		$fileInfoSubFolder = $this->view->getFileInfo(
			'/' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->folder1
			. $this->subfolder);

		// check if we have a valid file info
		$this->assertInstanceOf('\OC\Files\FileInfo', $fileInfoSubFolder);

		// re-enable the file proxy
		\OC_FileProxy::$enabled = $proxyStatus;

		// share the file with user3
		\OCP\Share::shareItem('folder', $fileInfoSubFolder['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_SHARE_USER3, \OCP\Constants::PERMISSION_ALL);

		// login as admin
		self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);

		// check if share key for user3 exists
		$this->assertTrue($this->view->file_exists(
			'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys' . $this->folder1
			. $this->subfolder . $this->subsubfolder . '/'
			. $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey'));

		// login as user3
		self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER3);

		// get file contents
		$retrievedCryptedFile = $this->view->file_get_contents(
			'/' . self::TEST_ENCRYPTION_SHARE_USER3 . '/files/' . $this->subfolder
			. $this->subsubfolder . '/' . $this->filename);

		// check if data is the same
		$this->assertEquals($this->dataShort, $retrievedCryptedFile);

		// get the file info
		$fileInfo = $this->view->getFileInfo(
			'/' . self::TEST_ENCRYPTION_SHARE_USER3 . '/files/' . $this->subfolder
			. $this->subsubfolder . '/' . $this->filename);

		// check if we have fileInfos
		$this->assertInstanceOf('\OC\Files\FileInfo', $fileInfo);

		// share the file with user3
		\OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_SHARE_USER4, \OCP\Constants::PERMISSION_ALL);

		// login as admin
		self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);

		// check if share key for user3 exists
		$this->assertTrue($this->view->file_exists(
			'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys' . $this->folder1
			. $this->subfolder . $this->subsubfolder . '/'
			. $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER4 . '.shareKey'));

		// login as user3
		self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER4);

		// get file contents
		$retrievedCryptedFile = $this->view->file_get_contents(
			'/' . self::TEST_ENCRYPTION_SHARE_USER4 . '/files/' . $this->filename);

		// check if data is the same
		$this->assertEquals($this->dataShort, $retrievedCryptedFile);

		// cleanup
		if ($withTeardown) {

			// login as user2
			self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER3);

			// unshare the file with user3
			\OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_SHARE_USER4);

			// check if share key not exists
			$this->assertFalse($this->view->file_exists(
				'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys'
				. $this->folder1 . $this->subfolder . $this->subsubfolder . '/'
				. $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER4 . '.shareKey'));

			// login as user1
			self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER2);

			// unshare the folder with user2
			\OCP\Share::unshare('folder', $fileInfoSubFolder['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_SHARE_USER3);

			// check if share key not exists
			$this->assertFalse($this->view->file_exists(
				'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys'
				. $this->folder1 . $this->subfolder . $this->subsubfolder . '/'
				. $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey'));

			// login as admin
			self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);

			// unshare the folder1 with user1
			\OCP\Share::unshare('folder', $fileInfoFolder1['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_SHARE_USER2);

			// check if share key not exists
			$this->assertFalse($this->view->file_exists(
				'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys'
				. $this->folder1 . $this->subfolder . $this->subsubfolder . '/'
				. $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));

			// cleanup
			$this->view->chroot('/' . self::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(
				'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys'
				. $this->folder1 . $this->subfolder . $this->subsubfolder . '/'
				. $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
		}
	}


	function testRemoteShareFile() {
		// login as admin
		//self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);

		// save file with content
		$cryptedFile = file_put_contents('crypt:///' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/'  . $this->filename, $this->dataShort);

		// test that data was successfully written
		$this->assertInternalType('int', $cryptedFile);

		// disable encryption proxy to prevent recursive calls
		$proxyStatus = \OC_FileProxy::$enabled;
		\OC_FileProxy::$enabled = false;

		// get the file info from previous created file
		$fileInfo = $this->view->getFileInfo(
			'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);

		// check if we have a valid file info
		$this->assertInstanceOf('\OC\Files\FileInfo', $fileInfo);

		// check if the unencrypted file size is stored
		$this->assertGreaterThan(0, $fileInfo['unencrypted_size']);

		// re-enable the file proxy
		\OC_FileProxy::$enabled = $proxyStatus;

		// share the file
		\OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_REMOTE, 'user1@server1', \OCP\Constants::PERMISSION_ALL);

		$publicShareKeyId = \OC::$server->getAppConfig()->getValue('files_encryption', 'publicShareKeyId');

		// check if share key for public exists
		$this->assertTrue($this->view->file_exists(
			'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
			. $this->filename . '/' . $publicShareKeyId . '.shareKey'));

		// unshare the file
		\OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_REMOTE, 'user1@server1');

		// check if share key not exists
		$this->assertFalse($this->view->file_exists(
			'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
			. $this->filename . '/' . $publicShareKeyId . '.shareKey'));

		// cleanup
		$this->view->chroot('/' . self::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(
			'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
			. $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
	}

		function testPublicShareFile() {
		// login as admin
		self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);

		// save file with content
		$cryptedFile = file_put_contents('crypt:///' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/'  . $this->filename, $this->dataShort);

		// test that data was successfully written
			$this->assertInternalType('int', $cryptedFile);

		// disable encryption proxy to prevent recursive calls
		$proxyStatus = \OC_FileProxy::$enabled;
		\OC_FileProxy::$enabled = false;

		// get the file info from previous created file
		$fileInfo = $this->view->getFileInfo(
			'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);

		// check if we have a valid file info
			$this->assertInstanceOf('\OC\Files\FileInfo', $fileInfo);

		// check if the unencrypted file size is stored
		$this->assertGreaterThan(0, $fileInfo['unencrypted_size']);

		// re-enable the file proxy
		\OC_FileProxy::$enabled = $proxyStatus;

		// share the file
		\OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_LINK, false, \OCP\Constants::PERMISSION_ALL);

		// login as admin
		self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);

		$publicShareKeyId = \OC::$server->getAppConfig()->getValue('files_encryption', 'publicShareKeyId');

		// check if share key for public exists
		$this->assertTrue($this->view->file_exists(
			'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
			. $this->filename . '/' . $publicShareKeyId . '.shareKey'));

		// some hacking to simulate public link
		//$GLOBALS['app'] = 'files_sharing';
		//$GLOBALS['fileOwner'] = self::TEST_ENCRYPTION_SHARE_USER1;
		self::logoutHelper();

		// get file contents
		$retrievedCryptedFile = file_get_contents('crypt:///' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/'  . $this->filename);

		// check if data is the same as we previously written
		$this->assertEquals($this->dataShort, $retrievedCryptedFile);

		// tear down

		// login as admin
		self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);

		// unshare the file
		\OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_LINK, null);

		// check if share key not exists
		$this->assertFalse($this->view->file_exists(
			'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
			. $this->filename . '/' . $publicShareKeyId . '.shareKey'));

		// cleanup
		$this->view->chroot('/' . self::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(
			'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
			. $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
	}

	/**
	 * @medium
	 */
	function testShareFileWithGroup() {
		// login as admin
		self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);

		// save file with content
		$cryptedFile = file_put_contents('crypt:///' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename, $this->dataShort);

		// test that data was successfully written
		$this->assertInternalType('int', $cryptedFile);

		// disable encryption proxy to prevent recursive calls
		$proxyStatus = \OC_FileProxy::$enabled;
		\OC_FileProxy::$enabled = false;

		// get the file info from previous created file
		$fileInfo = $this->view->getFileInfo(
			'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);

		// check if we have a valid file info
		$this->assertInstanceOf('\OC\Files\FileInfo', $fileInfo);

		// check if the unencrypted file size is stored
		$this->assertGreaterThan(0, $fileInfo['unencrypted_size']);

		// re-enable the file proxy
		\OC_FileProxy::$enabled = $proxyStatus;

		// share the file
		\OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, self::TEST_ENCRYPTION_SHARE_GROUP1, \OCP\Constants::PERMISSION_ALL);

		// login as admin
		self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);

		// check if share key for user2 and user3 exists
		$this->assertTrue($this->view->file_exists(
			'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
			. $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey'));
		$this->assertTrue($this->view->file_exists(
			'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
			. $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER4 . '.shareKey'));

		// login as user1
		self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER3);

		// get file contents
		$retrievedCryptedFile = $this->view->file_get_contents(
			'/' . self::TEST_ENCRYPTION_SHARE_USER3 . '/files/' . $this->filename);

		// check if data is the same as we previously written
		$this->assertEquals($this->dataShort, $retrievedCryptedFile);

		// login as admin
		self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);

		// unshare the file
		\OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, self::TEST_ENCRYPTION_SHARE_GROUP1);

		// check if share key not exists
		$this->assertFalse($this->view->file_exists(
			'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
			. $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey'));
		$this->assertFalse($this->view->file_exists(
			'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
			. $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER4 . '.shareKey'));

		// cleanup
		$this->view->chroot('/' . self::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(
			'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
			. $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));

	}

	/**
	 * @large
	 */
	function testRecoveryFile() {

		// login as admin
		self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);

		\OCA\Files_Encryption\Helper::adminEnableRecovery(null, 'test123');
		$recoveryKeyId = \OC::$server->getAppConfig()->getValue('files_encryption', 'recoveryKeyId');

		// login as admin
		self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);

		$util = new \OCA\Files_Encryption\Util(new \OC\Files\View('/'), self::TEST_ENCRYPTION_SHARE_USER1);

		// check if recovery password match
		$this->assertTrue($util->checkRecoveryPassword('test123'));

		// enable recovery for admin
		$this->assertTrue($util->setRecoveryForUser(1));
		$util->addRecoveryKeys();

		// create folder structure
		$this->view->mkdir('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files' . $this->folder1);
		$this->view->mkdir(
			'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files' . $this->folder1 . $this->subfolder);
		$this->view->mkdir(
			'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files' . $this->folder1 . $this->subfolder
			. $this->subsubfolder);

		// save file with content
		$cryptedFile1 = file_put_contents('crypt:///' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename, $this->dataShort);
		$cryptedFile2 = file_put_contents('crypt:///' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/'
			. $this->filename, $this->dataShort);

		// test that data was successfully written
		$this->assertInternalType('int', $cryptedFile1);
		$this->assertInternalType('int', $cryptedFile2);

		// check if share key for admin and recovery exists
		$this->assertTrue($this->view->file_exists(
			'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
			. $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
		$this->assertTrue($this->view->file_exists(
			'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
			. $this->filename . '/' . $recoveryKeyId . '.shareKey'));
		$this->assertTrue($this->view->file_exists(
			'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' . $this->folder1
			. $this->subfolder . $this->subsubfolder . '/'
			. $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
		$this->assertTrue($this->view->file_exists(
			'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' . $this->folder1
			. $this->subfolder . $this->subsubfolder . '/'
			. $this->filename . '/' . $recoveryKeyId . '.shareKey'));

		// disable recovery for admin
		$this->assertTrue($util->setRecoveryForUser(0));

		// remove all recovery keys
		$util->removeRecoveryKeys('/');

		// check if share key for recovery not exists
		$this->assertFalse($this->view->file_exists(
			'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
			. $this->filename . '/' . $recoveryKeyId . '.shareKey'));
		$this->assertFalse($this->view->file_exists(
			'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' . $this->folder1
			. $this->subfolder . $this->subsubfolder . '/'
			. $this->filename . '/' . $recoveryKeyId . '.shareKey'));

		// enable recovery for admin
		$this->assertTrue($util->setRecoveryForUser(1));

		// add recovery keys again
		$util->addRecoveryKeys('/');

		// check if share key for admin and recovery exists
		$this->assertTrue($this->view->file_exists(
			'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
			. $this->filename . '/' . $recoveryKeyId . '.shareKey'));
		$this->assertTrue($this->view->file_exists(
			'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' . $this->folder1
			. $this->subfolder . $this->subsubfolder . '/'
			. $this->filename . '/' . $recoveryKeyId . '.shareKey'));

		// cleanup
		$this->view->chroot('/' . self::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(
			'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
			. $this->filename . '/' . $recoveryKeyId . '.shareKey'));
		$this->assertFalse($this->view->file_exists(
			'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' . $this->folder1
			. $this->subfolder . $this->subsubfolder . '/'
			. $this->filename . '/' . $recoveryKeyId . '.shareKey'));

		$this->assertTrue(\OCA\Files_Encryption\Helper::adminEnableRecovery(null, 'test123'));
		$this->assertTrue(\OCA\Files_Encryption\Helper::adminDisableRecovery('test123'));
		$this->assertEquals(0, \OC::$server->getAppConfig()->getValue('files_encryption', 'recoveryAdminEnabled'));
	}

	/**
	 * @large
	 */
	function testRecoveryForUser() {

		// login as admin
		self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);

		$result = \OCA\Files_Encryption\Helper::adminEnableRecovery(null, 'test123');
		$this->assertTrue($result);

		$recoveryKeyId = \OC::$server->getAppConfig()->getValue('files_encryption', 'recoveryKeyId');

		// login as user2
		self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER2);

		$util = new \OCA\Files_Encryption\Util(new \OC\Files\View('/'), self::TEST_ENCRYPTION_SHARE_USER2);

		// enable recovery for admin
		$this->assertTrue($util->setRecoveryForUser(1));

		// add recovery keys for existing files (e.g. the auto-generated welcome.txt)
		$util->addRecoveryKeys();

		// create folder structure
		$this->view->mkdir('/' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files' . $this->folder1);
		$this->view->mkdir(
			'/' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files' . $this->folder1 . $this->subfolder);
		$this->view->mkdir(
			'/' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files' . $this->folder1 . $this->subfolder
			. $this->subsubfolder);

		// save file with content
		$cryptedFile1 = file_put_contents('crypt:///' . self::TEST_ENCRYPTION_SHARE_USER2. '/files/' . $this->filename, $this->dataShort);
		$cryptedFile2 = file_put_contents('crypt:///' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/'
			. $this->filename, $this->dataShort);

		// test that data was successfully written
		$this->assertInternalType('int', $cryptedFile1);
		$this->assertInternalType('int', $cryptedFile2);

		// check if share key for user and recovery exists
		$this->assertTrue($this->view->file_exists(
			'/' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/keys/'
			. $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
		$this->assertTrue($this->view->file_exists(
			'/' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/keys/'
			. $this->filename . '/' . $recoveryKeyId . '.shareKey'));
		$this->assertTrue($this->view->file_exists(
			'/' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/keys/' . $this->folder1
			. $this->subfolder . $this->subsubfolder . '/'
			. $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
		$this->assertTrue($this->view->file_exists(
			'/' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/keys/' . $this->folder1
			. $this->subfolder . $this->subsubfolder . '/'
			. $this->filename . '/' . $recoveryKeyId . '.shareKey'));

		// login as admin
		self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);

		// change password
		\OC_User::setPassword(self::TEST_ENCRYPTION_SHARE_USER2, 'test', 'test123');
		$params = array('uid' => self::TEST_ENCRYPTION_SHARE_USER2,
			'password' => 'test',
			'recoveryPassword' => 'test123');
		\OCA\Files_Encryption\Hooks::setPassphrase($params);

		// login as user2
		self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER2, false, 'test');

		// get file contents
		$retrievedCryptedFile1 = file_get_contents('crypt:///' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->filename);
		$retrievedCryptedFile2 = file_get_contents(
			'crypt:///' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename);

		// check if data is the same as we previously written
		$this->assertEquals($this->dataShort, $retrievedCryptedFile1);
		$this->assertEquals($this->dataShort, $retrievedCryptedFile2);

		// cleanup
		$this->view->chroot('/' . self::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(
			'/' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/keys/'
			. $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
		$this->assertFalse($this->view->file_exists(
			'/' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/keys/'
			. $this->filename . '/' . $recoveryKeyId . '.shareKey'));
		$this->assertFalse($this->view->file_exists(
			'/' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/keys/' . $this->folder1
			. $this->subfolder . $this->subsubfolder . '/'
			. $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
		$this->assertFalse($this->view->file_exists(
			'/' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/keys/' . $this->folder1
			. $this->subfolder . $this->subsubfolder . '/'
			. $this->filename . '/' . $recoveryKeyId . '.shareKey'));

		// enable recovery for admin
		$this->assertTrue($util->setRecoveryForUser(0));

		\OCA\Files_Encryption\Helper::adminDisableRecovery('test123');
		$this->assertEquals(0, \OC::$server->getAppConfig()->getValue('files_encryption', 'recoveryAdminEnabled'));

		//clean up, reset passwords
		\OC_User::setPassword(self::TEST_ENCRYPTION_SHARE_USER2, self::TEST_ENCRYPTION_SHARE_USER2, 'test123');
		$params = array('uid' => self::TEST_ENCRYPTION_SHARE_USER2,
			'password' => self::TEST_ENCRYPTION_SHARE_USER2,
			'recoveryPassword' => 'test123');
		\OCA\Files_Encryption\Hooks::setPassphrase($params);
	}

	/**
	 * @medium
	 */
	function testFailShareFile() {
		// login as admin
		self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);

		// save file with content
		$cryptedFile = file_put_contents('crypt:///' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename, $this->dataShort);

		// test that data was successfully written
		$this->assertInternalType('int', $cryptedFile);

		// disable encryption proxy to prevent recursive calls
		$proxyStatus = \OC_FileProxy::$enabled;
		\OC_FileProxy::$enabled = false;

		// get the file info from previous created file
		$fileInfo = $this->view->getFileInfo(
			'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);

		// check if we have a valid file info
		$this->assertInstanceOf('\OC\Files\FileInfo', $fileInfo);

		// check if the unencrypted file size is stored
		$this->assertGreaterThan(0, $fileInfo['unencrypted_size']);

		// break users public key
		$this->view->rename(\OCA\Files_Encryption\Keymanager::getPublicKeyPath() . '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '.publicKey',
			\OCA\Files_Encryption\Keymanager::getPublicKeyPath() . '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '.publicKey_backup');

		// re-enable the file proxy
		\OC_FileProxy::$enabled = $proxyStatus;

		// share the file
		try {
			\OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, self::TEST_ENCRYPTION_SHARE_GROUP1, \OCP\Constants::PERMISSION_ALL);
		} catch (\Exception $e) {
			$this->assertEquals(0, strpos($e->getMessage(), "Following users are not set up for encryption"));
		}


		// login as admin
		self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);

		// check if share key for user1 not exists
		$this->assertFalse($this->view->file_exists(
			'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
			. $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey'));

		// disable encryption proxy to prevent recursive calls
		$proxyStatus = \OC_FileProxy::$enabled;
		\OC_FileProxy::$enabled = false;

		// break user1 public key
		$this->view->rename(
			\OCA\Files_Encryption\Keymanager::getPublicKeyPath() . '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '.publicKey_backup',
			\OCA\Files_Encryption\Keymanager::getPublicKeyPath() . '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '.publicKey');

		// remove share file
		$this->view->unlink('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
			. $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER3
			. '.shareKey');

		// re-enable the file proxy
		\OC_FileProxy::$enabled = $proxyStatus;

		// unshare the file with user1
		\OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, self::TEST_ENCRYPTION_SHARE_GROUP1);

		// check if share key not exists
		$this->assertFalse($this->view->file_exists(
			'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
			. $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey'));

		// cleanup
		$this->view->chroot('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/');
		$this->view->unlink($this->filename);
		$this->view->chroot('/');
	}


	/**
	 * test rename a shared file mount point
	 */
	function testRename() {

		// login as admin
		self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);

		// save file with content
		$cryptedFile = file_put_contents('crypt:///' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename, $this->dataShort);

		// test that data was successfully written
		$this->assertInternalType('int', $cryptedFile);

		// get the file info from previous created file
		$fileInfo = $this->view->getFileInfo(
			'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);

		// check if we have a valid file info
		$this->assertInstanceOf('\OC\Files\FileInfo', $fileInfo);

		// share the file
		\OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_SHARE_USER2, \OCP\Constants::PERMISSION_ALL);

		// check if share key for user1 and user2 exists
		$this->assertTrue($this->view->file_exists(
				'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
				. $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
		$this->assertTrue($this->view->file_exists(
			'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
			. $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));


		// login as user2
		self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER2);

		$this->assertTrue($this->view->file_exists('/' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->filename));

		// get file contents
		$retrievedCryptedFile = $this->view->file_get_contents(
			'/' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->filename);

		// check if data is the same as we previously written
		$this->assertEquals($this->dataShort, $retrievedCryptedFile);

		\OC\Files\Filesystem::mkdir($this->folder1);

		// move the file to a subfolder
		\OC\Files\Filesystem::rename($this->filename, $this->folder1 . $this->filename);

		// check if we can read the moved file
		$retrievedRenamedFile = $this->view->file_get_contents(
			'/' . self::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->folder1 .  $this->filename);

		// check if data is the same as we previously written
		$this->assertEquals($this->dataShort, $retrievedRenamedFile);

		// check if share key for user2 and user1 still exists
		$this->assertTrue($this->view->file_exists(
				'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
				. $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
		$this->assertTrue($this->view->file_exists(
				'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
				. $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));

		// cleanup
		self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);
		$this->view->unlink('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
	}

	function testRenameGroupShare() {
		// login as admin
		self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);

		// save file with content
		$cryptedFile = file_put_contents('crypt:///' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename, $this->dataShort);

		// test that data was successfully written
		$this->assertInternalType('int', $cryptedFile);

		// get the file info from previous created file
		$fileInfo = $this->view->getFileInfo(
			'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);

		// check if we have a valid file info
		$this->assertInstanceOf('\OC\Files\FileInfo', $fileInfo);

		// share the file
		\OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, self::TEST_ENCRYPTION_SHARE_GROUP1, \OCP\Constants::PERMISSION_ALL);

		// check if share key for user1, user3 and user4 exists
		$this->assertTrue($this->view->file_exists(
				'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
				. $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
		$this->assertTrue($this->view->file_exists(
				'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
				. $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey'));
		$this->assertTrue($this->view->file_exists(
				'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
				. $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER4 . '.shareKey'));


		// login as user2
		self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER3);

		$this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));

		// get file contents
		$retrievedCryptedFile = \OC\Files\Filesystem::file_get_contents($this->filename);

		// check if data is the same as we previously written
		$this->assertEquals($this->dataShort, $retrievedCryptedFile);

		\OC\Files\Filesystem::mkdir($this->folder1);

		// move the file to a subfolder
		\OC\Files\Filesystem::rename($this->filename, $this->folder1 . $this->filename);

		// check if we can read the moved file
		$retrievedRenamedFile = \OC\Files\Filesystem::file_get_contents($this->folder1 . $this->filename);

		// check if data is the same as we previously written
		$this->assertEquals($this->dataShort, $retrievedRenamedFile);

		// check if share key for user1, user3 and user4 still exists
		$this->assertTrue($this->view->file_exists(
				'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
				. $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
		$this->assertTrue($this->view->file_exists(
				'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
				. $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey'));
		$this->assertTrue($this->view->file_exists(
				'/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/'
				. $this->filename . '/' . self::TEST_ENCRYPTION_SHARE_USER4 . '.shareKey'));

		// cleanup
		self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);
		\OC\Files\Filesystem::unlink($this->filename);
	}

	/**
	 * test if additional share keys are added if we move a folder to a shared parent
	 * @medium
	 */
	function testMoveFolder() {

		$view = new \OC\Files\View('/' . self::TEST_ENCRYPTION_SHARE_USER1);

		$filename = '/tmp-' . $this->getUniqueID();
		$folder = '/folder' . $this->getUniqueID();

		\OC\Files\Filesystem::mkdir($folder);

		// Save long data as encrypted file using stream wrapper
		$cryptedFile = \OC\Files\Filesystem::file_put_contents($folder . $filename, $this->dataShort);

		// Test that data was successfully written
		$this->assertInternalType('int', $cryptedFile);

		// Get file decrypted contents
		$decrypt = \OC\Files\Filesystem::file_get_contents($folder . $filename);

		$this->assertEquals($this->dataShort, $decrypt);

		$newFolder = '/newfolder/subfolder' . $this->getUniqueID();
		\OC\Files\Filesystem::mkdir('/newfolder');

		// get the file info from previous created file
		$fileInfo = \OC\Files\Filesystem::getFileInfo('/newfolder');
		$this->assertInstanceOf('\OC\Files\FileInfo', $fileInfo);

		// share the folder
		\OCP\Share::shareItem('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_SHARE_USER2, \OCP\Constants::PERMISSION_ALL);

		\OC\Files\Filesystem::rename($folder, $newFolder);

		// Get file decrypted contents
		$newDecrypt = \OC\Files\Filesystem::file_get_contents($newFolder . $filename);
		$this->assertEquals($this->dataShort, $newDecrypt);

		// check if additional share key for user2 exists
		$this->assertTrue($view->file_exists('files_encryption/keys' . $newFolder . '/' . $filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));

		// check that old keys were removed/moved properly
		$this->assertFalse($view->file_exists('files_encryption/keys' . $folder . '/' . $filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));

		// tear down
		\OC\Files\Filesystem::unlink($newFolder);
		\OC\Files\Filesystem::unlink('/newfolder');
	}

	function usersProvider() {
		return array(
			// test as owner
			array(self::TEST_ENCRYPTION_SHARE_USER1),
			// test as share receiver
			array(self::TEST_ENCRYPTION_SHARE_USER2),
		);
	}

	/**
	 * @dataProvider usersProvider
	 */
	function testMoveFileToFolder($userId) {
		$view = new \OC\Files\View('/' . self::TEST_ENCRYPTION_SHARE_USER1);

		$filename = '/tmp-' . $this->getUniqueID();
		$folder = '/folder' . $this->getUniqueID();

		\OC\Files\Filesystem::mkdir($folder);

		// Save long data as encrypted file using stream wrapper
		$cryptedFile = \OC\Files\Filesystem::file_put_contents($folder . $filename, $this->dataShort);

		// Test that data was successfully written
		$this->assertInternalType('int', $cryptedFile);

		// Get file decrypted contents
		$decrypt = \OC\Files\Filesystem::file_get_contents($folder . $filename);

		$this->assertEquals($this->dataShort, $decrypt);

		$subFolder = $folder . '/subfolder' . $this->getUniqueID();
		\OC\Files\Filesystem::mkdir($subFolder);

		// get the file info from previous created file
		$fileInfo = \OC\Files\Filesystem::getFileInfo($folder);
		$this->assertInstanceOf('\OC\Files\FileInfo', $fileInfo);

		// share the folder
		\OCP\Share::shareItem('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_SHARE_USER2, \OCP\Constants::PERMISSION_ALL);

		// check that the share keys exist
		$this->assertTrue($view->file_exists('files_encryption/keys' . $folder . '/' . $filename . '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
		$this->assertTrue($view->file_exists('files_encryption/keys' . $folder . '/' . $filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));

		// move the file into the subfolder as the test user
		self::loginHelper($userId);
		\OC\Files\Filesystem::rename($folder . $filename, $subFolder . $filename);
		self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);

		// Get file decrypted contents
		$newDecrypt = \OC\Files\Filesystem::file_get_contents($subFolder . $filename);
		$this->assertEquals($this->dataShort, $newDecrypt);

		// check if additional share key for user2 exists
		$this->assertTrue($view->file_exists('files_encryption/keys' . $subFolder . '/' . $filename . '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
		$this->assertTrue($view->file_exists('files_encryption/keys' . $subFolder . '/' . $filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));

		// check that old keys were removed/moved properly
		$this->assertFalse($view->file_exists('files_encryption/keys' . $folder . '/' . $filename . '/' . self::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
		$this->assertFalse($view->file_exists('files_encryption/keys' . $folder . '/' . $filename . '/' . self::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));

		// tear down
		\OC\Files\Filesystem::unlink($subFolder);
		\OC\Files\Filesystem::unlink($folder);
	}

}