summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/tests
diff options
context:
space:
mode:
authorBjoern Schiessle <schiessle@owncloud.com>2015-01-21 00:11:15 +0100
committerBjoern Schiessle <schiessle@owncloud.com>2015-01-21 17:11:34 +0100
commit7216983a0834324fb7d062721062385e805ddf94 (patch)
tree5b1ad787f838eee13361f486dfaf9dfa7126003a /apps/files_sharing/tests
parent8ba42abbe45affe7cd149c8e693c69b5994b2c98 (diff)
downloadnextcloud-server-7216983a0834324fb7d062721062385e805ddf94.tar.gz
nextcloud-server-7216983a0834324fb7d062721062385e805ddf94.zip
delete all server-to-server shares if a user gets deleted
Diffstat (limited to 'apps/files_sharing/tests')
-rw-r--r--apps/files_sharing/tests/server2server.php76
1 files changed, 76 insertions, 0 deletions
diff --git a/apps/files_sharing/tests/server2server.php b/apps/files_sharing/tests/server2server.php
index 0400d357b82..2d59f7be9cd 100644
--- a/apps/files_sharing/tests/server2server.php
+++ b/apps/files_sharing/tests/server2server.php
@@ -30,6 +30,14 @@ class Test_Files_Sharing_S2S_OCS_API extends TestCase {
const TEST_FOLDER_NAME = '/folder_share_api_test';
+ /**
+ * @var \OCP\IDBConnection
+ */
+ private $connection;
+
+ /**
+ * @var \OCA\Files_Sharing\API\Server2Server
+ */
private $s2s;
protected function setUp() {
@@ -49,6 +57,8 @@ class Test_Files_Sharing_S2S_OCS_API extends TestCase {
$this->registerHttpHelper($httpHelperMock);
$this->s2s = new \OCA\Files_Sharing\API\Server2Server();
+
+ $this->connection = \OC::$server->getDatabaseConnection();
}
protected function tearDown() {
@@ -132,4 +142,70 @@ class Test_Files_Sharing_S2S_OCS_API extends TestCase {
$data = $result->fetchAll();
$this->assertEmpty($data);
}
+
+ /**
+ * @dataProvider dataTestDeleteUser
+ */
+ function testDeleteUser($toDelete, $expected, $remainingUsers) {
+ $this->createDummyS2SShares();
+
+ $manager = new OCA\Files_Sharing\External\Manager(
+ \OC::$server->getDatabaseConnection(),
+ \OC\Files\Filesystem::getMountManager(),
+ \OC\Files\Filesystem::getLoader(),
+ \OC::$server->getUserSession(),
+ \OC::$server->getHTTPHelper());
+
+ $manager->removeUserShares($toDelete);
+
+ $query = $this->connection->prepare('SELECT `user` FROM `*PREFIX*share_external`');
+ $query->execute();
+ $result = $query->fetchAll();
+
+ foreach ($result as $r) {
+ $remainingShares[$r['user']] = isset($remainingShares[$r['user']]) ? $remainingShares[$r['user']] + 1 : 1;
+ }
+
+ $this->assertSame($remainingUsers, count($remainingShares));
+
+ foreach ($expected as $key => $value) {
+ if ($key === $toDelete) {
+ $this->assertArrayNotHasKey($key, $remainingShares);
+ } else {
+ $this->assertSame($value, $remainingShares[$key]);
+ }
+ }
+
+ }
+
+ function dataTestDeleteUser() {
+ return array(
+ array('user1', array('user1' => 0, 'user2' => 3, 'user3' => 3), 2),
+ array('user2', array('user1' => 4, 'user2' => 0, 'user3' => 3), 2),
+ array('user3', array('user1' => 4, 'user2' => 3, 'user3' => 0), 2),
+ array('user4', array('user1' => 4, 'user2' => 3, 'user3' => 3), 3),
+ );
+ }
+
+ private function createDummyS2SShares() {
+ $query = $this->connection->prepare('
+ INSERT INTO `*PREFIX*share_external`
+ (`remote`, `share_token`, `password`, `name`, `owner`, `user`, `mountpoint`, `mountpoint_hash`, `remote_id`, `accepted`)
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
+ ');
+
+ $users = array('user1', 'user2', 'user3');
+
+ for ($i = 0; $i < 10; $i++) {
+ $user = $users[$i%3];
+ $query->execute(array('remote', 'token', 'password', 'name', 'owner', $user, 'mount point', $i, $i, 0));
+ }
+
+ $query = $this->connection->prepare('SELECT `id` FROM `*PREFIX*share_external`');
+ $query->execute();
+ $dummyEntries = $query->fetchAll();
+
+ $this->assertSame(10, count($dummyEntries));
+ }
+
}