]> git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php
ff3c9432092313b2bd431535c9d60ae88b6ee631
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Tests / Controller / WallabagRestControllerTest.php
1 <?php
2
3 namespace Wallabag\CoreBundle\Tests\Controller;
4
5 use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
6 use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder;
7
8 class WallabagRestControllerTest extends WebTestCase
9 {
10 public function testGetSalt()
11 {
12 $client = $this->createClient();
13 $client->request('GET', '/api/salts/admin.json');
14 $this->assertEquals(200, $client->getResponse()->getStatusCode());
15
16 $client->request('GET', '/api/salts/notfound.json');
17 $this->assertEquals(404, $client->getResponse()->getStatusCode());
18 }
19
20 public function testGetEntries()
21 {
22 $client = $this->createClient();
23 $client->request('GET', '/api/salts/admin.json');
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());
45
46 $this->assertTrue(
47 $client->getResponse()->headers->contains(
48 'Content-Type',
49 'application/json'
50 )
51 );
52 }
53 }