]> git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php
cs
[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
7 class WallabagRestControllerTest extends WebTestCase
8 {
9 public function testGetSalt()
10 {
11 $client = $this->createClient();
12 $client->request('GET', '/api/salts/admin.json');
13 $this->assertEquals(200, $client->getResponse()->getStatusCode());
14
15 $client->request('GET', '/api/salts/notfound.json');
16 $this->assertEquals(404, $client->getResponse()->getStatusCode());
17 }
18
19 public function testGetEntries()
20 {
21 $client = $this->createClient();
22 $client->request('GET', '/api/salts/admin.json');
23 $content = json_decode($client->getResponse()->getContent());
24 $salt = $content[0];
25
26 $username = 'admin';
27 $password = 'test';
28
29 $encryptedPassword = sha1($password.$username.$salt);
30 $nonce = substr(md5(uniqid('nonce_', true)), 0, 16);
31
32 $now = new \DateTime('now', new \DateTimeZone('UTC'));
33 $created = (string) $now->format('Y-m-d\TH:i:s\Z');
34 $digest = base64_encode(sha1(base64_decode($nonce).$created.$encryptedPassword, true));
35
36 $headers = array(
37 'PHP_AUTH_USER' => 'username',
38 'HTTP_AUTHORIZATION' => 'Authorization profile="UsernameToken"',
39 'HTTP_x-wsse' => 'X-WSSE: UsernameToken Username="'.$username.'", PasswordDigest="'.$digest.'", Nonce="'.$nonce.'", Created="'.$created.'"',
40 );
41
42 $client->request('GET', '/api/entries', array(), array(), $headers);
43 $this->assertContains('Mailjet', $client->getResponse()->getContent());
44
45 $this->assertTrue(
46 $client->getResponse()->headers->contains(
47 'Content-Type',
48 'application/json'
49 )
50 );
51 }
52 }