示例#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)
示例#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)
示例#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)
示例#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)
示例#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)
示例#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
示例#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
示例#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)
示例#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
示例#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")
示例#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
示例#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
示例#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
示例#14
0
 def test_encode_idn(self):
     domain_bytes = encode_domain(self.idn_domain_name)
     self.assertEqual(domain_bytes, self.idn_domain_bytes)
示例#15
0
 def test_encode_good(self):
     domain_bytes = encode_domain(self.good_domain_name)
     self.assertEqual(domain_bytes, self.good_domain_bytes)
示例#16
0
 def test_encode_idn(self):
     domain_bytes = encode_domain(self.idn_domain_name)
     self.assertEqual(domain_bytes, self.idn_domain_bytes)
示例#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)
示例#18
0
 def test_encode_good(self):
     domain_bytes = encode_domain(self.good_domain_name)
     self.assertEqual(domain_bytes, self.good_domain_bytes)