You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SecurityTest.php 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 OCP\IUser;
  28. use Psr\Log\LoggerInterface;
  29. use Test\TestCase;
  30. class SecurityTest extends TestCase {
  31. /** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
  32. private $logger;
  33. /** @var Security */
  34. private $security;
  35. /** @var IUser|\PHPUnit\Framework\MockObject\MockObject */
  36. private $user;
  37. protected function setUp(): void {
  38. parent::setUp();
  39. $this->logger = $this->createMock(LoggerInterface::class);
  40. $this->security = new Security($this->logger);
  41. $this->user = $this->createMock(IUser::class);
  42. $this->user->method('getUID')->willReturn('myuid');
  43. $this->user->method('getDisplayName')->willReturn('mydisplayname');
  44. }
  45. public function testTwofactorFailed() {
  46. $this->logger->expects($this->once())
  47. ->method('info')
  48. ->with(
  49. $this->equalTo('Failed two factor attempt by user mydisplayname (myuid) with provider myprovider'),
  50. ['app' => 'admin_audit']
  51. );
  52. $this->security->twofactorFailed($this->user, ['provider' => 'myprovider']);
  53. }
  54. public function testTwofactorSuccess() {
  55. $this->logger->expects($this->once())
  56. ->method('info')
  57. ->with(
  58. $this->equalTo('Successful two factor attempt by user mydisplayname (myuid) with provider myprovider'),
  59. ['app' => 'admin_audit']
  60. );
  61. $this->security->twofactorSuccess($this->user, ['provider' => 'myprovider']);
  62. }
  63. }