aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php')
-rw-r--r--tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php194
1 files changed, 81 insertions, 113 deletions
diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
index 9ca52c64..1090a686 100644
--- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
@@ -297,119 +297,6 @@ class ConfigControllerTest extends WallabagCoreTestCase
297 $this->assertContains('flashes.config.notice.user_updated', $alert[0]); 297 $this->assertContains('flashes.config.notice.user_updated', $alert[0]);
298 } 298 }
299 299
300 public function testUserEnable2faEmail()
301 {
302 $this->logInAs('admin');
303 $client = $this->getClient();
304
305 $crawler = $client->request('GET', '/config');
306
307 $this->assertSame(200, $client->getResponse()->getStatusCode());
308
309 $form = $crawler->filter('button[id=update_user_save]')->form();
310
311 $data = [
312 'update_user[emailTwoFactor]' => '1',
313 ];
314
315 $client->submit($form, $data);
316
317 $this->assertSame(302, $client->getResponse()->getStatusCode());
318
319 $crawler = $client->followRedirect();
320
321 $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text']));
322 $this->assertContains('flashes.config.notice.user_updated', $alert[0]);
323
324 // restore user
325 $em = $this->getEntityManager();
326 $user = $em
327 ->getRepository('WallabagUserBundle:User')
328 ->findOneByUsername('admin');
329
330 $this->assertTrue($user->isEmailTwoFactor());
331
332 $user->setEmailTwoFactor(false);
333 $em->persist($user);
334 $em->flush();
335 }
336
337 public function testUserEnable2faGoogle()
338 {
339 $this->logInAs('admin');
340 $client = $this->getClient();
341
342 $crawler = $client->request('GET', '/config');
343
344 $this->assertSame(200, $client->getResponse()->getStatusCode());
345
346 $form = $crawler->filter('button[id=update_user_save]')->form();
347
348 $data = [
349 'update_user[googleTwoFactor]' => '1',
350 ];
351
352 $client->submit($form, $data);
353
354 $this->assertSame(302, $client->getResponse()->getStatusCode());
355
356 $crawler = $client->followRedirect();
357
358 $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text']));
359 $this->assertContains('flashes.config.notice.user_updated', $alert[0]);
360
361 // restore user
362 $em = $this->getEntityManager();
363 $user = $em
364 ->getRepository('WallabagUserBundle:User')
365 ->findOneByUsername('admin');
366
367 $this->assertTrue($user->isGoogleAuthenticatorEnabled());
368
369 $user->setGoogleAuthenticatorSecret(null);
370 $em->persist($user);
371 $em->flush();
372 }
373
374 public function testUserEnable2faBoth()
375 {
376 $this->logInAs('admin');
377 $client = $this->getClient();
378
379 $crawler = $client->request('GET', '/config');
380
381 $this->assertSame(200, $client->getResponse()->getStatusCode());
382
383 $form = $crawler->filter('button[id=update_user_save]')->form();
384
385 $data = [
386 'update_user[googleTwoFactor]' => '1',
387 'update_user[emailTwoFactor]' => '1',
388 ];
389
390 $client->submit($form, $data);
391
392 $this->assertSame(302, $client->getResponse()->getStatusCode());
393
394 $crawler = $client->followRedirect();
395
396 $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text']));
397 $this->assertContains('flashes.config.notice.user_updated', $alert[0]);
398
399 // restore user
400 $em = $this->getEntityManager();
401 $user = $em
402 ->getRepository('WallabagUserBundle:User')
403 ->findOneByUsername('admin');
404
405 $this->assertTrue($user->isGoogleAuthenticatorEnabled());
406 $this->assertFalse($user->isEmailTwoFactor());
407
408 $user->setGoogleAuthenticatorSecret(null);
409 $em->persist($user);
410 $em->flush();
411 }
412
413 public function testRssUpdateResetToken() 300 public function testRssUpdateResetToken()
414 { 301 {
415 $this->logInAs('admin'); 302 $this->logInAs('admin');
@@ -1113,4 +1000,85 @@ class ConfigControllerTest extends WallabagCoreTestCase
1113 $this->assertNotSame('yuyuyuyu', $client->getRequest()->getLocale()); 1000 $this->assertNotSame('yuyuyuyu', $client->getRequest()->getLocale());
1114 $this->assertNotSame('yuyuyuyu', $client->getContainer()->get('session')->get('_locale')); 1001 $this->assertNotSame('yuyuyuyu', $client->getContainer()->get('session')->get('_locale'));
1115 } 1002 }
1003
1004 public function testUserEnable2faEmail()
1005 {
1006 $this->logInAs('admin');
1007 $client = $this->getClient();
1008
1009 $crawler = $client->request('GET', '/config/otp/email');
1010
1011 $this->assertSame(302, $client->getResponse()->getStatusCode());
1012
1013 $crawler = $client->followRedirect();
1014
1015 $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text']));
1016 $this->assertContains('flashes.config.notice.otp_enabled', $alert[0]);
1017
1018 // restore user
1019 $em = $this->getEntityManager();
1020 $user = $em
1021 ->getRepository('WallabagUserBundle:User')
1022 ->findOneByUsername('admin');
1023
1024 $this->assertTrue($user->isEmailTwoFactor());
1025
1026 $user->setEmailTwoFactor(false);
1027 $em->persist($user);
1028 $em->flush();
1029 }
1030
1031 public function testUserEnable2faGoogle()
1032 {
1033 $this->logInAs('admin');
1034 $client = $this->getClient();
1035
1036 $crawler = $client->request('GET', '/config/otp/app');
1037
1038 $this->assertSame(200, $client->getResponse()->getStatusCode());
1039
1040 // restore user
1041 $em = $this->getEntityManager();
1042 $user = $em
1043 ->getRepository('WallabagUserBundle:User')
1044 ->findOneByUsername('admin');
1045
1046 $this->assertTrue($user->isGoogleTwoFactor());
1047 $this->assertGreaterThan(0, $user->getBackupCodes());
1048
1049 $user->setGoogleAuthenticatorSecret(false);
1050 $user->setBackupCodes(null);
1051 $em->persist($user);
1052 $em->flush();
1053 }
1054
1055 public function testUserEnable2faGoogleCancel()
1056 {
1057 $this->logInAs('admin');
1058 $client = $this->getClient();
1059
1060 $crawler = $client->request('GET', '/config/otp/app');
1061
1062 $this->assertSame(200, $client->getResponse()->getStatusCode());
1063
1064 // restore user
1065 $em = $this->getEntityManager();
1066 $user = $em
1067 ->getRepository('WallabagUserBundle:User')
1068 ->findOneByUsername('admin');
1069
1070 $this->assertTrue($user->isGoogleTwoFactor());
1071 $this->assertGreaterThan(0, $user->getBackupCodes());
1072
1073 $crawler = $client->request('GET', '/config/otp/app/cancel');
1074
1075 $this->assertSame(302, $client->getResponse()->getStatusCode());
1076
1077 $user = $em
1078 ->getRepository('WallabagUserBundle:User')
1079 ->findOneByUsername('admin');
1080
1081 $this->assertFalse($user->isGoogleTwoFactor());
1082 $this->assertEmpty($user->getBackupCodes());
1083 }
1116} 1084}