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.2KB

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