aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php3
-rw-r--r--tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php81
-rw-r--r--tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php28
-rw-r--r--tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php14
-rw-r--r--tests/Wallabag/UserBundle/Mailer/AuthCodeMailerTest.php2
5 files changed, 111 insertions, 17 deletions
diff --git a/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php b/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php
index 9b34f2a0..ed383a2c 100644
--- a/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php
+++ b/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php
@@ -59,7 +59,8 @@ class ShowUserCommandTest extends WallabagCoreTestCase
59 $this->assertContains('Username: admin', $tester->getDisplay()); 59 $this->assertContains('Username: admin', $tester->getDisplay());
60 $this->assertContains('Email: bigboss@wallabag.org', $tester->getDisplay()); 60 $this->assertContains('Email: bigboss@wallabag.org', $tester->getDisplay());
61 $this->assertContains('Display name: Big boss', $tester->getDisplay()); 61 $this->assertContains('Display name: Big boss', $tester->getDisplay());
62 $this->assertContains('2FA activated: no', $tester->getDisplay()); 62 $this->assertContains('2FA (email) activated', $tester->getDisplay());
63 $this->assertContains('2FA (OTP) activated', $tester->getDisplay());
63 } 64 }
64 65
65 public function testShowUser() 66 public function testShowUser()
diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
index c9dbbaa3..1090a686 100644
--- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
@@ -1000,4 +1000,85 @@ class ConfigControllerTest extends WallabagCoreTestCase
1000 $this->assertNotSame('yuyuyuyu', $client->getRequest()->getLocale()); 1000 $this->assertNotSame('yuyuyuyu', $client->getRequest()->getLocale());
1001 $this->assertNotSame('yuyuyuyu', $client->getContainer()->get('session')->get('_locale')); 1001 $this->assertNotSame('yuyuyuyu', $client->getContainer()->get('session')->get('_locale'));
1002 } 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 }
1003} 1084}
diff --git a/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php b/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php
index 395208a2..b03c7550 100644
--- a/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php
@@ -26,7 +26,7 @@ class SecurityControllerTest extends WallabagCoreTestCase
26 $this->assertContains('config.form_rss.description', $crawler->filter('body')->extract(['_text'])[0]); 26 $this->assertContains('config.form_rss.description', $crawler->filter('body')->extract(['_text'])[0]);
27 } 27 }
28 28
29 public function testLoginWith2Factor() 29 public function testLoginWith2FactorEmail()
30 { 30 {
31 $client = $this->getClient(); 31 $client = $this->getClient();
32 32
@@ -42,7 +42,7 @@ class SecurityControllerTest extends WallabagCoreTestCase
42 $user = $em 42 $user = $em
43 ->getRepository('WallabagUserBundle:User') 43 ->getRepository('WallabagUserBundle:User')
44 ->findOneByUsername('admin'); 44 ->findOneByUsername('admin');
45 $user->setTwoFactorAuthentication(true); 45 $user->setEmailTwoFactor(true);
46 $em->persist($user); 46 $em->persist($user);
47 $em->flush(); 47 $em->flush();
48 48
@@ -54,12 +54,12 @@ class SecurityControllerTest extends WallabagCoreTestCase
54 $user = $em 54 $user = $em
55 ->getRepository('WallabagUserBundle:User') 55 ->getRepository('WallabagUserBundle:User')
56 ->findOneByUsername('admin'); 56 ->findOneByUsername('admin');
57 $user->setTwoFactorAuthentication(false); 57 $user->setEmailTwoFactor(false);
58 $em->persist($user); 58 $em->persist($user);
59 $em->flush(); 59 $em->flush();
60 } 60 }
61 61
62 public function testTrustedComputer() 62 public function testLoginWith2FactorGoogle()
63 { 63 {
64 $client = $this->getClient(); 64 $client = $this->getClient();
65 65
@@ -69,15 +69,27 @@ class SecurityControllerTest extends WallabagCoreTestCase
69 return; 69 return;
70 } 70 }
71 71
72 $client->followRedirects();
73
72 $em = $client->getContainer()->get('doctrine.orm.entity_manager'); 74 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
73 $user = $em 75 $user = $em
74 ->getRepository('WallabagUserBundle:User') 76 ->getRepository('WallabagUserBundle:User')
75 ->findOneByUsername('admin'); 77 ->findOneByUsername('admin');
78 $user->setGoogleAuthenticatorSecret('26LDIHYGHNELOQEM');
79 $em->persist($user);
80 $em->flush();
81
82 $this->logInAsUsingHttp('admin');
83 $crawler = $client->request('GET', '/config');
84 $this->assertContains('scheb_two_factor.trusted', $crawler->filter('body')->extract(['_text'])[0]);
76 85
77 $date = new \DateTime(); 86 // restore user
78 $user->addTrustedComputer('ABCDEF', $date->add(new \DateInterval('P1M'))); 87 $user = $em
79 $this->assertTrue($user->isTrustedComputer('ABCDEF')); 88 ->getRepository('WallabagUserBundle:User')
80 $this->assertFalse($user->isTrustedComputer('FEDCBA')); 89 ->findOneByUsername('admin');
90 $user->setGoogleAuthenticatorSecret(null);
91 $em->persist($user);
92 $em->flush();
81 } 93 }
82 94
83 public function testEnabledRegistration() 95 public function testEnabledRegistration()
diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
index 3dd9273c..508adb1b 100644
--- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
+++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
@@ -163,7 +163,7 @@ class ContentProxyTest extends TestCase
163 163
164 $this->assertSame('http://1.1.1.1', $entry->getUrl()); 164 $this->assertSame('http://1.1.1.1', $entry->getUrl());
165 $this->assertSame('this is my title', $entry->getTitle()); 165 $this->assertSame('this is my title', $entry->getTitle());
166 $this->assertContains('this is my content', $entry->getContent()); 166 $this->assertContains('content', $entry->getContent());
167 $this->assertSame('http://3.3.3.3/cover.jpg', $entry->getPreviewPicture()); 167 $this->assertSame('http://3.3.3.3/cover.jpg', $entry->getPreviewPicture());
168 $this->assertSame('text/html', $entry->getMimetype()); 168 $this->assertSame('text/html', $entry->getMimetype());
169 $this->assertSame('fr', $entry->getLanguage()); 169 $this->assertSame('fr', $entry->getLanguage());
@@ -205,7 +205,7 @@ class ContentProxyTest extends TestCase
205 205
206 $this->assertSame('http://1.1.1.1', $entry->getUrl()); 206 $this->assertSame('http://1.1.1.1', $entry->getUrl());
207 $this->assertSame('this is my title', $entry->getTitle()); 207 $this->assertSame('this is my title', $entry->getTitle());
208 $this->assertContains('this is my content', $entry->getContent()); 208 $this->assertContains('content', $entry->getContent());
209 $this->assertNull($entry->getPreviewPicture()); 209 $this->assertNull($entry->getPreviewPicture());
210 $this->assertSame('text/html', $entry->getMimetype()); 210 $this->assertSame('text/html', $entry->getMimetype());
211 $this->assertSame('fr', $entry->getLanguage()); 211 $this->assertSame('fr', $entry->getLanguage());
@@ -247,7 +247,7 @@ class ContentProxyTest extends TestCase
247 247
248 $this->assertSame('http://1.1.1.1', $entry->getUrl()); 248 $this->assertSame('http://1.1.1.1', $entry->getUrl());
249 $this->assertSame('this is my title', $entry->getTitle()); 249 $this->assertSame('this is my title', $entry->getTitle());
250 $this->assertContains('this is my content', $entry->getContent()); 250 $this->assertContains('content', $entry->getContent());
251 $this->assertSame('text/html', $entry->getMimetype()); 251 $this->assertSame('text/html', $entry->getMimetype());
252 $this->assertNull($entry->getLanguage()); 252 $this->assertNull($entry->getLanguage());
253 $this->assertSame('200', $entry->getHttpStatus()); 253 $this->assertSame('200', $entry->getHttpStatus());
@@ -296,7 +296,7 @@ class ContentProxyTest extends TestCase
296 296
297 $this->assertSame('http://1.1.1.1', $entry->getUrl()); 297 $this->assertSame('http://1.1.1.1', $entry->getUrl());
298 $this->assertSame('this is my title', $entry->getTitle()); 298 $this->assertSame('this is my title', $entry->getTitle());
299 $this->assertContains('this is my content', $entry->getContent()); 299 $this->assertContains('content', $entry->getContent());
300 $this->assertNull($entry->getPreviewPicture()); 300 $this->assertNull($entry->getPreviewPicture());
301 $this->assertSame('text/html', $entry->getMimetype()); 301 $this->assertSame('text/html', $entry->getMimetype());
302 $this->assertSame('fr', $entry->getLanguage()); 302 $this->assertSame('fr', $entry->getLanguage());
@@ -332,7 +332,7 @@ class ContentProxyTest extends TestCase
332 332
333 $this->assertSame('http://1.1.1.1', $entry->getUrl()); 333 $this->assertSame('http://1.1.1.1', $entry->getUrl());
334 $this->assertSame('this is my title', $entry->getTitle()); 334 $this->assertSame('this is my title', $entry->getTitle());
335 $this->assertContains('this is my content', $entry->getContent()); 335 $this->assertContains('content', $entry->getContent());
336 $this->assertSame('text/html', $entry->getMimetype()); 336 $this->assertSame('text/html', $entry->getMimetype());
337 $this->assertSame('fr', $entry->getLanguage()); 337 $this->assertSame('fr', $entry->getLanguage());
338 $this->assertSame(4.0, $entry->getReadingTime()); 338 $this->assertSame(4.0, $entry->getReadingTime());
@@ -371,7 +371,7 @@ class ContentProxyTest extends TestCase
371 371
372 $this->assertSame('http://1.1.1.1', $entry->getUrl()); 372 $this->assertSame('http://1.1.1.1', $entry->getUrl());
373 $this->assertSame('this is my title', $entry->getTitle()); 373 $this->assertSame('this is my title', $entry->getTitle());
374 $this->assertContains('this is my content', $entry->getContent()); 374 $this->assertContains('content', $entry->getContent());
375 $this->assertSame('text/html', $entry->getMimetype()); 375 $this->assertSame('text/html', $entry->getMimetype());
376 $this->assertSame('fr', $entry->getLanguage()); 376 $this->assertSame('fr', $entry->getLanguage());
377 $this->assertSame(4.0, $entry->getReadingTime()); 377 $this->assertSame(4.0, $entry->getReadingTime());
@@ -406,7 +406,7 @@ class ContentProxyTest extends TestCase
406 406
407 $this->assertSame('http://1.1.1.1', $entry->getUrl()); 407 $this->assertSame('http://1.1.1.1', $entry->getUrl());
408 $this->assertSame('this is my title', $entry->getTitle()); 408 $this->assertSame('this is my title', $entry->getTitle());
409 $this->assertContains('this is my content', $entry->getContent()); 409 $this->assertContains('content', $entry->getContent());
410 $this->assertSame('text/html', $entry->getMimetype()); 410 $this->assertSame('text/html', $entry->getMimetype());
411 $this->assertSame('fr', $entry->getLanguage()); 411 $this->assertSame('fr', $entry->getLanguage());
412 $this->assertSame(4.0, $entry->getReadingTime()); 412 $this->assertSame(4.0, $entry->getReadingTime());
diff --git a/tests/Wallabag/UserBundle/Mailer/AuthCodeMailerTest.php b/tests/Wallabag/UserBundle/Mailer/AuthCodeMailerTest.php
index e34e13a8..1713c10c 100644
--- a/tests/Wallabag/UserBundle/Mailer/AuthCodeMailerTest.php
+++ b/tests/Wallabag/UserBundle/Mailer/AuthCodeMailerTest.php
@@ -33,7 +33,7 @@ TWIG;
33 public function testSendEmail() 33 public function testSendEmail()
34 { 34 {
35 $user = new User(); 35 $user = new User();
36 $user->setTwoFactorAuthentication(true); 36 $user->setEmailTwoFactor(true);
37 $user->setEmailAuthCode(666666); 37 $user->setEmailAuthCode(666666);
38 $user->setEmail('test@wallabag.io'); 38 $user->setEmail('test@wallabag.io');
39 $user->setName('Bob'); 39 $user->setName('Bob');