diff options
author | Jeremy Benoist <jeremy.benoist@gmail.com> | 2019-04-01 11:50:33 +0200 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2019-04-01 13:24:40 +0200 |
commit | 9c2b2aae70b06411336e6eb6ac43b3ebd30dc38c (patch) | |
tree | b8b37a0f8b3edd0c4db1678815d906a7b6126f31 | |
parent | bfe02a0b481055bb4e799200c8daa9a0ad987c71 (diff) | |
download | wallabag-9c2b2aae70b06411336e6eb6ac43b3ebd30dc38c.tar.gz wallabag-9c2b2aae70b06411336e6eb6ac43b3ebd30dc38c.tar.zst wallabag-9c2b2aae70b06411336e6eb6ac43b3ebd30dc38c.zip |
Keep url in exists endpoint
- Add migration
- Use md5 instead of sha512 (we don't need security here, just a hash)
- Update tests
8 files changed, 154 insertions, 77 deletions
diff --git a/app/DoctrineMigrations/Version20190401105353.php b/app/DoctrineMigrations/Version20190401105353.php new file mode 100644 index 00000000..4afc8b15 --- /dev/null +++ b/app/DoctrineMigrations/Version20190401105353.php | |||
@@ -0,0 +1,44 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Application\Migrations; | ||
4 | |||
5 | use Doctrine\DBAL\Schema\Schema; | ||
6 | use Wallabag\CoreBundle\Doctrine\WallabagMigration; | ||
7 | |||
8 | /** | ||
9 | * Add hashed_url in entry. | ||
10 | */ | ||
11 | class Version20190401105353 extends WallabagMigration | ||
12 | { | ||
13 | /** | ||
14 | * @param Schema $schema | ||
15 | */ | ||
16 | public function up(Schema $schema) | ||
17 | { | ||
18 | $entryTable = $schema->getTable($this->getTable('entry')); | ||
19 | |||
20 | $this->skipIf($entryTable->hasColumn('hashed_url'), 'It seems that you already played this migration.'); | ||
21 | |||
22 | $entryTable->addColumn('hashed_url', 'text', [ | ||
23 | 'length' => 32, | ||
24 | 'notnull' => false, | ||
25 | ]); | ||
26 | |||
27 | // sqlite doesn't have the MD5 function by default | ||
28 | if ('sqlite' !== $this->connection->getDatabasePlatform()->getName()) { | ||
29 | $this->addSql('UPDATE ' . $this->getTable('entry') . ' SET hashed_url = MD5(url)'); | ||
30 | } | ||
31 | } | ||
32 | |||
33 | /** | ||
34 | * @param Schema $schema | ||
35 | */ | ||
36 | public function down(Schema $schema) | ||
37 | { | ||
38 | $entryTable = $schema->getTable($this->getTable('entry')); | ||
39 | |||
40 | $this->skipIf(!$entryTable->hasColumn('hashed_url'), 'It seems that you already played this migration.'); | ||
41 | |||
42 | $entryTable->dropColumn('hashed_url'); | ||
43 | } | ||
44 | } | ||
diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php index 26746f7d..0ecf1a0e 100644 --- a/src/Wallabag/ApiBundle/Controller/EntryRestController.php +++ b/src/Wallabag/ApiBundle/Controller/EntryRestController.php | |||
@@ -27,10 +27,10 @@ class EntryRestController extends WallabagRestController | |||
27 | * @ApiDoc( | 27 | * @ApiDoc( |
28 | * parameters={ | 28 | * parameters={ |
29 | * {"name"="return_id", "dataType"="string", "required"=false, "format"="1 or 0", "description"="Set 1 if you want to retrieve ID in case entry(ies) exists, 0 by default"}, | 29 | * {"name"="return_id", "dataType"="string", "required"=false, "format"="1 or 0", "description"="Set 1 if you want to retrieve ID in case entry(ies) exists, 0 by default"}, |
30 | * {"name"="url", "dataType"="string", "required"=true, "format"="An url", "description"="Url to check if it exists"}, | 30 | * {"name"="url", "dataType"="string", "required"=true, "format"="An url", "description"="DEPRECATED, use hashed_url instead"}, |
31 | * {"name"="urls", "dataType"="string", "required"=false, "format"="An array of urls (?urls[]=http...&urls[]=http...)", "description"="Urls (as an array) to check if it exists"} | 31 | * {"name"="urls", "dataType"="string", "required"=false, "format"="An array of urls (?urls[]=http...&urls[]=http...)", "description"="DEPRECATED, use hashed_urls instead"}, |
32 | * {"name"="hashedurl", "dataType"="string", "required"=true, "format"="An url", "description"="Md5 url to check if it exists"}, | 32 | * {"name"="hashed_url", "dataType"="string", "required"=true, "format"="An url", "description"="Md5 url to check if it exists"}, |
33 | * {"name"="hashedurls", "dataType"="string", "required"=false, "format"="An array of urls (?urls[]=http...&urls[]=http...)", "description"="Md5 urls (as an array) to check if it exists"} | 33 | * {"name"="hashed_urls", "dataType"="string", "required"=false, "format"="An array of urls (?urls[]=http...&urls[]=http...)", "description"="Md5 urls (as an array) to check if it exists"} |
34 | * } | 34 | * } |
35 | * ) | 35 | * ) |
36 | * | 36 | * |
@@ -39,22 +39,18 @@ class EntryRestController extends WallabagRestController | |||
39 | public function getEntriesExistsAction(Request $request) | 39 | public function getEntriesExistsAction(Request $request) |
40 | { | 40 | { |
41 | $this->validateAuthentication(); | 41 | $this->validateAuthentication(); |
42 | $repo = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entry'); | ||
42 | 43 | ||
43 | $returnId = (null === $request->query->get('return_id')) ? false : (bool) $request->query->get('return_id'); | 44 | $returnId = (null === $request->query->get('return_id')) ? false : (bool) $request->query->get('return_id'); |
44 | $urls = $request->query->get('urls', []); | ||
45 | 45 | ||
46 | $hashedUrls = $request->query->get('hashedurls', []); | 46 | $urls = $request->query->get('urls', []); |
47 | $hashedUrls = $request->query->get('hashed_urls', []); | ||
47 | 48 | ||
48 | // handle multiple urls first | 49 | // handle multiple urls first |
49 | if (!empty($hashedUrls)) { | 50 | if (!empty($hashedUrls)) { |
50 | $results = []; | 51 | $results = []; |
51 | foreach ($hashedUrls as $hashedUrl) { | 52 | foreach ($hashedUrls as $hashedUrl) { |
52 | $res = $this->getDoctrine() | 53 | $res = $repo->findByHashedUrlAndUserId($hashedUrl, $this->getUser()->getId()); |
53 | ->getRepository('WallabagCoreBundle:Entry') | ||
54 | ->findOneBy([ | ||
55 | 'hashedUrl' => $hashedUrl, | ||
56 | 'user' => $this->getUser()->getId(), | ||
57 | ]); | ||
58 | 54 | ||
59 | // $results[$url] = $this->returnExistInformation($res, $returnId); | 55 | // $results[$url] = $this->returnExistInformation($res, $returnId); |
60 | $results[$hashedUrl] = $this->returnExistInformation($res, $returnId); | 56 | $results[$hashedUrl] = $this->returnExistInformation($res, $returnId); |
@@ -63,24 +59,33 @@ class EntryRestController extends WallabagRestController | |||
63 | return $this->sendResponse($results); | 59 | return $this->sendResponse($results); |
64 | } | 60 | } |
65 | 61 | ||
62 | // @deprecated, to be remove in 3.0 | ||
63 | if (!empty($urls)) { | ||
64 | $results = []; | ||
65 | foreach ($urls as $url) { | ||
66 | $res = $repo->findByUrlAndUserId($url, $this->getUser()->getId()); | ||
67 | |||
68 | $results[$url] = $this->returnExistInformation($res, $returnId); | ||
69 | } | ||
70 | |||
71 | return $this->sendResponse($results); | ||
72 | } | ||
73 | |||
66 | // let's see if it is a simple url? | 74 | // let's see if it is a simple url? |
67 | $hashedUrl = $request->query->get('hashedurl', ''); | 75 | $url = $request->query->get('url', ''); |
76 | $hashedUrl = $request->query->get('hashed_url', ''); | ||
68 | 77 | ||
69 | // if (empty($url)) { | 78 | if (empty($url) && empty($hashedUrl)) { |
70 | // throw $this->createAccessDeniedException('URL is empty?, logged user id: ' . $this->getUser()->getId()); | 79 | throw $this->createAccessDeniedException('URL is empty?, logged user id: ' . $this->getUser()->getId()); |
71 | // } | 80 | } |
72 | 81 | ||
73 | if (empty($hashedUrl)) { | 82 | $method = 'findByUrlAndUserId'; |
74 | throw $this->createAccessDeniedException('URL is empty?, logged user id: '.$this->getUser()->getId()); | 83 | if (!empty($hashedUrl)) { |
84 | $method = 'findByHashedUrlAndUserId'; | ||
85 | $url = $hashedUrl; | ||
75 | } | 86 | } |
76 | 87 | ||
77 | $res = $this->getDoctrine() | 88 | $res = $repo->$method($url, $this->getUser()->getId()); |
78 | ->getRepository('WallabagCoreBundle:Entry') | ||
79 | // ->findByUrlAndUserId($url, $this->getUser()->getId()); | ||
80 | ->findOneBy([ | ||
81 | 'hashedUrl' => $hashedUrl, | ||
82 | 'user' => $this->getUser()->getId(), | ||
83 | ]); | ||
84 | 89 | ||
85 | return $this->sendResponse(['exists' => $this->returnExistInformation($res, $returnId)]); | 90 | return $this->sendResponse(['exists' => $this->returnExistInformation($res, $returnId)]); |
86 | } | 91 | } |
diff --git a/src/Wallabag/CoreBundle/Command/GenerateUrlHashesCommand.php b/src/Wallabag/CoreBundle/Command/GenerateUrlHashesCommand.php index fe2644f2..fb598390 100644 --- a/src/Wallabag/CoreBundle/Command/GenerateUrlHashesCommand.php +++ b/src/Wallabag/CoreBundle/Command/GenerateUrlHashesCommand.php | |||
@@ -45,13 +45,13 @@ class GenerateUrlHashesCommand extends ContainerAwareCommand | |||
45 | } else { | 45 | } else { |
46 | $users = $this->getDoctrine()->getRepository('WallabagUserBundle:User')->findAll(); | 46 | $users = $this->getDoctrine()->getRepository('WallabagUserBundle:User')->findAll(); |
47 | 47 | ||
48 | $output->writeln(sprintf('Generating hashed urls for the %d user account entries', count($users))); | 48 | $output->writeln(sprintf('Generating hashed urls for "%d" users', \count($users))); |
49 | 49 | ||
50 | foreach ($users as $user) { | 50 | foreach ($users as $user) { |
51 | $output->writeln(sprintf('Processing user %s', $user->getUsername())); | 51 | $output->writeln(sprintf('Processing user: %s', $user->getUsername())); |
52 | $this->generateHashedUrls($user); | 52 | $this->generateHashedUrls($user); |
53 | } | 53 | } |
54 | $output->writeln(sprintf('Finished generated hashed urls')); | 54 | $output->writeln('Finished generated hashed urls'); |
55 | } | 55 | } |
56 | 56 | ||
57 | return 0; | 57 | return 0; |
@@ -67,13 +67,20 @@ class GenerateUrlHashesCommand extends ContainerAwareCommand | |||
67 | 67 | ||
68 | $entries = $repo->findByUser($user->getId()); | 68 | $entries = $repo->findByUser($user->getId()); |
69 | 69 | ||
70 | $i = 1; | ||
70 | foreach ($entries as $entry) { | 71 | foreach ($entries as $entry) { |
71 | $entry->setHashedUrl(hash('sha512', $entry->getUrl())); | 72 | $entry->setHashedUrl(hash('md5', $entry->getUrl())); |
72 | $em->persist($entry); | 73 | $em->persist($entry); |
73 | $em->flush(); | 74 | |
75 | if (0 === ($i % 20)) { | ||
76 | $em->flush(); | ||
77 | } | ||
78 | ++$i; | ||
74 | } | 79 | } |
75 | 80 | ||
76 | $this->output->writeln(sprintf('Generated hashed urls for user %s', $user->getUserName())); | 81 | $em->flush(); |
82 | |||
83 | $this->output->writeln(sprintf('Generated hashed urls for user: %s', $user->getUserName())); | ||
77 | } | 84 | } |
78 | 85 | ||
79 | /** | 86 | /** |
diff --git a/src/Wallabag/CoreBundle/DataFixtures/EntryFixtures.php b/src/Wallabag/CoreBundle/DataFixtures/EntryFixtures.php index 9c10500d..1b18cad6 100644 --- a/src/Wallabag/CoreBundle/DataFixtures/EntryFixtures.php +++ b/src/Wallabag/CoreBundle/DataFixtures/EntryFixtures.php | |||
@@ -30,7 +30,6 @@ class EntryFixtures extends Fixture implements DependentFixtureInterface | |||
30 | 'entry2' => [ | 30 | 'entry2' => [ |
31 | 'user' => 'admin-user', | 31 | 'user' => 'admin-user', |
32 | 'url' => 'http://0.0.0.0/entry2', | 32 | 'url' => 'http://0.0.0.0/entry2', |
33 | 'hashed_url' => hash('md5', 'http://0.0.0.0/entry2'), | ||
34 | 'reading_time' => 1, | 33 | 'reading_time' => 1, |
35 | 'domain' => 'domain.io', | 34 | 'domain' => 'domain.io', |
36 | 'mime' => 'text/html', | 35 | 'mime' => 'text/html', |
@@ -90,6 +89,7 @@ class EntryFixtures extends Fixture implements DependentFixtureInterface | |||
90 | foreach ($entries as $reference => $item) { | 89 | foreach ($entries as $reference => $item) { |
91 | $entry = new Entry($this->getReference($item['user'])); | 90 | $entry = new Entry($this->getReference($item['user'])); |
92 | $entry->setUrl($item['url']); | 91 | $entry->setUrl($item['url']); |
92 | $entry->setHashedUrl(hash('md5', $item['url'])); | ||
93 | $entry->setReadingTime($item['reading_time']); | 93 | $entry->setReadingTime($item['reading_time']); |
94 | $entry->setDomainName($item['domain']); | 94 | $entry->setDomainName($item['domain']); |
95 | $entry->setMimetype($item['mime']); | 95 | $entry->setMimetype($item['mime']); |
diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index 17a1ed58..a04f101f 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php | |||
@@ -26,7 +26,7 @@ use Wallabag\UserBundle\Entity\User; | |||
26 | * indexes={ | 26 | * indexes={ |
27 | * @ORM\Index(name="created_at", columns={"created_at"}), | 27 | * @ORM\Index(name="created_at", columns={"created_at"}), |
28 | * @ORM\Index(name="uid", columns={"uid"}), | 28 | * @ORM\Index(name="uid", columns={"uid"}), |
29 | * @ORM\Index(name="hashedurl", columns={"hashedurl"}) | 29 | * @ORM\Index(name="hashed_url", columns={"hashed_url"}) |
30 | * } | 30 | * } |
31 | * ) | 31 | * ) |
32 | * @ORM\HasLifecycleCallbacks() | 32 | * @ORM\HasLifecycleCallbacks() |
@@ -79,7 +79,7 @@ class Entry | |||
79 | /** | 79 | /** |
80 | * @var string | 80 | * @var string |
81 | * | 81 | * |
82 | * @ORM\Column(name="hashedurl", type="text", nullable=true) | 82 | * @ORM\Column(name="hashed_url", type="string", length=32, nullable=true) |
83 | */ | 83 | */ |
84 | private $hashedUrl; | 84 | private $hashedUrl; |
85 | 85 | ||
diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index 45366623..0c175abb 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php | |||
@@ -347,6 +347,30 @@ class EntryRepository extends EntityRepository | |||
347 | } | 347 | } |
348 | 348 | ||
349 | /** | 349 | /** |
350 | * Find an entry by its hashed url and its owner. | ||
351 | * If it exists, return the entry otherwise return false. | ||
352 | * | ||
353 | * @param $hashedUrl | ||
354 | * @param $userId | ||
355 | * | ||
356 | * @return Entry|bool | ||
357 | */ | ||
358 | public function findByHashedUrlAndUserId($hashedUrl, $userId) | ||
359 | { | ||
360 | $res = $this->createQueryBuilder('e') | ||
361 | ->where('e.hashedUrl = :hashed_url')->setParameter('hashed_url', urldecode($hashedUrl)) | ||
362 | ->andWhere('e.user = :user_id')->setParameter('user_id', $userId) | ||
363 | ->getQuery() | ||
364 | ->getResult(); | ||
365 | |||
366 | if (\count($res)) { | ||
367 | return current($res); | ||
368 | } | ||
369 | |||
370 | return false; | ||
371 | } | ||
372 | |||
373 | /** | ||
350 | * Count all entries for a user. | 374 | * Count all entries for a user. |
351 | * | 375 | * |
352 | * @param int $userId | 376 | * @param int $userId |
diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 8d96d7b8..fc4dc9d9 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | |||
@@ -971,40 +971,42 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
971 | $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \DateTime($content['starred_at']))->getTimestamp()); | 971 | $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \DateTime($content['starred_at']))->getTimestamp()); |
972 | } | 972 | } |
973 | 973 | ||
974 | public function testGetEntriesExistsWithReturnId() | 974 | public function dataForEntriesExistWithUrl() |
975 | { | 975 | { |
976 | $this->client->request('GET', '/api/entries/exists?url=http://0.0.0.0/entry2&return_id=1'); | 976 | $url = hash('md5', 'http://0.0.0.0/entry2'); |
977 | 977 | ||
978 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); | 978 | return [ |
979 | 979 | 'with_id' => [ | |
980 | $content = json_decode($this->client->getResponse()->getContent(), true); | 980 | 'url' => '/api/entries/exists?url=http://0.0.0.0/entry2&return_id=1', |
981 | 981 | 'expectedValue' => 2, | |
982 | // it returns a database id, we don't know it, so we only check it's greater than the lowest possible value | 982 | ], |
983 | $this->assertGreaterThan(1, $content['exists']); | 983 | 'without_id' => [ |
984 | } | 984 | 'url' => '/api/entries/exists?url=http://0.0.0.0/entry2', |
985 | 985 | 'expectedValue' => true, | |
986 | public function testGetEntriesExistsWithoutReturnId() | 986 | ], |
987 | { | 987 | 'hashed_url_with_id' => [ |
988 | $this->client->request('GET', '/api/entries/exists?url=http://0.0.0.0/entry2'); | 988 | 'url' => '/api/entries/exists?hashed_url=' . $url . '&return_id=1', |
989 | 989 | 'expectedValue' => 2, | |
990 | $this->client->request('GET', '/api/entries/exists?hashedurl=' . hash('md5', 'http://0.0.0.0/entry2')); | 990 | ], |
991 | 991 | 'hashed_url_without_id' => [ | |
992 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); | 992 | 'url' => '/api/entries/exists?hashed_url=' . $url . '', |
993 | 993 | 'expectedValue' => true, | |
994 | $content = json_decode($this->client->getResponse()->getContent(), true); | 994 | ], |
995 | 995 | ]; | |
996 | $this->assertTrue($content['exists']); | ||
997 | } | 996 | } |
998 | 997 | ||
999 | public function testGetEntriesExistsWithHash() | 998 | /** |
999 | * @dataProvider dataForEntriesExistWithUrl | ||
1000 | */ | ||
1001 | public function testGetEntriesExists($url, $expectedValue) | ||
1000 | { | 1002 | { |
1001 | $this->client->request('GET', '/api/entries/exists?hashedurl=' . hash('md5', 'http://0.0.0.0/entry2')); | 1003 | $this->client->request('GET', $url); |
1002 | 1004 | ||
1003 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); | 1005 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); |
1004 | 1006 | ||
1005 | $content = json_decode($this->client->getResponse()->getContent(), true); | 1007 | $content = json_decode($this->client->getResponse()->getContent(), true); |
1006 | 1008 | ||
1007 | $this->assertSame(2, $content['exists']); | 1009 | $this->assertSame($expectedValue, $content['exists']); |
1008 | } | 1010 | } |
1009 | 1011 | ||
1010 | public function testGetEntriesExistsWithManyUrls() | 1012 | public function testGetEntriesExistsWithManyUrls() |
@@ -1045,42 +1047,37 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
1045 | { | 1047 | { |
1046 | $url1 = 'http://0.0.0.0/entry2'; | 1048 | $url1 = 'http://0.0.0.0/entry2'; |
1047 | $url2 = 'http://0.0.0.0/entry10'; | 1049 | $url2 = 'http://0.0.0.0/entry10'; |
1048 | $this->client->request('GET', '/api/entries/exists?hashedurls[]='.hash('md5',$url1).'&hashedurls[]='.hash('md5',$url2) . '&return_id=1'); | 1050 | $this->client->request('GET', '/api/entries/exists?hashed_urls[]=' . hash('md5', $url1) . '&hashed_urls[]=' . hash('md5', $url2) . '&return_id=1'); |
1049 | 1051 | ||
1050 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); | 1052 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); |
1051 | 1053 | ||
1052 | $content = json_decode($this->client->getResponse()->getContent(), true); | 1054 | $content = json_decode($this->client->getResponse()->getContent(), true); |
1053 | 1055 | ||
1054 | $this->assertArrayHasKey($url1, $content); | ||
1055 | $this->assertArrayHasKey($url2, $content); | ||
1056 | $this->assertSame(2, $content[$url1]); | ||
1057 | $this->assertNull($content[$url2]); | ||
1058 | |||
1059 | $this->assertArrayHasKey(hash('md5', $url1), $content); | 1056 | $this->assertArrayHasKey(hash('md5', $url1), $content); |
1060 | $this->assertArrayHasKey(hash('md5', $url2), $content); | 1057 | $this->assertArrayHasKey(hash('md5', $url2), $content); |
1061 | $this->assertEquals(2, $content[hash('md5', $url1)]); | 1058 | $this->assertSame(2, $content[hash('md5', $url1)]); |
1062 | $this->assertEquals(false, $content[hash('md5', $url2)]); | 1059 | $this->assertNull($content[hash('md5', $url2)]); |
1063 | } | 1060 | } |
1064 | 1061 | ||
1065 | public function testGetEntriesExistsWithManyUrlsHashedReturnBool() | 1062 | public function testGetEntriesExistsWithManyUrlsHashedReturnBool() |
1066 | { | 1063 | { |
1067 | $url1 = 'http://0.0.0.0/entry2'; | 1064 | $url1 = 'http://0.0.0.0/entry2'; |
1068 | $url2 = 'http://0.0.0.0/entry10'; | 1065 | $url2 = 'http://0.0.0.0/entry10'; |
1069 | $this->client->request('GET', '/api/entries/exists?hashedurls[]='.hash('md5',$url1).'&hashedurls[]='.hash('md5',$url2)); | 1066 | $this->client->request('GET', '/api/entries/exists?hashed_urls[]=' . hash('md5', $url1) . '&hashed_urls[]=' . hash('md5', $url2)); |
1070 | 1067 | ||
1071 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); | 1068 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); |
1072 | 1069 | ||
1073 | $content = json_decode($this->client->getResponse()->getContent(), true); | 1070 | $content = json_decode($this->client->getResponse()->getContent(), true); |
1074 | 1071 | ||
1075 | $this->assertArrayHasKey($url1, $content); | 1072 | $this->assertArrayHasKey(hash('md5', $url1), $content); |
1076 | $this->assertArrayHasKey($url2, $content); | 1073 | $this->assertArrayHasKey(hash('md5', $url2), $content); |
1077 | $this->assertTrue($content[$url1]); | 1074 | $this->assertTrue($content[hash('md5', $url1)]); |
1078 | $this->assertFalse($content[$url2]); | 1075 | $this->assertFalse($content[hash('md5', $url2)]); |
1079 | } | 1076 | } |
1080 | 1077 | ||
1081 | public function testGetEntriesExistsWhichDoesNotExists() | 1078 | public function testGetEntriesExistsWhichDoesNotExists() |
1082 | { | 1079 | { |
1083 | $this->client->request('GET', '/api/entries/exists?hashedurl='.hash('md5','http://google.com/entry2')); | 1080 | $this->client->request('GET', '/api/entries/exists?hashed_url=' . hash('md5', 'http://google.com/entry2')); |
1084 | 1081 | ||
1085 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); | 1082 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); |
1086 | 1083 | ||
@@ -1091,7 +1088,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
1091 | 1088 | ||
1092 | public function testGetEntriesExistsWithNoUrl() | 1089 | public function testGetEntriesExistsWithNoUrl() |
1093 | { | 1090 | { |
1094 | $this->client->request('GET', '/api/entries/exists?hashedurl='); | 1091 | $this->client->request('GET', '/api/entries/exists?hashed_url='); |
1095 | 1092 | ||
1096 | $this->assertSame(403, $this->client->getResponse()->getStatusCode()); | 1093 | $this->assertSame(403, $this->client->getResponse()->getStatusCode()); |
1097 | } | 1094 | } |
diff --git a/tests/Wallabag/CoreBundle/Command/GenerateUrlHashesCommandTest.php b/tests/Wallabag/CoreBundle/Command/GenerateUrlHashesCommandTest.php index 8ca772cb..cc1e3fbc 100644 --- a/tests/Wallabag/CoreBundle/Command/GenerateUrlHashesCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/GenerateUrlHashesCommandTest.php | |||
@@ -22,7 +22,7 @@ class GenerateUrlHashesCommandTest extends WallabagCoreTestCase | |||
22 | 'command' => $command->getName(), | 22 | 'command' => $command->getName(), |
23 | ]); | 23 | ]); |
24 | 24 | ||
25 | $this->assertContains('Generating hashed urls for the 3 user account entries', $tester->getDisplay()); | 25 | $this->assertContains('Generating hashed urls for "3" users', $tester->getDisplay()); |
26 | $this->assertContains('Finished generated hashed urls', $tester->getDisplay()); | 26 | $this->assertContains('Finished generated hashed urls', $tester->getDisplay()); |
27 | } | 27 | } |
28 | 28 | ||
@@ -55,7 +55,7 @@ class GenerateUrlHashesCommandTest extends WallabagCoreTestCase | |||
55 | 'username' => 'admin', | 55 | 'username' => 'admin', |
56 | ]); | 56 | ]); |
57 | 57 | ||
58 | $this->assertContains('Generated hashed urls for user admin', $tester->getDisplay()); | 58 | $this->assertContains('Generated hashed urls for user: admin', $tester->getDisplay()); |
59 | } | 59 | } |
60 | 60 | ||
61 | public function testGenerateUrls() | 61 | public function testGenerateUrls() |
@@ -88,11 +88,11 @@ class GenerateUrlHashesCommandTest extends WallabagCoreTestCase | |||
88 | 'username' => 'admin', | 88 | 'username' => 'admin', |
89 | ]); | 89 | ]); |
90 | 90 | ||
91 | $this->assertContains('Generated hashed urls for user admin', $tester->getDisplay()); | 91 | $this->assertContains('Generated hashed urls for user: admin', $tester->getDisplay()); |
92 | 92 | ||
93 | $entry = $em->getRepository('WallabagCoreBundle:Entry')->findOneByUrl($url); | 93 | $entry = $em->getRepository('WallabagCoreBundle:Entry')->findOneByUrl($url); |
94 | 94 | ||
95 | $this->assertEquals($entry->getHashedUrl(), hash('sha512', $url)); | 95 | $this->assertSame($entry->getHashedUrl(), hash('md5', $url)); |
96 | 96 | ||
97 | $query = $em->createQuery('DELETE FROM Wallabag\CoreBundle\Entity\Entry e WHERE e.url = :url'); | 97 | $query = $em->createQuery('DELETE FROM Wallabag\CoreBundle\Entity\Entry e WHERE e.url = :url'); |
98 | $query->setParameter('url', $url); | 98 | $query->setParameter('url', $url); |