IpAddressTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 Lukas Reschke <lukas@statuscode.ch>
  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\Normalizer;
  22. use OC\Security\Normalizer\IpAddress;
  23. use Test\TestCase;
  24. class IpAddressTest extends TestCase {
  25. public function subnetDataProvider() {
  26. return [
  27. [
  28. '64.233.191.254',
  29. '64.233.191.254/32',
  30. ],
  31. [
  32. '192.168.0.123',
  33. '192.168.0.123/32',
  34. ],
  35. [
  36. '2001:0db8:85a3:0000:0000:8a2e:0370:7334',
  37. '2001:db8:85a3::8a2e:370:7334/128',
  38. ],
  39. [
  40. '[::1]',
  41. '::1/128',
  42. ],
  43. ];
  44. }
  45. /**
  46. * @dataProvider subnetDataProvider
  47. *
  48. * @param string $input
  49. * @param string $expected
  50. */
  51. public function testGetSubnet($input, $expected) {
  52. $this->assertSame($expected, (new IpAddress($input))->getSubnet());
  53. }
  54. public function testToString() {
  55. $this->assertSame('127.0.0.1', (string)(new IpAddress('127.0.0.1')));
  56. }
  57. }