def test_algorithmDefaultAttribute(self): """ L{dns.Record_CERT.algorithm} is a public L{int} attribute whose default value is 5 (RSA/SHA-1). Values are defined in DNSSEC https://tools.ietf.org/html/rfc4034#section-2.1.3 """ record = dns.Record_CERT() self.assertEqual(record.algorithm, 5) def test_algorithmOverride(self): """ L{dns.Record_CERT.__init__} accepts a C{algorithm} parameter which overrides the L{dns.Record_CERT.algorithm} attribute. """ record = dns.Record_CERT(algorithm=255) self.assertEqual(record.algorithm, 255) def test_publicKeyAttribute(self): """ L{dns.Record_CERT.publicKey} is a public L{bytes} attribute whose default value is C{b''}. https://tools.ietf.org/html/rfc4034#section-2.1.4 """ record = dns.Record_CERT() self.assertEqual(record.publicKey, b'') def test_publicKeyOverride(self): """ L{dns.Record_CERT.__init__} accepts a C{publicKey} parameter which overrides the L{dns.Record_CERT.publicKey} attribute. """ record = dns.Record_CERT(publicKey=b'foobar') self.assertEqual(record.publicKey, b'foobar') def test_encode(self): """ L{dns.Record_CERT.encode} packs the header fields and the key and writes them to a file like object passed in as an argument. """ record = DNSKEY_TEST_DATA.OBJECT() actualBytes = BytesIO() record.encode(actualBytes) self.assertEqual(actualBytes.getvalue(), DNSKEY_TEST_DATA.BYTES()) def test_decode(self): """ L{dns.Record_CERT.decode} unpacks the header fields from a file like object and populates the attributes of an existing L{dns.Record_CERT} instance. """ expectedBytes = DNSKEY_TEST_DATA.BYTES() record = dns.Record_CERT() record.decode(BytesIO(expectedBytes), length=len(expectedBytes)) self.assertEqual(record, DNSKEY_TEST_DATA.OBJECT()) def test_decodeShorterThanHeader(self): """ L{dns.Record_CERT.decode} raises L{EOFError} if the provided file object is shorter than the fixed length header parts. ie everything except key. """ record = dns.Record_CERT() self.assertRaises(EOFError, record.decode, BytesIO(b'x'), length=1) def test_decodeShorterThanKey(self): """ L{dns.Record_CERT.decode} raises L{EOFError} if the provided file object is shorter than length provided in the length argument. """ expectedBytes = DNSKEY_TEST_DATA.BYTES() record = dns.Record_CERT() self.assertRaises( EOFError, record.decode, BytesIO(expectedBytes[:-1]), length=len(expectedBytes))