ManagerTest.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. <?php
  2. /**
  3. * @author Christoph Wurst <christoph@owncloud.com>
  4. *
  5. * @copyright Copyright (c) 2016, ownCloud, Inc.
  6. * @license AGPL-3.0
  7. *
  8. * This code is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License, version 3,
  10. * as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License, version 3,
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>
  19. *
  20. */
  21. namespace Test\Authentication\TwoFactorAuth;
  22. use Exception;
  23. use OC;
  24. use OC\Authentication\Token\IProvider as TokenProvider;
  25. use OC\Authentication\TwoFactorAuth\Manager;
  26. use OC\Authentication\TwoFactorAuth\MandatoryTwoFactor;
  27. use OC\Authentication\TwoFactorAuth\ProviderLoader;
  28. use OCP\Activity\IEvent;
  29. use OCP\Activity\IManager;
  30. use OCP\AppFramework\Utility\ITimeFactory;
  31. use OCP\Authentication\TwoFactorAuth\IProvider;
  32. use OCP\Authentication\TwoFactorAuth\IRegistry;
  33. use OCP\IConfig;
  34. use OCP\ILogger;
  35. use OCP\ISession;
  36. use OCP\IUser;
  37. use PHPUnit\Framework\MockObject\MockObject;
  38. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  39. use Test\TestCase;
  40. class ManagerTest extends TestCase {
  41. /** @var IUser|MockObject */
  42. private $user;
  43. /** @var ProviderLoader|MockObject */
  44. private $providerLoader;
  45. /** @var IRegistry|MockObject */
  46. private $providerRegistry;
  47. /** @var MandatoryTwoFactor|MockObject */
  48. private $mandatoryTwoFactor;
  49. /** @var ISession|MockObject */
  50. private $session;
  51. /** @var Manager */
  52. private $manager;
  53. /** @var IConfig|MockObject */
  54. private $config;
  55. /** @var IManager|MockObject */
  56. private $activityManager;
  57. /** @var ILogger|MockObject */
  58. private $logger;
  59. /** @var IProvider|MockObject */
  60. private $fakeProvider;
  61. /** @var IProvider|MockObject */
  62. private $backupProvider;
  63. /** @var TokenProvider|MockObject */
  64. private $tokenProvider;
  65. /** @var ITimeFactory|MockObject */
  66. private $timeFactory;
  67. /** @var EventDispatcherInterface|MockObject */
  68. private $eventDispatcher;
  69. protected function setUp() {
  70. parent::setUp();
  71. $this->user = $this->createMock(IUser::class);
  72. $this->providerLoader = $this->createMock(ProviderLoader::class);
  73. $this->providerRegistry = $this->createMock(IRegistry::class);
  74. $this->mandatoryTwoFactor = $this->createMock(MandatoryTwoFactor::class);
  75. $this->session = $this->createMock(ISession::class);
  76. $this->config = $this->createMock(IConfig::class);
  77. $this->activityManager = $this->createMock(IManager::class);
  78. $this->logger = $this->createMock(ILogger::class);
  79. $this->tokenProvider = $this->createMock(TokenProvider::class);
  80. $this->timeFactory = $this->createMock(ITimeFactory::class);
  81. $this->eventDispatcher = $this->createMock(EventDispatcherInterface::class);
  82. $this->manager = new Manager(
  83. $this->providerLoader,
  84. $this->providerRegistry,
  85. $this->mandatoryTwoFactor,
  86. $this->session,
  87. $this->config,
  88. $this->activityManager,
  89. $this->logger,
  90. $this->tokenProvider,
  91. $this->timeFactory,
  92. $this->eventDispatcher
  93. );
  94. $this->fakeProvider = $this->createMock(IProvider::class);
  95. $this->fakeProvider->method('getId')->willReturn('email');
  96. $this->backupProvider = $this->getMockBuilder('\OCP\Authentication\TwoFactorAuth\IProvider')->getMock();
  97. $this->backupProvider->method('getId')->willReturn('backup_codes');
  98. $this->backupProvider->method('isTwoFactorAuthEnabledForUser')->willReturn(true);
  99. }
  100. private function prepareNoProviders() {
  101. $this->providerLoader->method('getProviders')
  102. ->with($this->user)
  103. ->will($this->returnValue([]));
  104. }
  105. private function prepareProviders() {
  106. $this->providerRegistry->expects($this->once())
  107. ->method('getProviderStates')
  108. ->with($this->user)
  109. ->willReturn([
  110. $this->fakeProvider->getId() => true,
  111. ]);
  112. $this->providerLoader->expects($this->once())
  113. ->method('getProviders')
  114. ->with($this->user)
  115. ->willReturn([$this->fakeProvider]);
  116. }
  117. private function prepareProvidersWitBackupProvider() {
  118. $this->providerLoader->method('getProviders')
  119. ->with($this->user)
  120. ->willReturn([
  121. $this->fakeProvider,
  122. $this->backupProvider,
  123. ]);
  124. }
  125. public function testIsTwoFactorAuthenticatedEnforced() {
  126. $this->mandatoryTwoFactor->expects($this->once())
  127. ->method('isEnforcedFor')
  128. ->with($this->user)
  129. ->willReturn(true);
  130. $enabled = $this->manager->isTwoFactorAuthenticated($this->user);
  131. $this->assertTrue($enabled);
  132. }
  133. public function testIsTwoFactorAuthenticatedNoProviders() {
  134. $this->mandatoryTwoFactor->expects($this->once())
  135. ->method('isEnforcedFor')
  136. ->with($this->user)
  137. ->willReturn(false);
  138. $this->providerRegistry->expects($this->once())
  139. ->method('getProviderStates')
  140. ->willReturn([]); // No providers registered
  141. $this->providerLoader->expects($this->once())
  142. ->method('getProviders')
  143. ->willReturn([]); // No providers loadable
  144. $this->assertFalse($this->manager->isTwoFactorAuthenticated($this->user));
  145. }
  146. public function testIsTwoFactorAuthenticatedOnlyBackupCodes() {
  147. $this->mandatoryTwoFactor->expects($this->once())
  148. ->method('isEnforcedFor')
  149. ->with($this->user)
  150. ->willReturn(false);
  151. $this->providerRegistry->expects($this->once())
  152. ->method('getProviderStates')
  153. ->willReturn([
  154. 'backup_codes' => true,
  155. ]);
  156. $backupCodesProvider = $this->createMock(IProvider::class);
  157. $backupCodesProvider
  158. ->method('getId')
  159. ->willReturn('backup_codes');
  160. $this->providerLoader->expects($this->once())
  161. ->method('getProviders')
  162. ->willReturn([
  163. $backupCodesProvider,
  164. ]);
  165. $this->assertFalse($this->manager->isTwoFactorAuthenticated($this->user));
  166. }
  167. public function testIsTwoFactorAuthenticatedFailingProviders() {
  168. $this->mandatoryTwoFactor->expects($this->once())
  169. ->method('isEnforcedFor')
  170. ->with($this->user)
  171. ->willReturn(false);
  172. $this->providerRegistry->expects($this->once())
  173. ->method('getProviderStates')
  174. ->willReturn([
  175. 'twofactor_totp' => true,
  176. 'twofactor_u2f' => false,
  177. ]); // Two providers registered, but …
  178. $this->providerLoader->expects($this->once())
  179. ->method('getProviders')
  180. ->willReturn([]); // … none of them is able to load, however …
  181. // … 2FA is still enforced
  182. $this->assertTrue($this->manager->isTwoFactorAuthenticated($this->user));
  183. }
  184. public function providerStatesFixData(): array {
  185. return [
  186. [false, false],
  187. [true, true],
  188. ];
  189. }
  190. /**
  191. * If the 2FA registry has not been populated when a user logs in,
  192. * the 2FA manager has to first fix the state before it checks for
  193. * enabled providers.
  194. *
  195. * If any of these providers is active, 2FA is enabled
  196. *
  197. * @dataProvider providerStatesFixData
  198. */
  199. public function testIsTwoFactorAuthenticatedFixesProviderStates(bool $providerEnabled, bool $expected) {
  200. $this->providerRegistry->expects($this->once())
  201. ->method('getProviderStates')
  202. ->willReturn([]); // Nothing registered yet
  203. $this->providerLoader->expects($this->once())
  204. ->method('getProviders')
  205. ->willReturn([
  206. $this->fakeProvider
  207. ]);
  208. $this->fakeProvider->expects($this->once())
  209. ->method('isTwoFactorAuthEnabledForUser')
  210. ->with($this->user)
  211. ->willReturn($providerEnabled);
  212. if ($providerEnabled) {
  213. $this->providerRegistry->expects($this->once())
  214. ->method('enableProviderFor')
  215. ->with(
  216. $this->fakeProvider,
  217. $this->user
  218. );
  219. } else {
  220. $this->providerRegistry->expects($this->once())
  221. ->method('disableProviderFor')
  222. ->with(
  223. $this->fakeProvider,
  224. $this->user
  225. );
  226. }
  227. $this->assertEquals($expected, $this->manager->isTwoFactorAuthenticated($this->user));
  228. }
  229. public function testGetProvider() {
  230. $this->providerRegistry->expects($this->once())
  231. ->method('getProviderStates')
  232. ->with($this->user)
  233. ->willReturn([
  234. $this->fakeProvider->getId() => true,
  235. ]);
  236. $this->providerLoader->expects($this->once())
  237. ->method('getProviders')
  238. ->with($this->user)
  239. ->willReturn([$this->fakeProvider]);
  240. $provider = $this->manager->getProvider($this->user, $this->fakeProvider->getId());
  241. $this->assertSame($this->fakeProvider, $provider);
  242. }
  243. public function testGetInvalidProvider() {
  244. $this->providerRegistry->expects($this->once())
  245. ->method('getProviderStates')
  246. ->with($this->user)
  247. ->willReturn([]);
  248. $this->providerLoader->expects($this->once())
  249. ->method('getProviders')
  250. ->with($this->user)
  251. ->willReturn([]);
  252. $provider = $this->manager->getProvider($this->user, 'nonexistent');
  253. $this->assertNull($provider);
  254. }
  255. public function testGetProviders() {
  256. $this->providerRegistry->expects($this->once())
  257. ->method('getProviderStates')
  258. ->with($this->user)
  259. ->willReturn([
  260. $this->fakeProvider->getId() => true,
  261. ]);
  262. $this->providerLoader->expects($this->once())
  263. ->method('getProviders')
  264. ->with($this->user)
  265. ->willReturn([$this->fakeProvider]);
  266. $expectedProviders = [
  267. 'email' => $this->fakeProvider,
  268. ];
  269. $providerSet = $this->manager->getProviderSet($this->user);
  270. $providers = $providerSet->getProviders();
  271. $this->assertEquals($expectedProviders, $providers);
  272. $this->assertFalse($providerSet->isProviderMissing());
  273. }
  274. public function testGetProvidersOneMissing() {
  275. $this->providerRegistry->expects($this->once())
  276. ->method('getProviderStates')
  277. ->with($this->user)
  278. ->willReturn([
  279. $this->fakeProvider->getId() => true,
  280. ]);
  281. $this->providerLoader->expects($this->once())
  282. ->method('getProviders')
  283. ->with($this->user)
  284. ->willReturn([]);
  285. $expectedProviders = [
  286. 'email' => $this->fakeProvider,
  287. ];
  288. $providerSet = $this->manager->getProviderSet($this->user);
  289. $this->assertTrue($providerSet->isProviderMissing());
  290. }
  291. public function testVerifyChallenge() {
  292. $this->prepareProviders();
  293. $challenge = 'passme';
  294. $event = $this->createMock(IEvent::class);
  295. $this->fakeProvider->expects($this->once())
  296. ->method('verifyChallenge')
  297. ->with($this->user, $challenge)
  298. ->will($this->returnValue(true));
  299. $this->session->expects($this->once())
  300. ->method('get')
  301. ->with('two_factor_remember_login')
  302. ->will($this->returnValue(false));
  303. $this->session->expects($this->at(1))
  304. ->method('remove')
  305. ->with('two_factor_auth_uid');
  306. $this->session->expects($this->at(2))
  307. ->method('remove')
  308. ->with('two_factor_remember_login');
  309. $this->session->expects($this->at(3))
  310. ->method('set')
  311. ->with(Manager::SESSION_UID_DONE, 'jos');
  312. $this->session->method('getId')
  313. ->willReturn('mysessionid');
  314. $this->activityManager->expects($this->once())
  315. ->method('generateEvent')
  316. ->willReturn($event);
  317. $this->user->expects($this->any())
  318. ->method('getUID')
  319. ->willReturn('jos');
  320. $event->expects($this->once())
  321. ->method('setApp')
  322. ->with($this->equalTo('core'))
  323. ->willReturnSelf();
  324. $event->expects($this->once())
  325. ->method('setType')
  326. ->with($this->equalTo('security'))
  327. ->willReturnSelf();
  328. $event->expects($this->once())
  329. ->method('setAuthor')
  330. ->with($this->equalTo('jos'))
  331. ->willReturnSelf();
  332. $event->expects($this->once())
  333. ->method('setAffectedUser')
  334. ->with($this->equalTo('jos'))
  335. ->willReturnSelf();
  336. $this->fakeProvider
  337. ->method('getDisplayName')
  338. ->willReturn('Fake 2FA');
  339. $event->expects($this->once())
  340. ->method('setSubject')
  341. ->with($this->equalTo('twofactor_success'), $this->equalTo([
  342. 'provider' => 'Fake 2FA',
  343. ]))
  344. ->willReturnSelf();
  345. $token = $this->createMock(OC\Authentication\Token\IToken::class);
  346. $this->tokenProvider->method('getToken')
  347. ->with('mysessionid')
  348. ->willReturn($token);
  349. $token->method('getId')
  350. ->willReturn(42);
  351. $this->config->expects($this->once())
  352. ->method('deleteUserValue')
  353. ->with('jos', 'login_token_2fa', 42);
  354. $result = $this->manager->verifyChallenge('email', $this->user, $challenge);
  355. $this->assertTrue($result);
  356. }
  357. public function testVerifyChallengeInvalidProviderId() {
  358. $this->prepareProviders();
  359. $challenge = 'passme';
  360. $this->fakeProvider->expects($this->never())
  361. ->method('verifyChallenge')
  362. ->with($this->user, $challenge);
  363. $this->session->expects($this->never())
  364. ->method('remove');
  365. $this->assertFalse($this->manager->verifyChallenge('dontexist', $this->user, $challenge));
  366. }
  367. public function testVerifyInvalidChallenge() {
  368. $this->prepareProviders();
  369. $challenge = 'dontpassme';
  370. $event = $this->createMock(IEvent::class);
  371. $this->fakeProvider->expects($this->once())
  372. ->method('verifyChallenge')
  373. ->with($this->user, $challenge)
  374. ->will($this->returnValue(false));
  375. $this->session->expects($this->never())
  376. ->method('remove');
  377. $this->activityManager->expects($this->once())
  378. ->method('generateEvent')
  379. ->willReturn($event);
  380. $this->user->expects($this->any())
  381. ->method('getUID')
  382. ->willReturn('jos');
  383. $event->expects($this->once())
  384. ->method('setApp')
  385. ->with($this->equalTo('core'))
  386. ->willReturnSelf();
  387. $event->expects($this->once())
  388. ->method('setType')
  389. ->with($this->equalTo('security'))
  390. ->willReturnSelf();
  391. $event->expects($this->once())
  392. ->method('setAuthor')
  393. ->with($this->equalTo('jos'))
  394. ->willReturnSelf();
  395. $event->expects($this->once())
  396. ->method('setAffectedUser')
  397. ->with($this->equalTo('jos'))
  398. ->willReturnSelf();
  399. $this->fakeProvider
  400. ->method('getDisplayName')
  401. ->willReturn('Fake 2FA');
  402. $event->expects($this->once())
  403. ->method('setSubject')
  404. ->with($this->equalTo('twofactor_failed'), $this->equalTo([
  405. 'provider' => 'Fake 2FA',
  406. ]))
  407. ->willReturnSelf();
  408. $this->assertFalse($this->manager->verifyChallenge('email', $this->user, $challenge));
  409. }
  410. public function testNeedsSecondFactor() {
  411. $user = $this->createMock(IUser::class);
  412. $this->session->expects($this->at(0))
  413. ->method('exists')
  414. ->with('app_password')
  415. ->willReturn(false);
  416. $this->session->expects($this->at(1))
  417. ->method('exists')
  418. ->with('two_factor_auth_uid')
  419. ->will($this->returnValue(false));
  420. $this->session->expects($this->at(2))
  421. ->method('exists')
  422. ->with(Manager::SESSION_UID_DONE)
  423. ->willReturn(false);
  424. $this->session->method('getId')
  425. ->willReturn('mysessionid');
  426. $token = $this->createMock(OC\Authentication\Token\IToken::class);
  427. $this->tokenProvider->method('getToken')
  428. ->with('mysessionid')
  429. ->willReturn($token);
  430. $token->method('getId')
  431. ->willReturn(42);
  432. $user->method('getUID')
  433. ->willReturn('user');
  434. $this->config->method('getUserKeys')
  435. ->with('user', 'login_token_2fa')
  436. ->willReturn([
  437. 42
  438. ]);
  439. $manager = $this->getMockBuilder(Manager::class)
  440. ->setConstructorArgs([
  441. $this->providerLoader,
  442. $this->providerRegistry,
  443. $this->mandatoryTwoFactor,
  444. $this->session,
  445. $this->config,
  446. $this->activityManager,
  447. $this->logger,
  448. $this->tokenProvider,
  449. $this->timeFactory,
  450. $this->eventDispatcher
  451. ])
  452. ->setMethods(['loadTwoFactorApp', 'isTwoFactorAuthenticated'])// Do not actually load the apps
  453. ->getMock();
  454. $manager->method('isTwoFactorAuthenticated')
  455. ->with($user)
  456. ->willReturn(true);
  457. $this->assertTrue($manager->needsSecondFactor($user));
  458. }
  459. public function testNeedsSecondFactorUserIsNull() {
  460. $user = null;
  461. $this->session->expects($this->never())
  462. ->method('exists');
  463. $this->assertFalse($this->manager->needsSecondFactor($user));
  464. }
  465. public function testNeedsSecondFactorWithNoProviderAvailableAnymore() {
  466. $this->prepareNoProviders();
  467. $user = null;
  468. $this->session->expects($this->never())
  469. ->method('exists')
  470. ->with('two_factor_auth_uid')
  471. ->will($this->returnValue(true));
  472. $this->session->expects($this->never())
  473. ->method('remove')
  474. ->with('two_factor_auth_uid');
  475. $this->assertFalse($this->manager->needsSecondFactor($user));
  476. }
  477. public function testPrepareTwoFactorLogin() {
  478. $this->user->method('getUID')
  479. ->will($this->returnValue('ferdinand'));
  480. $this->session->expects($this->at(0))
  481. ->method('set')
  482. ->with('two_factor_auth_uid', 'ferdinand');
  483. $this->session->expects($this->at(1))
  484. ->method('set')
  485. ->with('two_factor_remember_login', true);
  486. $this->session->method('getId')
  487. ->willReturn('mysessionid');
  488. $token = $this->createMock(OC\Authentication\Token\IToken::class);
  489. $this->tokenProvider->method('getToken')
  490. ->with('mysessionid')
  491. ->willReturn($token);
  492. $token->method('getId')
  493. ->willReturn(42);
  494. $this->timeFactory->method('getTime')
  495. ->willReturn(1337);
  496. $this->config->method('setUserValue')
  497. ->with('ferdinand', 'login_token_2fa', 42, 1337);
  498. $this->manager->prepareTwoFactorLogin($this->user, true);
  499. }
  500. public function testPrepareTwoFactorLoginDontRemember() {
  501. $this->user->method('getUID')
  502. ->will($this->returnValue('ferdinand'));
  503. $this->session->expects($this->at(0))
  504. ->method('set')
  505. ->with('two_factor_auth_uid', 'ferdinand');
  506. $this->session->expects($this->at(1))
  507. ->method('set')
  508. ->with('two_factor_remember_login', false);
  509. $this->session->method('getId')
  510. ->willReturn('mysessionid');
  511. $token = $this->createMock(OC\Authentication\Token\IToken::class);
  512. $this->tokenProvider->method('getToken')
  513. ->with('mysessionid')
  514. ->willReturn($token);
  515. $token->method('getId')
  516. ->willReturn(42);
  517. $this->timeFactory->method('getTime')
  518. ->willReturn(1337);
  519. $this->config->method('setUserValue')
  520. ->with('ferdinand', 'login_token_2fa', 42, 1337);
  521. $this->manager->prepareTwoFactorLogin($this->user, false);
  522. }
  523. public function testNeedsSecondFactorSessionAuth() {
  524. $user = $this->createMock(IUser::class);
  525. $user->method('getUID')
  526. ->willReturn('user');
  527. $this->session->method('exists')
  528. ->will($this->returnCallback(function ($var) {
  529. if ($var === Manager::SESSION_UID_KEY) {
  530. return false;
  531. } else if ($var === 'app_password') {
  532. return false;
  533. }
  534. return true;
  535. }));
  536. $this->session->expects($this->once())
  537. ->method('get')
  538. ->with(Manager::SESSION_UID_DONE)
  539. ->willReturn('user');
  540. $this->assertFalse($this->manager->needsSecondFactor($user));
  541. }
  542. public function testNeedsSecondFactorSessionAuthFailDBPass() {
  543. $user = $this->createMock(IUser::class);
  544. $user->method('getUID')
  545. ->willReturn('user');
  546. $this->session->method('exists')
  547. ->willReturn(false);
  548. $this->session->method('getId')
  549. ->willReturn('mysessionid');
  550. $token = $this->createMock(OC\Authentication\Token\IToken::class);
  551. $token->method('getId')
  552. ->willReturn(40);
  553. $this->tokenProvider->method('getToken')
  554. ->with('mysessionid')
  555. ->willReturn($token);
  556. $this->config->method('getUserKeys')
  557. ->with('user', 'login_token_2fa')
  558. ->willReturn([
  559. 42, 43, 44
  560. ]);
  561. $this->session->expects($this->once())
  562. ->method('set')
  563. ->with(Manager::SESSION_UID_DONE, 'user');
  564. $this->assertFalse($this->manager->needsSecondFactor($user));
  565. }
  566. public function testNeedsSecondFactorInvalidToken() {
  567. $this->prepareNoProviders();
  568. $user = $this->createMock(IUser::class);
  569. $user->method('getUID')
  570. ->willReturn('user');
  571. $this->session->method('exists')
  572. ->willReturn(false);
  573. $this->session->method('getId')
  574. ->willReturn('mysessionid');
  575. $this->tokenProvider->method('getToken')
  576. ->with('mysessionid')
  577. ->willThrowException(new OC\Authentication\Exceptions\InvalidTokenException());
  578. $this->config->method('getUserKeys')->willReturn([]);
  579. $this->assertFalse($this->manager->needsSecondFactor($user));
  580. }
  581. public function testNeedsSecondFactorAppPassword() {
  582. $user = $this->createMock(IUser::class);
  583. $this->session->method('exists')
  584. ->with('app_password')
  585. ->willReturn(true);
  586. $this->assertFalse($this->manager->needsSecondFactor($user));
  587. }
  588. }