summaryrefslogtreecommitdiffstats
path: root/apps/federation
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2015-12-07 15:28:06 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2016-01-12 14:24:47 +0100
commit1a20af253bc90de35a1bf3b65adb33ab44d17c1d (patch)
tree77a6f2181318cdffb85f97cdbcbf75bf40e3aa35 /apps/federation
parent0bf026cceab5f5e910f5e7c163397dbe76dbe0f2 (diff)
downloadnextcloud-server-1a20af253bc90de35a1bf3b65adb33ab44d17c1d.tar.gz
nextcloud-server-1a20af253bc90de35a1bf3b65adb33ab44d17c1d.zip
Adding tests and adjust PHPDoc
Diffstat (limited to 'apps/federation')
-rw-r--r--apps/federation/appinfo/application.php6
-rw-r--r--apps/federation/dav/fedauth.php10
-rw-r--r--apps/federation/lib/dbhandler.php1
-rw-r--r--apps/federation/tests/dav/fedauthtest.php52
-rw-r--r--apps/federation/tests/lib/dbhandlertest.php26
5 files changed, 85 insertions, 10 deletions
diff --git a/apps/federation/appinfo/application.php b/apps/federation/appinfo/application.php
index f0fefb948af..0214d73d900 100644
--- a/apps/federation/appinfo/application.php
+++ b/apps/federation/appinfo/application.php
@@ -153,8 +153,10 @@ class Application extends \OCP\AppFramework\App {
if ($event instanceof SabrePluginEvent) {
$authPlugin = $event->getServer()->getPlugin('auth');
if ($authPlugin instanceof Plugin) {
- $db = $container->getServer()->getDatabaseConnection();
- $authPlugin->addBackend(new FedAuth($db));
+ $h = new DbHandler($container->getServer()->getDatabaseConnection(),
+ $container->getServer()->getL10N('federation')
+ );
+ $authPlugin->addBackend(new FedAuth($h));
}
}
});
diff --git a/apps/federation/dav/fedauth.php b/apps/federation/dav/fedauth.php
index ade5448d1bc..56173233bf3 100644
--- a/apps/federation/dav/fedauth.php
+++ b/apps/federation/dav/fedauth.php
@@ -21,7 +21,6 @@
namespace OCA\Federation\DAV;
use OCA\Federation\DbHandler;
-use OCP\IDBConnection;
use Sabre\DAV\Auth\Backend\AbstractBasic;
class FedAuth extends AbstractBasic {
@@ -29,9 +28,9 @@ class FedAuth extends AbstractBasic {
/**
* FedAuth constructor.
*
- * @param IDBConnection $db
+ * @param DbHandler $db
*/
- public function __construct(IDBConnection $db) {
+ public function __construct(DbHandler $db) {
$this->db = $db;
$this->principalPrefix = 'principals/system/';
}
@@ -47,9 +46,6 @@ class FedAuth extends AbstractBasic {
* @return bool
*/
protected function validateUserPass($username, $password) {
- $h = new DbHandler($this->db,
- \OC::$server->getL10N('federation')
- );
- return $h->auth($username, $password);
+ return $this->db->auth($username, $password);
}
}
diff --git a/apps/federation/lib/dbhandler.php b/apps/federation/lib/dbhandler.php
index 0677430f799..f50854fefb3 100644
--- a/apps/federation/lib/dbhandler.php
+++ b/apps/federation/lib/dbhandler.php
@@ -206,6 +206,7 @@ class DbHandler {
*
* @param string $url
* @param int $status
+ * @param string|null $token
*/
public function setServerStatus($url, $status, $token = null) {
$hash = $this->hash($url);
diff --git a/apps/federation/tests/dav/fedauthtest.php b/apps/federation/tests/dav/fedauthtest.php
new file mode 100644
index 00000000000..845cfc622d2
--- /dev/null
+++ b/apps/federation/tests/dav/fedauthtest.php
@@ -0,0 +1,52 @@
+<?php
+/**
+ * @author Thomas Müller <thomas.mueller@tmit.eu>
+ *
+ * @copyright Copyright (c) 2015, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program 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, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+
+namespace OCA\Federation\Tests\DAV;
+
+use OCA\Federation\DAV\FedAuth;
+use OCA\Federation\DbHandler;
+use Test\TestCase;
+
+class FedAuthTest extends TestCase {
+
+ /**
+ * @dataProvider providesUser
+ *
+ * @param array $expected
+ * @param string $user
+ * @param string $password
+ */
+ public function testFedAuth($expected, $user, $password) {
+ /** @var DbHandler | \PHPUnit_Framework_MockObject_MockObject $db */
+ $db = $this->getMockBuilder('OCA\Federation\DbHandler')->disableOriginalConstructor()->getMock();
+ $db->method('auth')->willReturn(true);
+ $auth = new FedAuth($db);
+ $result = $this->invokePrivate($auth, 'validateUserPass', [$user, $password]);
+ $this->assertEquals($expected, $result);
+ }
+
+ public function providesUser() {
+ return [
+ [true, 'system', '123456']
+ ];
+ }
+}
diff --git a/apps/federation/tests/lib/dbhandlertest.php b/apps/federation/tests/lib/dbhandlertest.php
index 123eaaee450..65126e39f72 100644
--- a/apps/federation/tests/lib/dbhandlertest.php
+++ b/apps/federation/tests/lib/dbhandlertest.php
@@ -26,6 +26,7 @@ namespace OCA\Federation\Tests\lib;
use OCA\Federation\DbHandler;
use OCA\Federation\TrustedServers;
use OCP\IDBConnection;
+use OCP\IL10N;
use Test\TestCase;
/**
@@ -36,7 +37,7 @@ class DbHandlerTest extends TestCase {
/** @var DbHandler */
private $dbHandler;
- /** @var \PHPUnit_Framework_MockObject_MockObject */
+ /** @var IL10N | \PHPUnit_Framework_MockObject_MockObject */
private $il10n;
/** @var IDBConnection */
@@ -209,6 +210,11 @@ class DbHandlerTest extends TestCase {
$this->assertSame(TrustedServers::STATUS_OK,
$this->dbHandler->getServerStatus('https://server1')
);
+
+ // test sync token
+ $this->dbHandler->setServerStatus('http://server1', TrustedServers::STATUS_OK, 'token1234567890');
+ $servers = $this->dbHandler->getAllServer();
+ $this->assertSame('token1234567890', $servers[0]['sync_token']);
}
/**
@@ -256,4 +262,22 @@ class DbHandlerTest extends TestCase {
];
}
+ /**
+ * @dataProvider providesAuth
+ */
+ public function testAuth($expectedResult, $user, $password) {
+ if ($expectedResult) {
+ $this->dbHandler->addServer('url1');
+ $this->dbHandler->addSharedSecret('url1', $password);
+ }
+ $result = $this->dbHandler->auth($user, $password);
+ $this->assertEquals($expectedResult, $result);
+ }
+
+ public function providesAuth() {
+ return [
+ [false, 'foo', ''],
+ [true, 'system', '123456789'],
+ ];
+ }
}