reuse the url_hash instead of calculating a new hash for the address book

This commit is contained in:
Bjoern Schiessle 2016-02-26 17:02:13 +01:00
parent 62d7885c3b
commit eccd7cf654
5 changed files with 14 additions and 13 deletions

View File

@ -27,8 +27,7 @@
<type>text</type> <type>text</type>
<default></default> <default></default>
<notnull>true</notnull> <notnull>true</notnull>
<length>32</length> <comments>sha1 hash of the url without the protocol</comments>
<comments>md5 hash of the url without the protocol</comments>
</field> </field>
<field> <field>
<name>token</name> <name>token</name>

View File

@ -112,7 +112,7 @@ class DbHandler {
*/ */
public function getAllServer() { public function getAllServer() {
$query = $this->connection->getQueryBuilder(); $query = $this->connection->getQueryBuilder();
$query->select(['url', 'id', 'status', 'shared_secret', 'sync_token'])->from($this->dbTable); $query->select(['url', 'url_hash', 'id', 'status', 'shared_secret', 'sync_token'])->from($this->dbTable);
$result = $query->execute()->fetchAll(); $result = $query->execute()->fetchAll();
return $result; return $result;
} }
@ -252,11 +252,11 @@ class DbHandler {
*/ */
protected function hash($url) { protected function hash($url) {
$normalized = $this->normalizeUrl($url); $normalized = $this->normalizeUrl($url);
return md5($normalized); return sha1($normalized);
} }
/** /**
* normalize URL, used to create the md5 hash * normalize URL, used to create the sha1 hash
* *
* @param string $url * @param string $url
* @return string * @return string

View File

@ -40,7 +40,7 @@ class SyncFederationAddressBooks {
if (is_null($sharedSecret)) { if (is_null($sharedSecret)) {
continue; continue;
} }
$targetBookId = sha1($url); $targetBookId = $trustedServer['url_hash'];
$targetPrincipal = "principals/system/system"; $targetPrincipal = "principals/system/system";
$targetBookProperties = [ $targetBookProperties = [
'{DAV:}displayname' => $url '{DAV:}displayname' => $url

View File

@ -89,9 +89,9 @@ class DbHandlerTest extends TestCase {
public function dataTestAddServer() { public function dataTestAddServer() {
return [ return [
['http://owncloud.org', 'http://owncloud.org', md5('owncloud.org')], ['http://owncloud.org', 'http://owncloud.org', sha1('owncloud.org')],
['https://owncloud.org', 'https://owncloud.org', md5('owncloud.org')], ['https://owncloud.org', 'https://owncloud.org', sha1('owncloud.org')],
['http://owncloud.org/', 'http://owncloud.org', md5('owncloud.org')], ['http://owncloud.org/', 'http://owncloud.org', sha1('owncloud.org')],
]; ];
} }
@ -233,10 +233,10 @@ class DbHandlerTest extends TestCase {
public function dataTestHash() { public function dataTestHash() {
return [ return [
['server1', md5('server1')], ['server1', sha1('server1')],
['http://server1', md5('server1')], ['http://server1', sha1('server1')],
['https://server1', md5('server1')], ['https://server1', sha1('server1')],
['http://server1/', md5('server1')], ['http://server1/', sha1('server1')],
]; ];
} }

View File

@ -19,6 +19,7 @@ class SyncFederationAddressbooksTest extends \Test\TestCase {
willReturn([ willReturn([
[ [
'url' => 'https://cloud.drop.box', 'url' => 'https://cloud.drop.box',
'url_hash' => 'sha1',
'shared_secret' => 'iloveowncloud', 'shared_secret' => 'iloveowncloud',
'sync_token' => '0' 'sync_token' => '0'
] ]
@ -47,6 +48,7 @@ class SyncFederationAddressbooksTest extends \Test\TestCase {
willReturn([ willReturn([
[ [
'url' => 'https://cloud.drop.box', 'url' => 'https://cloud.drop.box',
'url_hash' => 'sha1',
'shared_secret' => 'iloveowncloud', 'shared_secret' => 'iloveowncloud',
'sync_token' => '0' 'sync_token' => '0'
] ]