diff options
author | pascal.bouchareine <pascal@gandi.net> | 2016-11-03 12:06:25 -0700 |
---|---|---|
committer | pascal.bouchareine <pascal@gandi.net> | 2016-11-03 12:32:07 -0700 |
commit | d9dc4eb31807e48f4be82776cdd7f2f494d73e71 (patch) | |
tree | de47cd7517cfb2031276cea12c3f819a0daadf9d /tests | |
parent | 13d1809ad2c7e9d26d6dc95909e0dfcdf202fa45 (diff) | |
download | dnspython-d9dc4eb31807e48f4be82776cdd7f2f494d73e71.tar.gz |
Implement EDNS Client Subnet option
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_option.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/test_option.py b/tests/test_option.py new file mode 100644 index 0000000..f91485a --- /dev/null +++ b/tests/test_option.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. +# +# Permission to use, copy, modify, and distribute this software and its +# documentation for any purpose with or without fee is hereby granted, +# provided that the above copyright notice and this permission notice +# appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT +# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +from __future__ import print_function + +try: + import unittest2 as unittest +except ImportError: + import unittest + +from io import BytesIO + +import dns.edns + +class OptionTestCase(unittest.TestCase): + def testGenericOption(self): + opt = dns.edns.GenericOption(3, b'data') + io = BytesIO() + opt.to_wire(io) + data = io.getvalue() + self.assertEqual(data, b'data') + + def testECSOption(self): + opt = dns.edns.ECSOption('1.2.3.4', 24) + io = BytesIO() + opt.to_wire(io) + data = io.getvalue() + self.assertEqual(data, b'\x00\x01\x18\x00\x01\x02\x03') + + def testECSOption_v6(self): + opt = dns.edns.ECSOption('2001:4b98::1') + io = BytesIO() + opt.to_wire(io) + data = io.getvalue() + self.assertEqual(data, b'\x00\x02\x38\x00\x20\x01\x4b\x98\x00\x00\x00') |