3 namespace Wallabag\CoreBundle\Tests\Controller
;
5 use Wallabag\CoreBundle\Tests\WallabagTestCase
;
7 class WallabagRestControllerTest
extends WallabagTestCase
10 * Generate HTTP headers for authenticate user on API
18 private function generateHeaders($username, $password, $salt)
20 $encryptedPassword = sha1($password.$username.$salt);
21 $nonce = substr(md5(uniqid('nonce_', true)), 0, 16);
23 $now = new \
DateTime('now', new \
DateTimeZone('UTC'));
24 $created = (string) $now->format('Y-m-d\TH:i:s\Z');
25 $digest = base64_encode(sha1(base64_decode($nonce).$created.$encryptedPassword, true));
28 'HTTP_AUTHORIZATION' => 'Authorization profile="UsernameToken"',
29 'HTTP_x-wsse' => 'X-WSSE: UsernameToken Username="'.$username.'", PasswordDigest="'.$digest.'", Nonce="'.$nonce.'", Created="'.$created.'"',
33 public function testGetSalt()
35 $client = $this->createClient();
36 $client->request('GET', '/api/salts/admin.json');
37 $this->assertEquals(200, $client->getResponse()->getStatusCode());
39 $client->request('GET', '/api/salts/notfound.json');
40 $this->assertEquals(404, $client->getResponse()->getStatusCode());
43 public function testGetOneEntry()
45 $client = $this->createClient();
46 $client->request('GET', '/api/salts/admin.json');
47 $salt = json_decode($client->getResponse()->getContent());
49 $headers = $this->generateHeaders('admin', 'test', $salt[0]);
51 $entry = $client->getContainer()
52 ->get('doctrine.orm.entity_manager')
53 ->getRepository('WallabagCoreBundle:Entry')
54 ->findOneByIsArchived(false);
57 $this->markTestSkipped('No content found in db.');
60 $client->request('GET', '/api/entries/'.$entry->getId().'.json', array(), array(), $headers);
61 $this->assertContains($entry->getTitle(), $client->getResponse()->getContent());
64 $client->getResponse()->headers
->contains(
71 public function testGetEntries()
73 $client = $this->createClient();
74 $client->request('GET', '/api/salts/admin.json');
75 $salt = json_decode($client->getResponse()->getContent());
77 $headers = $this->generateHeaders('admin', 'test', $salt[0]);
79 $client->request('GET', '/api/entries', array(), array(), $headers);
80 $this->assertContains('Mailjet', $client->getResponse()->getContent());
83 $client->getResponse()->headers
->contains(
90 public function testDeleteEntry()
92 $client = $this->createClient();
93 $client->request('GET', '/api/salts/admin.json');
94 $salt = json_decode($client->getResponse()->getContent());
96 $headers = $this->generateHeaders('admin', 'test', $salt[0]);
98 $entry = $client->getContainer()
99 ->get('doctrine.orm.entity_manager')
100 ->getRepository('WallabagCoreBundle:Entry')
101 ->findOneByIsDeleted(false);
104 $this->markTestSkipped('No content found in db.');
107 $client->request('DELETE', '/api/entries/'.$entry->getId().'.json', array(), array(), $headers);
109 $this->assertEquals(200, $client->getResponse()->getStatusCode());
111 $res = $client->getContainer()
112 ->get('doctrine.orm.entity_manager')
113 ->getRepository('WallabagCoreBundle:Entry')
114 ->findOneById($entry->getId());
115 $this->assertEquals($res->isDeleted(), true);