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>
<default></default>
<notnull>true</notnull>
<length>32</length>
<comments>md5 hash of the url without the protocol</comments>
<comments>sha1 hash of the url without the protocol</comments>
</field>
<field>
<name>token</name>

View File

@ -112,7 +112,7 @@ class DbHandler {
*/
public function getAllServer() {
$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();
return $result;
}
@ -252,11 +252,11 @@ class DbHandler {
*/
protected function hash($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
* @return string

View File

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

View File

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

View File

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