diff options
author | Jeremy Benoist <j0k3r@users.noreply.github.com> | 2015-10-06 09:19:06 +0200 |
---|---|---|
committer | Jeremy Benoist <j0k3r@users.noreply.github.com> | 2015-10-06 09:19:06 +0200 |
commit | 16dabc326311f084d671be188c7941bbb3c341c9 (patch) | |
tree | 3210a7688ea2bfa1bff5fd0422b52adf570edcdc /src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php | |
parent | fdef5f460524215d806e244e5546865f4b8e01df (diff) | |
parent | 8263e71192989dc0fd28a41ac22f9c5b32eb11c4 (diff) | |
download | wallabag-16dabc326311f084d671be188c7941bbb3c341c9.tar.gz wallabag-16dabc326311f084d671be188c7941bbb3c341c9.tar.zst wallabag-16dabc326311f084d671be188c7941bbb3c341c9.zip |
Merge pull request #1436 from wallabag/v2-register
Public registration & oAuth2 \o/
Diffstat (limited to 'src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php')
-rw-r--r-- | src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php | 201 |
1 files changed, 0 insertions, 201 deletions
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php deleted file mode 100644 index 759ef01b..00000000 --- a/src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php +++ /dev/null | |||
@@ -1,201 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Tests\Controller; | ||
4 | |||
5 | use Symfony\Component\Filesystem\Filesystem; | ||
6 | use Symfony\Component\Finder\Finder; | ||
7 | use Wallabag\CoreBundle\Tests\WallabagCoreTestCase; | ||
8 | |||
9 | class SecurityControllerTest extends WallabagCoreTestCase | ||
10 | { | ||
11 | public function testLogin() | ||
12 | { | ||
13 | $client = $this->getClient(); | ||
14 | |||
15 | $crawler = $client->request('GET', '/new'); | ||
16 | |||
17 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
18 | $this->assertContains('login', $client->getResponse()->headers->get('location')); | ||
19 | } | ||
20 | |||
21 | public function testLoginFail() | ||
22 | { | ||
23 | $client = $this->getClient(); | ||
24 | |||
25 | $crawler = $client->request('GET', '/login'); | ||
26 | |||
27 | $form = $crawler->filter('button[type=submit]')->form(); | ||
28 | $data = array( | ||
29 | '_username' => 'admin', | ||
30 | '_password' => 'admin', | ||
31 | ); | ||
32 | |||
33 | $client->submit($form, $data); | ||
34 | |||
35 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
36 | $this->assertContains('login', $client->getResponse()->headers->get('location')); | ||
37 | |||
38 | $crawler = $client->followRedirect(); | ||
39 | |||
40 | $this->assertContains('Bad credentials', $client->getResponse()->getContent()); | ||
41 | } | ||
42 | |||
43 | public function testRedirectionAfterLogin() | ||
44 | { | ||
45 | $client = $this->getClient(); | ||
46 | $client->followRedirects(); | ||
47 | |||
48 | $crawler = $client->request('GET', '/config'); | ||
49 | |||
50 | $form = $crawler->filter('button[type=submit]')->form(); | ||
51 | |||
52 | $data = array( | ||
53 | '_username' => 'admin', | ||
54 | '_password' => 'mypassword', | ||
55 | ); | ||
56 | |||
57 | $client->submit($form, $data); | ||
58 | |||
59 | $this->assertContains('RSS', $client->getResponse()->getContent()); | ||
60 | } | ||
61 | |||
62 | public function testForgotPassword() | ||
63 | { | ||
64 | $client = $this->getClient(); | ||
65 | |||
66 | $crawler = $client->request('GET', '/forgot-password'); | ||
67 | |||
68 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
69 | |||
70 | $this->assertContains('Forgot password', $client->getResponse()->getContent()); | ||
71 | |||
72 | $form = $crawler->filter('button[type=submit]'); | ||
73 | |||
74 | $this->assertCount(1, $form); | ||
75 | |||
76 | return array( | ||
77 | 'form' => $form->form(), | ||
78 | 'client' => $client, | ||
79 | ); | ||
80 | } | ||
81 | |||
82 | /** | ||
83 | * @depends testForgotPassword | ||
84 | */ | ||
85 | public function testSubmitForgotPasswordFail($parameters) | ||
86 | { | ||
87 | $form = $parameters['form']; | ||
88 | $client = $parameters['client']; | ||
89 | |||
90 | $data = array( | ||
91 | 'forgot_password[email]' => 'material', | ||
92 | ); | ||
93 | |||
94 | $client->submit($form, $data); | ||
95 | |||
96 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
97 | $this->assertContains('No user found with this email', $client->getResponse()->getContent()); | ||
98 | } | ||
99 | |||
100 | /** | ||
101 | * @depends testForgotPassword | ||
102 | * | ||
103 | * Instead of using collector which slow down the test suite | ||
104 | * http://symfony.com/doc/current/cookbook/email/testing.html | ||
105 | * | ||
106 | * Use a different way where Swift store email as file | ||
107 | */ | ||
108 | public function testSubmitForgotPassword($parameters) | ||
109 | { | ||
110 | $form = $parameters['form']; | ||
111 | $client = $parameters['client']; | ||
112 | |||
113 | $spoolDir = $client->getKernel()->getContainer()->getParameter('swiftmailer.spool.default.file.path'); | ||
114 | |||
115 | // cleanup pool dir | ||
116 | $filesystem = new Filesystem(); | ||
117 | $filesystem->remove($spoolDir); | ||
118 | |||
119 | // to use `getCollector` since `collect: false` in config_test.yml | ||
120 | $client->enableProfiler(); | ||
121 | |||
122 | $data = array( | ||
123 | 'forgot_password[email]' => 'bobby@wallabag.org', | ||
124 | ); | ||
125 | |||
126 | $client->submit($form, $data); | ||
127 | |||
128 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
129 | |||
130 | $crawler = $client->followRedirect(); | ||
131 | |||
132 | $this->assertContains('An email has been sent to', $client->getResponse()->getContent()); | ||
133 | |||
134 | // find every files (ie: emails) inside the spool dir except hidden files | ||
135 | $finder = new Finder(); | ||
136 | $finder | ||
137 | ->in($spoolDir) | ||
138 | ->ignoreDotFiles(true) | ||
139 | ->files(); | ||
140 | |||
141 | $this->assertCount(1, $finder, 'Only one email has been sent'); | ||
142 | |||
143 | foreach ($finder as $file) { | ||
144 | $message = unserialize(file_get_contents($file)); | ||
145 | |||
146 | $this->assertInstanceOf('Swift_Message', $message); | ||
147 | $this->assertEquals('Reset Password', $message->getSubject()); | ||
148 | $this->assertEquals('no-reply@wallabag.org', key($message->getFrom())); | ||
149 | $this->assertEquals('bobby@wallabag.org', key($message->getTo())); | ||
150 | $this->assertContains( | ||
151 | 'To reset your password - please visit', | ||
152 | $message->getBody() | ||
153 | ); | ||
154 | } | ||
155 | } | ||
156 | |||
157 | public function testReset() | ||
158 | { | ||
159 | $client = $this->getClient(); | ||
160 | $user = $client->getContainer() | ||
161 | ->get('doctrine.orm.entity_manager') | ||
162 | ->getRepository('WallabagCoreBundle:User') | ||
163 | ->findOneByEmail('bobby@wallabag.org'); | ||
164 | |||
165 | $crawler = $client->request('GET', '/forgot-password/'.$user->getConfirmationToken()); | ||
166 | |||
167 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
168 | $this->assertCount(2, $crawler->filter('input[type=password]')); | ||
169 | $this->assertCount(1, $form = $crawler->filter('button[type=submit]')); | ||
170 | $this->assertCount(1, $form); | ||
171 | |||
172 | $data = array( | ||
173 | 'change_passwd[new_password][first]' => 'mypassword', | ||
174 | 'change_passwd[new_password][second]' => 'mypassword', | ||
175 | ); | ||
176 | |||
177 | $client->submit($form->form(), $data); | ||
178 | |||
179 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
180 | $this->assertContains('login', $client->getResponse()->headers->get('location')); | ||
181 | } | ||
182 | |||
183 | public function testResetBadToken() | ||
184 | { | ||
185 | $client = $this->getClient(); | ||
186 | |||
187 | $client->request('GET', '/forgot-password/UIZOAU29UE902IEPZO'); | ||
188 | |||
189 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | ||
190 | } | ||
191 | |||
192 | public function testCheckEmailWithoutEmail() | ||
193 | { | ||
194 | $client = $this->getClient(); | ||
195 | |||
196 | $client->request('GET', '/forgot-password/check-email'); | ||
197 | |||
198 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
199 | $this->assertContains('forgot-password', $client->getResponse()->headers->get('location')); | ||
200 | } | ||
201 | } | ||