1
0

HostnameClassifierTest.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace lib\Net;
  8. use OC\Net\HostnameClassifier;
  9. use Test\TestCase;
  10. class HostnameClassifierTest extends TestCase {
  11. private HostnameClassifier $classifier;
  12. protected function setUp(): void {
  13. parent::setUp();
  14. $this->classifier = new HostnameClassifier();
  15. }
  16. public function localHostnamesData():array {
  17. return [
  18. ['localhost'],
  19. ['localHost'],
  20. ['random-host'],
  21. ['another-host.local'],
  22. ['service.localhost'],
  23. ['randomdomain.internal'],
  24. ];
  25. }
  26. /**
  27. * @dataProvider localHostnamesData
  28. */
  29. public function testLocalHostname(string $host): void {
  30. $isLocal = $this->classifier->isLocalHostname($host);
  31. self::assertTrue($isLocal);
  32. }
  33. public function publicHostnamesData(): array {
  34. return [
  35. ['example.com'],
  36. ['example.net'],
  37. ['example.org'],
  38. ['host.domain'],
  39. ['cloud.domain.tld'],
  40. ];
  41. }
  42. /**
  43. * @dataProvider publicHostnamesData
  44. */
  45. public function testPublicHostname(string $host): void {
  46. $isLocal = $this->classifier->isLocalHostname($host);
  47. self::assertFalse($isLocal);
  48. }
  49. }