SecurityTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\AdminAudit\Tests\Actions;
  8. use OCA\AdminAudit\Actions\Security;
  9. use OCA\AdminAudit\AuditLogger;
  10. use OCP\Authentication\TwoFactorAuth\IProvider;
  11. use OCP\IUser;
  12. use PHPUnit\Framework\MockObject\MockObject;
  13. use Test\TestCase;
  14. class SecurityTest extends TestCase {
  15. private AuditLogger|MockObject $logger;
  16. private Security $security;
  17. private MockObject|IUser $user;
  18. protected function setUp(): void {
  19. parent::setUp();
  20. $this->logger = $this->createMock(AuditLogger::class);
  21. $this->security = new Security($this->logger);
  22. $this->user = $this->createMock(IUser::class);
  23. $this->user->method('getUID')->willReturn('myuid');
  24. $this->user->method('getDisplayName')->willReturn('mydisplayname');
  25. }
  26. public function testTwofactorFailed() {
  27. $this->logger->expects($this->once())
  28. ->method('info')
  29. ->with(
  30. $this->equalTo('Failed two factor attempt by user mydisplayname (myuid) with provider myprovider'),
  31. ['app' => 'admin_audit']
  32. );
  33. $provider = $this->createMock(IProvider::class);
  34. $provider->method('getDisplayName')
  35. ->willReturn('myprovider');
  36. $this->security->twofactorFailed($this->user, $provider);
  37. }
  38. public function testTwofactorSuccess() {
  39. $this->logger->expects($this->once())
  40. ->method('info')
  41. ->with(
  42. $this->equalTo('Successful two factor attempt by user mydisplayname (myuid) with provider myprovider'),
  43. ['app' => 'admin_audit']
  44. );
  45. $provider = $this->createMock(IProvider::class);
  46. $provider->method('getDisplayName')
  47. ->willReturn('myprovider');
  48. $this->security->twofactorSuccess($this->user, $provider);
  49. }
  50. }