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 /tests/Wallabag/ApiBundle | |
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
Diffstat (limited to 'tests/Wallabag/ApiBundle')
-rw-r--r-- | tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | 75 |
1 files changed, 36 insertions, 39 deletions
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 | } |