Ejemplo n.º 1
0
    def test_encode_relative(self):
        domain_bytes = encode_domain(self.good_relative_domain_name,
                                     allow_relative=True)
        self.assertEqual(domain_bytes, self.good_relative_domain_bytes)

        domain_bytes = encode_domain(self.good_domain_name + '.',
                                     allow_relative=True)
        self.assertEqual(domain_bytes, self.good_domain_bytes)
Ejemplo n.º 2
0
 def validate(self):
     """
     Validate that the contents of this object conform to protocol specs.
     """
     # Allow for empty domain name
     if self.domain_name:
         # Otherwise try to encode it
         encode_domain(self.domain_name, allow_relative=True)
Ejemplo n.º 3
0
    def validate(self):
        """
        Validate that the contents of this object conform to protocol specs.
        """
        if not isinstance(self.fqdn, str):
            raise ValueError("FQDN must be a string")

        # Let the domain encoder check for errors
        encode_domain(self.fqdn)
Ejemplo n.º 4
0
    def validate(self):
        """
        Validate that the contents of this object conform to protocol specs.
        """
        if not isinstance(self.fqdn, str):
            raise ValueError("FQDN must be a string")

        # Let the domain encoder check for errors
        encode_domain(self.fqdn)
Ejemplo n.º 5
0
    def validate(self):
        """
        Validate that the contents of this object conform to protocol specs.
        """
        if not isinstance(self.domain_names, list):
            raise ValueError("Domain names must be a list of strings")

        for domain_name in self.domain_names:
            # Just encode to validate
            encode_domain(domain_name)
Ejemplo n.º 6
0
    def config_datatype(value: str) -> str:
        """
        Convert string data from the configuration to, well, a string. But a validated string!

        :param value: String from config file
        :return: Parsed fqdn
        """
        # Let the domain encoder check for errors
        encode_domain(value)
        return value
Ejemplo n.º 7
0
    def config_datatype(value: str) -> str:
        """
        Convert string data from the configuration to, well, a string. But a validated string!

        :param value: String from config file
        :return: Parsed fqdn
        """
        # Let the domain encoder check for errors
        encode_domain(value)
        return value
Ejemplo n.º 8
0
    def validate(self):
        """
        Validate that the contents of this object conform to protocol specs.
        """
        if len(self.domain_name) > 255:
            raise ValueError("Domain name must be 255 characters or less")

        # Allow for empty domain name
        if self.domain_name:
            # Otherwise try to encode it
            encode_domain(self.domain_name, allow_relative=True)
Ejemplo n.º 9
0
def domain_name(value: str) -> str:
    """
    Validate and clean a domain name.

    :param value: Domain name
    :return: Validated and cleaned domain name
    """
    # Lowercase
    value = value.lower()

    # Test validity by trying to encode it
    encode_domain(value)

    # Ok for now
    return value
Ejemplo n.º 10
0
    def validate(self):
        """
        Validate that the contents of this object conform to protocol specs.
        """
        if not isinstance(self.fqdn, str):
            raise ValueError("Tunnel endpoint name must be a string")

        # Let the domain encoder check for errors
        fqdn = encode_domain(self.fqdn)

        if len(fqdn) < 4:
            raise ValueError("The FQDN of the tunnel endpoint is too short")
Ejemplo n.º 11
0
    def save(self) -> Union[bytes, bytearray]:
        """
        Save the internal state of this object as a buffer.

        :return: The buffer with the data from this element
        """
        fqdn_buffer = encode_domain(self.fqdn)

        buffer = bytearray()
        buffer.extend(pack('!HH', self.option_type, len(fqdn_buffer)))
        buffer.extend(fqdn_buffer)
        return buffer
Ejemplo n.º 12
0
    def save(self) -> bytes:
        """
        Save the internal state of this object as a buffer.

        :return: The buffer with the data from this element
        """
        fqdn_buffer = encode_domain(self.fqdn)

        buffer = bytearray()
        buffer.extend(pack('!HH', self.suboption_type, len(fqdn_buffer)))
        buffer.extend(fqdn_buffer)
        return buffer
Ejemplo n.º 13
0
    def save(self) -> Union[bytes, bytearray]:
        """
        Save the internal state of this object as a buffer.

        :return: The buffer with the data from this element
        """
        domain_buffer = encode_domain(self.domain_name)

        buffer = bytearray()
        buffer.extend(pack('!HHB', self.option_type, 1 + len(domain_buffer), self.flags))
        buffer.extend(domain_buffer)
        return buffer
Ejemplo n.º 14
0
 def test_encode_idn(self):
     domain_bytes = encode_domain(self.idn_domain_name)
     self.assertEqual(domain_bytes, self.idn_domain_bytes)
Ejemplo n.º 15
0
 def test_encode_good(self):
     domain_bytes = encode_domain(self.good_domain_name)
     self.assertEqual(domain_bytes, self.good_domain_bytes)
Ejemplo n.º 16
0
 def test_encode_idn(self):
     domain_bytes = encode_domain(self.idn_domain_name)
     self.assertEqual(domain_bytes, self.idn_domain_bytes)
Ejemplo n.º 17
0
    def test_encode_relative(self):
        domain_bytes = encode_domain(self.good_domain_name, allow_relative=True)
        self.assertEqual(domain_bytes, self.good_relative_domain_bytes)

        domain_bytes = encode_domain(self.good_domain_name + '.', allow_relative=True)
        self.assertEqual(domain_bytes, self.good_domain_bytes)
Ejemplo n.º 18
0
 def test_encode_good(self):
     domain_bytes = encode_domain(self.good_domain_name)
     self.assertEqual(domain_bytes, self.good_domain_bytes)