From 68c6f1bd7fbf2f01730ee38b1291251494c80eb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 6 Feb 2015 18:02:12 +0100 Subject: [PATCH 01/16] Test for GET on empty database --- .../Controller/WallabagRestControllerTest.php | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php diff --git a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php new file mode 100644 index 000000000..0949b92d9 --- /dev/null +++ b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php @@ -0,0 +1,22 @@ +createClient(); + $client->request('GET', '/api/entries'); + $this->assertTrue($client->getResponse()->isOk()); + + $this->assertTrue( + $client->getResponse()->headers->contains( + 'Content-Type', + 'application/json' + ) + ); + $this->assertEquals('[]', $client->getResponse()->getContent()); + } +} \ No newline at end of file From f5deb024a2dd5a2cb27263a51f4653609407597e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Tue, 10 Feb 2015 20:07:55 +0100 Subject: [PATCH 02/16] add test for api/salts --- .../CoreBundle/Repository/EntryRepository.php | 1 - .../Controller/WallabagRestControllerTest.php | 15 +++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index b6f867070..bedc90d2b 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php @@ -2,7 +2,6 @@ namespace Wallabag\CoreBundle\Repository; -use Doctrine\ORM\Query; use Doctrine\ORM\EntityRepository; use Doctrine\ORM\Tools\Pagination\Paginator; diff --git a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php index 0949b92d9..d9e6a1618 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php @@ -6,7 +6,18 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; class WallabagRestControllerTest extends WebTestCase { - public function testEmptyGetEntries() { + public function testGetSalt() + { + $client = $this->createClient(); + $client->request('GET', '/api/salts/admin.json'); + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $client->request('GET', '/api/salts/notfound.json'); + $this->assertEquals(404, $client->getResponse()->getStatusCode()); + } + + public function testEmptyGetEntries() + { $client = $this->createClient(); $client->request('GET', '/api/entries'); $this->assertTrue($client->getResponse()->isOk()); @@ -19,4 +30,4 @@ class WallabagRestControllerTest extends WebTestCase ); $this->assertEquals('[]', $client->getResponse()->getContent()); } -} \ No newline at end of file +} From e1dd7f70c5cc0a0086d83d5fcdaa7a25081a5e6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Tue, 10 Feb 2015 23:13:34 +0100 Subject: [PATCH 03/16] first test for API, need refactor --- .../Controller/WallabagRestController.php | 2 +- .../Controller/WallabagRestControllerTest.php | 28 ++++++++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php index 27d11da5e..fcd212efb 100644 --- a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php @@ -33,7 +33,7 @@ class WallabagRestController extends Controller throw $this->createNotFoundException(); } - return $user->getSalt(); + return array($user->getSalt()); } /** * Retrieve all entries. It could be filtered by many options. diff --git a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php index d9e6a1618..ff3c94320 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php @@ -3,6 +3,7 @@ namespace Wallabag\CoreBundle\Tests\Controller; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; +use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder; class WallabagRestControllerTest extends WebTestCase { @@ -16,11 +17,31 @@ class WallabagRestControllerTest extends WebTestCase $this->assertEquals(404, $client->getResponse()->getStatusCode()); } - public function testEmptyGetEntries() + public function testGetEntries() { $client = $this->createClient(); - $client->request('GET', '/api/entries'); - $this->assertTrue($client->getResponse()->isOk()); + $client->request('GET', '/api/salts/admin.json'); + $content = json_decode($client->getResponse()->getContent()); + $salt = $content[0]; + + $username = 'admin'; + $password = 'test'; + + $encryptedPassword = sha1($password.$username.$salt); + $nonce = substr(md5(uniqid('nonce_', true)), 0, 16); + + $now = new \DateTime('now', new \DateTimeZone('UTC')); + $created = (string)$now->format( 'Y-m-d\TH:i:s\Z' ); + $digest = base64_encode(sha1(base64_decode($nonce).$created.$encryptedPassword, true)); + + $headers = array( + 'PHP_AUTH_USER' => 'username', + 'HTTP_AUTHORIZATION' => 'Authorization profile="UsernameToken"', + 'HTTP_x-wsse' => 'X-WSSE: UsernameToken Username="'.$username.'", PasswordDigest="'.$digest.'", Nonce="'.$nonce.'", Created="'.$created.'"' + ); + + $client->request('GET', '/api/entries', array(), array(), $headers); + $this->assertContains('Mailjet', $client->getResponse()->getContent()); $this->assertTrue( $client->getResponse()->headers->contains( @@ -28,6 +49,5 @@ class WallabagRestControllerTest extends WebTestCase 'application/json' ) ); - $this->assertEquals('[]', $client->getResponse()->getContent()); } } From 0536b809b0be31790a07a0eb232cce81051845ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 6 Feb 2015 18:02:12 +0100 Subject: [PATCH 04/16] Test for GET on empty database --- .../CoreBundle/Tests/Controller/WallabagRestControllerTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php index ff3c94320..4ebc4786a 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php @@ -3,7 +3,6 @@ namespace Wallabag\CoreBundle\Tests\Controller; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; -use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder; class WallabagRestControllerTest extends WebTestCase { @@ -50,4 +49,4 @@ class WallabagRestControllerTest extends WebTestCase ) ); } -} +} \ No newline at end of file From 2734044aca228c853147a8a944a2ebc7b2c7f23b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Tue, 10 Feb 2015 20:07:55 +0100 Subject: [PATCH 05/16] add test for api/salts --- .../CoreBundle/Tests/Controller/WallabagRestControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php index 4ebc4786a..edbb62d2c 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php @@ -49,4 +49,4 @@ class WallabagRestControllerTest extends WebTestCase ) ); } -} \ No newline at end of file +} From 91f78f26f2594db3f21c712f3ec30e4d06283dff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Tue, 10 Feb 2015 23:13:34 +0100 Subject: [PATCH 06/16] first test for API, need refactor --- .../CoreBundle/Tests/Controller/WallabagRestControllerTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php index edbb62d2c..ff3c94320 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php @@ -3,6 +3,7 @@ namespace Wallabag\CoreBundle\Tests\Controller; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; +use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder; class WallabagRestControllerTest extends WebTestCase { From 2725de8efb7fd3af9b1d5b12a137d21e4adc5b10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Wed, 11 Feb 2015 06:31:16 +0100 Subject: [PATCH 07/16] cs --- .../Tests/Controller/WallabagRestControllerTest.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php index ff3c94320..274a816f4 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php @@ -3,7 +3,6 @@ namespace Wallabag\CoreBundle\Tests\Controller; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; -use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder; class WallabagRestControllerTest extends WebTestCase { @@ -31,13 +30,13 @@ class WallabagRestControllerTest extends WebTestCase $nonce = substr(md5(uniqid('nonce_', true)), 0, 16); $now = new \DateTime('now', new \DateTimeZone('UTC')); - $created = (string)$now->format( 'Y-m-d\TH:i:s\Z' ); + $created = (string) $now->format('Y-m-d\TH:i:s\Z'); $digest = base64_encode(sha1(base64_decode($nonce).$created.$encryptedPassword, true)); $headers = array( 'PHP_AUTH_USER' => 'username', 'HTTP_AUTHORIZATION' => 'Authorization profile="UsernameToken"', - 'HTTP_x-wsse' => 'X-WSSE: UsernameToken Username="'.$username.'", PasswordDigest="'.$digest.'", Nonce="'.$nonce.'", Created="'.$created.'"' + 'HTTP_x-wsse' => 'X-WSSE: UsernameToken Username="'.$username.'", PasswordDigest="'.$digest.'", Nonce="'.$nonce.'", Created="'.$created.'"', ); $client->request('GET', '/api/entries', array(), array(), $headers); From 19aee7cd545a904d830037e8df785b1703ac62fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Wed, 11 Feb 2015 06:41:44 +0100 Subject: [PATCH 08/16] refactor and test one entry --- .../Controller/WallabagRestControllerTest.php | 61 ++++++++++++++----- 1 file changed, 45 insertions(+), 16 deletions(-) diff --git a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php index 274a816f4..1240844b9 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php @@ -6,6 +6,31 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; class WallabagRestControllerTest extends WebTestCase { + /** + * Generate HTTP headers for authenticate user on API + * + * @param $username + * @param $password + * @param $salt + * + * @return array + */ + private function generateHeaders($username, $password, $salt) + { + $encryptedPassword = sha1($password.$username.$salt); + $nonce = substr(md5(uniqid('nonce_', true)), 0, 16); + + $now = new \DateTime('now', new \DateTimeZone('UTC')); + $created = (string) $now->format('Y-m-d\TH:i:s\Z'); + $digest = base64_encode(sha1(base64_decode($nonce).$created.$encryptedPassword, true)); + + return array( + 'PHP_AUTH_USER' => 'username', + 'HTTP_AUTHORIZATION' => 'Authorization profile="UsernameToken"', + 'HTTP_x-wsse' => 'X-WSSE: UsernameToken Username="'.$username.'", PasswordDigest="'.$digest.'", Nonce="'.$nonce.'", Created="'.$created.'"', + ); + } + public function testGetSalt() { $client = $this->createClient(); @@ -16,28 +41,32 @@ class WallabagRestControllerTest extends WebTestCase $this->assertEquals(404, $client->getResponse()->getStatusCode()); } + public function testGetOneEntry() + { + $client = $this->createClient(); + $client->request('GET', '/api/salts/admin.json'); + $content = json_decode($client->getResponse()->getContent()); + + $headers = $this->generateHeaders('admin', 'test', $content[0]); + + $client->request('GET', '/api/entries/1.json', array(), array(), $headers); + $this->assertContains('This is my content', $client->getResponse()->getContent()); + + $this->assertTrue( + $client->getResponse()->headers->contains( + 'Content-Type', + 'application/json' + ) + ); + } + public function testGetEntries() { $client = $this->createClient(); $client->request('GET', '/api/salts/admin.json'); $content = json_decode($client->getResponse()->getContent()); - $salt = $content[0]; - $username = 'admin'; - $password = 'test'; - - $encryptedPassword = sha1($password.$username.$salt); - $nonce = substr(md5(uniqid('nonce_', true)), 0, 16); - - $now = new \DateTime('now', new \DateTimeZone('UTC')); - $created = (string) $now->format('Y-m-d\TH:i:s\Z'); - $digest = base64_encode(sha1(base64_decode($nonce).$created.$encryptedPassword, true)); - - $headers = array( - 'PHP_AUTH_USER' => 'username', - 'HTTP_AUTHORIZATION' => 'Authorization profile="UsernameToken"', - 'HTTP_x-wsse' => 'X-WSSE: UsernameToken Username="'.$username.'", PasswordDigest="'.$digest.'", Nonce="'.$nonce.'", Created="'.$created.'"', - ); + $headers = $this->generateHeaders('admin', 'test', $content[0]); $client->request('GET', '/api/entries', array(), array(), $headers); $this->assertContains('Mailjet', $client->getResponse()->getContent()); From c9fa9677c1ae7b9be2305cef8f61fa2e0fc14d58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Wed, 11 Feb 2015 07:43:43 +0100 Subject: [PATCH 09/16] DELETE entry and use of query for fetch entries --- .../Controller/WallabagRestControllerTest.php | 49 ++++++++++++++++--- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php index 1240844b9..c7704aa86 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php @@ -45,12 +45,21 @@ class WallabagRestControllerTest extends WebTestCase { $client = $this->createClient(); $client->request('GET', '/api/salts/admin.json'); - $content = json_decode($client->getResponse()->getContent()); + $salt = json_decode($client->getResponse()->getContent()); - $headers = $this->generateHeaders('admin', 'test', $content[0]); + $headers = $this->generateHeaders('admin', 'test', $salt[0]); - $client->request('GET', '/api/entries/1.json', array(), array(), $headers); - $this->assertContains('This is my content', $client->getResponse()->getContent()); + $entry = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findOneByIsArchived(false); + + if (!$entry) { + $this->markTestSkipped('No content found in db.'); + } + + $client->request('GET', '/api/entries/'.$entry->getId().'.json', array(), array(), $headers); + $this->assertContains($entry->getTitle(), $client->getResponse()->getContent()); $this->assertTrue( $client->getResponse()->headers->contains( @@ -64,9 +73,9 @@ class WallabagRestControllerTest extends WebTestCase { $client = $this->createClient(); $client->request('GET', '/api/salts/admin.json'); - $content = json_decode($client->getResponse()->getContent()); + $salt = json_decode($client->getResponse()->getContent()); - $headers = $this->generateHeaders('admin', 'test', $content[0]); + $headers = $this->generateHeaders('admin', 'test', $salt[0]); $client->request('GET', '/api/entries', array(), array(), $headers); $this->assertContains('Mailjet', $client->getResponse()->getContent()); @@ -78,4 +87,32 @@ class WallabagRestControllerTest extends WebTestCase ) ); } + + public function testDeleteEntry() + { + $client = $this->createClient(); + $client->request('GET', '/api/salts/admin.json'); + $salt = json_decode($client->getResponse()->getContent()); + + $headers = $this->generateHeaders('admin', 'test', $salt[0]); + + $entry = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findOneByIsDeleted(false); + + if (!$entry) { + $this->markTestSkipped('No content found in db.'); + } + + $client->request('DELETE', '/api/entries/'.$entry->getId().'.json', array(), array(), $headers); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $res = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findOneById($entry->getId()); + $this->assertEquals($res->isDeleted(), true); + } } From 70b54da2b13d4c32530ee2f634acb8453d7829a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Wed, 11 Feb 2015 07:52:58 +0100 Subject: [PATCH 10/16] test line, forgot to remove it --- .../CoreBundle/Tests/Controller/WallabagRestControllerTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php index c7704aa86..cbc316211 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php @@ -25,7 +25,6 @@ class WallabagRestControllerTest extends WebTestCase $digest = base64_encode(sha1(base64_decode($nonce).$created.$encryptedPassword, true)); return array( - 'PHP_AUTH_USER' => 'username', 'HTTP_AUTHORIZATION' => 'Authorization profile="UsernameToken"', 'HTTP_x-wsse' => 'X-WSSE: UsernameToken Username="'.$username.'", PasswordDigest="'.$digest.'", Nonce="'.$nonce.'", Created="'.$created.'"', ); From 874e3e10a45a5b3c662bac1112bbdc1acb0adb95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Wed, 11 Feb 2015 11:52:10 +0100 Subject: [PATCH 11/16] phpdoc --- src/Wallabag/CoreBundle/Controller/WallabagRestController.php | 2 +- .../Tests/Controller/WallabagRestControllerTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php index fcd212efb..3cfb8a778 100644 --- a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php @@ -20,7 +20,7 @@ class WallabagRestController extends Controller * {"name"="username", "dataType"="string", "required"=true, "description"="username"} * } * ) - * @return string + * @return array */ public function getSaltAction($username) { diff --git a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php index cbc316211..298cf10c1 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php @@ -2,9 +2,9 @@ namespace Wallabag\CoreBundle\Tests\Controller; -use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; +use Wallabag\CoreBundle\Tests\WallabagTestCase; -class WallabagRestControllerTest extends WebTestCase +class WallabagRestControllerTest extends WallabagTestCase { /** * Generate HTTP headers for authenticate user on API From f170f315941b461a2bcd85843583baedbc48efd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Wed, 11 Feb 2015 15:15:06 +0100 Subject: [PATCH 12/16] add test for empty salt --- src/Wallabag/CoreBundle/Controller/WallabagRestController.php | 2 +- .../CoreBundle/Tests/Controller/WallabagRestControllerTest.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php index 3cfb8a778..e9cd8c939 100644 --- a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php @@ -33,7 +33,7 @@ class WallabagRestController extends Controller throw $this->createNotFoundException(); } - return array($user->getSalt()); + return array($user->getSalt() ?: null); } /** * Retrieve all entries. It could be filtered by many options. diff --git a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php index 298cf10c1..815903fad 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php @@ -35,6 +35,7 @@ class WallabagRestControllerTest extends WallabagTestCase $client = $this->createClient(); $client->request('GET', '/api/salts/admin.json'); $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertNotEmpty(json_decode($client->getResponse()->getContent())); $client->request('GET', '/api/salts/notfound.json'); $this->assertEquals(404, $client->getResponse()->getStatusCode()); From 9ca5fd43f9cd3dbf00511748492298aaf3145575 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Wed, 11 Feb 2015 15:35:40 +0100 Subject: [PATCH 13/16] test with bad headers --- .../Tests/Controller/WallabagRestControllerTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php index 815903fad..b48311674 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php @@ -67,6 +67,15 @@ class WallabagRestControllerTest extends WallabagTestCase 'application/json' ) ); + + // Now testing with bad headers + $badHeaders = array( + 'HTTP_AUTHORIZATION' => 'Authorization profile="UsernameToken"', + 'HTTP_x-wsse' => 'X-WSSE: UsernameToken Username="admin", PasswordDigest="Wr0ngDig3st", Nonce="n0Nc3", Created="2015-01-01T13:37:00Z"', + ); + + $client->request('GET', '/api/entries/'.$entry->getId().'.json', array(), array(), $badHeaders); + $this->assertEquals(403, $client->getResponse()->getStatusCode()); } public function testGetEntries() From 59f18f9a85db8248c41c03a763727a0072700a65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Wed, 11 Feb 2015 16:08:13 +0100 Subject: [PATCH 14/16] create single test for bad headers --- .../Controller/WallabagRestControllerTest.php | 35 ++++++++++++++----- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php index b48311674..50b612340 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php @@ -41,6 +41,32 @@ class WallabagRestControllerTest extends WallabagTestCase $this->assertEquals(404, $client->getResponse()->getStatusCode()); } + public function testWithBadHeaders() + { + $client = $this->createClient(); + $client->request('GET', '/api/salts/admin.json'); + $salt = json_decode($client->getResponse()->getContent()); + + $headers = $this->generateHeaders('admin', 'test', $salt[0]); + + $entry = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findOneByIsArchived(false); + + if (!$entry) { + $this->markTestSkipped('No content found in db.'); + } + + $badHeaders = array( + 'HTTP_AUTHORIZATION' => 'Authorization profile="UsernameToken"', + 'HTTP_x-wsse' => 'X-WSSE: UsernameToken Username="admin", PasswordDigest="Wr0ngDig3st", Nonce="n0Nc3", Created="2015-01-01T13:37:00Z"', + ); + + $client->request('GET', '/api/entries/'.$entry->getId().'.json', array(), array(), $badHeaders); + $this->assertEquals(403, $client->getResponse()->getStatusCode()); + } + public function testGetOneEntry() { $client = $this->createClient(); @@ -67,15 +93,6 @@ class WallabagRestControllerTest extends WallabagTestCase 'application/json' ) ); - - // Now testing with bad headers - $badHeaders = array( - 'HTTP_AUTHORIZATION' => 'Authorization profile="UsernameToken"', - 'HTTP_x-wsse' => 'X-WSSE: UsernameToken Username="admin", PasswordDigest="Wr0ngDig3st", Nonce="n0Nc3", Created="2015-01-01T13:37:00Z"', - ); - - $client->request('GET', '/api/entries/'.$entry->getId().'.json', array(), array(), $badHeaders); - $this->assertEquals(403, $client->getResponse()->getStatusCode()); } public function testGetEntries() From d9b71755935e3cb550c1282d8d2e7d2b8966514f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Wed, 11 Feb 2015 18:22:59 +0100 Subject: [PATCH 15/16] test if GET /api/entries returns 1 or more results --- .../Tests/Controller/WallabagRestControllerTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php index 50b612340..00b969052 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php @@ -104,6 +104,15 @@ class WallabagRestControllerTest extends WallabagTestCase $headers = $this->generateHeaders('admin', 'test', $salt[0]); $client->request('GET', '/api/entries', array(), array(), $headers); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + /* var_dump(count(json_decode($client->getResponse()->getContent()))); + var_dump($client->getResponse()->getContent()); + die; +*/ + $this->assertGreaterThanOrEqual(1, count(json_decode($client->getResponse()->getContent()))); + $this->assertContains('Mailjet', $client->getResponse()->getContent()); $this->assertTrue( From 8c7e0f95b925e0797d3e2bdedf890a74d86d0a60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Thu, 12 Feb 2015 08:46:40 +0100 Subject: [PATCH 16/16] remove debug lines --- .../Tests/Controller/WallabagRestControllerTest.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php index 00b969052..d77e23037 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php @@ -107,10 +107,6 @@ class WallabagRestControllerTest extends WallabagTestCase $this->assertEquals(200, $client->getResponse()->getStatusCode()); - /* var_dump(count(json_decode($client->getResponse()->getContent()))); - var_dump($client->getResponse()->getContent()); - die; -*/ $this->assertGreaterThanOrEqual(1, count(json_decode($client->getResponse()->getContent()))); $this->assertContains('Mailjet', $client->getResponse()->getContent());