diff --git a/apps/federation/lib/dbhandler.php b/apps/federation/lib/dbhandler.php index 61ba5c87cfd9013336a8d3bc539d8809dff3efd2..7606593f780b884554fc278f59bb212256eab50b 100644 --- a/apps/federation/lib/dbhandler.php +++ b/apps/federation/lib/dbhandler.php @@ -68,6 +68,7 @@ class DbHandler { */ public function addServer($url) { $hash = $this->hash($url); + $url = rtrim($url, '/'); $query = $this->connection->getQueryBuilder(); $query->insert($this->dbTable) ->values( diff --git a/apps/federation/tests/lib/dbhandlertest.php b/apps/federation/tests/lib/dbhandlertest.php index e47df092f8c145404bf8d3b59d33dca755377b2b..123eaaee45039a1ec8bcb33da7c091f64d0e41a6 100644 --- a/apps/federation/tests/lib/dbhandlertest.php +++ b/apps/federation/tests/lib/dbhandlertest.php @@ -67,17 +67,33 @@ class DbHandlerTest extends TestCase { $query->execute(); } - public function testAddServer() { - $id = $this->dbHandler->addServer('server1'); + /** + * @dataProvider dataTestAddServer + * + * @param string $url passed to the method + * @param string $expectedUrl the url we expect to be written to the db + * @param string $expectedHash the hash value we expect to be written to the db + */ + public function testAddServer($url, $expectedUrl, $expectedHash) { + $id = $this->dbHandler->addServer($url); $query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable); $result = $query->execute()->fetchAll(); $this->assertSame(1, count($result)); - $this->assertSame('server1', $result[0]['url']); + $this->assertSame($expectedUrl, $result[0]['url']); $this->assertSame($id, (int)$result[0]['id']); + $this->assertSame($expectedHash, $result[0]['url_hash']); $this->assertSame(TrustedServers::STATUS_PENDING, (int)$result[0]['status']); } + public function dataTestAddServer() { + return [ + ['http://owncloud.org', 'http://owncloud.org', md5('owncloud.org')], + ['https://owncloud.org', 'https://owncloud.org', md5('owncloud.org')], + ['http://owncloud.org/', 'http://owncloud.org', md5('owncloud.org')], + ]; + } + public function testRemove() { $id1 = $this->dbHandler->addServer('server1'); $id2 = $this->dbHandler->addServer('server2');