IpAddressTest.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace Test\Security\Normalizer;
  8. use OC\Security\Normalizer\IpAddress;
  9. use Test\TestCase;
  10. class IpAddressTest extends TestCase {
  11. public function subnetDataProvider() {
  12. return [
  13. [
  14. '64.233.191.254',
  15. '64.233.191.254/32',
  16. ],
  17. [
  18. '192.168.0.123',
  19. '192.168.0.123/32',
  20. ],
  21. [
  22. '::ffff:192.168.0.123',
  23. '192.168.0.123/32',
  24. ],
  25. [
  26. '0:0:0:0:0:ffff:192.168.0.123',
  27. '192.168.0.123/32',
  28. ],
  29. [
  30. '0:0:0:0:0:ffff:c0a8:7b',
  31. '192.168.0.123/32',
  32. ],
  33. [
  34. '2001:0db8:85a3:0000:0000:8a2e:0370:7334',
  35. '2001:db8:85a3::/64',
  36. ],
  37. [
  38. '2001:db8:3333:4444:5555:6666:7777:8888',
  39. '2001:db8:3333:4444::/64',
  40. ],
  41. [
  42. '::1234:5678',
  43. '::/64',
  44. ],
  45. [
  46. '[::1]',
  47. '::/64',
  48. ],
  49. ];
  50. }
  51. /**
  52. * @dataProvider subnetDataProvider
  53. *
  54. * @param string $input
  55. * @param string $expected
  56. */
  57. public function testGetSubnet($input, $expected): void {
  58. $this->assertSame($expected, (new IpAddress($input))->getSubnet());
  59. }
  60. public function testToString(): void {
  61. $this->assertSame('127.0.0.1', (string)(new IpAddress('127.0.0.1')));
  62. }
  63. }