CapabilitiesTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 Roeland Jago Douma <roeland@famdouma.nl>
  4. *
  5. * @license GNU AGPL version 3 or any later version
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Affero General Public License as
  9. * published by the Free Software Foundation, either version 3 of the
  10. * License, or (at your option) any later version.
  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
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. */
  21. namespace Test\Security\Bruteforce;
  22. use OC\Security\Bruteforce\Capabilities;
  23. use OC\Security\Bruteforce\Throttler;
  24. use OCP\IRequest;
  25. use Test\TestCase;
  26. class CapabilitiesTest extends TestCase {
  27. /** @var Capabilities */
  28. private $capabilities;
  29. /** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */
  30. private $request;
  31. /** @var Throttler|\PHPUnit_Framework_MockObject_MockObject */
  32. private $throttler;
  33. public function setUp() {
  34. parent::setUp();
  35. $this->request = $this->createMock(IRequest::class);
  36. $this->request->method('getRemoteAddress')
  37. ->willReturn('10.10.10.10');
  38. $this->throttler = $this->createMock(Throttler::class);
  39. $this->capabilities = new Capabilities(
  40. $this->request,
  41. $this->throttler
  42. );
  43. }
  44. public function testGetCapabilities() {
  45. $this->throttler->expects($this->atLeastOnce())
  46. ->method('getDelay')
  47. ->with('10.10.10.10')
  48. ->willReturn(42);
  49. $expected = [
  50. 'bruteforce' => [
  51. 'delay' => 42
  52. ]
  53. ];
  54. $result = $this->capabilities->getCapabilities();
  55. $this->assertEquals($expected, $result);
  56. }
  57. }