1 # Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
3 # Permission to use, copy, modify, and distribute this software and its
4 # documentation for any purpose with or without fee is hereby granted,
5 # provided that the above copyright notice and this permission notice
6 # appear in all copies.
8 # THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
9 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
11 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
14 # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 import dns
.reversename
25 class NameTestCase(unittest
.TestCase
):
27 self
.origin
= dns
.name
.from_text('example.')
29 def testFromTextRel1(self
):
30 n
= dns
.name
.from_text('foo.bar')
31 self
.failUnless(n
.labels
== ('foo', 'bar', ''))
33 def testFromTextRel2(self
):
34 n
= dns
.name
.from_text('foo.bar', origin
=self
.origin
)
35 self
.failUnless(n
.labels
== ('foo', 'bar', 'example', ''))
37 def testFromTextRel3(self
):
38 n
= dns
.name
.from_text('foo.bar', origin
=None)
39 self
.failUnless(n
.labels
== ('foo', 'bar'))
41 def testFromTextRel4(self
):
42 n
= dns
.name
.from_text('@', origin
=None)
43 self
.failUnless(n
== dns
.name
.empty
)
45 def testFromTextRel5(self
):
46 n
= dns
.name
.from_text('@', origin
=self
.origin
)
47 self
.failUnless(n
== self
.origin
)
49 def testFromTextAbs1(self
):
50 n
= dns
.name
.from_text('foo.bar.')
51 self
.failUnless(n
.labels
== ('foo', 'bar', ''))
53 def testTortureFromText(self
):
58 r
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
59 r
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
60 r
'\000.\008.\010.\032.\046.\092.\099.\255',
65 r
'\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255.\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255.\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255.\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255',
71 '\\', # yes, we don't want the 'r' prefix!
75 r
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
76 r
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
77 r
'\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255.\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255.\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255.\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255',
81 n
= dns
.name
.from_text(t
)
83 self
.fail("good test '%s' raised an exception" % t
)
87 n
= dns
.name
.from_text(t
)
91 self
.fail("bad test '%s' did not raise an exception" % t
)
93 def testImmutable1(self
):
95 self
.origin
.labels
= ()
96 self
.failUnlessRaises(TypeError, bad
)
98 def testImmutable2(self
):
100 self
.origin
.labels
[0] = 'foo'
101 self
.failUnlessRaises(TypeError, bad
)
104 self
.failUnless(dns
.name
.root
.is_absolute())
107 self
.failUnless(not dns
.name
.empty
.is_absolute())
110 self
.failUnless(self
.origin
.is_absolute())
113 n
= dns
.name
.from_text('foo', origin
=None)
114 self
.failUnless(not n
.is_absolute())
117 n
= dns
.name
.from_text('*.foo', origin
=None)
118 self
.failUnless(n
.is_wild())
121 n
= dns
.name
.from_text('*a.foo', origin
=None)
122 self
.failUnless(not n
.is_wild())
125 n
= dns
.name
.from_text('a.*.foo', origin
=None)
126 self
.failUnless(not n
.is_wild())
129 self
.failUnless(not dns
.name
.root
.is_wild())
132 self
.failUnless(not dns
.name
.empty
.is_wild())
135 n1
= dns
.name
.from_text('fOo.COM')
136 n2
= dns
.name
.from_text('foo.com')
137 self
.failUnless(hash(n1
) == hash(n2
))
139 def testCompare1(self
):
140 n1
= dns
.name
.from_text('a')
141 n2
= dns
.name
.from_text('b')
142 self
.failUnless(n1
< n2
)
143 self
.failUnless(n2
> n1
)
145 def testCompare2(self
):
146 n1
= dns
.name
.from_text('')
147 n2
= dns
.name
.from_text('b')
148 self
.failUnless(n1
< n2
)
149 self
.failUnless(n2
> n1
)
151 def testCompare3(self
):
152 self
.failUnless(dns
.name
.empty
< dns
.name
.root
)
153 self
.failUnless(dns
.name
.root
> dns
.name
.empty
)
155 def testCompare4(self
):
156 self
.failUnless(dns
.name
.root
!= 1)
158 def testCompare5(self
):
159 self
.failUnless(dns
.name
.root
< 1 or dns
.name
.root
> 1)
161 def testSubdomain1(self
):
162 self
.failUnless(not dns
.name
.empty
.is_subdomain(dns
.name
.root
))
164 def testSubdomain2(self
):
165 self
.failUnless(not dns
.name
.root
.is_subdomain(dns
.name
.empty
))
167 def testSubdomain3(self
):
168 n
= dns
.name
.from_text('foo', origin
=self
.origin
)
169 self
.failUnless(n
.is_subdomain(self
.origin
))
171 def testSubdomain4(self
):
172 n
= dns
.name
.from_text('foo', origin
=self
.origin
)
173 self
.failUnless(n
.is_subdomain(dns
.name
.root
))
175 def testSubdomain5(self
):
176 n
= dns
.name
.from_text('foo', origin
=self
.origin
)
177 self
.failUnless(n
.is_subdomain(n
))
179 def testSuperdomain1(self
):
180 self
.failUnless(not dns
.name
.empty
.is_superdomain(dns
.name
.root
))
182 def testSuperdomain2(self
):
183 self
.failUnless(not dns
.name
.root
.is_superdomain(dns
.name
.empty
))
185 def testSuperdomain3(self
):
186 n
= dns
.name
.from_text('foo', origin
=self
.origin
)
187 self
.failUnless(self
.origin
.is_superdomain(n
))
189 def testSuperdomain4(self
):
190 n
= dns
.name
.from_text('foo', origin
=self
.origin
)
191 self
.failUnless(dns
.name
.root
.is_superdomain(n
))
193 def testSuperdomain5(self
):
194 n
= dns
.name
.from_text('foo', origin
=self
.origin
)
195 self
.failUnless(n
.is_superdomain(n
))
197 def testCanonicalize1(self
):
198 n
= dns
.name
.from_text('FOO.bar', origin
=self
.origin
)
200 self
.failUnless(c
.labels
== ('foo', 'bar', 'example', ''))
202 def testToText1(self
):
203 n
= dns
.name
.from_text('FOO.bar', origin
=self
.origin
)
205 self
.failUnless(t
== 'FOO.bar.example.')
207 def testToText2(self
):
208 n
= dns
.name
.from_text('FOO.bar', origin
=self
.origin
)
210 self
.failUnless(t
== 'FOO.bar.example')
212 def testToText3(self
):
213 n
= dns
.name
.from_text('FOO.bar', origin
=None)
215 self
.failUnless(t
== 'FOO.bar')
217 def testToText4(self
):
218 t
= dns
.name
.empty
.to_text()
219 self
.failUnless(t
== '@')
221 def testToText5(self
):
222 t
= dns
.name
.root
.to_text()
223 self
.failUnless(t
== '.')
225 def testToText6(self
):
226 n
= dns
.name
.from_text('FOO bar', origin
=None)
228 self
.failUnless(t
== r
'FOO\032bar')
230 def testToText7(self
):
231 n
= dns
.name
.from_text(r
'FOO\.bar', origin
=None)
233 self
.failUnless(t
== r
'FOO\.bar')
235 def testToText8(self
):
236 n
= dns
.name
.from_text(r
'\070OO\.bar', origin
=None)
238 self
.failUnless(t
== r
'FOO\.bar')
240 def testSlice1(self
):
241 n
= dns
.name
.from_text(r
'a.b.c.', origin
=None)
243 self
.failUnless(s
== ('a', 'b', 'c', ''))
245 def testSlice2(self
):
246 n
= dns
.name
.from_text(r
'a.b.c.', origin
=None)
248 self
.failUnless(s
== ('a', 'b'))
250 def testSlice3(self
):
251 n
= dns
.name
.from_text(r
'a.b.c.', origin
=None)
253 self
.failUnless(s
== ('c', ''))
255 def testEmptyLabel1(self
):
257 n
= dns
.name
.Name(['a', '', 'b'])
258 self
.failUnlessRaises(dns
.name
.EmptyLabel
, bad
)
260 def testEmptyLabel2(self
):
262 n
= dns
.name
.Name(['', 'b'])
263 self
.failUnlessRaises(dns
.name
.EmptyLabel
, bad
)
265 def testEmptyLabel3(self
):
266 n
= dns
.name
.Name(['b', ''])
269 def testLongLabel(self
):
270 n
= dns
.name
.Name(['a' * 63])
273 def testLabelTooLong(self
):
275 n
= dns
.name
.Name(['a' * 64, 'b'])
276 self
.failUnlessRaises(dns
.name
.LabelTooLong
, bad
)
278 def testLongName(self
):
279 n
= dns
.name
.Name(['a' * 63, 'a' * 63, 'a' * 63, 'a' * 62])
282 def testNameTooLong(self
):
284 n
= dns
.name
.Name(['a' * 63, 'a' * 63, 'a' * 63, 'a' * 63])
285 self
.failUnlessRaises(dns
.name
.NameTooLong
, bad
)
287 def testConcat1(self
):
288 n1
= dns
.name
.Name(['a', 'b'])
289 n2
= dns
.name
.Name(['c', 'd'])
290 e
= dns
.name
.Name(['a', 'b', 'c', 'd'])
292 self
.failUnless(r
== e
)
294 def testConcat2(self
):
295 n1
= dns
.name
.Name(['a', 'b'])
296 n2
= dns
.name
.Name([])
297 e
= dns
.name
.Name(['a', 'b'])
299 self
.failUnless(r
== e
)
301 def testConcat2(self
):
302 n1
= dns
.name
.Name([])
303 n2
= dns
.name
.Name(['a', 'b'])
304 e
= dns
.name
.Name(['a', 'b'])
306 self
.failUnless(r
== e
)
308 def testConcat3(self
):
309 n1
= dns
.name
.Name(['a', 'b', ''])
310 n2
= dns
.name
.Name([])
311 e
= dns
.name
.Name(['a', 'b', ''])
313 self
.failUnless(r
== e
)
315 def testConcat4(self
):
316 n1
= dns
.name
.Name(['a', 'b'])
317 n2
= dns
.name
.Name(['c', ''])
318 e
= dns
.name
.Name(['a', 'b', 'c', ''])
320 self
.failUnless(r
== e
)
322 def testConcat5(self
):
324 n1
= dns
.name
.Name(['a', 'b', ''])
325 n2
= dns
.name
.Name(['c'])
327 self
.failUnlessRaises(dns
.name
.AbsoluteConcatenation
, bad
)
329 def testBadEscape(self
):
331 n
= dns
.name
.from_text(r
'a.b\0q1.c.')
333 self
.failUnlessRaises(dns
.name
.BadEscape
, bad
)
335 def testDigestable1(self
):
336 n
= dns
.name
.from_text('FOO.bar')
337 d
= n
.to_digestable()
338 self
.failUnless(d
== '\x03foo\x03bar\x00')
340 def testDigestable2(self
):
341 n1
= dns
.name
.from_text('FOO.bar')
342 n2
= dns
.name
.from_text('foo.BAR.')
343 d1
= n1
.to_digestable()
344 d2
= n2
.to_digestable()
345 self
.failUnless(d1
== d2
)
347 def testDigestable3(self
):
348 d
= dns
.name
.root
.to_digestable()
349 self
.failUnless(d
== '\x00')
351 def testDigestable4(self
):
352 n
= dns
.name
.from_text('FOO.bar', None)
353 d
= n
.to_digestable(dns
.name
.root
)
354 self
.failUnless(d
== '\x03foo\x03bar\x00')
356 def testBadDigestable(self
):
358 n
= dns
.name
.from_text('FOO.bar', None)
359 d
= n
.to_digestable()
360 self
.failUnlessRaises(dns
.name
.NeedAbsoluteNameOrOrigin
, bad
)
362 def testToWire1(self
):
363 n
= dns
.name
.from_text('FOO.bar')
364 f
= cStringIO
.StringIO()
366 n
.to_wire(f
, compress
)
367 self
.failUnless(f
.getvalue() == '\x03FOO\x03bar\x00')
369 def testToWire2(self
):
370 n
= dns
.name
.from_text('FOO.bar')
371 f
= cStringIO
.StringIO()
373 n
.to_wire(f
, compress
)
374 n
.to_wire(f
, compress
)
375 self
.failUnless(f
.getvalue() == '\x03FOO\x03bar\x00\xc0\x00')
377 def testToWire3(self
):
378 n1
= dns
.name
.from_text('FOO.bar')
379 n2
= dns
.name
.from_text('foo.bar')
380 f
= cStringIO
.StringIO()
382 n1
.to_wire(f
, compress
)
383 n2
.to_wire(f
, compress
)
384 self
.failUnless(f
.getvalue() == '\x03FOO\x03bar\x00\xc0\x00')
386 def testToWire4(self
):
387 n1
= dns
.name
.from_text('FOO.bar')
388 n2
= dns
.name
.from_text('a.foo.bar')
389 f
= cStringIO
.StringIO()
391 n1
.to_wire(f
, compress
)
392 n2
.to_wire(f
, compress
)
393 self
.failUnless(f
.getvalue() == '\x03FOO\x03bar\x00\x01\x61\xc0\x00')
395 def testToWire5(self
):
396 n1
= dns
.name
.from_text('FOO.bar')
397 n2
= dns
.name
.from_text('a.foo.bar')
398 f
= cStringIO
.StringIO()
400 n1
.to_wire(f
, compress
)
402 self
.failUnless(f
.getvalue() == \
403 '\x03FOO\x03bar\x00\x01\x61\x03foo\x03bar\x00')
405 def testToWire6(self
):
406 n
= dns
.name
.from_text('FOO.bar')
408 self
.failUnless(v
== '\x03FOO\x03bar\x00')
410 def testBadToWire(self
):
412 n
= dns
.name
.from_text('FOO.bar', None)
413 f
= cStringIO
.StringIO()
415 n
.to_wire(f
, compress
)
416 self
.failUnlessRaises(dns
.name
.NeedAbsoluteNameOrOrigin
, bad
)
418 def testSplit1(self
):
419 n
= dns
.name
.from_text('foo.bar.')
420 (prefix
, suffix
) = n
.split(2)
421 ep
= dns
.name
.from_text('foo', None)
422 es
= dns
.name
.from_text('bar.', None)
423 self
.failUnless(prefix
== ep
and suffix
== es
)
425 def testSplit2(self
):
426 n
= dns
.name
.from_text('foo.bar.')
427 (prefix
, suffix
) = n
.split(1)
428 ep
= dns
.name
.from_text('foo.bar', None)
429 es
= dns
.name
.from_text('.', None)
430 self
.failUnless(prefix
== ep
and suffix
== es
)
432 def testSplit3(self
):
433 n
= dns
.name
.from_text('foo.bar.')
434 (prefix
, suffix
) = n
.split(0)
435 ep
= dns
.name
.from_text('foo.bar.', None)
436 es
= dns
.name
.from_text('', None)
437 self
.failUnless(prefix
== ep
and suffix
== es
)
439 def testSplit4(self
):
440 n
= dns
.name
.from_text('foo.bar.')
441 (prefix
, suffix
) = n
.split(3)
442 ep
= dns
.name
.from_text('', None)
443 es
= dns
.name
.from_text('foo.bar.', None)
444 self
.failUnless(prefix
== ep
and suffix
== es
)
446 def testBadSplit1(self
):
448 n
= dns
.name
.from_text('foo.bar.')
449 (prefix
, suffix
) = n
.split(-1)
450 self
.failUnlessRaises(ValueError, bad
)
452 def testBadSplit2(self
):
454 n
= dns
.name
.from_text('foo.bar.')
455 (prefix
, suffix
) = n
.split(4)
456 self
.failUnlessRaises(ValueError, bad
)
458 def testRelativize1(self
):
459 n
= dns
.name
.from_text('a.foo.bar.', None)
460 o
= dns
.name
.from_text('bar.', None)
461 e
= dns
.name
.from_text('a.foo', None)
462 self
.failUnless(n
.relativize(o
) == e
)
464 def testRelativize2(self
):
465 n
= dns
.name
.from_text('a.foo.bar.', None)
468 self
.failUnless(n
.relativize(o
) == e
)
470 def testRelativize3(self
):
471 n
= dns
.name
.from_text('a.foo.bar.', None)
472 o
= dns
.name
.from_text('blaz.', None)
474 self
.failUnless(n
.relativize(o
) == e
)
476 def testRelativize4(self
):
477 n
= dns
.name
.from_text('a.foo', None)
480 self
.failUnless(n
.relativize(o
) == e
)
482 def testDerelativize1(self
):
483 n
= dns
.name
.from_text('a.foo', None)
484 o
= dns
.name
.from_text('bar.', None)
485 e
= dns
.name
.from_text('a.foo.bar.', None)
486 self
.failUnless(n
.derelativize(o
) == e
)
488 def testDerelativize2(self
):
490 o
= dns
.name
.from_text('a.foo.bar.', None)
492 self
.failUnless(n
.derelativize(o
) == e
)
494 def testDerelativize3(self
):
495 n
= dns
.name
.from_text('a.foo.bar.', None)
496 o
= dns
.name
.from_text('blaz.', None)
498 self
.failUnless(n
.derelativize(o
) == e
)
500 def testChooseRelativity1(self
):
501 n
= dns
.name
.from_text('a.foo.bar.', None)
502 o
= dns
.name
.from_text('bar.', None)
503 e
= dns
.name
.from_text('a.foo', None)
504 self
.failUnless(n
.choose_relativity(o
, True) == e
)
506 def testChooseRelativity2(self
):
507 n
= dns
.name
.from_text('a.foo.bar.', None)
508 o
= dns
.name
.from_text('bar.', None)
510 self
.failUnless(n
.choose_relativity(o
, False) == e
)
512 def testChooseRelativity3(self
):
513 n
= dns
.name
.from_text('a.foo', None)
514 o
= dns
.name
.from_text('bar.', None)
515 e
= dns
.name
.from_text('a.foo.bar.', None)
516 self
.failUnless(n
.choose_relativity(o
, False) == e
)
518 def testChooseRelativity4(self
):
519 n
= dns
.name
.from_text('a.foo', None)
522 self
.failUnless(n
.choose_relativity(o
, True) == e
)
524 def testChooseRelativity5(self
):
525 n
= dns
.name
.from_text('a.foo', None)
528 self
.failUnless(n
.choose_relativity(o
, False) == e
)
530 def testChooseRelativity6(self
):
531 n
= dns
.name
.from_text('a.foo.', None)
534 self
.failUnless(n
.choose_relativity(o
, True) == e
)
536 def testChooseRelativity7(self
):
537 n
= dns
.name
.from_text('a.foo.', None)
540 self
.failUnless(n
.choose_relativity(o
, False) == e
)
542 def testFromWire1(self
):
543 w
= '\x03foo\x00\xc0\x00'
544 (n1
, cused1
) = dns
.name
.from_wire(w
, 0)
545 (n2
, cused2
) = dns
.name
.from_wire(w
, cused1
)
546 en1
= dns
.name
.from_text('foo.')
550 self
.failUnless(n1
== en1
and cused1
== ecused1
and \
551 n2
== en2
and cused2
== ecused2
)
553 def testFromWire1(self
):
554 w
= '\x03foo\x00\x01a\xc0\x00\x01b\xc0\x05'
556 (n1
, cused1
) = dns
.name
.from_wire(w
, current
)
558 (n2
, cused2
) = dns
.name
.from_wire(w
, current
)
560 (n3
, cused3
) = dns
.name
.from_wire(w
, current
)
561 en1
= dns
.name
.from_text('foo.')
562 en2
= dns
.name
.from_text('a.foo.')
563 en3
= dns
.name
.from_text('b.a.foo.')
567 self
.failUnless(n1
== en1
and cused1
== ecused1
and \
568 n2
== en2
and cused2
== ecused2
and \
569 n3
== en3
and cused3
== ecused3
)
571 def testBadFromWire1(self
):
573 w
= '\x03foo\xc0\x04'
574 (n
, cused
) = dns
.name
.from_wire(w
, 0)
575 self
.failUnlessRaises(dns
.name
.BadPointer
, bad
)
577 def testBadFromWire2(self
):
579 w
= '\x03foo\xc0\x05'
580 (n
, cused
) = dns
.name
.from_wire(w
, 0)
581 self
.failUnlessRaises(dns
.name
.BadPointer
, bad
)
583 def testBadFromWire3(self
):
586 (n
, cused
) = dns
.name
.from_wire(w
, 0)
587 self
.failUnlessRaises(dns
.name
.BadLabelType
, bad
)
589 def testBadFromWire4(self
):
592 (n
, cused
) = dns
.name
.from_wire(w
, 0)
593 self
.failUnlessRaises(dns
.name
.BadLabelType
, bad
)
595 def testParent1(self
):
596 n
= dns
.name
.from_text('foo.bar.')
597 self
.failUnless(n
.parent() == dns
.name
.from_text('bar.'))
598 self
.failUnless(n
.parent().parent() == dns
.name
.root
)
600 def testParent2(self
):
601 n
= dns
.name
.from_text('foo.bar', None)
602 self
.failUnless(n
.parent() == dns
.name
.from_text('bar', None))
603 self
.failUnless(n
.parent().parent() == dns
.name
.empty
)
605 def testParent3(self
):
609 self
.failUnlessRaises(dns
.name
.NoParent
, bad
)
611 def testParent4(self
):
615 self
.failUnlessRaises(dns
.name
.NoParent
, bad
)
617 def testFromUnicode1(self
):
618 n
= dns
.name
.from_text(u
'foo.bar')
619 self
.failUnless(n
.labels
== ('foo', 'bar', ''))
621 def testFromUnicode2(self
):
622 n
= dns
.name
.from_text(u
'foo\u1234bar.bar')
623 self
.failUnless(n
.labels
== ('xn--foobar-r5z', 'bar', ''))
625 def testFromUnicodeAlternateDot1(self
):
626 n
= dns
.name
.from_text(u
'foo\u3002bar')
627 self
.failUnless(n
.labels
== ('foo', 'bar', ''))
629 def testFromUnicodeAlternateDot2(self
):
630 n
= dns
.name
.from_text(u
'foo\uff0ebar')
631 self
.failUnless(n
.labels
== ('foo', 'bar', ''))
633 def testFromUnicodeAlternateDot3(self
):
634 n
= dns
.name
.from_text(u
'foo\uff61bar')
635 self
.failUnless(n
.labels
== ('foo', 'bar', ''))
637 def testToUnicode1(self
):
638 n
= dns
.name
.from_text(u
'foo.bar')
640 self
.failUnless(s
== u
'foo.bar.')
642 def testToUnicode2(self
):
643 n
= dns
.name
.from_text(u
'foo\u1234bar.bar')
645 self
.failUnless(s
== u
'foo\u1234bar.bar.')
647 def testToUnicode3(self
):
648 n
= dns
.name
.from_text('foo.bar')
650 self
.failUnless(s
== u
'foo.bar.')
652 def testReverseIPv4(self
):
653 e
= dns
.name
.from_text('1.0.0.127.in-addr.arpa.')
654 n
= dns
.reversename
.from_address('127.0.0.1')
655 self
.failUnless(e
== n
)
657 def testReverseIPv6(self
):
658 e
= dns
.name
.from_text('1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa.')
659 n
= dns
.reversename
.from_address('::1')
660 self
.failUnless(e
== n
)
662 def testBadReverseIPv4(self
):
664 n
= dns
.reversename
.from_address('127.0.foo.1')
665 self
.failUnlessRaises(dns
.exception
.SyntaxError, bad
)
667 def testBadReverseIPv6(self
):
669 n
= dns
.reversename
.from_address('::1::1')
670 self
.failUnlessRaises(dns
.exception
.SyntaxError, bad
)
672 def testForwardIPv4(self
):
673 n
= dns
.name
.from_text('1.0.0.127.in-addr.arpa.')
675 text
= dns
.reversename
.to_address(n
)
676 self
.failUnless(text
== e
)
678 def testForwardIPv6(self
):
679 n
= dns
.name
.from_text('1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa.')
681 text
= dns
.reversename
.to_address(n
)
682 self
.failUnless(text
== e
)
684 def testE164ToEnum(self
):
685 text
= '+1 650 555 1212'
686 e
= dns
.name
.from_text('2.1.2.1.5.5.5.0.5.6.1.e164.arpa.')
687 n
= dns
.e164
.from_e164(text
)
688 self
.failUnless(n
== e
)
690 def testEnumToE164(self
):
691 n
= dns
.name
.from_text('2.1.2.1.5.5.5.0.5.6.1.e164.arpa.')
693 text
= dns
.e164
.to_e164(n
)
694 self
.failUnless(text
== e
)
696 if __name__
== '__main__':