1
0

IpAddressTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2017 Lukas Reschke <lukas@statuscode.ch>
  5. *
  6. * @license GNU AGPL version 3 or any later version
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as
  10. * published by the Free Software Foundation, either version 3 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. namespace Test\Security\Normalizer;
  23. use OC\Security\Normalizer\IpAddress;
  24. use Test\TestCase;
  25. class IpAddressTest extends TestCase {
  26. public function subnetDataProvider() {
  27. return [
  28. [
  29. '64.233.191.254',
  30. '64.233.191.254/32',
  31. ],
  32. [
  33. '192.168.0.123',
  34. '192.168.0.123/32',
  35. ],
  36. [
  37. '2001:0db8:85a3:0000:0000:8a2e:0370:7334',
  38. '2001:db8:85a3::/64',
  39. ],
  40. [
  41. '2001:db8:3333:4444:5555:6666:7777:8888',
  42. '2001:db8:3333:4444::/64',
  43. ],
  44. [
  45. '::1234:5678',
  46. '::/64',
  47. ],
  48. [
  49. '[::1]',
  50. '::/64',
  51. ],
  52. ];
  53. }
  54. /**
  55. * @dataProvider subnetDataProvider
  56. *
  57. * @param string $input
  58. * @param string $expected
  59. */
  60. public function testGetSubnet($input, $expected) {
  61. $this->assertSame($expected, (new IpAddress($input))->getSubnet());
  62. }
  63. public function testToString() {
  64. $this->assertSame('127.0.0.1', (string)(new IpAddress('127.0.0.1')));
  65. }
  66. }