1
0

IpAddressTest.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. '::ffff:192.168.0.123',
  38. '192.168.0.123/32',
  39. ],
  40. [
  41. '0:0:0:0:0:ffff:192.168.0.123',
  42. '192.168.0.123/32',
  43. ],
  44. [
  45. '0:0:0:0:0:ffff:c0a8:7b',
  46. '192.168.0.123/32',
  47. ],
  48. [
  49. '2001:0db8:85a3:0000:0000:8a2e:0370:7334',
  50. '2001:db8:85a3::/64',
  51. ],
  52. [
  53. '2001:db8:3333:4444:5555:6666:7777:8888',
  54. '2001:db8:3333:4444::/64',
  55. ],
  56. [
  57. '::1234:5678',
  58. '::/64',
  59. ],
  60. [
  61. '[::1]',
  62. '::/64',
  63. ],
  64. ];
  65. }
  66. /**
  67. * @dataProvider subnetDataProvider
  68. *
  69. * @param string $input
  70. * @param string $expected
  71. */
  72. public function testGetSubnet($input, $expected) {
  73. $this->assertSame($expected, (new IpAddress($input))->getSubnet());
  74. }
  75. public function testToString() {
  76. $this->assertSame('127.0.0.1', (string)(new IpAddress('127.0.0.1')));
  77. }
  78. }