Ϫf?xdZddlZddlmZddlmZddlmZmZddl m Z m Z ddl m Z ddlmZdd lmZmZdd lmZdd lmZdd lmZe j2e j4e j6e j8e j:e j<e j>e j@e jBe jDe jFe jHe jJe jLe jNe jPe jRe jTe jVe jXe jZe j\e j^e j`e jbe jdgZ3Gd dejhZ5GddejlZ7GddejlZ8GddejlZ9GddejlZ:dZ;dZ<GddejhZ=GddeejhZ>GddZ?Gdd ejlZ@Gd!d"e?ZAGd#d$ejlZBGd%d&ejlZCGd'd(eejlZDGd)d*ejlZEGd+d,ejhZFd-ZGd.ZHGd/d0ejhZIGd1d2ZJGd3d4eejlZKGd5d6eejlZLGd7d8eMZNGd9d:ZOGd;d<ZPGd=d>ZQGd?d@ZRGdAdBZSGdCdDZTGdEdFZUGdGdHZVGdIdJeeZW dfdKZXGdLdMZYGdNdOZZGdPdQeYeZejhZ[GdRdSeYeZejhZ\GdTdUeYejhZ]GdVdWeejhZ^GdXdYZ_GdZd[e_ejhZ`Gd\d]e_ejhZaGd^d_ejhZbGd`daejhZcGdbdcZdGdddeejhZey)gz Tests for twisted.names.dns. N)BytesIO) verifyClass)addresstask)CannotListenErrorConnectionDone)dns)Failure) FancyEqMixin FancyStrMixin) proto_helpers)ComparisonTestsMixin)unittestc*eZdZdZdZdZdZdZy)DomainStringTestscN|jdtjdy)zA L{dns.domainString} returns L{bytes} unchanged. stwistedmatrix.comN assertEqualr domainStringselfs =/usr/lib/python3/dist-packages/twisted/names/test/test_dns.py test_byteszDomainStringTests.test_bytes7s$    1 2 cN|jdtjdy)z` L{dns.domainString} converts a native string to L{bytes} if necessary. example.com example.comNrrs r test_nativezDomainStringTests.test_native@s )9)9-)HIrcN|jdtjdy)zS L{dns.domainString} always converts a unicode string to L{bytes}. s foo.examplez foo.exampleNrrs r test_textzDomainStringTests.test_textGs )9)9-)HIrcN|jdtjdy)A L{dns.domainString} encodes Unicode using IDNA. s xn--fwg.testu‽.testNrrs r test_idnazDomainStringTests.test_idnaMs #*:*:=*IJrc|jttjd|jttjtjdy)r"i(#z bar.exampleN) assertRaises TypeErrorr rNamers r test_nonsensezDomainStringTests.test_nonsenseSs= )S%5%5t< )S%5%5sxx 7NOrN)__name__ __module__ __qualname__rrr r#r(rrrr6s JJ K PrrceZdZdZdZy) Ord2ByteTestsz& Tests for L{dns._ord2bytes}. cN|jdtjdy)z L{dns._ord2byte} accepts an integer and returns a byte string of length one with an ordinal value equal to the given integer. N)rr _ord2bytesrs r test_ord2bytezOrd2ByteTests.test_ord2byte`s #.."67rN)r)r*r+__doc__r3r,rrr.r.[s 8rr.cHeZdZdZdZdZdZdZdZdZ dZ d Z d d Z y ) Str2TimeTestsz$ Tests for L{dns.str2name}. cbt}|j|tj|y)zY When passed a non-string object, L{dns.str2name} returns it unmodified. N)objectassertIsr str2time)rtimes rtest_nonStringzStr2TimeTests.test_nonStringms"x dCLL./rcN|jdtjdy)z Passed a string giving a number of seconds, L{dns.str2time} returns the number of seconds represented. For example, C{"10S"} represents C{10} seconds. 10SNrr r:rs r test_secondszStr2TimeTests.test_secondsts S\\%01rcN|jdtjdy)z Like C{test_seconds}, but for the C{"M"} suffix which multiplies the time value by C{60} (the number of seconds in a minute!). x2MNr@rs r test_minuteszStr2TimeTests.test_minutes|s d!34rcN|jdtjdy)z Like C{test_seconds}, but for the C{"H"} suffix which multiplies the time value by C{3600}, the number of seconds in an hour. i0*3HNr@rs r test_hourszStr2TimeTests.test_hourss 3<<#56rcN|jdtjdy)z Like L{test_seconds}, but for the C{"D"} suffix which multiplies the time value by C{86400}, the number of seconds in a day. iF4DNr@rs r test_dayszStr2TimeTests.test_dayss CLL$67rcN|jdtjdy)z Like L{test_seconds}, but for the C{"W"} suffix which multiplies the time value by C{604800}, the number of seconds in a week. i$.5WNr@rs r test_weekszStr2TimeTests.test_weekss S\\$%78rcN|jdtjdy)z Like L{test_seconds}, but for the C{"Y"} suffix which multiplies the time value by C{31536000}, the number of seconds in a year. i5G 6YNr@rs r test_yearszStr2TimeTests.test_yearss s||D'9:rcN|jttjdy)zY If a non-integer prefix is given, L{dns.str2time} raises L{ValueError}. fooSNr% ValueErrorr r:rs rtest_invalidPrefixz Str2TimeTests.test_invalidPrefixs *cllF;rNcN|jttjdy)zV If an invalid suffix is given, L{dns.str2time} raises L{ValueError}. 1QNrTrs rtest_invalidSuffixz Str2TimeTests.test_invalidSuffixs *cllD9r)returnN) r)r*r+r4r<rArErHrKrNrQrVrYr,rrr6r6hs4025789;< :rr6cLeZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z y ) NameTestsz Tests for L{Name}, the representation of a single domain name with support for encoding into and decoding from DNS message format. c|jttjd|jttjt |jttjgy)zy When constructed with a name which is neither C{bytes} nor C{str}, L{Name} raises L{TypeError}. {N)r%r&r r'r8rs rtest_nonStringNamezNameTests.test_nonStringNamesH )SXXs3 )SXXvx8 )SXXr2rctjd}|j|jt|j d|jy)zg L{dns.Name} automatically encodes unicode domain name using C{idna} encoding. uéchec.example.orgsxn--chec-9oa.example.orgN)r r'assertIsInstancenamebytesr)rrbs rtest_unicodeNamezNameTests.test_unicodeNames< xx01 dii/ 4dii@rctj}|jtd|j |j dy)z L{Name.decode} populates the L{Name} instance with name information read from the file-like object passed to it. examplecomrN)r r'decoderrrb)rns r test_decodezNameTests.test_decodes5 HHJ 234 0rctjd}t}|j||j |j dy)zy L{Name.encode} encodes its name information and writes it to the file-like object passed to it. foo.example.comsfooexamplecomN)r r'rencodergetvaluerrbstreams r test_encodezNameTests.test_encodes> xx*+ F *,LMrcbtjd}ddi}d}t}|j|t |tj j z}|j|||jd|jt |d|jd|d|y)am If a compression dictionary is passed to it, L{Name.encode} uses offset information from it to encode its name with references to existing labels in the stream instead of including another copy of them in the output. It also updates the compression dictionary with the location of the name it writes to the stream. rkrssome prefix to change .tell()sfooN)rrk) r r'rwritelenMessage headerSizerlrrm)rrb compressionpreviousroexpecteds rtest_encodeWithCompressionz$NameTests.test_encodeWithCompressionsxx*+%t, 4 Xx=3;;#9#99 FK( +V__->s8}-OP !x @+ rc \d}tj}|j||j|jtj dddg|j|j tjddddtjdd g|j|jtjd tjtjdtjd d g|j}|j||y ) z A resource record of unknown type and class is parsed into an L{UnknownRecord} instance with its data preserved, and an L{UnknownRecord} instance is serialized to a string equal to the one it was parsed from. sDfoobarޭ ޭsomedatabazbanfoo.barii)typeclsissomedatattlr}r~rpayloadsbaz.ban1.2.3.4N)r rufromStrrqueriesQueryanswersRRHeader UnknownRecord additionalAINRecord_AtoStr)rwiremsgencs r test_unknownzNameTests.test_unknowns  :kkm D  KK *6v>   KK --ksC     NN LL<   iik d#rc2td}|jdtj}|j ||j d|j |j d|j|j ||j |j d|j d|j|j ||j |j d|j d|jy ) a If the leading byte of an encoded label (in bytes read from a stream passed to L{Name.decode}) has its two high bits set, the next byte is treated as a pointer to another label in the stream and that label is included in the name being decoded. s,xxxxxxxxxxxxxxxxxxxxfisiarpafoobar s f.isi.arpa sfoo.f.isi.arpa&sbar.foo.f.isi.arpa,N)rseekr r'rgrrbtell)rrorbs rtest_decodeWithCompressionz$NameTests.test_decodeWithCompression:s    Bxxz F  2 V[[]+ F $56 V[[]+ F $9: V[[]+rctj}td}|jt|j |y)z L{Name.decode} raises L{ValueError} if the stream passed to it includes a compression pointer which forms a loop, causing the name to be undecodable. sN)r r'rr%rUrgrns rtest_rejectCompressionLoopz$NameTests.test_rejectCompressionLoopYs/ xxz% *dkk6:rctjd}tjd}|j||tjd}|j||y)z L{Name} instances are equal as long as they have the same value for L{Name.name}, regardless of the case. r|sfOO.barN)r r'r)rname1name2name3s r test_equalityzNameTests.test_equalitycsN $$ &$ &rc|tjd}tjd}|j||y)zq L{Name} instances are not equal as long as they have different L{Name.name} attributes. r|sbar.fooN)r r'assertNotEqual)rrrs rtest_inequalityzNameTests.test_inequalityos0 $$ E5)rN)r)r*r+r4r_rdrirprzrrrrrr,rrr\r\s= 3A1N 2H$T,>; '*rr\ceZdZdZgdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZy)RoundtripDNSTestsz5 Encoding and then decoding various objects. ) example.orgsgo-away.fish.tvs23strikesback.netc(|jD]}t}tj|j ||j ddtj}|j ||j|j|y)Nr) namesrr r'rlrrgrrbrrhfresults r test_namezRoundtripDNSTests.test_namesl -A A HHQK  q ! FF1aLXXZF MM!    V[[! , -rc|jD]}tddD]}tddD]}t}tj|||j ||j ddtj}|j||j|jj||j|j||j|j|y)z L{dns.Query.encode} returns a byte string representing the fields of the query which can be decoded into a new L{dns.Query} instance using L{dns.Query.decode}. rN) rrangerr rrlrrgrrbr}r~)rrhdnstypednsclsrrs r test_queryzRoundtripDNSTests.test_querys  9A B< 9#Aqk 9F AIIa&188;FF1aL YY[FMM!$$$V[[%5%5q9$$V[[':$$VZZ8 9 9 9rct}tjddddj||j ddtj}|j ||j |jtjd|j |jd|j |jd|j |jdy)a L{dns.RRHeader.encode} encodes the record header's information and writes it to the file-like object passed to it and L{dns.RRHeader.decode} reads from a file-like object to re-construct a L{dns.RRHeader} instance. stest.orgrrN) rr rrlrrgrrbr'r}r~r)rrrs rtest_resourceRecordHeaderz+RoundtripDNSTests.test_resourceRecordHeaders I [!Q+2215 q!  a chh{&;< a( Q' R(rc|jtd5tjtjtj dddy#1swYyxYw)zy L{RRHeader()} raises L{ValueError} when the given type and the type of the payload don't match. z#Payload type \(AAAA\) .* type \(A\)r}rN)assertRaisesRegexrUr rr Record_AAAArs r%test_resourceRecordHeaderTypeMismatchz7RoundtripDNSTests.test_resourceRecordHeaderTypeMismatchsG  # #J0V W @ LLceeS__-> ? @ @ @s 8AA!c>d}|D]}t}tj|j||j ddtj}|j ||j |jtj|y)a  L{dns.SimpleRecord.encode} encodes the record's name information and writes it to the file-like object passed to it and L{dns.SimpleRecord.decode} reads from a file-like object to re-construct a L{dns.SimpleRecord} instance. )sthis.are.test.names0will.compress.will.this.will.name.will.hopefullystest.CASE.preSErVatIOn.YeAHsa.s.h.o.r.t.c.a.s.e.t.o.t.e.s.ts singletonrN) rr SimpleRecordrlrrgrrbr')rrsrrs rtest_resourcesz RoundtripDNSTests.test_resourcess}  7A A   Q  & &q ) FF1aL%%'F MM!    V[[#((1+ 6  7rc tD]B}||}}t|}t|}|j|||d|d|dDy)z= Instances of all record types are hashable. z != z (for )N) RECORD_TYPEShashr)rkk1k2hk1hk2s r test_hashablezRoundtripDNSTests.test_hashablesY DAS!#Br(Cr(C   S##d3%vaS'B C  Drc(|jD]}t}tj|j ||j ddtj}|j ||j|j|y)z8 Test L{dns.Charstr} encode and decode. rN) rrr Charstrrlrrgrstringrs r test_CharstrzRoundtripDNSTests.test_Charstrsn /A A KKN ! !! $ FF1aL[[]F MM!    V]]A . /rct}|j||j}|jdd|j }|j |||j ||y)z Assert that encoding C{record} and then decoding the resulting bytes creates a record which compares equal to C{record}. @type record: L{dns.IEncodable} @param record: A record instance to encode rN)rrlrr __class__rgr)rrecordrolengthreplicas r_recordRoundtripTestz&RoundtripDNSTests._recordRoundtripTests\ f Aq""$vv& )rczt}|j||j|j|y)a3 Assert that encoding C{record} produces the expected bytes. @type record: L{dns.IEncodable} @param record: A record instance to encode @type expectedEncoding: L{bytes} @param expectedEncoding: The value which C{record.encode()} should produce. N)rrlrrm)rexpectedEncodingrros rassertEncodedFormatz%RoundtripDNSTests.assertEncodedFormats/ f *,<=rc Z|jtjdddddddy ) z The byte stream written by L{dns.Record_SOA.encode} can be used by L{dns.Record_SOA.decode} to reconstruct the state of the original L{dns.Record_SOA} instance. foobar "8NZ)mnamernameserialrefreshretryexpireminimumN)rr Record_SOArs rtest_SOAzRoundtripDNSTests.test_SOAs3 !! NN  rcL|jtjdy)z The byte stream written by L{dns.Record_A.encode} can be used by L{dns.Record_A.decode} to reconstruct the state of the original L{dns.Record_A} instance. rN)rr rrs rtest_AzRoundtripDNSTests.test_A s !!#,,y"9:rcL|jtjdy)z The byte stream written by L{dns.Record_NULL.encode} can be used by L{dns.Record_NULL.decode} to reconstruct the state of the original L{dns.Record_NULL} instance. sfoo barN)rr Record_NULLrs r test_NULLzRoundtripDNSTests.test_NULL(s !!#//*"=>rcP|jtjdddy)z The byte stream written by L{dns.Record_WKS.encode} can be used by L{dns.Record_WKS.decode} to reconstruct the state of the original L{dns.Record_WKS} instance. rrsxyzN)rr Record_WKSrs rtest_WKSzRoundtripDNSTests.test_WKS0s !!#..Av"FGrcL|jtjdy)z The byte stream written by L{dns.Record_AAAA.encode} can be used by L{dns.Record_AAAA.decode} to reconstruct the state of the original L{dns.Record_AAAA} instance. z::1N)rr rrs r test_AAAAzRoundtripDNSTests.test_AAAA8s !!#//%"89rcP|jtjdddy)z The byte stream written by L{dns.Record_A6.encode} can be used by L{dns.Record_A6.decode} to reconstruct the state of the original L{dns.Record_A6} instance. z::1:2rN)rr Record_A6rs rtest_A6zRoundtripDNSTests.test_A6@s !!#--7F"CDrcT|jtjddddy)z The byte stream written by L{dns.Record_SRV.encode} can be used by L{dns.Record_SRV.decode} to reconstruct the state of the original L{dns.Record_SRV} instance. rrr)priorityweightporttargetN)rr Record_SRVrs rtest_SRVzRoundtripDNSTests.test_SRVHs$ !! NNAaa O rcd}tjtjjtjj|}|j ||j d|z|y)z The byte stream written by L{dns.Record_SSHFP.encode} can be used by L{dns.Record_SSHFP.decode} to reconstruct the state of the original L{dns.Record_SSHFP} instance. s9^kK 2U` ) algorithmfingerprintType fingerprintsN)r Record_SSHFP ALGORITHM_DSSFINGERPRINT_TYPE_SHA1rr)rfprrs r test_SSHFPzRoundtripDNSTests.test_SSHFPRse B   &&44,,BB  !!"%   r!126rc @ddg}|D]\}}}}}}tj||||||}t} |j| | j ddtj} | j | |j |j| j|j |j| j|j |j| j|j |j| j|j |j| j|j |jj| jj|j |j| jy)z= Test L{dns.Record_NAPTR} encode and decode. )dr>usip+E2Us!!^.*$!sip:information@domain.tld!r)r 2sshttp+I2L+I2C+I2Rrs_http._tcp.gatech.edurN)r Record_NAPTRrrlrrgrorder preferenceflagsserviceregexp replacementrbr) rnaptrsrrrrrrrinerouts r test_NAPTRzRoundtripDNSTests.test_NAPTRes? S O  GM 0 BE:ugv{""z5'6;C A JJqM FF1aL##%D KKN   SYY 3   S^^T__ =   SYY 3   S[[$,, 7   SZZ 5   S__1143C3C3H3H I   SWWdhh / 0rcP|jtjddy)z The byte stream written by L{dns.Record_AFSDB.encode} can be used by L{dns.Record_AFSDB.decode} to reconstruct the state of the original L{dns.Record_AFSDB} instance. rr)subtypehostnameN)rr Record_AFSDBrs r test_AFSDBzRoundtripDNSTests.test_AFSDBs !!#"2"21~"VWrcP|jtjddy)z The byte stream written by L{dns.Record_RP.encode} can be used by L{dns.Record_RP.decode} to reconstruct the state of the original L{dns.Record_RP} instance. alice.example.comr)mboxtxtN)rr Record_RPrs rtest_RPzRoundtripDNSTests.test_RPs! !! MM3 H rcP|jtjddy)z The byte stream written by L{dns.Record_HINFO.encode} can be used by L{dns.Record_HINFO.decode} to reconstruct the state of the original L{dns.Record_HINFO} instance. sfastsgreat)cpuosN)rr Record_HINFOrs r test_HINFOzRoundtripDNSTests.test_HINFOs !!#"2"2w8"LMrcP|jtjddy)z The byte stream written by L{dns.Record_MINFO.encode} can be used by L{dns.Record_MINFO.decode} to reconstruct the state of the original L{dns.Record_MINFO} instance. rr)rmailbxemailbxN)rr Record_MINFOrs r test_MINFOzRoundtripDNSTests.test_MINFOs !!#"2"266"RSrcP|jtjddy)z The byte stream written by L{dns.Record_MX.encode} can be used by L{dns.Record_MX.decode} to reconstruct the state of the original L{dns.Record_MX} instance. rr)rrbN)rr Record_MXrs rtest_MXzRoundtripDNSTests.test_MXs !!#--1>"RSrc:d}tjdddd|}|j|d|zdz}|j||tjd d d tjd | }|j|d|zdz}|j||y)z The byte stream written by L{dns.Record_TSIG.encode} can be used by L{dns.Record_TSIG.decode} to reconstruct the state of the original L{dns.Record_TSIG} instance. s !"#0123zhmac-md5.sig-alg.reg.int/qUZ*r)r timeSigned originalIDfudgeMACs$hmac-md5sig-algregintZUq/s*z hmac-sha256l's)rr8r9error otherDatar;s hmac-sha256 's N)r Record_TSIGrrEBADTIME)rmacr rdatas r test_TSIGzRoundtripDNSTests.test_TSIGs V __0!   !!"% 8 * *    + __#!,,1   !!"% 8 ( (    +rcN|jtjddy)z The byte stream written by L{dns.Record_TXT.encode} can be used by L{dns.Record_TXT.decode} to reconstruct the state of the original L{dns.Record_TXT} instance. rrN)rr Record_TXTrs rtest_TXTzRoundtripDNSTests.test_TXTs !!#.."@ArN)r)r*r+r4rrrrrrrrrrrrrrrrrr rr!r'r,r1r4rCrFr,rrrrys GE -9*)(@7,D /*">  $;?H:E 7&04X NTT',RBrrs s c|eZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZy) MessageTestsz1 Tests for L{twisted.names.dns.Message}. c`|jtjjdy)zC L{dns.Message.authenticData} has default value 0. rNrr ru authenticDatars rtest_authenticDataDefaultz&MessageTests.test_authenticDataDefaults  44a8rcd|jtjdjdy)z L{dns.Message.__init__} accepts a C{authenticData} argument which is assigned to L{dns.Message.authenticData}. rrKNrJrs rtest_authenticDataOverridez'MessageTests.test_authenticDataOverrides# 15CCQGrct|jtjdjty)zr L{dns.Message.toStr} encodes L{dns.Message.authenticData} into byte4 of the byte string. rrNN)rr rurMESSAGE_AUTHENTIC_DATA_BYTESrs rtest_authenticDataEncodez%MessageTests.test_authenticDataEncodes*  KKa ( . . 02N rctj}|jt|j |j dy)zp L{dns.Message.fromStr} decodes byte4 and assigns bit3 to L{dns.Message.authenticData}. rN)r rurrQrrKrms rtest_authenticDataDecodez%MessageTests.test_authenticDataDecode s0 KKM ./ !,rc`|jtjjdy)zF L{dns.Message.checkingDisabled} has default value 0. rNrr rucheckingDisabledrs rtest_checkingDisabledDefaultz)MessageTests.test_checkingDisabledDefaults  77;rcd|jtjdjdy)z L{dns.Message.__init__} accepts a C{checkingDisabled} argument which is assigned to L{dns.Message.checkingDisabled}. rrYNrXrs rtest_checkingDisabledOverridez*MessageTests.test_checkingDisabledOverrides# a8II1Mrct|jtjdjty)zu L{dns.Message.toStr} encodes L{dns.Message.checkingDisabled} into byte4 of the byte string. rr\N)rr rurMESSAGE_CHECKING_DISABLED_BYTESrs rtest_checkingDisabledEncodez(MessageTests.test_checkingDisabledEncode#s*  KK + 1 1 35T rctj}|jt|j |j dy)zs L{dns.Message.fromStr} decodes byte4 and assigns bit4 to L{dns.Message.checkingDisabled}. rN)r rurr_rrYrTs rtest_checkingDisabledDecodez(MessageTests.test_checkingDisabledDecode,s2 KKM 12 ++Q/rc^|jdttjy)z L{dns.Message.__repr__} omits field values and sections which are identical to their defaults. The id field value is always shown. zN)rreprr rurs rtest_reprDefaultszMessageTests.test_reprDefaults6s )4 +>?rc rtjddddddd}|jdt|y)zM L{dns.Message.__repr__} displays flags if they are L{True}. T)answerauthtruncrecDesrecAvrKrYzRNr rurrdrTs rtest_reprFlagsIfSetz MessageTests.test_reprFlagsIfSet=sE KK!    G  rcltjdddd}|jdt|y)zk L{dns.Message.__repr__} displays field values if they differ from their defaults. r>r()idopCoderCodemaxSizez-NrlrTs rtest_reprNonDefautFieldsz%MessageTests.test_reprNonDefautFieldsSs0 KK2bB ?  J G rctj}gd|_gd|_gd|_gd|_|j dt|y)e L{dns.Message.__repr__} displays sections which differ from their defaults. rrrrrr r> rz^N)r rurr authorityrrrdrTs rtest_reprNonDefaultSectionsz(MessageTests.test_reprNonDefaultSections^sG KKM   #    G rcntj}|jt|jdy)zy Test that a message which has been truncated causes an EOFError to be raised when it is parsed. rN)r rur%EOFErrorrrrs rtest_emptyMessagezMessageTests.test_emptyMessagess% kkm (CKK5rcbtj}|jd|j|jd|j |j d|j|jtj|j |jd|j |jd|j|jg|j|jg|j|jg|j|jgy)ze Test that bytes representing an empty query message can be decoded as such. s z)Message was not supposed to be an answer.z-Message was not supposed to be authoritative.z)Message was not supposed to be truncated.N)r rurrrq assertFalsergrrOP_QUERYrhrirrrrrs rtest_emptyQueryzMessageTests.test_emptyQuery{s kkm    % %PQ S\\2 #RS $OP b) b) + ,rcdjtdDcgc]}tj|c}}tj|}tj dtj |}tj}|jj|t}|j||jddtj}|j||j|jdjtj|j!|jdjj|ycc}w)z| A I{NULL} record with an arbitrary payload can be encoded and decoded as part of a L{dns.Message}. rrtestnamerrN)joinrr r2rrNULLrurappendrrlrrgrarrrircrecr msg1rmsg2s rrzMessageTests.test_NULLs U3Z@#..+@Aooe$ \\+sxx ={{} B I A q! {{} A dll1o55sG a0088%@AsE#c|jtjjdtjy)z L{Message.lookupRecordType} returns C{dns.UnknownRecord} if it is called with an integer which doesn't correspond to any known record type. iN)r9r rulookupRecordTyperrs rtest_lookupRecordTypeDefaultz)MessageTests.test_lookupRecordTypeDefaults) ckkm44U;S=N=NOrct}tjtjdd}|j |tj }|j d|jz|j|j|g|j|jdjy)z The L{RRHeader} instances created by L{Message} from a non-authoritative message are marked as not authoritative. rrrrs N) rr rrrlrurrmrrrrhrbufrgmessages rtest_nonAuthoritativeMessagez)MessageTests.test_nonAuthoritativeMessages icll9!&DE c++- ,,. )  6(3 +001rct}tjtjdd}|j |tj }|j d|jzd|_|j|j|g|j|jdjy)z The L{RRHeader} instances created by L{Message} from an authoritative message are marked as authoritative. rrrrs TN) rr rrrlrurrmrhrr assertTruers rtest_authoritativeMessagez&MessageTests.test_authoritativeMessages icll9!&DE c++- ,,. )   6(3 *//0rN)r)r*r+r4rLrOrRrVrZr]r`rbrermrurrrrrrrr,rrrHrHsf9 H -< N 0@ ,   *6-4A& P201rrHcpeZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZy)MessageComparisonTestszD Tests for the rich comparison of L{dns.Message} instances. c|jdg}|jdg}|jdg}|jdg}tjdi|}|r||_|r||_|r||_|r||_|S)a Create a L{dns.Message}. The L{dns.Message} constructor doesn't accept C{queries}, C{answers}, C{authority}, C{additional} arguments, so we extract them from the kwargs supplied to this factory function and assign them to the message. @param args: Positional arguments. @param kwargs: Keyword arguments. @return: A L{dns.Message} instance. rrrrr,)popr rurrrr)rargskwargsrrrrrUs rmessageFactoryz%MessageComparisonTests.messageFactorys**Y+**Y+JJ{B/ ZZ b1 KK !& ! AI AI #AK %ALrc|j|jd|jd|jdy)zd Two L{dns.Message} instances compare equal if they have the same id value. r>rqrN"assertNormalEqualityImplementationrrs rtest_idzMessageComparisonTests.test_idsE //   2  &   2  &   2  & rc|j|jd|jd|jdy)zg Two L{dns.Message} instances compare equal if they have the same answer flag. rrgrNrrs r test_answerz"MessageComparisonTests.test_answerE //   q  )   q  )   q  ) rc|j|jd|jd|jdy)zh Two L{dns.Message} instances compare equal if they have the same opCode value. r>rrrNrrs r test_opCodez"MessageComparisonTests.test_opCodesE //   r  *   r  *   r  * rc|j|jd|jd|jdy)zg Two L{dns.Message} instances compare equal if they have the same recDes flag. rrjrNrrs r test_recDesz"MessageComparisonTests.test_recDes&rrc|j|jd|jd|jdy)zf Two L{dns.Message} instances compare equal if they have the same recAv flag. rrkrNrrs r test_recAvz!MessageComparisonTests.test_recAv1E //   a  (   a  (   a  ( rc|j|jd|jd|jdy)ze Two L{dns.Message} instances compare equal if they have the same auth flag. rrhrNrrs r test_authz MessageComparisonTests.test_auth<sE //   Q  '   Q  '   Q  ' rc|j|jd|jd|jdy)zg Two L{dns.Message} instances compare equal if they have the same rCode value. r>rsrNrrs r test_rCodez!MessageComparisonTests.test_rCodeGE //   b  )   b  )   b  ) rc|j|jd|jd|jdy)zf Two L{dns.Message} instances compare equal if they have the same trunc flag. rrirNrrs r test_truncz!MessageComparisonTests.test_truncRrrc|j|jd|jd|jdy)zi Two L{dns.Message} instances compare equal if they have the same maxSize value. r>rtrNrrs r test_maxSizez#MessageComparisonTests.test_maxSize]sE //     +     +     + rc|j|jd|jd|jdy)zn Two L{dns.Message} instances compare equal if they have the same authenticData flag. rrNrNrrs rtest_authenticDataz)MessageComparisonTests.test_authenticDatahsE //   a  0   a  0   a  0 rc|j|jd|jd|jdy)zq Two L{dns.Message} instances compare equal if they have the same checkingDisabled flag. rr\rNrrs rtest_checkingDisabledz,MessageComparisonTests.test_checkingDisabledssE //     3     3     3 rc |j|jtjdg|jtjdg|jtjdgy)zc Two L{dns.Message} instances compare equal if they have the same queries. rrrNrrr rrs r test_queriesz#MessageComparisonTests.test_queries~i //   >)B(C  D   >)B(C  D   >)B(C  D rc |j|jtjdtjdg|jtjdtjdg|jtjdtjdgy)zc Two L{dns.Message} instances compare equal if they have the same answers. rrrrr4.3.2.1Nrrr rrrs r test_answersz#MessageComparisonTests.test_answers //   ncll9>UVW     ncll9>UVW     ncll9>UVW   rc |j|jtjdtjtj g|jtjdtjtj g|jtjdtjtj gy)zm Two L{dns.Message} instances compare equal if they have the same authority records. rrrrNrrr rSOArrs rtest_authorityz%MessageComparisonTests.test_authority //   LLcggs~~GWX     LLcggs~~GWX     LLcggs~~GWX   rc |j|jtjdtjdg|jtjdtjdg|jtjdtjdgy)zn Two L{dns.Message} instances compare equal if they have the same additional records. rrrrrNrrs rtest_additionalz&MessageComparisonTests.test_additional //   LLi9PQ     LLi9PQ     LLi9PQ   rN)r)r*r+r4rrrrrrrrrrrrrrrrr,rrrrsW6                         " . rrceZdZdZdZddZy)TestControllerz Pretend to be a DNS query processor for a DNSDatagramProtocol. @ivar messages: the list of received messages. @type messages: C{list} of (msg, protocol, address) cg|_y)zG Initialize the controller: create a list of messages. N)messagesrs r__init__zTestController.__init__s  rNc@|jj|||fy)zN Save the message so that it can be checked during the tests. N)rr)rrprotoaddrs rmessageReceivedzTestController.messageReceiveds c5$/0rN)r)r*r+r4rrr,rrrrs 1rrc@eZdZdZdZdZdZdZdZdZ dZ d Z y ) DatagramProtocolTestsz= Test various aspects of L{dns.DNSDatagramProtocol}. cDtj|_t|_t j |j|_tj}|jj||jj|j_ y)zQ Create a L{dns.DNSDatagramProtocol} with a deterministic clock. N) rClockclockr controllerr DNSDatagramProtocolrr FakeDatagramTransportmakeConnection callLater)r transports rsetUpzDatagramProtocolTests.setUpsgZZ\ (*,,T__= !779  !!),#zz33 rc|jjdtjddd|j |j j gy)z Test that when a short datagram is received, datagramReceived does not raise an exception while processing it. rUDP 127.0.0.190NrdatagramReceivedr IPv4Addressrrrrs rtest_truncatedPacketz*DatagramProtocolTests.test_truncatedPacketsB ##C)<).cb+   V^^A.66AACY Or)rqueryr rrrt liveMessageskeysrunextiterrqrrr addCallbackrr)rdrUr s` rtest_simpleQueryz&DatagramProtocolTests.test_simpleQuery s JJ  1CIIf4E3F G TZZ4499; Test that query timeouts after some seconds. rrrr>r rr r rrrtrradvance assertFailureDNSQueryTimeoutErrorrrs rtest_queryTimeoutz'DatagramProtocolTests.test_queryTimeouts JJ  1CIIf4E3F G TZZ445q9 2 1c667 TZZ445q9rcd}||jj_|jjdt j dg}|j |tS)z Exceptions raised by the transport's write method should be turned into C{Failure}s passed to errbacks of the C{Deferred} returned by L{DNSDatagramProtocol.query}. ctdNbar RuntimeError)rrs r writeErrorz9DatagramProtocolTests.test_writeError..writeError- u% %rrrrrrsr r rrr"rr#rs rtest_writeErrorz%DatagramProtocolTests.test_writeError&sQ &&0 " JJ  1CIIf4E3F G!!!\22rcd}||j_d|j_|jjdt j dg}|j |tS)z Exception L{CannotListenError} raised by C{listenUDP} should be turned into a C{Failure} passed to errback of the C{Deferred} returned by L{DNSDatagramProtocol.query}. ctdddr)rr,rrstartListeningErrorzCDatagramProtocolTests.test_listenError..startListeningError<s#D$5 5rNrr)rstartListeningrr r rrr)rr*rs rtest_listenErrorz&DatagramProtocolTests.test_listenError5sX 6%8 !#  JJ  1CIIf4E3F G!!!%677rc~tj}d|_tjtjdg|_|j j|jd|j|jjddj|jy) z When receiving a message whose id is not in L{DNSDatagramProtocol.liveMessages} or L{DNSDatagramProtocol.resends}, the message will be received by L{DNSDatagramProtocol.controller}. rrrrrrN) r rurqrrrrrrrrr)rrs r$test_receiveMessageNotInLiveMessagesz:DatagramProtocolTests.test_receiveMessageNotInLiveMessagesFs ++- << Y0OPQ ##GMMO5IJ 11"5a8>>@'--/RrN) r)r*r+r4rrrrrr'r,r/r,rrrrs0 477("  38" Srrc"eZdZdZdZdZdZy)TestTCPControllera  Pretend to be a DNS query processor for a DNSProtocol. @ivar connections: A list of L{DNSProtocol} instances which have notified this controller that they are connected and have not yet notified it that their connection has been lost. c<tj|g|_yr)rr connectionsrs rrzTestTCPController.__init__\s%rc:|jj|yr)r3rrrs rconnectionMadez TestTCPController.connectionMade` &rc:|jj|yr)r3remover5s rconnectionLostz TestTCPController.connectionLostcr7rN)r)r*r+r4rr6r:r,rrr1r1Ss''rr1c4eZdZdZdZdZdZdZdZdZ y) DNSProtocolTestsz5 Test various aspects of L{dns.DNSProtocol}. c@tj|_t|_t j |j|_|jjtj|jj|j_ y)zI Create a L{dns.DNSProtocol} with a deterministic clock. N) rrrr1rr DNSProtocolrrr StringTransportrrs rrzDNSProtocolTests.setUpls`ZZ\ +-__T__5  !!-"?"?"AB#zz33 rc |j|jj|jg|jj t t d|j|jjgy)z L{dns.DNSProtocol} calls its controller's C{connectionMade} method with itself when it is connected to a transport and its controller's C{connectionLost} method when it is disconnected. zFake Connection DoneN)rrr3rr:r rrs rtest_connectionTrackingz(DNSProtocolTests.test_connectionTrackingvs[ 44tzzlC !!'.9O*P"QR 44b9rc|jjtjdg}|j t |jj d|jjd|j|tj|j t |jj d|S)rrr<rrrs rrz"DNSProtocolTests.test_queryTimeouts JJ  cii/0 1 TZZ445q9 2 1c667 TZZ445q9rcjjtjdg}j t jj jdtj}ttjj j|_ tjtjdg|_fd}|j||j!}t#j$dt ||z}jj'||S)rrrrrrctj|jdjjdyrrr s rr z-DNSProtocolTests.test_simpleQuery..cbr r!H)rr r rrrtrrrurrrqrrrrrstructpack dataReceived)rrrUr rs` rrz!DNSProtocolTests.test_simpleQuerys JJ  cii/0 1 TZZ4499;.writeErrorr$rrr%r&s rr'z DNSProtocolTests.test_writeErrorsN &&0 " JJ  cii/0 1!!!\22rctj}d|_tjtjdg|_|j }tjdt||z}|jj||j|jjddj |j y) z When receiving a message whose id is not in L{DNSProtocol.liveMessages} the message will be received by L{DNSProtocol.controller}. rrrrrFr.rN)r rurqrrrrrGrHrtrrIrrr)rrrs rr/z5DNSProtocolTests.test_receiveMessageNotInLiveMessagess ++- << Y0OPQT3v;/&8 ' 11"5a8>>@'--/RrN) r)r*r+r4rrArrr'r/r,rrr<r<gs&4: & 3 Srr<ceZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZdZdZdZdZdZdZy) ReprTestszE Tests for the C{__repr__} implementation of record classes. cb|jttjdddy)z The repr of a L{dns.Record_NS} instance includes the name of the nameserver and the TTL of the record. rzN)rrdr Record_NSrs rtest_nszReprTests.test_ns(  ~t4 57W rcb|jttjdddy)z The repr of a L{dns.Record_MD} instance includes the name of the mail destination and the TTL of the record. rrPzN)rrdr Record_MDrs rtest_mdzReprTests.test_mdrSrcb|jttjdddy)z The repr of a L{dns.Record_MF} instance includes the name of the mail forwarder and the TTL of the record. rrPzN)rrdr Record_MFrs rtest_mfzReprTests.test_mfrSrcb|jttjdddy)z The repr of a L{dns.Record_CNAME} instance includes the name of the mail forwarder and the TTL of the record. rrPz!N)rrdr Record_CNAMErs r test_cnamezReprTests.test_cname*  !!.$7 8 / rcb|jttjdddy)z} The repr of a L{dns.Record_MB} instance includes the name of the mailbox and the TTL of the record. rrPzN)rrdr Record_MBrs rtest_mbzReprTests.test_mbrSrcb|jttjdddy)z The repr of a L{dns.Record_MG} instance includes the name of the mail group member and the TTL of the record. rrPzN)rrdr Record_MGrs rtest_mgzReprTests.test_mgrSrcb|jttjdddy)z The repr of a L{dns.Record_MR} instance includes the name of the mail rename domain and the TTL of the record. rrPzN)rrdr Record_MRrs rtest_mrzReprTests.test_mrrSrcb|jttjdddy)z~ The repr of a L{dns.Record_PTR} instance includes the name of the pointer and the TTL of the record. rrPzN)rrdr Record_PTRrs rtest_ptrzReprTests.test_ptrs(  5 6 - rcb|jttjdddy)z The repr of a L{dns.Record_DNAME} instance includes the name of the non-terminal DNS name redirection and the TTL of the record. rrPz!N)rrdr Record_DNAMErs r test_dnamezReprTests.test_dname r]rcb|jttjdddy)z The repr of a L{dns.Record_A} instance includes the dotted-quad string representation of the address it is for and the TTL of the record. ri7zN)rrdr rrs rtest_azReprTests.test_as(  i- .0M rcp|jttjdddddddd d y ) zh The repr of a L{dns.Record_SOA} instance includes all of the authority fields. smNamesrNamer^r>rr)rrrrrrrrzZN)rrdr rrs rtest_soazReprTests.test_soasC  ""   5 rcb|jttjdddy)z The repr of a L{dns.Record_NULL} instance includes the repr of its payload and the TTL of the record. sabcdr^zN)rrdr rrs r test_nullzReprTests.test_null4s(  #. /1P rc f|jttjddddy)z The repr of a L{dns.Record_WKS} instance includes the dotted-quad string representation of the address it is for, the IP protocol number it is for, and the TTL of the record. z2.3.4.5r|rrz&N)rrdr rrs rtest_wkszReprTests.test_wks=s*   1!4 5 4 rcd|jttjdddy)z The repr of a L{dns.Record_AAAA} instance includes the colon-separated hex string representation of the address it is for and the TTL of the record. z 8765::1234r>rz N)rrdr rrs r test_aaaazReprTests.test_aaaaHs(  26 7 . rc h|jttjdddddy)z The repr of a L{dns.Record_A6} instance includes the colon-separated hex string representation of the address it is for and the TTL of the record. rz 1234::5678r|r>rz,N)rrdr rrs rtest_a6zReprTests.test_a6Ss,  q, C D : rc h|jttjddddddy)z The repr of a L{dns.Record_SRV} instance includes the name and port of the target and the priority, weight, and TTL of the record. rrrrrz9N)rrdr rrs rtest_srvzReprTests.test_srv^s.  1a; < G rc ptjddddddd}|jt|dy ) z The repr of a L{dns.Record_NAPTR} instance includes the order, preference, flags, service, regular expression, replacement, and TTL of the record. rr}Shttps /foo/bar/ibazrzYN)r rrrdrrs r test_naptrzReprTests.test_naptrhs: !!!Qg}faP  L 7 rc d|jttjddddy)z{ The repr of a L{dns.Record_AFSDB} instance includes the subtype, hostname, and TTL of the record. rrrz,N)rrdr r rs r test_afsdbzReprTests.test_afsdbus,  !!!^Q7 8 : rc d|jttjddddy)zw The repr of a L{dns.Record_RP} instance includes the mbox, txt, and TTL fields of the record. r#sadmin.example.comrz7N)rrdr r&rs rtest_rpzReprTests.test_rps,  35I1M N E rc d|jttjddddy)zx The repr of a L{dns.Record_HINFO} instance includes the cpu, os, and TTL fields of the record. ssparcsminixrz%N)rrdr r+rs r test_hinfozReprTests.test_hinfos,  !!(Hb9 : 3 rchtjddd}|jt|dy)z The repr of a L{dns.Record_MINFO} instance includes the rmailbx, emailbx, and TTL fields of the record. r#bob.example.comzFN)r r0rrdrs r test_minfozReprTests.test_minfos2 !!"68JBO  L W rc d|jttjddddy)z~ The repr of a L{dns.Record_MX} instance includes the preference, name, and TTL fields of the record. smx.example.comrz,N)rrdr r3rs rtest_mxzReprTests.test_mxs+  r#4a8 9 : rc f|jttjddddy)zr The repr of a L{dns.Record_TXT} instance includes the data and ttl fields of the record. rrrrz N)rrdr rErs rtest_txtzReprTests.test_txt*  B7 8 . rc f|jttjddddy)zr The repr of a L{dns.Record_SPF} instance includes the data and ttl fields of the record. rrrrz N)rrdr Record_SPFrs rtest_spfzReprTests.test_spfrrcb|jttjdddy)zu The repr of a L{dns.UnknownRecord} instance includes the data and ttl fields of the record. sfoobarrz"N)rrdr rrs rrzReprTests.test_unknowns*  ""="5 6 1 rN)r)r*r+r4rRrVrYr\r`rcrfrirlrnrrrtrvrxrzr|rrrrrrrrrr,rrrNrNs           ,                   rrNceZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!d Z"d!Z#y")# EqualityTestszM Tests for the equality and non-equality behavior of record classes. c(|j|||Sr)r)r firstValueOnesecondValueOnevalueTwos r _equalityTestzEqualityTests._equalityTests66 >8  rc|jtjdtjdtjdy)zt Two L{dns.Charstr} instances compare equal if and only if they have the same string value. abcdefN)rr rrs r test_charstrzEqualityTests.test_charstrs4  KK V!4ckk&6I rc|jtjdtjdtjdy)zo Two L{dns.Name} instances compare equal if and only if they have the same name value. rrN)rr r'rs rrzEqualityTests.test_names1 388F+SXXf-=sxx?OPrc|j|dd|dd|dd|j|dd|dd|ddy)z Assert that instances of C{cls} with the same attributes compare equal to each other and instances with different attributes compare as not equal. @param cls: A L{dns.SimpleRecord} subclass. rr^iArN)r)rr~s r_simpleEqualityTestz!EqualityTests._simpleEqualityTests\   $c.#&>NTW@X    $c.#&>NTW@X rc |jtjdtjdtjdtjdtjdtjd|jtjdtjdtjdtjdtjdtjd|jtjdtjtjdtjtjdtj |jtjdtj tjdtjdtj tjdtjdtjtjd|jtjddtjdtjddtjdtjdd tjd|jtjdd tjd tjdd tjd tjdd tjd y )z Two L{dns.RRHeader} instances compare equal if and only if they have the same name, type, class, time to live, payload, and authoritative bit. rrrr1.2.3.5)r~rrC)rrrCr)rhrrN)rr rrrMXrCSrs r test_rrheaderzEqualityTests.test_rrheaders  LLi1H I LLi1H I LLi1H I   LLi1H I LLi1H I LLi1H I   LL / LL / LL 0   LLSVVS\\)=T U LLSVVS\\)=T U LLSVVS\\)=T U   LLRi9P Q LLRi9P Q LLS#,,y:Q R   LLai9P Q LLai9P Q LLai9P Q rcB|jtjy)zv Two L{dns.Record_NS} instances compare equal if and only if they have the same name and TTL. N)rr rQrs rrRzEqualityTests.test_ns#   /rcB|jtjyzv Two L{dns.Record_MD} instances compare equal if and only if they have the same name and TTL. N)rr rUrs rrVzEqualityTests.test_md*rrcB|jtjy)zv Two L{dns.Record_MF} instances compare equal if and only if they have the same name and TTL. N)rr rXrs rrYzEqualityTests.test_mf1rrcB|jtjy)zy Two L{dns.Record_CNAME} instances compare equal if and only if they have the same name and TTL. N)rr r[rs rr\zEqualityTests.test_cname8   !1!12rcB|jtjy)zv Two L{dns.Record_MB} instances compare equal if and only if they have the same name and TTL. N)rr r_rs rr`zEqualityTests.test_mb?rrcB|jtjy)zv Two L{dns.Record_MG} instances compare equal if and only if they have the same name and TTL. N)rr rbrs rrczEqualityTests.test_mgFrrcB|jtjy)zv Two L{dns.Record_MR} instances compare equal if and only if they have the same name and TTL. N)rr rers rrfzEqualityTests.test_mrMrrcB|jtjy)zw Two L{dns.Record_PTR} instances compare equal if and only if they have the same name and TTL. N)rr rhrs rrizEqualityTests.test_ptrTs   0rcB|jtjyr)rr rkrs rrlzEqualityTests.test_dname[rrc@|jtjddtjddtjdd|jtjddtjddtjddy)zx Two L{dns.Record_A} instances compare equal if and only if they have the same address and TTL. rrrzrN)rr rrs rrnzEqualityTests.test_absv  LLA & LLA & LLA &  LLA & LLA & LLA & rc|jtjddddddddtjddddddddtjd ddddddd|jtjddddddddtjddddddddtjdd dddddd|jtjddddddddtjddddddddtjddd ddddd|jtjddddddddtjddddddddtjdddd dddd|jtjddddddddtjddddddddtjddddd ddd|jtjddddddddtjddddddddtjdddddd dd|jtjddddddddtjddddddddtjddddddd d|jtjddddddddtjddddddddtjdd dddddd y ) z Two L{dns.Record_SOA} instances compare equal if and only if they have the same mname, rname, serial, refresh, minimum, expire, retry, and ttl. smnamesrnamer^rprqr>rrosxnamerN)rr rrs rrrzEqualityTests.test_soats  NN8XsCb"b I NN8XsCb"b I NN8XsCb"b I  NN8XsCb"b I NN8XsCb"b I NN8XsCb"b I  NN8XsCb"b I NN8XsCb"b I NN8Xq#sBB G  NN8XsCb"b I NN8XsCb"b I NN8XsAsBB G  NN8XsCb"b I NN8XsCb"b I NN8XsCBB G  NN8XsCb"b I NN8XsCb"b I NN8XsCaR H  NN8XsCb"b I NN8XsCb"b I NN8XsCb!R H  NN8XsCb"b I NN8XsCb"b I NN8XsCb"a H rc@|jtjddtjddtjdd|jtjddtjddtjddy)z{ Two L{dns.Record_NULL} instances compare equal if and only if they have the same payload and ttl. zfoo barr>zbar foor N)rr rrs rrtzEqualityTests.test_nullsv  OOIr * OOIr * OOIr *  OOIr * OOIr * OOIs + rc |jtjddddtjddddtjdddd|jtjddddtjddddtjdddd|jtjddddtjddddtjdddd|jtjddddtjddddtjddddy ) z Two L{dns.Record_WKS} instances compare equal if and only if they have the same address, protocol, map, and ttl. rrfoorrr r N)rr rrs rrvzEqualityTests.test_wkss  NN9a 2 NN9a 2 NN9a 2  NN9a 2 NN9a 2 NN9c5! 4  NN9a 2 NN9a 2 NN9a 2  NN9a 2 NN9a 2 NN9a 4 rc@|jtjddtjddtjdd|jtjddtjddtjddy)z{ Two L{dns.Record_AAAA} instances compare equal if and only if they have the same address and ttl. z1::2rz2::1r>N)rr rrs rrxzEqualityTests.test_aaaasv  OOFA & OOFA & OOFA &  OOFA & OOFA & OOFB ' rc |jtjddddtjddddtjdddd|jtjddddtjddddtjdddd|jtjddddtjddddtjdddd|jtjddddtjddddtjddddy ) z Two L{dns.Record_A6} instances compare equal if and only if they have the same prefix, prefix length, suffix, and ttl. r1z::abcdrr>rz::abcd:0rr N)rr rrs rrzzEqualityTests.test_a6s  MM"h ; MM"h ; MM"h ;  MM"h ; MM"h ; MM"j." =  MM"h ; MM"h ; MM"h ;  MM"h ; MM"h ; MM"h < rc t|jtjdddddtjdddddtjddddd|jtjdddddtjdddddtjddddd|jtjdddddtjdddddtjddddd|jtjdddddtjdddddtjdddd d|jtjdddddtjdddddtjddddd y ) z Two L{dns.Record_SRV} instances compare equal if and only if they have the same priority, weight, port, target, and ttl. r>rrorrpr ri,rN)rr rrs rr|zEqualityTests.test_srvs~  NN2r2~r : NN2r2~r : NN3B ;  NN2r2~r : NN2r2~r : NN2sB ;  NN2r2~r : NN2r2~r : NN2r3 ;  NN2r2~r : NN2r2~r : NN2r2~r :  NN2r2~r : NN2r2~r : NN2r2~s ; rc |jtjddddtjddddtjdddd|jtjddddtjddddtjdddd|jtjddddtjddddtjdddd|jtjddddtjddddtjddddy)z Two L{dns.Record_SSHFP} instances compare equal if and only if they have the same key type, fingerprint type, fingerprint, and ttl. rrshappydayrpshappxday-N)rr rrs r test_sshfpzEqualityTests.test_sshfp2s2    Q; 3   Q; 3   Q; 3    Q; 3   Q; 3   Q; 3    Q; 3   Q; 3   Q; 3    Q; 3   Q; 3   Q; 3 rc (|jtjdddddddtjdddddddtjddddddd|jtjdddddddtjdddddddtjddddddd|jtjdddddddtjdddddddtjddd dddd|jtjdddddddtjdddddddtjdddd ddd|jtjdddddddtjdddddddtjddddd dd|jtjdddddddtjdddddddtjddddd d d|jtjdddddddtjdddddddtjddddd dd y)z Two L{dns.Record_NAPTR} instances compare equal if and only if they have the same order, preference, flags, service, regexp, replacement, and ttl. rrr rs /foo/bar/rrrprs /bar/foo/squuxrN)rr rrs rrzEqualityTests.test_naptrPs    Q4\62 N   Q4\62 N   Q4\62 N    Q4\62 N   Q4\62 N   Q4\62 N    Q4\62 N   Q4\62 N   Q4\62 N    Q4\62 N   Q4\62 N   Q4, K    Q4\62 N   Q4\62 N   Q4\62 N    Q4\62 N   Q4\62 N   Q4\7B O    Q4\62 N   Q4\62 N   Q4\61 M rc |jtjdddtjdddtjddd|jtjdddtjdddtjddd|jtjdddtjdddtjdddy)z Two L{dns.Record_AFSDB} instances compare equal if and only if they have the same subtype, hostname, and ttl. rrrrrN)rr r rs rrzEqualityTests.test_afsdbs    Q 2   Q 2   Q 2    Q 2   Q 2   Q 2    Q 2   Q 2   Q 2 rc |jtjdddtjdddtjddd|jtjdddtjdddtjddd|jtjdddtjdddtjdddy)zx Two L{Record_RP} instances compare equal if and only if they have the same mbox, txt, and ttl. r#s alice is nicer>rsalice is not nicer N)rr r&rs rrzEqualityTests.test_rps  MM.0@" E MM.0@" E MM,.> C  MM.0@" E MM.0@" E MM.0Db I  MM.0@" E MM.0@" E MM.0@# F rc |jtjdddtjdddtjddd|jtjdddtjdddtjddd|jtjdddtjdddtjdddy)z} Two L{dns.Record_HINFO} instances compare equal if and only if they have the same cpu, os, and ttl. zx86-64plan9r>i386plan11r N)rr r+rs rrzEqualityTests.test_hinfos    Xw 3   Xw 3   VWb 1    Xw 3   Xw 3   Xx 4    Xw 3   Xw 3   Xw 4 rc |jtjdddtjdddtjddd|jtjdddtjdddtjddd|jtjdddtjdddtjdddy)z Two L{dns.Record_MINFO} instances compare equal if and only if they have the same rmailbx, emailbx, and ttl. srmailboxsemailboxr>s someplaces somethingr N)rr r0rs rrzEqualityTests.test_minfos    [+r :   [+r :   \; ;    [+r :   [+r :   [, ;    [+r :   [+r :   [+s ; rc |jtjdddtjdddtjddd|jtjdddtjdddtjddd|jtjdddtjdddtjdddy)z Two L{dns.Record_MX} instances compare equal if and only if they have the same preference, name, and ttl. r>rrr s example.netrN)rr r3rs rrzEqualityTests.test_mxs  MM"nb 1 MM"nb 1 MM#~r 2  MM"nb 1 MM"nb 1 MM"nb 1  MM"nb 1 MM"nb 1 MM"nc 2 rc |jtjdddtjdddtjdddd|jtjdddtjdddtjddd|jtjdddtjdddtjdddy)zw Two L{dns.Record_TXT} instances compare equal if and only if they have the same data and ttl. rr r>rbazr N)rr rErs rrzEqualityTests.test_txt  NN5%R 0 NN5%R 0 NN5%B 7  NN5%R 0 NN5%R 0 NN5%R 0  NN5%R 0 NN5%R 0 NN5%S 1 rc |jtjdddtjdddtjdddd|jtjdddtjdddtjddd|jtjdddtjdddtjdddy)zs L{dns.Record_SPF} instances compare equal if and only if they have the same data and ttl. rr r>rrr N)rr rrs rrzEqualityTests.test_spf rrc Zdddddtjddd}d d d d d tjddd}|jD]f}|j }||||<|j tj di|tj di|tj di|hy)z L{dns.Record_TSIG} instances compare equal if and only if they have the same RDATA (algorithm, timestamp, MAC, etc.) and ttl. z hmac-sha224r6rscrrp)rr8r:r;r9r=r>rz hmac-sha512ipUZrsirNr,)r OKr@rcopyrr?)rbaseargsaltargskwaltereds r test_tsigzEqualityTests.test_tsig) s '$*VV  '$*\\$  --/ BmmoG!"+GBK   *'**'*+(+  rc|jtjddtjddtjdd|jtjddtjddtjdd|jtjddtjddtjddy)zv L{dns.UnknownRecord} instances compare equal if and only if they have the same data and ttl. rr>rfoobarr r N)rr rrs rrzEqualityTests.test_unknownK s    e ,   e ,   hB /    e ,   e ,   e ,    e ,   e ,   e - rN)$r)r*r+r4rrrrrrRrVrYr\r`rcrfrirlrnrrrtrvrxrzr|rrrrrrrrrrrr,rrrrs  Q "/ b000300013 $5 n $ < $ B" H :Jrct|ddy)z L{dns._isSubdomainOf} returns C{True} if the first name is a subdomain of the second name but the first name has a trailing ".". foo.example.com.rNrrs rtest_subdomainWithTrailingDotz0IsSubdomainOfTests.test_subdomainWithTrailingDot s D"5~Frct|ddy)z L{dns._isSubdomainOf} returns C{True} if the first name is a subdomain of the second name but the second name has a trailing ".". rk example.com.Nrrs rtest_superdomainWithTrailingDotz2IsSubdomainOfTests.test_superdomainWithTrailingDot" s D"4oFrct|ddy)z L{dns._isSubdomainOf} returns C{True} if the first name is a subdomain of the second name and both names have a trailing ".". rrNrrs rtest_bothWithTrailingDotz+IsSubdomainOfTests.test_bothWithTrailingDot* s D"5Grct|ddy)zw L{dns._isSubdomainOf} returns C{False} if the first name is empty and the second name is not. rrNrrs rtest_emptySubdomainz&IsSubdomainOfTests.test_emptySubdomain2 s tS.9rct|ddy)zv L{dns._isSubdomainOf} returns C{True} if the second name is empty and the first name is not. rkrNrrs rtest_emptySuperdomainz(IsSubdomainOfTests.test_emptySuperdomain9 s D"4c:rc8t|ddt|ddy)z` L{dns._isSubdomainOf} does case-insensitive comparison of name labels. rkrsFOO.EXAMPLE.COMrNrrs rtest_caseInsensitiveComparisonz1IsSubdomainOfTests.test_caseInsensitiveComparison@ s D"4nED"4nErN)r)r*r+r4r r r rrrrrrrr r"r,rrrr sMBFFIMKGGH:;Frrc2eZdZdZeddZedZy)OPTNonStandardAttributesz Generate byte and instance representations of an L{dns._OPTHeader} where all attributes are set to non-default values. For testing whether attributes have really been read from the byte string during decoding. cd}|rd}d|zS)aT Return L{bytes} representing an encoded OPT record. @param excludeName: A flag that controls whether to exclude the name field. This allows a non-standard name to be prepended during the test. @type excludeName: L{bool} @param excludeOptions: A flag that controls whether to exclude the RDLEN field. This allows encoded variable options to be appended during the test. @type excludeOptions: L{bool} @return: L{bytes} representing the encoded OPT record returned by L{object}. rrs )r,)r~ excludeNameexcludeOptionsrdlens rrczOPTNonStandardAttributes.bytesS s%$ E   rc4tjddddS)z Return a new L{dns._OPTHeader} instance. @return: A L{dns._OPTHeader} instance with attributes that match the encoded record returned by L{bytes}. rrT)udpPayloadSize extendedRCODEversiondnssecOK)r _OPTHeaderr~s rr8zOPTNonStandardAttributes.objectr s~~aT  rN)FF)r)r*r+r4 classmethodrcr8r,rrr$r$J s/<    rr$ceZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!d Z"y!)"OPTHeaderTestsz4 Tests for L{twisted.names.dns._OPTHeader}. cTttjtjy)zA L{dns._OPTHeader} implements L{dns.IEncodable}. N)rr IEncodabler/rs rtest_interfacezOPTHeaderTests.test_interface s CNNCNN3rc|jtjjtjdy)zq L{dns._OPTHeader.name} is an instance attribute whose value is fixed as the root domain rN)rr r/rbr'rs rrzOPTHeaderTests.test_name s) ).. >rc tj}|jtt|dtj dy)z5 L{dns._OPTHeader.name} is readonly. rbrN)r r/r%AttributeErrorsetattrr'rhs rtest_nameReadonlyz OPTHeaderTests.test_nameReadonly s/ NN  .'1fchh~>VWrc`|jtjjdy)z^ L{dns._OPTHeader.type} is an instance attribute with fixed value 41. )N)rr r/r}rs r test_typezOPTHeaderTests.test_type s! )..3rctj}|jtt|dtj y)z5 L{dns._OPTHeader.type} is readonly. r}N)r r/r%r9r:rr;s rtest_typeReadonlyz OPTHeaderTests.test_typeReadonly s* NN  .'1fceeDrc`|jtjjdy)zt L{dns._OPTHeader.udpPayloadSize} defaults to 4096 as recommended in rfc6891 section-6.2.5. Nrr r/r+rs rtest_udpPayloadSizez"OPTHeaderTests.test_udpPayloadSize s! )88$?rcd|jtjdjdy)z` L{dns._OPTHeader.udpPayloadSize} can be overridden in the constructor. r*r+NrErs rtest_udpPayloadSizeOverridez*OPTHeaderTests.test_udpPayloadSizeOverride s# s;JJCPrc`|jtjjdy)z@ L{dns._OPTHeader.extendedRCODE} defaults to 0. rNrr r/r,rs rtest_extendedRCODEz!OPTHeaderTests.test_extendedRCODE s! )77;rcd|jtjdjdy)z_ L{dns._OPTHeader.extendedRCODE} can be overridden in the constructor. rr,NrKrs rtest_extendedRCODEOverridez)OPTHeaderTests.test_extendedRCODEOverride s# a8FFJrc`|jtjjdy)z: L{dns._OPTHeader.version} defaults to 0. rNrr r/r-rs r test_versionzOPTHeaderTests.test_version s! )1115rcd|jtjdjdy)zY L{dns._OPTHeader.version} can be overridden in the constructor. rr-NrQrs rtest_versionOverridez#OPTHeaderTests.test_versionOverride s# 2::A>rc^|jtjjy)z? L{dns._OPTHeader.dnssecOK} defaults to False. N)rr r/r.rs r test_dnssecOKzOPTHeaderTests.test_dnssecOK s )223rcb|jtjdjy)zZ L{dns._OPTHeader.dnssecOK} can be overridden in the constructor. Tr.N)rr r/r.rs rtest_dnssecOKOverridez$OPTHeaderTests.test_dnssecOKOverride s 5>>?rc`|jtjjgy)zC L{dns._OPTHeader.options} defaults to empty list. N)rr r/optionsrs r test_optionszOPTHeaderTests.test_options s! )1126rcltjdg}|j|jdgy)zY L{dns._OPTHeader.options} can be overridden in the constructor. )rrr\N)r r/rr\r;s rtest_optionsOverridez#OPTHeaderTests.test_optionsOverride s, NNO#4 5 _$56rct}tjj||j |j tj y)z L{dns._OPTHeader.encode} packs the header fields and writes them to a file like object passed in as an argument. N)rr$r8rlrrmrc)rbs rrpzOPTHeaderTests.test_encode sB I '')003 '?'E'E'GHrc2tj}tjddtjddg|_t }|j ||j|jtjddzy) z L{dns._OPTHeader.options} is a list of L{dns._OPTVariableOption} instances which are packed into the rdata area of the header. r foobarbazrquxTr' foobarbazquxN) r$r8r _OPTVariableOptionr\rrlrrmrc)rr<rcs rtest_encodeWithOptionsz%OPTHeaderTests.test_encodeWithOptions s % + + -  " "1l 3  " "1f -   I    JJL $ * *$ * ?  rctj}|jttj |j |tjy)z L{dns._OPTHeader.decode} unpacks the header fields from a file like object and populates the attributes of an existing L{dns._OPTHeader} instance. N)r r/rgrr$rcrr8)r decodedHeaders rrizOPTHeaderTests.test_decode sG ( W%=%C%C%EFG (@(G(G(IJrcttj}tj}|j ||j |jt|jy)zk L{dns._OPTHeader.decode} reads all the bytes of the record that is being decoded. N rr$rcr r/rgrrrtrmrrcrls rtest_decodeAllExpectedBytesz*OPTHeaderTests.test_decodeAllExpectedBytes sS ,224 5( Q 3qzz|#45rcttjdz}tj}|j ||j |jt|jtdz y)z L{dns._OPTHeader.decode} reads only the bytes from the current file position to the end of the record that is being decoded. Trailing bytes are not consumed. sxxxxNrnros rtest_decodeOnlyExpectedBytesz+OPTHeaderTests.test_decodeOnlyExpectedBytes& sa ,224w> ?( Q 3qzz|#4s7|#CDrcttjddz}tj}|j ||j |jtjdy)z L{dns._OPTHeader.decode} discards the name which is encoded in the supplied bytes. The name attribute of the resulting L{dns._OPTHeader} instance will always be L{dns.Name(b'')}. T)r&rfrN) rr$rcr r/rgrrbr'rrcr<s rtest_decodeDiscardsNamez&OPTHeaderTests.test_decodeDiscardsName3 sZ  $ * *t * >66}ENN!++fEF   )+<=rc^|jttjdy)z L{dns._OPTHeader.__repr__} displays the name and type and all the fixed and extended header values of the OPT record. zb<_OPTHeader name= type=41 udpPayloadSize=4096 extendedRCODE=0 version=0 dnssecOK=False options=[]>N)rrdr r/rs r test_reprzOPTHeaderTests.test_repr s&  ! "  rc|jtjdtjdtjdy)zh Two L{OPTHeader} instances compare equal if they have the same udpPayloadSize. r*rHrDNrr r/rs rtest_equalityUdpPayloadSizez*OPTHeaderTests.test_equalityUdpPayloadSize s6 // NN# . NN# . NN$ / rc|jtjdtjdtjdy)zg Two L{OPTHeader} instances compare equal if they have the same extendedRCODE. rrNrNrrs rtest_equalityExtendedRCODEz)OPTHeaderTests.test_equalityExtendedRCODE s6 // NN + NN + NN + rc|jtjdtjdtjdy)za Two L{OPTHeader} instances compare equal if they have the same version. rrTrNrrs rtest_equalityVersionz#OPTHeaderTests.test_equalityVersion s6 // NN1 % NN1 % NN1 % rc|jtjdtjdtjdy)zh Two L{OPTHeader} instances compare equal if they have the same dnssecOK flags. TrYFNrrs rtest_equalityDnssecOKz$OPTHeaderTests.test_equalityDnssecOK s6 // NND ) NND ) NNE * rc  |jtjtjddgtjtjddgtjtjddgy)za Two L{OPTHeader} instances compare equal if they have the same options. rxr`ryN)rr r/rirs rtest_equalityOptionsz#OPTHeaderTests.test_equalityOptions sf // NNC$:$:1d$C#D E NNC$:$:1d$C#D E NNC$:$:1d$C#D E rN)#r)r*r+r4r6rr=r@rBrFrIrLrOrRrUrWrZr]rarprjrirprrrurxr{r}rrrrrrrr,rrr3r3 s4 ?X4E@Q< K6 ?4 @7 7I 6 K 6 E 01"1" >>6 "          rr3c4eZdZdZdZdZdZdZdZdZ y) OPTVariableOptionTestsz. Tests for L{dns._OPTVariableOption}. cTttjtjy)zI L{dns._OPTVariableOption} implements L{dns.IEncodable}. N)rr r5rirs rr6z%OPTVariableOptionTests.test_interface s CNNC$:$:;rctjdd}|j|jd|j|jdy)z L{dns._OPTVariableOption.__init__} requires code and data arguments which are saved as public instance attributes. rrN)r rirrrr;s rtest_constructorArgumentsz0OPTVariableOptionTests.test_constructorArguments s>  " "1d + # &rcb|jttjdddy)zf L{dns._OPTVariableOption.__repr__} displays the code and data of the option. rrz"<_OPTVariableOption code=1 data=x>N)rrdr rirs rrz OPTVariableOptionTests.test_repr s*  ''40 1 9 rc@|jtjddtjddtjdd|jtjddtjddtjddy)zs Two OPTVariableOption instances compare equal if they have the same code and data values. rrrrN)rr rirs rrz$OPTVariableOptionTests.test_equality s //  " "1d +  " "1d +  " "1d + //  " "1d +  " "1d +  " "1d + rctjdd}t}|j||j |j dy)z L{dns._OPTVariableOption.encode} encodes the code and data instance attributes to a byte string which also includes the data length. rfoobar foobarN)r rirrlrrm)rorcs rrpz"OPTVariableOptionTests.test_encode sD  " "1i 0 I    JJL  rctd}tj}|j||j |j d|j |j dy)z L{dns._OPTVariableOption.decode} is a classmethod that decodes a byte string and returns a L{dns._OPTVariableOption} instance. rrrN)rr rirgrrr)rrcrs rriz"OPTVariableOptionTests.test_decode% sV     " " $   # +rN) r)r*r+r4r6rrrrprir,rrrr s%< '  " ,rrceZdZdZdZy) RaisedArgszp An exception which can be raised by fakes to test that the fake is called with expected arguments. c ||_||_y)z Store the positional and keyword arguments as attributes. @param args: The positional args. @param kwargs: The keyword args. Nrrrrrs rrzRaisedArgs.__init__< s  rN)r)r*r+r4rr,rrrr6 s  rrc0eZdZdZedZedZy) MessageEmptyz^ Generate byte string and constructor arguments for an empty L{dns._EDNSMessage}. c y) Bytes which are expected when encoding an instance constructed using C{kwargs} and which are expected to result in an identical instance when decoded. @return: The L{bytes} of a wire encoded message. s r,r0s rrczMessageEmpty.bytesM   rc Ftddtjdddddd S) Keyword constructor arguments which are expected to result in an instance which returns C{bytes} when encoded. @return: A L{dict} of keyword arguments. rTrN rqrgrrrhrirjrkrs ednsVersion)dictr OP_STATUSr0s rrzMessageEmpty.kwargs` s0==  rNr)r*r+r4r1rcrr,rrrrG s/   $  rrc0eZdZdZedZedZy)MessageTruncatedz= An empty response message whose TR bit is set to 1. c y)rs r,r0s rrczMessageTruncated.bytesz rrc *tddddddddd S)rrrrNr)rr0s rrzMessageTruncated.kwargs s,  rNrr,rrrru s/  $  rrc0eZdZdZedZedZy)MessageNonAuthoritativez. A minimal non-authoritative message. c y)rsr,r0s rrczMessageNonAuthoritative.bytes   rc xtdddtjdtjdddg S) rrrNrrrFrrhrqrhrrrr rrr0s rrzMessageNonAuthoritative.kwargs s: S#,,ya*HuU   rNrr,rrrr /  2  rrc0eZdZdZedZedZy)MessageAuthoritativez* A minimal authoritative message. c y)rsr,r0s rrczMessageAuthoritative.bytes rrc xtdddtjdtjddd g S) rrrNrrrrTrrrr0s rrzMessageAuthoritative.kwargs s: S#,,ya*HtT   rNrr,rrrr rrrc0eZdZdZedZedZy)MessageCompletez An example of a fully populated non-edns response message. Contains name compression, answers, authority, and additional records. c y)rsnexamplecom 'ns1 hostmaster  ))r,r0s rrczMessageComplete.bytes s % ' rctddtjdddddtjdtjgtj dtjddtj ddd d d d d dgtj dtjddtjddgtj dtjddtjddg S)rrrrNrTns1.example.comhostmaster.example.comrrrrrrrrr}rrhrns1.example.comr5.6.7.8) rqrgrrrhrjrkrsrrrrr rr rrrrrNSrQrrr0s rrzMessageComplete.kwargs= s==YY~sww78 ""NN&07) *() *  & ""MM*;L  &"LL C K. . rNrr,rrrr s0 / / b5 5 rrc0eZdZdZedZedZy)MessageEDNSQueryz' A minimal EDNS query message. c y)rs,wwwexamplecom)r,r0s rrczMessageEDNSQuery.bytes{ s   rctddtjddddddtjdtjgg S)rrrFswww.example.com) rqrgrrrhrjrkrsrr.rr)rr rrrr0s rrzMessageEDNSQuery.kwargs sI<<YY13559:  rNrr,rrrrv s/  <  rrc0eZdZdZedZedZy)MessageEDNSCompletez An example of a fully populated edns response message. Contains name compression, answers, authority, and additional records. c y)rsyexamplecom 'ns1 hostmaster  )))r,r0s rrczMessageEDNSComplete.bytes s - / rcPtd'idddddtjddddd dd dd d d ddddddddddtjdtjgdtj dtjddtj dddddddd !gd"tj dtjddtjd#d$!gd%tj dtjddtjd&d$!gS)(rrqrrgrrrrhrirrjrkrsrrrr.TrKrYrtrrrrrrrrrrrrrrrrrrr,rr0s rrzMessageEDNSComplete.kwargs sl3 3 3 ==3  3  3  3 3 3 3 3 3 "3 3 YY~sww783  ""NN&07) *() *  3 D ""MM*;L C3 V &"LL C U3 3 rNrr,rrrr s0 7 7 r: : rrc0eZdZdZedZedZy)MessageEDNSExtendedRCODEz? An example of an EDNS message with an extended RCODE. c y)rs )r,r0s rrczMessageEDNSExtendedRCODE.bytes5s   rcRtddtjddddddddggggS)rrFi rD)rqrgrrrhrirjrkrsrr.rtrrrr)rr rr0s rrzMessageEDNSExtendedRCODE.kwargsPsB<<  rNrr,rrrr0s/  4  rrc$eZdZdZdxZZdZdZy)MessageComparablez A wrapper around L{dns.Message} which is comparable so that it can be tested using some of the L{dns._EDNSMessage} tests. ) rqrgrrrhrirjrkrsrrrrc||_yr)original)rrs rrzMessageComparable.__init__s   rc.t|j|Sr)getattrr)rkeys r __getattr__zMessageComparable.__getattr__st}}c**rN)r)r*r+r4showAttributescompareAttributesrrr,rrrrks  * N&!+rrc||}i}||d}|}t|||d<|di||i}t|||d<|j||y)a Verify that an attribute has the expected default value and that a corresponding argument passed to a constructor is assigned to that attribute. @param testCase: The L{TestCase} whose assert methods will be called. @type testCase: L{unittest.TestCase} @param cls: The constructor under test. @type cls: L{type} @param argName: The name of the constructor argument under test. @type argName: L{str} @param defaultVal: The expected default value of C{attrName} / C{argName} @type defaultVal: L{object} @param altVal: A value which is different from the default. Used to test that supplied constructor arguments are actually assigned to the correct attribute. @type altVal: L{object} @param attrName: The name of the attribute under test if different from C{argName}. Defaults to C{argName} @type attrName: L{str} N defaultValaltValrrr,)rr) rr~argNamerrattrNameactualryrs rverifyConstructorArgumentrsi> F(F;H A"1h/F<  w Aq(+F8 6*rceZdZdZdZdZy)ConstructorTestsMixinzl Helper methods for verifying default attribute values and corresponding constructor arguments. c8t||j|||y)a Wrap L{verifyConstructorArgument} to provide simpler interface for testing Message and _EDNSMessage constructor arguments. @param argName: The name of the constructor argument. @param defaultVal: The expected default value. @param altVal: An alternative value which is expected to be assigned to a correspondingly named attribute. rr~rrrNrr)rrrrs r_verifyConstructorArgumentz0ConstructorTestsMixin._verifyConstructorArguments! "##!  rcF|dvsJt||j||| y)a  Wrap L{verifyConstructorArgument} to provide simpler interface for testing _EDNSMessage constructor flags. @param argName: The name of the constructor flag argument @param defaultVal: The expected default value of the flag )TFrNr)rrrs r_verifyConstructorFlagz,ConstructorTestsMixin._verifyConstructorFlags1]***!##!!>  rN)r)r*r+r4rrr,rrrrs  $ rrc^eZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZy)CommonConstructorTestsMixina Tests for constructor arguments and their associated attributes that are common to both L{twisted.names.dns._EDNSMessage} and L{dns.Message}. TestCase classes that use this mixin must provide a C{messageFactory} method which accepts any argment supported by L{dns.Message.__init__}. TestCases must also mixin ConstructorTestsMixin which provides some custom assertions for testing constructor arguments. c,|jdddy)zk L{dns._EDNSMessage.id} defaults to C{0} and can be overridden in the constructor. rqrrrNrrs rrz#CommonConstructorTestsMixin.test_ids ''1'Erc*|jddy)zs L{dns._EDNSMessage.answer} defaults to C{False} and can be overridden in the constructor. rgFrNrrs rrz'CommonConstructorTestsMixin.test_answer ##H#?rcd|jdtjtjy)zz L{dns._EDNSMessage.opCode} defaults to L{dns.OP_QUERY} and can be overridden in the constructor. rrrN)rr rrrs rrz'CommonConstructorTestsMixin.test_opCodes& '' cmm ( rc*|jddy)zq L{dns._EDNSMessage.auth} defaults to C{False} and can be overridden in the constructor. rhFrNrrs rrz%CommonConstructorTestsMixin.test_auths ##Fu#=rc*|jddy)zr L{dns._EDNSMessage.trunc} defaults to C{False} and can be overridden in the constructor. riFrNrrs rrz&CommonConstructorTestsMixin.test_trunc  ##G#>rc*|jddy)zs L{dns._EDNSMessage.recDes} defaults to C{False} and can be overridden in the constructor. rjFrNrrs rrz'CommonConstructorTestsMixin.test_recDesrrc*|jddy)zr L{dns._EDNSMessage.recAv} defaults to C{False} and can be overridden in the constructor. rkFrNrrs rrz&CommonConstructorTestsMixin.test_recAvr rc,|jdddy)zn L{dns._EDNSMessage.rCode} defaults to C{0} and can be overridden in the constructor. rsrr^rNrrs rrz&CommonConstructorTestsMixin.test_rCodes ''Ac'Jrc,|jdddy)zr L{dns._EDNSMessage.maxSize} defaults to C{512} and can be overridden in the constructor. rtr*rrNrrs rrz(CommonConstructorTestsMixin.test_maxSize%s '' c$'OrcX|j|jjgy)z@ L{dns._EDNSMessage.queries} defaults to C{[]}. N)rrrrs rrz(CommonConstructorTestsMixin.test_queries,# ,,.66;rcX|j|jjgy)z@ L{dns._EDNSMessage.answers} defaults to C{[]}. N)rrrrs rrz(CommonConstructorTestsMixin.test_answers2rrcX|j|jjgy)zB L{dns._EDNSMessage.authority} defaults to C{[]}. N)rrrrs rrz*CommonConstructorTestsMixin.test_authority8s# ,,.88"=rcX|j|jjgy)zC L{dns._EDNSMessage.additional} defaults to C{[]}. N)rrrrs rrz+CommonConstructorTestsMixin.test_additional>s# ,,.992>rN)r)r*r+r4rrrrrrrrrrrrrr,rrrrsM F@ >?@?KP< < > ?rrc(eZdZdZej Zy)EDNSMessageConstructorTestszt Tests for L{twisted.names.dns._EDNSMessage} constructor arguments that are shared with L{dns.Message}. Nr)r*r+r4r _EDNSMessagerr,rrrrE %%Nrrc(eZdZdZej Zy)MessageConstructorTestszt Tests for L{twisted.names.dns.Message} constructor arguments that are shared with L{dns._EDNSMessage}. N)r)r*r+r4r rurr,rrrrPs [[NrrceZdZdZej ZdZdZdZ dZ dZ dZ dZ d Zd Zd Zd Zd ZdZdZdZdZy)EDNSMessageSpecificsTestsz Tests for L{dns._EDNSMessage}. These tests are for L{dns._EDNSMessage} APIs which are not shared with L{dns.Message}. c,|jdddy)zt L{dns._EDNSMessage.ednsVersion} defaults to C{0} and can be overridden in the constructor. rrNrrrs rtest_ednsVersionz*EDNSMessageSpecificsTests.test_ednsVersiones '' !D'Qrc*|jddy)zu L{dns._EDNSMessage.dnssecOK} defaults to C{False} and can be overridden in the constructor. r.FrNrrs rrWz'EDNSMessageSpecificsTests.test_dnssecOKls ##J5#Arc*|jddy)zz L{dns._EDNSMessage.authenticData} defaults to C{False} and can be overridden in the constructor. rKFrNrrs rrz,EDNSMessageSpecificsTests.test_authenticDatass ##O#Frc*|jddy)z} L{dns._EDNSMessage.checkingDisabled} defaults to C{False} and can be overridden in the constructor. rYFrNrrs rrz/EDNSMessageSpecificsTests.test_checkingDisabledzs ##$65#Irc|jtjdg}|j|jtjdgy)zS L{dns._EDNSMessage.queries} can be overridden in the constructor. rrN)rr rrrrs rtest_queriesOverridez.EDNSMessageSpecificsTests.test_queriesOverridesC!!399^+D*E!F syy'@&ABrc |jtjdtjdg}|j |j tjdtjdgy)zS L{dns._EDNSMessage.answers} can be overridden in the constructor. rrrrN)rr rrrrrs rtest_answersOverridez.EDNSMessageSpecificsTests.test_answersOverridesc!!\\.#,,y:QRS"   KK#,,~s||I?VWX rc <|jtjdtjtjg}|j |j tjdtjtjgy)U L{dns._EDNSMessage.authority} can be overridden in the constructor. rrrN)rr rrrrrrs rtest_authorityOverridez0EDNSMessageSpecificsTests.test_authorityOverridesn!! ^#''3>>CST"   MM \\.sww@P Q R rc |jtjdtjdg}|j |j tjdtjdgy)r'rrrrN)rr rrrrrs rtest_additionalOverridez1EDNSMessageSpecificsTests.test_additionalOverridesd!! ^S\\)=TUV"   NN \\.#,,y2I J K rcV|jdt|jy)z L{dns._EDNSMessage.__repr__} omits field values and sections which are identical to their defaults. The id field value is always shown. z<_EDNSMessage id=0>Nrrdrrs rrez+EDNSMessageSpecificsTests.test_reprDefaultss# .T5H5H5J0KLrc l|jdddddddd}|jdt|y)zR L{dns._EDNSMessage.__repr__} displays flags if they are L{True}. T)rgrhrirjrkrKrYr.z`<_EDNSMessage id=0 flags=answer,auth,trunc,recDes,recAv,authenticData,checkingDisabled,dnssecOK>NrrrdrTs rrmz-EDNSMessageSpecificsTests.test_reprFlagsIfSetsO   !    G  rcf|jddddd}|jdt|y) zp L{dns._EDNSMessage.__repr__} displays field values if they differ from their defaults. r>rrorpr)rqrrrsrtrzA<_EDNSMessage id=10 opCode=20 rCode=30 maxSize=40 ednsVersion=50>Nr.rTs rruz2EDNSMessageSpecificsTests.test_reprNonDefautFieldss<   2bBTV  W   G rc|j}gd|_gd|_gd|_gd|_|j dt |y)rwrxryr{r~zc<_EDNSMessage id=0 queries=[1, 2, 3] answers=[4, 5, 6] authority=[7, 8, 9] additional=[10, 11, 12]>N)rrrrrrrdrTs rrz5EDNSMessageSpecificsTests.test_reprNonDefaultSectionssJ    !   #    G rcGdd}tj}||_t}|j t |j |}|j|fif|j|jfy)z L{dns._EDNSMessage.fromString} calls L{dns._EDNSMessage._messageFactory} to create a new L{dns.Message} instance which is used to decode the supplied bytes. ceZdZdZdZy)UEDNSMessageSpecificsTests.test_fromStrCallsMessageFactory..FakeMessageFactory/ Fake message factory. ct||)z Fake fromStr method which raises the arguments it was passed. @param args: positional arguments @param kwargs: keyword arguments rrs rrz]EDNSMessageSpecificsTests.test_fromStrCallsMessageFactory..FakeMessageFactory.fromStrs!v..rNr)r*r+r4rr,rrFakeMessageFactoryr3s   /rr8N) r r_messageFactoryr8r%rrrrr)rr8rU dummyBytesrs rtest_fromStrCallsMessageFactoryz9EDNSMessageSpecificsTests.test_fromStrCallsMessageFactorysg / /    .X   j!))Z @ :-,qvvqxx.@Arctj}Gdd}|fd|_d}||_|j t |j d}|jfif|j|jfy)z~ L{dns._EDNSMessage.fromString} calls L{dns._EDNSMessage._fromMessage} with a L{dns.Message} instance ceZdZdZdZy)REDNSMessageSpecificsTests.test_fromStrCallsFromMessage..FakeMessageFactoryr4cy)zw A noop fake version of fromStr @param bytes: the bytes to be decoded Nr,)rrcs rrzZEDNSMessageSpecificsTests.test_fromStrCallsFromMessage..FakeMessageFactory.fromStrsrNr7r,rrr8r>s   rr8cSrr,) fakeMessagesrzHEDNSMessageSpecificsTests.test_fromStrCallsFromMessage..$sKrct||rr6rs rfakeFromMessagezOEDNSMessageSpecificsTests.test_fromStrCallsFromMessage..fakeFromMessage&T6* *rrN) r rr9 _fromMessager%rrrrr)rrUr8rDrrAs @rtest_fromStrCallsFromMessagez6EDNSMessageSpecificsTests.test_fromStrCallsFromMessagesy      )* / +)   j!))S 9 ;."-/ABrctj}d}||_|jt|j }|j dif|j|jfy)zP L{dns._EDNSMessage.toStr} calls L{dns._EDNSMessage._toMessage} ct||rr6rs r fakeToMessagezIEDNSMessageSpecificsTests.test_toStrCallsToMessage..fakeToMessage3rErr,N) r r _toMessager%rrrrr)rrUrJrs rtest_toStrCallsToMessagez2EDNSMessageSpecificsTests.test_toStrCallsToMessage-sW     +%   j!'' 2 "bAFFAHH#56rctj}tGfddfd}||_|j |j y)z} L{dns._EDNSMessage.toStr} calls C{toStr} on the message returned by L{dns._EDNSMessage._toMessage}. ceZdZdZfdZy)LEDNSMessageSpecificsTests.test_toStrCallsToMessageToStr..FakeMessagez& Fake Message cS)zk Fake toStr which returns dummyBytes. @return: dummyBytes r,)rr:s rrzREDNSMessageSpecificsTests.test_toStrCallsToMessageToStr..FakeMessage.toStrGs "!rN)r)r*r+r4r)r:sr FakeMessagerOBs   "rrQcSrr,)rrrQs rrJzNEDNSMessageSpecificsTests.test_toStrCallsToMessageToStr..fakeToMessageOs = rN)r rr8rKrr)rrUrJrQr:s @@rtest_toStrCallsToMessageToStrz7EDNSMessageSpecificsTests.test_toStrCallsToMessageToStr:sH    X  " " !%  QWWY/rN)r)r*r+r4r rrrrWrrr#r%r(r*rermrurr;rGrLrSr,rrrr[sl%%NRBGJC      M . " *B6C: 70rrceZdZdZej ZdZdZdZ dZ dZ dZ dZ d Zd Zd Zd Zd ZdZdZdZdZdZy)EDNSMessageEqualityTestsz Tests for equality between L{dns._EDNSMessage} instances. These tests will not work with L{dns.Message} because it does not use L{twisted.python.util.FancyEqMixin}. c|j|jd|jd|jdy)zc Two L{dns._EDNSMessage} instances compare equal if they have the same id. rrrNrrs rrz EDNSMessageEqualityTests.test_idasE //   1  %   1  %   1  % rc|j|jd|jd|jdy)zl Two L{dns._EDNSMessage} instances compare equal if they have the same answer flag. TrFNrrs rrz$EDNSMessageEqualityTests.test_answerlE //   t  ,   t  ,   u  - rc|j|jtj|jtj|jtjy)zg Two L{dns._EDNSMessage} instances compare equal if they have the same opCode. rN)rrr r OP_INVERSErs rrz$EDNSMessageEqualityTests.test_opCodewsQ //   s}}  5   s}}  5   s~~  6 rc|j|jd|jd|jdy)zj Two L{dns._EDNSMessage} instances compare equal if they have the same auth flag. TrFNrrs rrz"EDNSMessageEqualityTests.test_authsE //   T  *   T  *   U  + rc|j|jd|jd|jdy)zk Two L{dns._EDNSMessage} instances compare equal if they have the same trunc flag. TrFNrrs rrz#EDNSMessageEqualityTests.test_truncE //   d  +   d  +   e  , rc|j|jd|jd|jdy)zl Two L{dns._EDNSMessage} instances compare equal if they have the same recDes flag. TrFNrrs rrz$EDNSMessageEqualityTests.test_recDesrXrc|j|jd|jd|jdy)zk Two L{dns._EDNSMessage} instances compare equal if they have the same recAv flag. TrFNrrs rrz#EDNSMessageEqualityTests.test_recAvr]rc|j|jd|jd|jdy)zf Two L{dns._EDNSMessage} instances compare equal if they have the same rCode. r1rrNrrs rrz#EDNSMessageEqualityTests.test_rCoderrc|j|jd|jd|jdy)zl Two L{dns._EDNSMessage} instances compare equal if they have the same ednsVersion. rrNrrs rrz)EDNSMessageEqualityTests.test_ednsVersionsE //   A  .   A  .   D  1 rc|j|jd|jd|jdy)zi Two L{dns._EDNSMessage} instances compare equal if they have the same dnssecOK. TrYFNrrs rrWz&EDNSMessageEqualityTests.test_dnssecOKsE //     .     .     / rc|j|jd|jd|jdy)zt Two L{dns._EDNSMessage} instances compare equal if they have the same authenticData flags. TrNFNrrs rrz+EDNSMessageEqualityTests.test_authenticDatasE //   d  3   d  3   e  4 rc|j|jd|jd|jdy)zw Two L{dns._EDNSMessage} instances compare equal if they have the same checkingDisabled flags. Tr\FNrrs rrz.EDNSMessageEqualityTests.test_checkingDisabledsE //     6     6     7 rc|j|jd|jd|jdy)zh Two L{dns._EDNSMessage} instances compare equal if they have the same maxSize. irrNrrs rrz%EDNSMessageEqualityTests.test_maxSizesE //     -     -     - rc |j|jtjdg|jtjdg|jtjdgy)zh Two L{dns._EDNSMessage} instances compare equal if they have the same queries. rrrNrrs rrz%EDNSMessageEqualityTests.test_queriesrrc |j|jtjdtjdg|jtjdtjdg|jtjdtjdgy)zh Two L{dns._EDNSMessage} instances compare equal if they have the same answers. rrrrrrNrrs rrz%EDNSMessageEqualityTests.test_answersrrc |j|jtjdtjtj g|jtjdtjtj g|jtjdtjtj gy)zr Two L{dns._EDNSMessage} instances compare equal if they have the same authority records. rrrrNrrs rrz'EDNSMessageEqualityTests.test_authority rrc |j|jtjdtjdg|jtjdtjdg|jtjdtjdgy)zs Two L{dns._EDNSMessage} instances compare equal if they have the same additional records. rrrrrNrrs rrz(EDNSMessageEqualityTests.test_additional#rrN)r)r*r+r4r rrrrrrrrrrrrWrrrrrrrr,rrrUrUWsi%%N                             " . rrUcReZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zy )StandardEncodingTestsMixina Tests for the encoding and decoding of various standard (not EDNS) messages. These tests should work with both L{dns._EDNSMessage} and L{dns.Message}. TestCase classes that use this mixin must provide a C{messageFactory} method which accepts any argment supported by L{dns._EDNSMessage.__init__}. EDNS specific arguments may be discarded if not supported by the message class under construction. c|j|jditjj tj y)z2 An empty message can be encoded. Nr,)rrrrrrcrs rtest_emptyMessageEncodez2StandardEncodingTestsMixin.test_emptyMessageEncodeHsB  D   8,"5"5"7 8 > > @,BTBTBV rc |j}|jtj|j ||jditj y)z@ An empty message byte sequence can be decoded. Nr,)rrrrcrrrTs rtest_emptyMessageDecodez2StandardEncodingTestsMixin.test_emptyMessageDecodePsQ    ! ,$$&' /D//H,2E2E2GHIrc|j|jditjj tj y)zA A fully populated query message can be encoded. Nr,)rrrrrrcrs rtest_completeQueryEncodez3StandardEncodingTestsMixin.test_completeQueryEncodeYsC  D   ;/"8"8": ; A A C  ! ! # rc |j}|jtjf|j ||jditj y)zG A fully populated message byte string can be decoded. Nr,)rrrrcrrrTs rtest_completeQueryDecodez3StandardEncodingTestsMixin.test_completeQueryDecodebsT    ! /'')*+ /D//K/2H2H2JKLrcdjtdDcgc]}tj|c}}tj|}tj dtj |}|j}|jj||j}|j}|j||j|jdjtj|j|jdjj|ycc}w)zu A I{NULL} record with an arbitrary payload can be encoded and decoded as part of a message. rrrrrN)rrr r2rrrrrrrrrarrrs rrz$StandardEncodingTestsMixin.test_NULLks U3Z@#..+@Aooe$ \\+sxx =""$ B JJL""$ Q dll1o55sG a0088%@AsD>c|j|jditjj tj y)zv If the message C{authoritative} attribute is set to 0, the encoded bytes will have AA bit 0. Nr,)rrrrrrcrs r"test_nonAuthoritativeMessageEncodez=StandardEncodingTestsMixin.test_nonAuthoritativeMessageEncode}sD  D   C"9"@"@"B C I I K # ) ) + rc |j}|jtj|j ||jditj y)z The L{dns.RRHeader} instances created by a message from a non-authoritative message byte string are marked as not authoritative. Nr,)rrrrcrrrTs r"test_nonAuthoritativeMessageDecodez=StandardEncodingTestsMixin.test_nonAuthoritativeMessageDecodesS    ! )//12 /D//S2I2P2P2RSTrc|j|jditjj tj y)zv If the message C{authoritative} attribute is set to 1, the encoded bytes will have AA bit 1. Nr,)rrrrrrcrs rtest_authoritativeMessageEncodez:StandardEncodingTestsMixin.test_authoritativeMessageEncodesD  D   @"6"="="? @ F F H & & ( rc |j}|jtj|j ||jditj y)z The message and its L{dns.RRHeader} instances created by C{decode} from an authoritative message byte string, are marked as authoritative. Nr,)rrrrcrrrTs rtest_authoritativeMessageDecodez:StandardEncodingTestsMixin.test_authoritativeMessageDecodesS    ! &,,./ /D//P2F2M2M2OPQrc|j|jditjj tj y)zm If the message C{trunc} attribute is set to 1 the encoded bytes will have TR bit 1. Nr,)rrrrrrcrs rtest_truncatedMessageEncodez6StandardEncodingTestsMixin.test_truncatedMessageEncodesD  D   <"2"9"9"; < B B D  " " $ rc |j}|jtj|j ||jditj y)zn The message instance created by decoding a truncated message is marked as truncated. Nr,)rrrrcrrrTs rtest_truncatedMessageDecodez6StandardEncodingTestsMixin.test_truncatedMessageDecodesS    ! "((*+ /D//L2B2I2I2KLMrN)r)r*r+r4rnrprrrtrrwryr{r}rrr,rrrlrl;sD  J MA$ U R Nrrlc(eZdZdZej Zy) EDNSMessageStandardEncodingTestszq Tests for the encoding and decoding of various standard (non-EDNS) messages by L{dns._EDNSMessage}. Nrr,rrrrrrrc eZdZdZedZy)MessageStandardEncodingTestszl Tests for the encoding and decoding of various standard (non-EDNS) messages by L{dns.Message}. c .|jdg}|jdg}|jdg}|jdg}|jddtjdi|}||_||_||_||_t|S)a This function adapts constructor arguments expected by _EDNSMessage.__init__ to arguments suitable for use with the Message.__init__. Also handles the fact that unlike L{dns._EDNSMessage}, L{dns.Message.__init__} does not accept queries, answers etc as arguments. Also removes any L{dns._EDNSMessage} specific arguments. @param args: The positional arguments which will be passed to L{dns.Message.__init__}. @param kwargs: The keyword arguments which will be stripped of EDNS specific arguments before being passed to L{dns.Message.__init__}. @return: An L{dns.Message} instance. rrrrrNr,)rr rurrrrr)rrrrrrUs rrz+MessageStandardEncodingTests.messageFactorys***Y+**Y+JJ{B/ ZZ b1  =$' KK !& !   !  ##rN)r)r*r+r4 staticmethodrr,rrrrs  $ $rrcdeZdZdZej ZdZdZdZ dZ dZ dZ dZ d Zd Zd Zy ) EDNSMessageEDNSEncodingTestszz Tests for the encoding and decoding of various EDNS messages. These test will not work with L{dns.Message}. c|j}|jtj|j |j gy)z The L(_EDNSMessage} instance created by L{dns._EDNSMessage.decode} from an EDNS query never includes OPT records in the additional section. N)rrrrcrrrTs r&test_ednsMessageDecodeStripsOptRecordszCEDNSMessageEDNSEncodingTests.test_ednsMessageDecodeStripsOptRecordss<    ! "((*+ r*rc*tj}tjdtjdg|_tj}|j |j |j|jy)a  An L(_EDNSMessage} instance created from a byte string containing multiple I{OPT} records will discard all the C{OPT} records. C{ednsVersion} will be set to L{None}. @see: U{https://tools.ietf.org/html/rfc6891#section-6.1.1} rrTrN) r rur/rrrr assertIsNoner)rrU ednsMessages r(test_ednsMessageDecodeMultipleOptRecordszEEDNSMessageEDNSEncodingTests.test_ednsMessageDecodeMultipleOptRecordssc KKMq13>>!3LM &&( AGGI& +112rcDtj}|jtj tj j |}g}dD],}t||t||us|j|.|r|jd|yy)z L{dns._EDNSMessage._fromMessage} returns an L{_EDNSMessage} instance whose queries, answers, authority and additional lists are copies (not references to) the original message lists. )rrrrzZMessage and _EDNSMessage shared references to the following section lists after decoding: N) r rurrrcrrFrrfail)rstandardMessager duplicatesrs rtest_fromMessageCopiesSectionsz;EDNSMessageEDNSEncodingTests.test_fromMessageCopiesSectionss ++- 0 6 6 89&&33OD  I ,H1W[(5SS!!(+ ,  II6@C  rctjd}|j|j|jgy)zf L{dns._EDNSMessage.toStr} makes no in place changes to the message instance. rrbN)r rrrr)rrs rtest_toMessageCopiesSectionsz9EDNSMessageEDNSEncodingTests.test_toMessageCopiesSections+s6 &&15  //4rct}tjd}|j|tj}|j d|j |tj}|g|_g}|jtjj|j|jjtjtj|jtjj|j|jjdtjtj|jtjj|j|jdgdz|y)a L{dns._EDNSMessage} can decode OPT records, regardless of their position in the additional records section. "The OPT RR MAY be placed anywhere within the additional data section." @see: U{https://tools.ietf.org/html/rfc6891#section-6.1.1} rrTr)r}rN)rr r/rlrrrgrurrrrFrrinsertr)rrc optRecord optRRHeaderrUactualMessagess rtest_optHeaderPositionz3EDNSMessageEDNSEncodingTests.test_optHeaderPosition4s) INN1- lln  q 1 KKM#} c..;;A>JJK CLLcee45c..;;A>JJK As||78c..;;A>JJK !q.1rc |j}|jtj|j ||jditj y)z The L(_EDNSMessage} instance created by L{dns._EDNSMessage.fromStr} derives its edns specific values (C{ednsVersion}, etc) from the supplied OPT record. Nr,)rrrrcrrrTs rtest_ednsDecodez,EDNSMessageEDNSEncodingTests.test_ednsDecodeRsS    ! %++-. /D//O2E2L2L2NOPrc|j|jditjj tj y)z The L(_EDNSMessage} instance created by L{dns._EDNSMessage.toStr} encodes its edns specific values (C{ednsVersion}, etc) into an OPT record added to the additional section. Nr,)rrrrrrcrs rtest_ednsEncodez,EDNSMessageEDNSEncodingTests.test_ednsEncode]sD  D   ?"5"<"<"> ? E E G  % % ' rc|j|jditjj tj y)z The L(_EDNSMessage.toStr} encodes the extended I{RCODE} (>=16) by assigning the lower 4bits to the message RCODE field and the upper 4bits to the OPT pseudo record. Nr,)rrrrrrcrs rtest_extendedRcodeEncodez5EDNSMessageEDNSEncodingTests.test_extendedRcodeEncodehsD  D   D":"A"A"C D J J L $ * * , rc |j}|jtj|j ||jditj y)z The L(_EDNSMessage} instance created by L{dns._EDNSMessage.fromStr} derives RCODE from the supplied OPT record. Nr,)rrrrcrrrTs rtest_extendedRcodeDecodez5EDNSMessageEDNSEncodingTests.test_extendedRcodeDecodessS    ! *0023 /D//T2J2Q2Q2STUrc|jdd}|j}|jd|j|jdj fy)z Note that EXTENDED-RCODE value 0 indicates that an unextended RCODE is in use (values 0 through 15). https://tools.ietf.org/html/rfc6891#section-6.1.3 rr)rsr)rrN)rrKrrsrr,)rrrs rtest_extendedRcodeZeroz3EDNSMessageEDNSEncodingTests.test_extendedRcodeZero}sW)))B %002    " "O$>$>q$A$O$O P rN)r)r*r+r4r rrrrrrrrrrrrr,rrrrsH %%N+3",52< Q    V  rrc4eZdZdZdZdZdZdZdZdZ y) ResponseFromMessageTestsz0 Tests for L{dns._responseFromMessage}. ctj}tjtj|}|j||y)z L{dns.Message._responseFromMessage} is a constructor function which generates a new I{answer} message from an existing L{dns.Message} like instance. responseConstructorrN)r ru_responseFromMessage assertIsNotrrequestresponses r$test_responseFromMessageResponseTypez=ResponseFromMessageTests.test_responseFromMessageResponseTypes: ++-++ # W  (+rcGdd}tj}|jtj|||y)zN L{dns._responseFromMessage} returns a new instance of C{cls} ceZdZdZgZy)AResponseFromMessageTests.test_responseType..SuppliedClassrN)r)r*r+rqrr,rr SuppliedClassrs BGrrrN)r rurar)rr expectedClasss rtest_responseTypez*ResponseFromMessageTests.test_responseTypes?       $ $$1=?    rc |jdtjtjtjdjy)zi L{dns._responseFromMessage} copies the C{id} attribute of the original message. irrN)rr rrurqrs rtest_responseIdz(ResponseFromMessageTests.test_responseIds:    $ $$'KK9M b  rctj}tjtj|}|jd|j|jfy)zP L{dns._responseFromMessage} sets the C{answer} flag to L{True} r)FTN)r rurrrgrs rtest_responseAnswerz,ResponseFromMessageTests.test_responseAnswersG++-++ # W  (IJrctj}tttg}|dd|_|j |tj tj|jy)zn L{dns._responseFromMessage} copies the C{queries} attribute of the original message. Nr)r rur8rrr)rrexpectedQueriess rtest_responseQueriesz-ResponseFromMessageTests.test_responseQueriessZ ++-!8VXvx8)!,    $ $$'KK g  rc|jdtjtjtjdjy)z L{dns._responseFromMessage} accepts other C{kwargs} which are assigned to the new message before it is returned. r^)rrrsN)rr rrursrs rtest_responseKwargsz,ResponseFromMessageTests.test_responseKwargss9    $ $$'KKc e  rN) r)r*r+r4rrrrrrr,rrrrs& , $  K  rrc0eZdZdZ ddZdefdZy)Fooz An example class for use in L{dns._compactRepr} tests. It follows the pattern of initialiser settable flags, fields and sections found in L{dns.Message} and L{dns._EDNSMessage}. Nc`||_||_||_||_||_|g}||_y)zK Set some flags, fields and sections as public attributes. N)field1field2alwaysShowFieldflagTrue flagFalsesection1)rrrrrrrs rrz Foo.__init__s:  .  "  H  rrZctj|djdjdjdjS)zO Call L{dns._compactRepr} to generate a string representation. rzfield1 field2 alwaysShowFieldzflagTrue flagFalsezsection1 section2) alwaysShow fieldNames flagNames sectionNames)r _compactReprsplitrs r__repr__z Foo.__repr__sJ (..06<<>*002,224   r)rrASTFN)r)r*r+r4rstrrr,rrrrs,!,  #  rrc,eZdZdZeZdZdZdZdZ y)CompactReprTestsz( Tests for L{dns._compactRepr}. cV|jdt|jy)z L{dns._compactRepr} omits field values and sections which have the default value. Flags which are True are always shown. z)Nr,rs r test_defaultszCompactReprTests.test_defaultss%  7d>Q>Q>S9T rc`|jdd}|jdt|y)zV L{dns._compactRepr} displays flags if they have a non-default value. T)rrz3Nr.rTs rtest_flagsIfSetz CompactReprTests.test_flagsIfSets1     >  J G rc`|jdd}|jdt|y)zg L{dns._compactRepr} displays field values if they differ from their defaults. r>r)rrz=Nr.rTs rtest_nonDefautFieldsz%CompactReprTests.test_nonDefautFields's5   r"  5   G rc~|j}gd|_gd|_|jdt |y)zY L{dns._compactRepr} displays sections which differ from their defaults. )rrr)rrrzON)rrsection2rrdrTs rtest_nonDefaultSectionsz(CompactReprTests.test_nonDefaultSections7s<    !     G rN) r)r*r+r4rrrrrrr,rrrr s"N    rrr)fr4rGiorzope.interface.verifyrtwisted.internetrrtwisted.internet.errorrr twisted.namesr twisted.python.failurer twisted.python.utilr r twisted.testr twisted.test.testutilsr twisted.trialrrQrUrXr[r_rbrerhrkrrrrrr r&r+r0r3rErrrrr?rrSynchronousTestCaserTestCaser.r6r\rrQr_rHrrrr1r<rNrrrrrrr$r3r ExceptionrrrrrrrrrrrrrrrrrUrlrrrrrrr,rrrs  -*D*;&7"MMMMMMMMMMMMNNLLNNOONNNNMMMMNNOOMMOO5 <"P44"PJ 8H%% 8A:H%%A:HJ*!!J*Z_B))_BF  q18//q1ha 183O3Oa H11*rSH--rSj''(QSx((QShI !!I XZ  ((*;*;Z  z+ H%%+ \0W440Wf&&\F55\F~2 2 jd )8+<+<d N M,183D3DM,`"+ + \* * Z. . b. . bo o d8 8 v| | ~8 8 v+ m+::>++\' ' Tc?c?L&68T8T&!68T8T!y0 5x7S7Sy0xa 3X5Q5Qa H|N|N~& < <&)$ < <)$XY 8#?#?Y xS x;;S l' ' T9 x339 r