aboutsummaryrefslogtreecommitdiffstats
path: root/src/resource_inventory/tests
diff options
context:
space:
mode:
authorParker Berberian <pberberian@iol.unh.edu>2019-06-28 09:58:54 -0400
committerParker Berberian <pberberian@iol.unh.edu>2019-06-28 10:28:53 -0400
commita02f1d81f6651ddf5b9353c2e1d7fbf873a19466 (patch)
tree081b06663ca04c39d818740efda166d99c78dff9 /src/resource_inventory/tests
parent1293c6e1d23d8fe62ee6721ff9a107ca571d9244 (diff)
Adds Hostname Validator
Creates a single place to validate hostnames, with public fields for regex that can be copied to the frontend. We do hostname validation inconsistently all over the place, we should move to using this single validator. Change-Id: I7b71fd89843a7e5b7f9d93dcb23f4645abe71dd0 Signed-off-by: Parker Berberian <pberberian@iol.unh.edu>
Diffstat (limited to 'src/resource_inventory/tests')
-rw-r--r--src/resource_inventory/tests/test_managers.py54
1 files changed, 53 insertions, 1 deletions
diff --git a/src/resource_inventory/tests/test_managers.py b/src/resource_inventory/tests/test_managers.py
index 0e7c673..46cee5a 100644
--- a/src/resource_inventory/tests/test_managers.py
+++ b/src/resource_inventory/tests/test_managers.py
@@ -11,7 +11,7 @@ from django.test import TestCase
from django.contrib.auth.models import User
from resource.inventory_manager import InventoryManager
-from resource.resource_manager import ResourceManager
+from resource.resource_manager import ResourceManager, HostNameValidator
from account.models import Lab
from resource.models import (
Host,
@@ -247,3 +247,55 @@ class ResourceManagerTestCase(TestCase):
def test_convert_bundle(self):
ResourceManager.getInstance().convertResoureBundle(self.genericBundle, self.lab.name)
# verify bundle configuration
+
+
+class HostNameValidatorTestCase(TestCase):
+
+ def test_valid_hostnames(self):
+ self.assertTrue(HostNameValidator.is_valid_hostname("localhost"))
+ self.assertTrue(HostNameValidator.is_valid_hostname("Localhost"))
+ self.assertTrue(HostNameValidator.is_valid_hostname("localHost"))
+ self.assertTrue(HostNameValidator.is_valid_hostname("LOCALHOST"))
+ self.assertTrue(HostNameValidator.is_valid_hostname("f"))
+ self.assertTrue(HostNameValidator.is_valid_hostname("abc123doreyme"))
+ self.assertTrue(HostNameValidator.is_valid_hostname("F9999999"))
+ self.assertTrue(HostNameValidator.is_valid_hostname("my-host"))
+ self.assertTrue(HostNameValidator.is_valid_hostname("My-Host"))
+ self.assertTrue(HostNameValidator.is_valid_hostname("MY-HOST"))
+ self.assertTrue(HostNameValidator.is_valid_hostname("a-long-name-for-my-host"))
+
+ def test_invalid_hostnames(self):
+ self.assertFalse(HostNameValidator.is_valid_hostname("-long-name-for-my-host"))
+ self.assertFalse(HostNameValidator.is_valid_hostname("546"))
+ self.assertFalse(HostNameValidator.is_valid_hostname("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))
+
+ def test_invalid_chars(self):
+ self.assertFalse(HostNameValidator.is_valid_hostname("contains!char"))
+ self.assertFalse(HostNameValidator.is_valid_hostname("contains@char"))
+ self.assertFalse(HostNameValidator.is_valid_hostname("contains#char"))
+ self.assertFalse(HostNameValidator.is_valid_hostname("contains$char"))
+ self.assertFalse(HostNameValidator.is_valid_hostname("contains%char"))
+ self.assertFalse(HostNameValidator.is_valid_hostname("contains^char"))
+ self.assertFalse(HostNameValidator.is_valid_hostname("contains&char"))
+ self.assertFalse(HostNameValidator.is_valid_hostname("contains*char"))
+ self.assertFalse(HostNameValidator.is_valid_hostname("contains(char"))
+ self.assertFalse(HostNameValidator.is_valid_hostname("contains)char"))
+ self.assertFalse(HostNameValidator.is_valid_hostname("contains_char"))
+ self.assertFalse(HostNameValidator.is_valid_hostname("contains=char"))
+ self.assertFalse(HostNameValidator.is_valid_hostname("contains+char"))
+ self.assertFalse(HostNameValidator.is_valid_hostname("contains|char"))
+ self.assertFalse(HostNameValidator.is_valid_hostname("contains\\char"))
+ self.assertFalse(HostNameValidator.is_valid_hostname("contains[char"))
+ self.assertFalse(HostNameValidator.is_valid_hostname("contains]char"))
+ self.assertFalse(HostNameValidator.is_valid_hostname("contains;char"))
+ self.assertFalse(HostNameValidator.is_valid_hostname("contains:char"))
+ self.assertFalse(HostNameValidator.is_valid_hostname("contains'char"))
+ self.assertFalse(HostNameValidator.is_valid_hostname('contains"char'))
+ self.assertFalse(HostNameValidator.is_valid_hostname("contains'char"))
+ self.assertFalse(HostNameValidator.is_valid_hostname("contains<char"))
+ self.assertFalse(HostNameValidator.is_valid_hostname("contains>char"))
+ self.assertFalse(HostNameValidator.is_valid_hostname("contains,char"))
+ self.assertFalse(HostNameValidator.is_valid_hostname("contains?char"))
+ self.assertFalse(HostNameValidator.is_valid_hostname("contains/char"))
+ self.assertFalse(HostNameValidator.is_valid_hostname("contains`char"))
+ self.assertFalse(HostNameValidator.is_valid_hostname("contains~char"))