SecurityTest.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2018 Roeland Jago Douma <roeland@famdouma.nl>
  5. *
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OCA\AdminAudit\Tests\Actions;
  26. use OCA\AdminAudit\Actions\Security;
  27. use OCA\AdminAudit\AuditLogger;
  28. use OCP\Authentication\TwoFactorAuth\IProvider;
  29. use OCP\IUser;
  30. use Test\TestCase;
  31. class SecurityTest extends TestCase {
  32. /** @var AuditLogger|\PHPUnit\Framework\MockObject\MockObject */
  33. private $logger;
  34. /** @var Security */
  35. private $security;
  36. /** @var IUser|\PHPUnit\Framework\MockObject\MockObject */
  37. private $user;
  38. protected function setUp(): void {
  39. parent::setUp();
  40. $this->logger = $this->createMock(AuditLogger::class);
  41. $this->security = new Security($this->logger);
  42. $this->user = $this->createMock(IUser::class);
  43. $this->user->method('getUID')->willReturn('myuid');
  44. $this->user->method('getDisplayName')->willReturn('mydisplayname');
  45. }
  46. public function testTwofactorFailed() {
  47. $this->logger->expects($this->once())
  48. ->method('info')
  49. ->with(
  50. $this->equalTo('Failed two factor attempt by user mydisplayname (myuid) with provider myprovider'),
  51. ['app' => 'admin_audit']
  52. );
  53. $provider = $this->createMock(IProvider::class);
  54. $provider->method('getDisplayName')
  55. ->willReturn('myprovider');
  56. $this->security->twofactorFailed($this->user, $provider);
  57. }
  58. public function testTwofactorSuccess() {
  59. $this->logger->expects($this->once())
  60. ->method('info')
  61. ->with(
  62. $this->equalTo('Successful two factor attempt by user mydisplayname (myuid) with provider myprovider'),
  63. ['app' => 'admin_audit']
  64. );
  65. $provider = $this->createMock(IProvider::class);
  66. $provider->method('getDisplayName')
  67. ->willReturn('myprovider');
  68. $this->security->twofactorSuccess($this->user, $provider);
  69. }
  70. }