3 namespace Wallabag\CoreBundle\Tests\Controller
;
5 use Symfony\Bundle\FrameworkBundle\Test\WebTestCase
;
6 use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder
;
8 class WallabagRestControllerTest
extends WebTestCase
10 public function testGetSalt()
12 $client = $this->createClient();
13 $client->request('GET', '/api/salts/admin.json');
14 $this->assertEquals(200, $client->getResponse()->getStatusCode());
16 $client->request('GET', '/api/salts/notfound.json');
17 $this->assertEquals(404, $client->getResponse()->getStatusCode());
20 public function testGetEntries()
22 $client = $this->createClient();
23 $client->request('GET', '/api/salts/admin.json');
24 $content = json_decode($client->getResponse()->getContent());
30 $encryptedPassword = sha1($password.$username.$salt);
31 $nonce = substr(md5(uniqid('nonce_', true)), 0, 16);
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));
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.'"'
43 $client->request('GET', '/api/entries', array(), array(), $headers);
44 $this->assertContains('Mailjet', $client->getResponse()->getContent());
47 $client->getResponse()->headers
->contains(