Esempio n. 1
0
def parse_hostname(request):
    message = message_parser.parse_message(request,
                                           required_fields=['hostname'])
    hostname = message['hostname']
    if not hostname_validator.validate(hostname):
        raise errors.InvalidHostnameError(
            'The hostname contains invalid characters.')
    return hostname
Esempio n. 2
0
def parse_hostname(request):
    message = message_parser.parse_message(request, ['hostname'])
    hostname = message['hostname']
    if not hostname_validator.validate(hostname):
        raise errors.InvalidHostnameError(
            'Hostnames can only contain the letters a-z, digits and dashes'
            ' (it cannot start with a dash, though). It must contain 1-63'
            ' characters and cannot be "localhost".')
    return hostname
Esempio n. 3
0
 def test_accepts_hostname_with_exactly_63_characters(self):
     self.assertTrue(hostname.validate('a' * 63))
Esempio n. 4
0
 def test_accepts_hostname_with_valid_characters(self):
     self.assertTrue(hostname.validate('tiny-pilot123'))
Esempio n. 5
0
 def test_rejects_hostname_that_starts_with_a_dash(self):
     self.assertFalse(hostname.validate('-invalid'))
Esempio n. 6
0
 def test_rejects_hostname_that_is_longer_than_63_chars(self):
     self.assertFalse(hostname.validate('a' * 64))
Esempio n. 7
0
 def test_rejects_empty_hostname(self):
     self.assertFalse(hostname.validate(''))
Esempio n. 8
0
 def test_rejects_localhost_as_hostname(self):
     self.assertFalse(hostname.validate('localhost'))
Esempio n. 9
0
 def test_rejects_hostnames_with_invalid_characters(self):
     self.assertFalse(hostname.validate('TINYPILOT'))
     self.assertFalse(hostname.validate('tinypilot***'))
     self.assertFalse(hostname.validate('tiny.pilot'))
Esempio n. 10
0
 def test_rejects_hostname_that_is_not_a_string(self):
     self.assertFalse(hostname.validate(1))
     self.assertFalse(hostname.validate(None))