diff options
Diffstat (limited to 'src/Wallabag')
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/WallabagRestController.php | 2 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Tests/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 27d11da5..fcd212ef 100644 --- a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php | |||
@@ -33,7 +33,7 @@ class WallabagRestController extends Controller | |||
33 | throw $this->createNotFoundException(); | 33 | throw $this->createNotFoundException(); |
34 | } | 34 | } |
35 | 35 | ||
36 | return $user->getSalt(); | 36 | return array($user->getSalt()); |
37 | } | 37 | } |
38 | /** | 38 | /** |
39 | * Retrieve all entries. It could be filtered by many options. | 39 | * 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 d9e6a161..ff3c9432 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php | |||
@@ -3,6 +3,7 @@ | |||
3 | namespace Wallabag\CoreBundle\Tests\Controller; | 3 | namespace Wallabag\CoreBundle\Tests\Controller; |
4 | 4 | ||
5 | use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | 5 | use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
6 | use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder; | ||
6 | 7 | ||
7 | class WallabagRestControllerTest extends WebTestCase | 8 | class WallabagRestControllerTest extends WebTestCase |
8 | { | 9 | { |
@@ -16,11 +17,31 @@ class WallabagRestControllerTest extends WebTestCase | |||
16 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | 17 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); |
17 | } | 18 | } |
18 | 19 | ||
19 | public function testEmptyGetEntries() | 20 | public function testGetEntries() |
20 | { | 21 | { |
21 | $client = $this->createClient(); | 22 | $client = $this->createClient(); |
22 | $client->request('GET', '/api/entries'); | 23 | $client->request('GET', '/api/salts/admin.json'); |
23 | $this->assertTrue($client->getResponse()->isOk()); | 24 | $content = json_decode($client->getResponse()->getContent()); |
25 | $salt = $content[0]; | ||
26 | |||
27 | $username = 'admin'; | ||
28 | $password = 'test'; | ||
29 | |||
30 | $encryptedPassword = sha1($password.$username.$salt); | ||
31 | $nonce = substr(md5(uniqid('nonce_', true)), 0, 16); | ||
32 | |||
33 | $now = new \DateTime('now', new \DateTimeZone('UTC')); | ||
34 | $created = (string)$now->format( 'Y-m-d\TH:i:s\Z' ); | ||
35 | $digest = base64_encode(sha1(base64_decode($nonce).$created.$encryptedPassword, true)); | ||
36 | |||
37 | $headers = array( | ||
38 | 'PHP_AUTH_USER' => 'username', | ||
39 | 'HTTP_AUTHORIZATION' => 'Authorization profile="UsernameToken"', | ||
40 | 'HTTP_x-wsse' => 'X-WSSE: UsernameToken Username="'.$username.'", PasswordDigest="'.$digest.'", Nonce="'.$nonce.'", Created="'.$created.'"' | ||
41 | ); | ||
42 | |||
43 | $client->request('GET', '/api/entries', array(), array(), $headers); | ||
44 | $this->assertContains('Mailjet', $client->getResponse()->getContent()); | ||
24 | 45 | ||
25 | $this->assertTrue( | 46 | $this->assertTrue( |
26 | $client->getResponse()->headers->contains( | 47 | $client->getResponse()->headers->contains( |
@@ -28,6 +49,5 @@ class WallabagRestControllerTest extends WebTestCase | |||
28 | 'application/json' | 49 | 'application/json' |
29 | ) | 50 | ) |
30 | ); | 51 | ); |
31 | $this->assertEquals('[]', $client->getResponse()->getContent()); | ||
32 | } | 52 | } |
33 | } | 53 | } |