xfrout_test.py.in 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428
  1. # Copyright (C) 2010 Internet Systems Consortium.
  2. #
  3. # Permission to use, copy, modify, and distribute this software for any
  4. # purpose with or without fee is hereby granted, provided that the above
  5. # copyright notice and this permission notice appear in all copies.
  6. #
  7. # THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM
  8. # DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
  9. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
  10. # INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
  11. # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
  12. # FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
  13. # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  14. # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. '''Tests for the XfroutSession and UnixSockServer classes '''
  16. import unittest
  17. import os
  18. from isc.testutils.tsigctx_mock import MockTSIGContext
  19. from isc.cc.session import *
  20. import isc.config
  21. from isc.dns import *
  22. from isc.testutils.rrset_utils import *
  23. from xfrout import *
  24. import xfrout
  25. import isc.log
  26. import isc.acl.dns
  27. TESTDATA_SRCDIR = os.getenv("TESTDATASRCDIR")
  28. TSIG_KEY = TSIGKey("example.com:SFuWd/q99SzF8Yzd1QbB9g==")
  29. #
  30. # Commonly used (mostly constant) test parameters
  31. #
  32. TEST_ZONE_NAME_STR = "example.com."
  33. TEST_ZONE_NAME = Name(TEST_ZONE_NAME_STR)
  34. TEST_RRCLASS = RRClass.IN()
  35. IXFR_OK_VERSION = 2011111802
  36. IXFR_NG_VERSION = 2011111803
  37. SOA_CURRENT_VERSION = 2011112001
  38. # our fake socket, where we can read and insert messages
  39. class MySocket():
  40. def __init__(self, family, type):
  41. self.family = family
  42. self.type = type
  43. self.sendqueue = bytearray()
  44. def connect(self, to):
  45. pass
  46. def close(self):
  47. pass
  48. def send(self, data):
  49. self.sendqueue.extend(data);
  50. return len(data)
  51. def readsent(self):
  52. if len(self.sendqueue) >= 2:
  53. size = 2 + struct.unpack("!H", self.sendqueue[:2])[0]
  54. else:
  55. size = 0
  56. result = self.sendqueue[:size]
  57. self.sendqueue = self.sendqueue[size:]
  58. return result
  59. def read_msg(self, parse_options=Message.PARSE_DEFAULT, need_len=False):
  60. sent_data = self.readsent()
  61. get_msg = Message(Message.PARSE)
  62. get_msg.from_wire(bytes(sent_data[2:]), parse_options)
  63. if need_len:
  64. return (get_msg, len(sent_data) - 2)
  65. return get_msg
  66. def clear_send(self):
  67. del self.sendqueue[:]
  68. class MockDataSrcClient:
  69. def __init__(self, type, config):
  70. pass
  71. def find_zone(self, zone_name):
  72. '''Mock version of find_zone().
  73. It returns itself (subsequently acting as a mock ZoneFinder) for
  74. some test zone names. For a special name it returns NOTFOUND to
  75. emulate the condition where the specified zone doen't exist.
  76. '''
  77. self._zone_name = zone_name
  78. if zone_name == Name('notauth.example.com'):
  79. return (isc.datasrc.DataSourceClient.NOTFOUND, None)
  80. return (isc.datasrc.DataSourceClient.SUCCESS, self)
  81. def find(self, name, rrtype, options=ZoneFinder.FIND_DEFAULT):
  82. '''Mock ZoneFinder.find().
  83. (At the moment) this method only handles query for type SOA.
  84. By default it returns a normal SOA RR(set) whose owner name is
  85. the query name It also emulates some unusual cases for special
  86. zone names.
  87. '''
  88. if name == Name('nosoa.example.com') and rrtype == RRType.SOA():
  89. return (ZoneFinder.NXDOMAIN, None, 0)
  90. elif name == Name('multisoa.example.com') and rrtype == RRType.SOA():
  91. soa_rrset = create_soa(SOA_CURRENT_VERSION)
  92. soa_rrset.add_rdata(soa_rrset.get_rdata()[0])
  93. return (ZoneFinder.SUCCESS, soa_rrset, 0)
  94. elif name == Name('maxserial.example.com'):
  95. soa_rrset = create_soa(0xffffffff)
  96. return (ZoneFinder.SUCCESS, soa_rrset, 0)
  97. elif rrtype == RRType.SOA():
  98. return (ZoneFinder.SUCCESS, create_soa(SOA_CURRENT_VERSION), 0)
  99. raise ValueError('Unexpected input to mock finder: bug in test case?')
  100. def get_iterator(self, zone_name, adjust_ttl=False):
  101. if zone_name == Name('notauth.example.com'):
  102. raise isc.datasrc.Error('no such zone')
  103. self._zone_name = zone_name
  104. return self
  105. def get_soa(self): # emulate ZoneIterator.get_soa()
  106. if self._zone_name == Name('nosoa.example.com'):
  107. return None
  108. soa_rrset = create_soa(SOA_CURRENT_VERSION)
  109. if self._zone_name == Name('multisoa.example.com'):
  110. soa_rrset.add_rdata(soa_rrset.get_rdata()[0])
  111. return soa_rrset
  112. def get_journal_reader(self, zone_name, begin_serial, end_serial):
  113. if zone_name == Name('notauth2.example.com'):
  114. return isc.datasrc.ZoneJournalReader.NO_SUCH_ZONE, None
  115. if zone_name == Name('nojournal.example.com'):
  116. raise isc.datasrc.NotImplemented('journaling not supported')
  117. if begin_serial == IXFR_NG_VERSION:
  118. return isc.datasrc.ZoneJournalReader.NO_SUCH_VERSION, None
  119. return isc.datasrc.ZoneJournalReader.SUCCESS, self
  120. class MyCCSession(isc.config.ConfigData):
  121. def __init__(self):
  122. module_spec = isc.config.module_spec_from_file(
  123. xfrout.SPECFILE_LOCATION)
  124. ConfigData.__init__(self, module_spec)
  125. def get_remote_config_value(self, module_name, identifier):
  126. if module_name == "Auth" and identifier == "database_file":
  127. return "initdb.file", False
  128. else:
  129. return "unknown", False
  130. # This constant dictionary stores all default configuration parameters
  131. # defined in the xfrout spec file.
  132. DEFAULT_CONFIG = MyCCSession().get_full_config()
  133. # We subclass the Session class we're testing here, only overriding a few
  134. # methods
  135. class MyXfroutSession(XfroutSession):
  136. def _handle(self):
  137. pass
  138. def _close_socket(self):
  139. pass
  140. def _send_data(self, sock, data):
  141. size = len(data)
  142. total_count = 0
  143. while total_count < size:
  144. count = sock.send(data[total_count:])
  145. total_count += count
  146. class Dbserver:
  147. def __init__(self):
  148. self._shutdown_event = threading.Event()
  149. self.transfer_counter = 0
  150. self._max_transfers_out = DEFAULT_CONFIG['transfers_out']
  151. def get_db_file(self):
  152. return 'test.sqlite3'
  153. def increase_transfers_counter(self):
  154. self.transfer_counter += 1
  155. return True
  156. def decrease_transfers_counter(self):
  157. self.transfer_counter -= 1
  158. class TestXfroutSessionBase(unittest.TestCase):
  159. '''Base classs for tests related to xfrout sessions
  160. This class defines common setup/teadown and utility methods. Actual
  161. tests are delegated to subclasses.
  162. '''
  163. def getmsg(self):
  164. msg = Message(Message.PARSE)
  165. msg.from_wire(self.mdata)
  166. return msg
  167. def create_mock_tsig_ctx(self, error):
  168. # This helper function creates a MockTSIGContext for a given key
  169. # and TSIG error to be used as a result of verify (normally faked
  170. # one)
  171. mock_ctx = MockTSIGContext(TSIG_KEY)
  172. mock_ctx.error = error
  173. return mock_ctx
  174. def message_has_tsig(self, msg):
  175. return msg.get_tsig_record() is not None
  176. def create_request_data(self, with_question=True, with_tsig=False,
  177. ixfr=None, qtype=None, zone_name=TEST_ZONE_NAME,
  178. soa_class=TEST_RRCLASS, num_soa=1):
  179. '''Create a commonly used XFR request data.
  180. By default the request type is AXFR; if 'ixfr' is an integer,
  181. the request type will be IXFR and an SOA with the serial being
  182. the value of the parameter will be included in the authority
  183. section.
  184. This method has various minor parameters only for creating bad
  185. format requests for testing purposes:
  186. qtype: the RR type of the question section. By default automatically
  187. determined by the value of ixfr, but could be an invalid type
  188. for testing.
  189. zone_name: the query (zone) name. for IXFR, it's also used as
  190. the owner name of the SOA in the authority section.
  191. soa_class: IXFR only. The RR class of the SOA RR in the authority
  192. section.
  193. num_soa: IXFR only. The number of SOA RDATAs in the authority
  194. section.
  195. '''
  196. msg = Message(Message.RENDER)
  197. query_id = 0x1035
  198. msg.set_qid(query_id)
  199. msg.set_opcode(Opcode.QUERY())
  200. msg.set_rcode(Rcode.NOERROR())
  201. req_type = RRType.AXFR() if ixfr is None else RRType.IXFR()
  202. if with_question:
  203. msg.add_question(Question(zone_name, RRClass.IN(),
  204. req_type if qtype is None else qtype))
  205. if req_type == RRType.IXFR():
  206. soa = RRset(zone_name, soa_class, RRType.SOA(), RRTTL(0))
  207. # In the RDATA only the serial matters.
  208. for i in range(0, num_soa):
  209. soa.add_rdata(Rdata(RRType.SOA(), soa_class,
  210. 'm r ' + str(ixfr) + ' 1 1 1 1'))
  211. msg.add_rrset(Message.SECTION_AUTHORITY, soa)
  212. renderer = MessageRenderer()
  213. if with_tsig:
  214. tsig_ctx = MockTSIGContext(TSIG_KEY)
  215. msg.to_wire(renderer, tsig_ctx)
  216. else:
  217. msg.to_wire(renderer)
  218. request_data = renderer.get_data()
  219. return request_data
  220. def set_request_type(self, type):
  221. self.xfrsess._request_type = type
  222. if type == RRType.AXFR():
  223. self.xfrsess._request_typestr = 'AXFR'
  224. else:
  225. self.xfrsess._request_typestr = 'IXFR'
  226. def setUp(self):
  227. self.sock = MySocket(socket.AF_INET,socket.SOCK_STREAM)
  228. self.xfrsess = MyXfroutSession(self.sock, None, Dbserver(),
  229. TSIGKeyRing(),
  230. (socket.AF_INET, socket.SOCK_STREAM,
  231. ('127.0.0.1', 12345)),
  232. # When not testing ACLs, simply accept
  233. isc.acl.dns.REQUEST_LOADER.load(
  234. [{"action": "ACCEPT"}]),
  235. {})
  236. self.set_request_type(RRType.AXFR()) # test AXFR by default
  237. self.mdata = self.create_request_data()
  238. self.soa_rrset = create_soa(SOA_CURRENT_VERSION)
  239. # some test replaces a module-wide function. We should ensure the
  240. # original is used elsewhere.
  241. self.orig_get_rrset_len = xfrout.get_rrset_len
  242. def tearDown(self):
  243. xfrout.get_rrset_len = self.orig_get_rrset_len
  244. # transfer_counter must be always be reset no matter happens within
  245. # the XfroutSession object. We check the condition here.
  246. self.assertEqual(0, self.xfrsess._server.transfer_counter)
  247. class TestXfroutSession(TestXfroutSessionBase):
  248. def test_quota_error(self):
  249. '''Emulating the server being too busy.
  250. '''
  251. self.xfrsess._request_data = self.mdata
  252. self.xfrsess._server.increase_transfers_counter = lambda : False
  253. XfroutSession._handle(self.xfrsess)
  254. self.assertEqual(self.sock.read_msg().get_rcode(), Rcode.REFUSED())
  255. def test_quota_ok(self):
  256. '''The default case in terms of the xfrout quota.
  257. '''
  258. # set up a bogus request, which should result in FORMERR. (it only
  259. # has to be something that is different from the previous case)
  260. self.xfrsess._request_data = \
  261. self.create_request_data(ixfr=IXFR_OK_VERSION, num_soa=2)
  262. # Replace the data source client to avoid datasrc related exceptions
  263. self.xfrsess.ClientClass = MockDataSrcClient
  264. XfroutSession._handle(self.xfrsess)
  265. self.assertEqual(self.sock.read_msg().get_rcode(), Rcode.FORMERR())
  266. def test_exception_from_session(self):
  267. '''Test the case where the main processing raises an exception.
  268. We just check it doesn't any unexpected disruption and (in tearDown)
  269. transfer_counter is correctly reset to 0.
  270. '''
  271. def dns_xfrout_start(fd, msg, quota):
  272. raise ValueError('fake exception')
  273. self.xfrsess.dns_xfrout_start = dns_xfrout_start
  274. XfroutSession._handle(self.xfrsess)
  275. def test_parse_query_message(self):
  276. # Valid AXFR
  277. [get_rcode, get_msg] = self.xfrsess._parse_query_message(self.mdata)
  278. self.assertEqual(RRType.AXFR(), self.xfrsess._request_type)
  279. self.assertEqual(get_rcode.to_text(), "NOERROR")
  280. # Valid IXFR
  281. request_data = self.create_request_data(ixfr=2011111801)
  282. rcode, msg = self.xfrsess._parse_query_message(request_data)
  283. self.assertEqual(RRType.IXFR(), self.xfrsess._request_type)
  284. self.assertEqual(Rcode.NOERROR(), rcode)
  285. # Broken request: no question
  286. self.assertRaises(RuntimeError, self.xfrsess._parse_query_message,
  287. self.create_request_data(with_question=False))
  288. # Broken request: invalid RR type (neither AXFR nor IXFR)
  289. self.assertRaises(RuntimeError, self.xfrsess._parse_query_message,
  290. self.create_request_data(qtype=RRType.A()))
  291. # NOERROR
  292. request_data = self.create_request_data(ixfr=IXFR_OK_VERSION)
  293. rcode, msg = self.xfrsess._parse_query_message(request_data)
  294. self.assertEqual(rcode.to_text(), "NOERROR")
  295. # tsig signed query message
  296. request_data = self.create_request_data(with_tsig=True)
  297. # BADKEY
  298. [rcode, msg] = self.xfrsess._parse_query_message(request_data)
  299. self.assertEqual(rcode.to_text(), "NOTAUTH")
  300. self.assertTrue(self.xfrsess._tsig_ctx is not None)
  301. # NOERROR
  302. self.assertEqual(TSIGKeyRing.SUCCESS,
  303. self.xfrsess._tsig_key_ring.add(TSIG_KEY))
  304. [rcode, msg] = self.xfrsess._parse_query_message(request_data)
  305. self.assertEqual(rcode.to_text(), "NOERROR")
  306. self.assertTrue(self.xfrsess._tsig_ctx is not None)
  307. def check_transfer_acl(self, acl_setter):
  308. # ACL checks, put some ACL inside
  309. acl_setter(isc.acl.dns.REQUEST_LOADER.load([
  310. {
  311. "from": "127.0.0.1",
  312. "action": "ACCEPT"
  313. },
  314. {
  315. "from": "192.0.2.1",
  316. "action": "DROP"
  317. }
  318. ]))
  319. # Localhost (the default in this test) is accepted
  320. rcode, msg = self.xfrsess._parse_query_message(self.mdata)
  321. self.assertEqual(rcode.to_text(), "NOERROR")
  322. # This should be dropped completely, therefore returning None
  323. self.xfrsess._remote = (socket.AF_INET, socket.SOCK_STREAM,
  324. ('192.0.2.1', 12345))
  325. rcode, msg = self.xfrsess._parse_query_message(self.mdata)
  326. self.assertEqual(None, rcode)
  327. # This should be refused, therefore REFUSED
  328. self.xfrsess._remote = (socket.AF_INET, socket.SOCK_STREAM,
  329. ('192.0.2.2', 12345))
  330. rcode, msg = self.xfrsess._parse_query_message(self.mdata)
  331. self.assertEqual(rcode.to_text(), "REFUSED")
  332. # TSIG signed request
  333. request_data = self.create_request_data(with_tsig=True)
  334. # If the TSIG check fails, it should not check ACL
  335. # (If it checked ACL as well, it would just drop the request)
  336. self.xfrsess._remote = (socket.AF_INET, socket.SOCK_STREAM,
  337. ('192.0.2.1', 12345))
  338. self.xfrsess._tsig_key_ring = TSIGKeyRing()
  339. rcode, msg = self.xfrsess._parse_query_message(request_data)
  340. self.assertEqual(rcode.to_text(), "NOTAUTH")
  341. self.assertTrue(self.xfrsess._tsig_ctx is not None)
  342. # ACL using TSIG: successful case
  343. acl_setter(isc.acl.dns.REQUEST_LOADER.load([
  344. {"key": "example.com", "action": "ACCEPT"}, {"action": "REJECT"}
  345. ]))
  346. self.assertEqual(TSIGKeyRing.SUCCESS,
  347. self.xfrsess._tsig_key_ring.add(TSIG_KEY))
  348. [rcode, msg] = self.xfrsess._parse_query_message(request_data)
  349. self.assertEqual(rcode.to_text(), "NOERROR")
  350. # ACL using TSIG: key name doesn't match; should be rejected
  351. acl_setter(isc.acl.dns.REQUEST_LOADER.load([
  352. {"key": "example.org", "action": "ACCEPT"}, {"action": "REJECT"}
  353. ]))
  354. [rcode, msg] = self.xfrsess._parse_query_message(request_data)
  355. self.assertEqual(rcode.to_text(), "REFUSED")
  356. # ACL using TSIG: no TSIG; should be rejected
  357. acl_setter(isc.acl.dns.REQUEST_LOADER.load([
  358. {"key": "example.org", "action": "ACCEPT"}, {"action": "REJECT"}
  359. ]))
  360. [rcode, msg] = self.xfrsess._parse_query_message(self.mdata)
  361. self.assertEqual(rcode.to_text(), "REFUSED")
  362. #
  363. # ACL using IP + TSIG: both should match
  364. #
  365. acl_setter(isc.acl.dns.REQUEST_LOADER.load([
  366. {"ALL": [{"key": "example.com"}, {"from": "192.0.2.1"}],
  367. "action": "ACCEPT"},
  368. {"action": "REJECT"}
  369. ]))
  370. # both matches
  371. self.xfrsess._remote = (socket.AF_INET, socket.SOCK_STREAM,
  372. ('192.0.2.1', 12345))
  373. [rcode, msg] = self.xfrsess._parse_query_message(request_data)
  374. self.assertEqual(rcode.to_text(), "NOERROR")
  375. # TSIG matches, but address doesn't
  376. self.xfrsess._remote = (socket.AF_INET, socket.SOCK_STREAM,
  377. ('192.0.2.2', 12345))
  378. [rcode, msg] = self.xfrsess._parse_query_message(request_data)
  379. self.assertEqual(rcode.to_text(), "REFUSED")
  380. # Address matches, but TSIG doesn't (not included)
  381. self.xfrsess._remote = (socket.AF_INET, socket.SOCK_STREAM,
  382. ('192.0.2.1', 12345))
  383. [rcode, msg] = self.xfrsess._parse_query_message(self.mdata)
  384. self.assertEqual(rcode.to_text(), "REFUSED")
  385. # Neither address nor TSIG matches
  386. self.xfrsess._remote = (socket.AF_INET, socket.SOCK_STREAM,
  387. ('192.0.2.2', 12345))
  388. [rcode, msg] = self.xfrsess._parse_query_message(self.mdata)
  389. self.assertEqual(rcode.to_text(), "REFUSED")
  390. def test_transfer_acl(self):
  391. # ACL checks only with the default ACL
  392. def acl_setter(acl):
  393. self.xfrsess._acl = acl
  394. self.check_transfer_acl(acl_setter)
  395. def test_transfer_zoneacl(self):
  396. # ACL check with a per zone ACL + default ACL. The per zone ACL
  397. # should match the queryied zone, so it should be used.
  398. def acl_setter(acl):
  399. zone_key = ('IN', 'example.com.')
  400. self.xfrsess._zone_config[zone_key] = {}
  401. self.xfrsess._zone_config[zone_key]['transfer_acl'] = acl
  402. self.xfrsess._acl = isc.acl.dns.REQUEST_LOADER.load([
  403. {"from": "127.0.0.1", "action": "DROP"}])
  404. self.check_transfer_acl(acl_setter)
  405. def test_transfer_zoneacl_nomatch(self):
  406. # similar to the previous one, but the per zone doesn't match the
  407. # query. The default should be used.
  408. def acl_setter(acl):
  409. zone_key = ('IN', 'example.org.')
  410. self.xfrsess._zone_config[zone_key] = {}
  411. self.xfrsess._zone_config[zone_key]['transfer_acl'] = \
  412. isc.acl.dns.REQUEST_LOADER.load([
  413. {"from": "127.0.0.1", "action": "DROP"}])
  414. self.xfrsess._acl = acl
  415. self.check_transfer_acl(acl_setter)
  416. def test_get_transfer_acl(self):
  417. # set the default ACL. If there's no specific zone ACL, this one
  418. # should be used.
  419. self.xfrsess._acl = isc.acl.dns.REQUEST_LOADER.load([
  420. {"from": "127.0.0.1", "action": "ACCEPT"}])
  421. acl = self.xfrsess._get_transfer_acl(Name('example.com'), RRClass.IN())
  422. self.assertEqual(acl, self.xfrsess._acl)
  423. # install a per zone config with transfer ACL for example.com. Then
  424. # that ACL will be used for example.com; for others the default ACL
  425. # will still be used.
  426. com_acl = isc.acl.dns.REQUEST_LOADER.load([
  427. {"from": "127.0.0.1", "action": "REJECT"}])
  428. self.xfrsess._zone_config[('IN', 'example.com.')] = {}
  429. self.xfrsess._zone_config[('IN', 'example.com.')]['transfer_acl'] = \
  430. com_acl
  431. self.assertEqual(com_acl,
  432. self.xfrsess._get_transfer_acl(Name('example.com'),
  433. RRClass.IN()))
  434. self.assertEqual(self.xfrsess._acl,
  435. self.xfrsess._get_transfer_acl(Name('example.org'),
  436. RRClass.IN()))
  437. # Name matching should be case insensitive.
  438. self.assertEqual(com_acl,
  439. self.xfrsess._get_transfer_acl(Name('EXAMPLE.COM'),
  440. RRClass.IN()))
  441. def test_send_data(self):
  442. self.xfrsess._send_data(self.sock, self.mdata)
  443. senddata = self.sock.readsent()
  444. self.assertEqual(senddata, self.mdata)
  445. def test_reply_xfrout_query_with_error_rcode(self):
  446. msg = self.getmsg()
  447. self.xfrsess._reply_query_with_error_rcode(msg, self.sock, Rcode(3))
  448. get_msg = self.sock.read_msg()
  449. self.assertEqual(get_msg.get_rcode().to_text(), "NXDOMAIN")
  450. # tsig signed message
  451. msg = self.getmsg()
  452. self.xfrsess._tsig_ctx = self.create_mock_tsig_ctx(TSIGError.NOERROR)
  453. self.xfrsess._reply_query_with_error_rcode(msg, self.sock, Rcode(3))
  454. get_msg = self.sock.read_msg()
  455. self.assertEqual(get_msg.get_rcode().to_text(), "NXDOMAIN")
  456. self.assertTrue(self.message_has_tsig(get_msg))
  457. def test_send_message(self):
  458. msg = self.getmsg()
  459. msg.make_response()
  460. # SOA record data with different cases
  461. soa_rrset = RRset(Name('Example.com.'), RRClass.IN(), RRType.SOA(),
  462. RRTTL(3600))
  463. soa_rrset.add_rdata(Rdata(RRType.SOA(), RRClass.IN(),
  464. 'master.Example.com. admin.exAmple.com. ' +
  465. '2011112001 3600 1800 2419200 7200'))
  466. msg.add_rrset(Message.SECTION_ANSWER, soa_rrset)
  467. self.xfrsess._send_message(self.sock, msg)
  468. send_out_data = self.sock.readsent()[2:]
  469. # CASE_INSENSITIVE compression mode
  470. render = MessageRenderer();
  471. render.set_length_limit(XFROUT_MAX_MESSAGE_SIZE)
  472. msg.to_wire(render)
  473. self.assertNotEqual(render.get_data(), send_out_data)
  474. # CASE_SENSITIVE compression mode
  475. render.clear()
  476. render.set_compress_mode(MessageRenderer.CASE_SENSITIVE)
  477. render.set_length_limit(XFROUT_MAX_MESSAGE_SIZE)
  478. msg.to_wire(render)
  479. self.assertEqual(render.get_data(), send_out_data)
  480. def test_clear_message(self):
  481. msg = self.getmsg()
  482. qid = msg.get_qid()
  483. opcode = msg.get_opcode()
  484. rcode = msg.get_rcode()
  485. self.xfrsess._clear_message(msg)
  486. self.assertEqual(msg.get_qid(), qid)
  487. self.assertEqual(msg.get_opcode(), opcode)
  488. self.assertEqual(msg.get_rcode(), rcode)
  489. self.assertTrue(msg.get_header_flag(Message.HEADERFLAG_AA))
  490. def test_send_message_with_last_soa(self):
  491. msg = self.getmsg()
  492. msg.make_response()
  493. self.xfrsess._send_message_with_last_soa(msg, self.sock,
  494. self.soa_rrset, 0)
  495. get_msg = self.sock.read_msg()
  496. # tsig context does not exist
  497. self.assertFalse(self.message_has_tsig(get_msg))
  498. self.assertEqual(get_msg.get_rr_count(Message.SECTION_QUESTION), 1)
  499. self.assertEqual(get_msg.get_rr_count(Message.SECTION_ANSWER), 1)
  500. self.assertEqual(get_msg.get_rr_count(Message.SECTION_AUTHORITY), 0)
  501. answer = get_msg.get_section(Message.SECTION_ANSWER)[0]
  502. self.assertEqual(answer.get_name().to_text(), "example.com.")
  503. self.assertEqual(answer.get_class(), RRClass("IN"))
  504. self.assertEqual(answer.get_type().to_text(), "SOA")
  505. rdata = answer.get_rdata()
  506. self.assertEqual(rdata[0], self.soa_rrset.get_rdata()[0])
  507. # Sending the message with last soa together
  508. self.xfrsess._send_message_with_last_soa(msg, self.sock,
  509. self.soa_rrset, 0)
  510. get_msg = self.sock.read_msg()
  511. # tsig context does not exist
  512. self.assertFalse(self.message_has_tsig(get_msg))
  513. def test_send_message_with_last_soa_with_tsig(self):
  514. # create tsig context
  515. self.xfrsess._tsig_ctx = self.create_mock_tsig_ctx(TSIGError.NOERROR)
  516. msg = self.getmsg()
  517. msg.make_response()
  518. # Sending the message with last soa together
  519. self.xfrsess._send_message_with_last_soa(msg, self.sock,
  520. self.soa_rrset, 0)
  521. get_msg = self.sock.read_msg()
  522. self.assertTrue(self.message_has_tsig(get_msg))
  523. self.assertEqual(get_msg.get_rr_count(Message.SECTION_QUESTION), 1)
  524. self.assertEqual(get_msg.get_rr_count(Message.SECTION_ANSWER), 1)
  525. self.assertEqual(get_msg.get_rr_count(Message.SECTION_AUTHORITY), 0)
  526. def test_trigger_send_message_with_last_soa(self):
  527. rrset_a = RRset(Name("example.com"), RRClass.IN(), RRType.A(), RRTTL(3600))
  528. rrset_a.add_rdata(Rdata(RRType.A(), RRClass.IN(), "192.0.2.1"))
  529. msg = self.getmsg()
  530. msg.make_response()
  531. msg.add_rrset(Message.SECTION_ANSWER, rrset_a)
  532. # length larger than MAX-len(rrset)
  533. length_need_split = xfrout.XFROUT_MAX_MESSAGE_SIZE - \
  534. get_rrset_len(self.soa_rrset) + 1
  535. # give the function a value that is larger than MAX-len(rrset)
  536. # this should have triggered the sending of two messages
  537. # (1 with the rrset we added manually, and 1 that triggered
  538. # the sending in _with_last_soa)
  539. self.xfrsess._send_message_with_last_soa(msg, self.sock,
  540. self.soa_rrset,
  541. length_need_split)
  542. get_msg = self.sock.read_msg()
  543. self.assertFalse(self.message_has_tsig(get_msg))
  544. self.assertEqual(get_msg.get_rr_count(Message.SECTION_QUESTION), 1)
  545. self.assertEqual(get_msg.get_rr_count(Message.SECTION_ANSWER), 1)
  546. self.assertEqual(get_msg.get_rr_count(Message.SECTION_AUTHORITY), 0)
  547. answer = get_msg.get_section(Message.SECTION_ANSWER)[0]
  548. self.assertEqual(answer.get_name().to_text(), "example.com.")
  549. self.assertEqual(answer.get_class(), RRClass("IN"))
  550. self.assertEqual(answer.get_type().to_text(), "A")
  551. rdata = answer.get_rdata()
  552. self.assertEqual(rdata[0].to_text(), "192.0.2.1")
  553. get_msg = self.sock.read_msg()
  554. self.assertFalse(self.message_has_tsig(get_msg))
  555. self.assertEqual(get_msg.get_rr_count(Message.SECTION_QUESTION), 0)
  556. self.assertEqual(get_msg.get_rr_count(Message.SECTION_ANSWER), 1)
  557. self.assertEqual(get_msg.get_rr_count(Message.SECTION_AUTHORITY), 0)
  558. answer = get_msg.get_section(Message.SECTION_ANSWER)[0]
  559. self.assertEqual(answer.get_name().to_text(), "example.com.")
  560. self.assertEqual(answer.get_class(), RRClass("IN"))
  561. self.assertEqual(answer.get_type().to_text(), "SOA")
  562. rdata = answer.get_rdata()
  563. self.assertEqual(rdata[0], self.soa_rrset.get_rdata()[0])
  564. # and it should not have sent anything else
  565. self.assertEqual(0, len(self.sock.sendqueue))
  566. def test_trigger_send_message_with_last_soa_with_tsig(self):
  567. self.xfrsess._tsig_ctx = self.create_mock_tsig_ctx(TSIGError.NOERROR)
  568. msg = self.getmsg()
  569. msg.make_response()
  570. msg.add_rrset(Message.SECTION_ANSWER, self.soa_rrset)
  571. # length larger than MAX-len(rrset)
  572. length_need_split = xfrout.XFROUT_MAX_MESSAGE_SIZE - \
  573. get_rrset_len(self.soa_rrset) + 1
  574. # give the function a value that is larger than MAX-len(rrset)
  575. # this should have triggered the sending of two messages
  576. # (1 with the rrset we added manually, and 1 that triggered
  577. # the sending in _with_last_soa)
  578. self.xfrsess._send_message_with_last_soa(msg, self.sock,
  579. self.soa_rrset,
  580. length_need_split)
  581. # Both messages should have TSIG RRs
  582. get_msg = self.sock.read_msg()
  583. self.assertTrue(self.message_has_tsig(get_msg))
  584. get_msg = self.sock.read_msg()
  585. self.assertTrue(self.message_has_tsig(get_msg))
  586. # and it should not have sent anything else
  587. self.assertEqual(0, len(self.sock.sendqueue))
  588. def test_get_rrset_len(self):
  589. self.assertEqual(82, get_rrset_len(self.soa_rrset))
  590. def test_xfrout_axfr_setup(self):
  591. self.xfrsess.ClientClass = MockDataSrcClient
  592. # Successful case. A zone iterator should be set up.
  593. self.assertEqual(self.xfrsess._xfrout_setup(
  594. self.getmsg(), TEST_ZONE_NAME, TEST_RRCLASS), Rcode.NOERROR())
  595. self.assertNotEqual(None, self.xfrsess._iterator)
  596. # Failure cases
  597. self.assertEqual(self.xfrsess._xfrout_setup(
  598. self.getmsg(), Name('notauth.example.com'), TEST_RRCLASS),
  599. Rcode.NOTAUTH())
  600. self.assertEqual(self.xfrsess._xfrout_setup(
  601. self.getmsg(), Name('nosoa.example.com'), TEST_RRCLASS),
  602. Rcode.SERVFAIL())
  603. self.assertEqual(self.xfrsess._xfrout_setup(
  604. self.getmsg(), Name('multisoa.example.com'), TEST_RRCLASS),
  605. Rcode.SERVFAIL())
  606. def test_xfrout_ixfr_setup(self):
  607. self.xfrsess.ClientClass = MockDataSrcClient
  608. self.set_request_type(RRType.IXFR())
  609. # Successful case of pure IXFR. A zone journal reader should be set
  610. # up.
  611. self.mdata = self.create_request_data(ixfr=IXFR_OK_VERSION)
  612. self.assertEqual(self.xfrsess._xfrout_setup(
  613. self.getmsg(), TEST_ZONE_NAME, TEST_RRCLASS), Rcode.NOERROR())
  614. self.assertNotEqual(None, self.xfrsess._jnl_reader)
  615. # Successful case, but as a result of falling back to AXFR-style
  616. # IXFR. A zone iterator should be set up instead of a journal reader.
  617. self.mdata = self.create_request_data(ixfr=IXFR_NG_VERSION)
  618. self.assertEqual(self.xfrsess._xfrout_setup(
  619. self.getmsg(), TEST_ZONE_NAME, TEST_RRCLASS), Rcode.NOERROR())
  620. self.assertNotEqual(None, self.xfrsess._iterator)
  621. self.assertEqual(None, self.xfrsess._jnl_reader)
  622. # Successful case, but the requested SOA serial is greater than that of
  623. # the local SOA. Both iterator and jnl_reader should be None,
  624. # indicating that the response will contain just one SOA.
  625. self.mdata = self.create_request_data(ixfr=SOA_CURRENT_VERSION+1)
  626. self.assertEqual(self.xfrsess._xfrout_setup(
  627. self.getmsg(), TEST_ZONE_NAME, TEST_RRCLASS), Rcode.NOERROR())
  628. self.assertEqual(None, self.xfrsess._iterator)
  629. self.assertEqual(None, self.xfrsess._jnl_reader)
  630. # Similar to the previous case, but the requested serial is equal to
  631. # the local SOA.
  632. self.mdata = self.create_request_data(ixfr=SOA_CURRENT_VERSION)
  633. self.assertEqual(self.xfrsess._xfrout_setup(
  634. self.getmsg(), TEST_ZONE_NAME, TEST_RRCLASS), Rcode.NOERROR())
  635. self.assertEqual(None, self.xfrsess._iterator)
  636. self.assertEqual(None, self.xfrsess._jnl_reader)
  637. # Similar to the previous case, but the comparison should be done
  638. # based on serial number arithmetic, not as integers.
  639. zone_name = Name('maxserial.example.com') # whose SOA is 0xffffffff
  640. self.mdata = self.create_request_data(ixfr=1, zone_name=zone_name)
  641. self.assertEqual(self.xfrsess._xfrout_setup(
  642. self.getmsg(), zone_name, TEST_RRCLASS), Rcode.NOERROR())
  643. self.assertEqual(None, self.xfrsess._iterator)
  644. self.assertEqual(None, self.xfrsess._jnl_reader)
  645. # The data source doesn't support journaling. Should fallback to AXFR.
  646. zone_name = Name('nojournal.example.com')
  647. self.mdata = self.create_request_data(ixfr=IXFR_OK_VERSION,
  648. zone_name=zone_name)
  649. self.assertEqual(self.xfrsess._xfrout_setup(
  650. self.getmsg(), zone_name, TEST_RRCLASS), Rcode.NOERROR())
  651. self.assertNotEqual(None, self.xfrsess._iterator)
  652. # Failure cases
  653. zone_name = Name('notauth.example.com')
  654. self.mdata = self.create_request_data(ixfr=IXFR_OK_VERSION,
  655. zone_name=zone_name)
  656. self.assertEqual(self.xfrsess._xfrout_setup(
  657. self.getmsg(), zone_name, TEST_RRCLASS), Rcode.NOTAUTH())
  658. # this is a strange case: zone's SOA will be found but the journal
  659. # reader won't be created due to 'no such zone'.
  660. zone_name = Name('notauth2.example.com')
  661. self.mdata = self.create_request_data(ixfr=IXFR_OK_VERSION,
  662. zone_name=zone_name)
  663. self.assertEqual(self.xfrsess._xfrout_setup(
  664. self.getmsg(), zone_name, TEST_RRCLASS), Rcode.NOTAUTH())
  665. zone_name = Name('nosoa.example.com')
  666. self.mdata = self.create_request_data(ixfr=IXFR_OK_VERSION,
  667. zone_name=zone_name)
  668. self.assertEqual(self.xfrsess._xfrout_setup(
  669. self.getmsg(), zone_name, TEST_RRCLASS), Rcode.SERVFAIL())
  670. zone_name = Name('multisoa.example.com')
  671. self.mdata = self.create_request_data(ixfr=IXFR_OK_VERSION,
  672. zone_name=zone_name)
  673. self.assertEqual(self.xfrsess._xfrout_setup(
  674. self.getmsg(), zone_name, TEST_RRCLASS), Rcode.SERVFAIL())
  675. # query name doesn't match the SOA's owner
  676. self.mdata = self.create_request_data(ixfr=IXFR_OK_VERSION)
  677. self.assertEqual(self.xfrsess._xfrout_setup(
  678. self.getmsg(), zone_name, TEST_RRCLASS), Rcode.FORMERR())
  679. # query's RR class doesn't match the SOA's class
  680. zone_name = TEST_ZONE_NAME # make sure the name matches this time
  681. self.mdata = self.create_request_data(ixfr=IXFR_OK_VERSION,
  682. soa_class=RRClass.CH())
  683. self.assertEqual(self.xfrsess._xfrout_setup(
  684. self.getmsg(), zone_name, TEST_RRCLASS), Rcode.FORMERR())
  685. # multiple SOA RRs
  686. self.mdata = self.create_request_data(ixfr=IXFR_OK_VERSION,
  687. num_soa=2)
  688. self.assertEqual(self.xfrsess._xfrout_setup(
  689. self.getmsg(), zone_name, TEST_RRCLASS), Rcode.FORMERR())
  690. def test_dns_xfrout_start_formerror(self):
  691. # formerror
  692. self.xfrsess.dns_xfrout_start(self.sock, b"\xd6=\x00\x00\x00\x01\x00")
  693. sent_data = self.sock.readsent()
  694. self.assertEqual(len(sent_data), 0)
  695. def test_dns_xfrout_start_notauth(self):
  696. def notauth(msg, name, rrclass):
  697. return Rcode.NOTAUTH()
  698. self.xfrsess._xfrout_setup = notauth
  699. self.xfrsess.dns_xfrout_start(self.sock, self.mdata)
  700. get_msg = self.sock.read_msg()
  701. self.assertEqual(get_msg.get_rcode().to_text(), "NOTAUTH")
  702. def test_dns_xfrout_start_datasrc_servfail(self):
  703. def internal_raise(x, y):
  704. raise isc.datasrc.Error('exception for the sake of test')
  705. self.xfrsess.ClientClass = internal_raise
  706. self.xfrsess.dns_xfrout_start(self.sock, self.mdata)
  707. self.assertEqual(self.sock.read_msg().get_rcode(), Rcode.SERVFAIL())
  708. def test_dns_xfrout_start_noerror(self):
  709. def noerror(msg, name, rrclass):
  710. return Rcode.NOERROR()
  711. self.xfrsess._xfrout_setup = noerror
  712. def myreply(msg, sock):
  713. self.sock.send(b"success")
  714. self.xfrsess._reply_xfrout_query = myreply
  715. self.xfrsess.dns_xfrout_start(self.sock, self.mdata)
  716. self.assertEqual(self.sock.readsent(), b"success")
  717. def test_reply_xfrout_query_axfr(self):
  718. self.xfrsess._soa = self.soa_rrset
  719. self.xfrsess._iterator = [self.soa_rrset]
  720. self.xfrsess._reply_xfrout_query(self.getmsg(), self.sock)
  721. reply_msg = self.sock.read_msg()
  722. self.assertEqual(reply_msg.get_rr_count(Message.SECTION_ANSWER), 2)
  723. def test_reply_xfrout_query_axfr_with_tsig(self):
  724. rrset = RRset(Name('a.example.com'), RRClass.IN(), RRType.A(),
  725. RRTTL(3600))
  726. rrset.add_rdata(Rdata(RRType.A(), RRClass.IN(), '192.0.2.1'))
  727. global xfrout
  728. def get_rrset_len(rrset):
  729. return 65520
  730. self.xfrsess._soa = self.soa_rrset
  731. self.xfrsess._iterator = [rrset for i in range(0, 100)]
  732. xfrout.get_rrset_len = get_rrset_len
  733. self.xfrsess._tsig_ctx = self.create_mock_tsig_ctx(TSIGError.NOERROR)
  734. self.xfrsess._reply_xfrout_query(self.getmsg(), self.sock)
  735. # All messages must have TSIG as we don't support the feature of
  736. # skipping intermediate TSIG records (with bulk signing).
  737. for i in range(0, 102): # 102 = all 100 RRs from iterator and 2 SOAs
  738. reply_msg = self.sock.read_msg()
  739. # With the hack of get_rrset_len() above, every message must have
  740. # exactly one RR in the answer section.
  741. self.assertEqual(reply_msg.get_rr_count(Message.SECTION_ANSWER), 1)
  742. self.assertTrue(self.message_has_tsig(reply_msg))
  743. # and it should not have sent anything else
  744. self.assertEqual(0, len(self.sock.sendqueue))
  745. def test_reply_xfrout_query_ixfr(self):
  746. # Creating a pure (incremental) IXFR response. Intermediate SOA
  747. # RRs won't be skipped.
  748. self.xfrsess._soa = create_soa(SOA_CURRENT_VERSION)
  749. self.xfrsess._iterator = [create_soa(IXFR_OK_VERSION),
  750. create_a(Name('a.example.com'), '192.0.2.2'),
  751. create_soa(SOA_CURRENT_VERSION),
  752. create_aaaa(Name('a.example.com'),
  753. '2001:db8::1')]
  754. self.xfrsess._jnl_reader = self.xfrsess._iterator
  755. self.xfrsess._reply_xfrout_query(self.getmsg(), self.sock)
  756. reply_msg = self.sock.read_msg(Message.PRESERVE_ORDER)
  757. actual_records = reply_msg.get_section(Message.SECTION_ANSWER)
  758. expected_records = self.xfrsess._iterator[:]
  759. expected_records.insert(0, create_soa(SOA_CURRENT_VERSION))
  760. expected_records.append(create_soa(SOA_CURRENT_VERSION))
  761. self.assertEqual(len(expected_records), len(actual_records))
  762. for (expected_rr, actual_rr) in zip(expected_records, actual_records):
  763. self.assertTrue(rrsets_equal(expected_rr, actual_rr))
  764. def test_reply_xfrout_query_axfr_maxlen(self):
  765. # The test RR(set) has the length of 65535 - 12 (size of hdr) bytes:
  766. # owner name = 1 (root), fixed fields (type,class,TTL,RDLEN) = 10
  767. # RDATA = 65512 (= 65535 - 12 - 1 - 10)
  768. self.xfrsess._soa = self.soa_rrset
  769. test_rr = create_generic(Name('.'), 65512)
  770. self.xfrsess._iterator = [self.soa_rrset, test_rr]
  771. self.xfrsess._reply_xfrout_query(self.getmsg(), self.sock)
  772. # The first message should contain the beginning SOA, and only that RR
  773. r = self.sock.read_msg()
  774. self.assertEqual(1, r.get_rr_count(Message.SECTION_ANSWER))
  775. self.assertTrue(rrsets_equal(self.soa_rrset,
  776. r.get_section(Message.SECTION_ANSWER)[0]))
  777. # The second message should contain the beginning SOA, and only that RR
  778. # The wire format data should have the possible maximum size.
  779. r, rlen = self.sock.read_msg(need_len=True)
  780. self.assertEqual(65535, rlen)
  781. self.assertEqual(1, r.get_rr_count(Message.SECTION_ANSWER))
  782. self.assertTrue(rrsets_equal(test_rr,
  783. r.get_section(Message.SECTION_ANSWER)[0]))
  784. # The third message should contain the ending SOA, and only that RR
  785. r = self.sock.read_msg()
  786. self.assertEqual(1, r.get_rr_count(Message.SECTION_ANSWER))
  787. self.assertTrue(rrsets_equal(self.soa_rrset,
  788. r.get_section(Message.SECTION_ANSWER)[0]))
  789. # there should be no more message
  790. self.assertEqual(0, len(self.sock.sendqueue))
  791. def maxlen_test_common_setup(self, tsig=False):
  792. '''Common initialization for some of the tests below
  793. For those tests we use '.' for all owner names and names in RDATA
  794. to avoid having unexpected results due to compression. It returns
  795. the created SOA for convenience.
  796. If tsig is True, also setup TSIG (mock) context. In our test cases
  797. the size of the TSIG RR is 81 bytes (key name = example.com,
  798. algorithm = hmac-md5)
  799. '''
  800. soa = RRset(Name('.'), RRClass.IN(), RRType.SOA(), RRTTL(3600))
  801. soa.add_rdata(Rdata(RRType.SOA(), RRClass.IN(), '. . 0 0 0 0 0'))
  802. self.mdata = self.create_request_data(zone_name=Name('.'))
  803. self.xfrsess._soa = soa
  804. if tsig:
  805. self.xfrsess._tsig_ctx = \
  806. self.create_mock_tsig_ctx(TSIGError.NOERROR)
  807. self.xfrsess._tsig_len = 81
  808. return soa
  809. def maxlen_test_common_checks(self, soa_rr, test_rr, expected_n_rr):
  810. '''A set of common assertion checks for some tests below.
  811. In all cases two AXFR response messages should have been created.
  812. expected_n_rr is a list of two elements, each specifies the expected
  813. number of answer RRs for each message: expected_n_rr[0] is the expected
  814. number of the first answer RRs; expected_n_rr[1] is the expected number
  815. of the second answer RRs. The message that contains two RRs should
  816. have the maximum possible wire length (65535 bytes). And, in all
  817. cases, the resulting RRs should be in the order of SOA, another RR,
  818. SOA.
  819. '''
  820. # Check the first message
  821. r, rlen = self.sock.read_msg(need_len=True)
  822. if expected_n_rr[0] == 2:
  823. self.assertEqual(65535, rlen)
  824. self.assertEqual(expected_n_rr[0],
  825. r.get_rr_count(Message.SECTION_ANSWER))
  826. actual_rrs = r.get_section(Message.SECTION_ANSWER)[:]
  827. # Check the second message
  828. r, rlen = self.sock.read_msg(need_len=True)
  829. if expected_n_rr[1] == 2:
  830. self.assertEqual(65535, rlen)
  831. self.assertEqual(expected_n_rr[1],
  832. r.get_rr_count(Message.SECTION_ANSWER))
  833. actual_rrs.extend(r.get_section(Message.SECTION_ANSWER))
  834. for (expected_rr, actual_rr) in zip([soa_rr, test_rr, soa_rr],
  835. actual_rrs):
  836. self.assertTrue(rrsets_equal(expected_rr, actual_rr))
  837. # there should be no more message
  838. self.assertEqual(0, len(self.sock.sendqueue))
  839. def test_reply_xfrout_query_axfr_maxlen_with_soa(self):
  840. # Similar to the 'maxlen' test, but the first message should be
  841. # able to contain both SOA and the large RR.
  842. soa = self.maxlen_test_common_setup()
  843. # The first message will contain the question (5 bytes), so the
  844. # test RDATA should allow a room for that.
  845. test_rr = create_generic(Name('.'), 65512 - 5 - get_rrset_len(soa))
  846. self.xfrsess._iterator = [soa, test_rr]
  847. self.xfrsess._reply_xfrout_query(self.getmsg(), self.sock)
  848. self.maxlen_test_common_checks(soa, test_rr, [2, 1])
  849. def test_reply_xfrout_query_axfr_maxlen_with_soa_with_tsig(self):
  850. # Similar to the previous case, but with TSIG (whose size is 81 bytes).
  851. soa = self.maxlen_test_common_setup(True)
  852. test_rr = create_generic(Name('.'), 65512 - 5 - 81 -
  853. get_rrset_len(soa))
  854. self.xfrsess._iterator = [soa, test_rr]
  855. self.xfrsess._reply_xfrout_query(self.getmsg(), self.sock)
  856. self.maxlen_test_common_checks(soa, test_rr, [2, 1])
  857. def test_reply_xfrout_query_axfr_maxlen_with_endsoa(self):
  858. # Similar to the max w/ soa test, but the first message cannot contain
  859. # both SOA and the long RR due to the question section. The second
  860. # message should be able to contain both.
  861. soa = self.maxlen_test_common_setup()
  862. test_rr = create_generic(Name('.'), 65512 - get_rrset_len(soa))
  863. self.xfrsess._iterator = [soa, test_rr]
  864. self.xfrsess._reply_xfrout_query(self.getmsg(), self.sock)
  865. self.maxlen_test_common_checks(soa, test_rr, [1, 2])
  866. def test_reply_xfrout_query_axfr_maxlen_with_endsoa_with_tsig(self):
  867. # Similar to the previous case, but with TSIG.
  868. soa = self.maxlen_test_common_setup(True)
  869. test_rr = create_generic(Name('.'), 65512 - 81 - get_rrset_len(soa))
  870. self.xfrsess._iterator = [soa, test_rr]
  871. self.xfrsess._reply_xfrout_query(self.getmsg(), self.sock)
  872. self.maxlen_test_common_checks(soa, test_rr, [1, 2])
  873. def test_reply_xfrout_query_axfr_toobigdata(self):
  874. # Similar to the 'maxlen' test, but the RR doesn't even fit in a
  875. # single message.
  876. self.xfrsess._soa = self.soa_rrset
  877. test_rr = create_generic(Name('.'), 65513) # 1 byte larger than 'max'
  878. self.xfrsess._iterator = [self.soa_rrset, test_rr]
  879. # the reply method should fail with exception
  880. self.assertRaises(XfroutSessionError, self.xfrsess._reply_xfrout_query,
  881. self.getmsg(), self.sock)
  882. # The first message should still have been sent and contain the
  883. # beginning SOA, and only that RR
  884. r = self.sock.read_msg()
  885. self.assertEqual(1, r.get_rr_count(Message.SECTION_ANSWER))
  886. self.assertTrue(rrsets_equal(self.soa_rrset,
  887. r.get_section(Message.SECTION_ANSWER)[0]))
  888. # And there should have been no other messages sent
  889. self.assertEqual(0, len(self.sock.sendqueue))
  890. def test_reply_xfrout_query_ixfr_soa_only(self):
  891. # Creating an IXFR response that contains only one RR, which is the
  892. # SOA of the current version.
  893. self.xfrsess._soa = create_soa(SOA_CURRENT_VERSION)
  894. self.xfrsess._iterator = None
  895. self.xfrsess._jnl_reader = None
  896. self.xfrsess._reply_xfrout_query(self.getmsg(), self.sock)
  897. reply_msg = self.sock.read_msg(Message.PRESERVE_ORDER)
  898. answer = reply_msg.get_section(Message.SECTION_ANSWER)
  899. self.assertEqual(1, len(answer))
  900. self.assertTrue(rrsets_equal(create_soa(SOA_CURRENT_VERSION),
  901. answer[0]))
  902. class TestXfroutSessionWithSQLite3(TestXfroutSessionBase):
  903. '''Tests for XFR-out sessions using an SQLite3 DB.
  904. These are provided mainly to confirm the implementation actually works
  905. in an environment closer to actual operational environments. So we
  906. only check a few common cases; other details are tested using mock
  907. data sources.
  908. '''
  909. def setUp(self):
  910. super().setUp()
  911. self.xfrsess._request_data = self.mdata
  912. self.xfrsess._server.get_db_file = lambda : TESTDATA_SRCDIR + \
  913. 'test.sqlite3'
  914. self.ns_name = 'a.dns.example.com'
  915. def check_axfr_stream(self, response):
  916. '''Common checks for AXFR(-style) response for the test zone.
  917. '''
  918. # This zone contains two A RRs for the same name with different TTLs.
  919. # These TTLs should be preseved in the AXFR stream.
  920. actual_records = response.get_section(Message.SECTION_ANSWER)
  921. self.assertEqual(5, len(actual_records))
  922. # The first and last RR should be the expected SOA
  923. expected_soa = create_soa(2011112001)
  924. self.assertTrue(rrsets_equal(expected_soa, actual_records[0]))
  925. self.assertTrue(rrsets_equal(expected_soa, actual_records[-1]))
  926. # The ordering of the intermediate RRs can differ depending on the
  927. # internal details of the SQLite3 library, so we sort them by a simple
  928. # rule sufficient for the purpose here, and then compare them.
  929. expected_others = [create_ns(self.ns_name),
  930. create_a(Name(self.ns_name), '192.0.2.1', 3600),
  931. create_a(Name(self.ns_name), '192.0.2.2', 7200)]
  932. keyfn = lambda x: (x.get_type(), x.get_ttl())
  933. for (expected_rr, actual_rr) in zip(sorted(expected_others, key=keyfn),
  934. sorted(actual_records[1:4],
  935. key=keyfn)):
  936. self.assertTrue(rrsets_equal(expected_rr, actual_rr))
  937. def test_axfr_normal_session(self):
  938. XfroutSession._handle(self.xfrsess)
  939. response = self.sock.read_msg(Message.PRESERVE_ORDER);
  940. self.assertEqual(Rcode.NOERROR(), response.get_rcode())
  941. self.check_axfr_stream(response)
  942. def test_ixfr_to_axfr(self):
  943. self.xfrsess._request_data = \
  944. self.create_request_data(ixfr=IXFR_NG_VERSION)
  945. XfroutSession._handle(self.xfrsess)
  946. response = self.sock.read_msg(Message.PRESERVE_ORDER);
  947. self.assertEqual(Rcode.NOERROR(), response.get_rcode())
  948. # This is an AXFR-style IXFR. So the question section should indicate
  949. # that it's an IXFR resposne.
  950. self.assertEqual(RRType.IXFR(), response.get_question()[0].get_type())
  951. self.check_axfr_stream(response)
  952. def test_ixfr_normal_session(self):
  953. # See testdata/creatediff.py. There are 8 changes between two
  954. # versions. So the answer section should contain all of these and
  955. # two beginning and trailing SOAs.
  956. self.xfrsess._request_data = \
  957. self.create_request_data(ixfr=IXFR_OK_VERSION)
  958. XfroutSession._handle(self.xfrsess)
  959. response = self.sock.read_msg(Message.PRESERVE_ORDER)
  960. actual_records = response.get_section(Message.SECTION_ANSWER)
  961. expected_records = [create_soa(2011112001), create_soa(2011111802),
  962. create_soa(2011111900),
  963. create_a(Name(self.ns_name), '192.0.2.2', 7200),
  964. create_soa(2011111900),
  965. create_a(Name(self.ns_name), '192.0.2.53'),
  966. create_aaaa(Name(self.ns_name), '2001:db8::1'),
  967. create_soa(2011112001),
  968. create_a(Name(self.ns_name), '192.0.2.1'),
  969. create_soa(2011112001)]
  970. self.assertEqual(len(expected_records), len(actual_records))
  971. for (expected_rr, actual_rr) in zip(expected_records, actual_records):
  972. self.assertTrue(rrsets_equal(expected_rr, actual_rr))
  973. def ixfr_soa_only_common_checks(self, request_serial):
  974. self.xfrsess._request_data = \
  975. self.create_request_data(ixfr=request_serial)
  976. XfroutSession._handle(self.xfrsess)
  977. response = self.sock.read_msg(Message.PRESERVE_ORDER);
  978. answers = response.get_section(Message.SECTION_ANSWER)
  979. self.assertEqual(1, len(answers))
  980. self.assertTrue(rrsets_equal(create_soa(SOA_CURRENT_VERSION),
  981. answers[0]))
  982. def test_ixfr_soa_only(self):
  983. # The requested SOA serial is the latest one. The response should
  984. # contain exactly one SOA of that serial.
  985. self.ixfr_soa_only_common_checks(SOA_CURRENT_VERSION)
  986. def test_ixfr_soa_only2(self):
  987. # Similar to the previous test, but the requested SOA is larger than
  988. # the current.
  989. self.ixfr_soa_only_common_checks(SOA_CURRENT_VERSION + 1)
  990. class MyUnixSockServer(UnixSockServer):
  991. def __init__(self):
  992. self._shutdown_event = threading.Event()
  993. self._common_init()
  994. self._cc = MyCCSession()
  995. self.update_config_data(self._cc.get_full_config())
  996. class TestUnixSockServer(unittest.TestCase):
  997. def setUp(self):
  998. self.write_sock, self.read_sock = socket.socketpair()
  999. self.unix = MyUnixSockServer()
  1000. def test_guess_remote(self):
  1001. """Test we can guess the remote endpoint when we have only the
  1002. file descriptor. This is needed, because we get only that one
  1003. from auth."""
  1004. # We test with UDP, as it can be "connected" without other
  1005. # endpoint. Note that in the current implementation _guess_remote()
  1006. # unconditionally returns SOCK_STREAM.
  1007. sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  1008. sock.connect(('127.0.0.1', 12345))
  1009. self.assertEqual((socket.AF_INET, socket.SOCK_STREAM,
  1010. ('127.0.0.1', 12345)),
  1011. self.unix._guess_remote(sock.fileno()))
  1012. if socket.has_ipv6:
  1013. # Don't check IPv6 address on hosts not supporting them
  1014. sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
  1015. sock.connect(('::1', 12345))
  1016. self.assertEqual((socket.AF_INET6, socket.SOCK_STREAM,
  1017. ('::1', 12345, 0, 0)),
  1018. self.unix._guess_remote(sock.fileno()))
  1019. # Try when pretending there's no IPv6 support
  1020. # (No need to pretend when there's really no IPv6)
  1021. xfrout.socket.has_ipv6 = False
  1022. sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  1023. sock.connect(('127.0.0.1', 12345))
  1024. self.assertEqual((socket.AF_INET, socket.SOCK_STREAM,
  1025. ('127.0.0.1', 12345)),
  1026. self.unix._guess_remote(sock.fileno()))
  1027. # Return it back
  1028. xfrout.socket.has_ipv6 = True
  1029. def test_receive_query_message(self):
  1030. send_msg = b"\xd6=\x00\x00\x00\x01\x00"
  1031. msg_len = struct.pack('H', socket.htons(len(send_msg)))
  1032. self.write_sock.send(msg_len)
  1033. self.write_sock.send(send_msg)
  1034. recv_msg = self.unix._receive_query_message(self.read_sock)
  1035. self.assertEqual(recv_msg, send_msg)
  1036. def check_default_ACL(self):
  1037. context = isc.acl.dns.RequestContext(socket.getaddrinfo("127.0.0.1",
  1038. 1234, 0, socket.SOCK_DGRAM,
  1039. socket.IPPROTO_UDP,
  1040. socket.AI_NUMERICHOST)[0][4])
  1041. self.assertEqual(isc.acl.acl.ACCEPT, self.unix._acl.execute(context))
  1042. def check_loaded_ACL(self, acl):
  1043. context = isc.acl.dns.RequestContext(socket.getaddrinfo("127.0.0.1",
  1044. 1234, 0, socket.SOCK_DGRAM,
  1045. socket.IPPROTO_UDP,
  1046. socket.AI_NUMERICHOST)[0][4])
  1047. self.assertEqual(isc.acl.acl.ACCEPT, acl.execute(context))
  1048. context = isc.acl.dns.RequestContext(socket.getaddrinfo("192.0.2.1",
  1049. 1234, 0, socket.SOCK_DGRAM,
  1050. socket.IPPROTO_UDP,
  1051. socket.AI_NUMERICHOST)[0][4])
  1052. self.assertEqual(isc.acl.acl.REJECT, acl.execute(context))
  1053. def test_update_config_data(self):
  1054. self.check_default_ACL()
  1055. tsig_key_str = 'example.com:SFuWd/q99SzF8Yzd1QbB9g=='
  1056. tsig_key_list = [tsig_key_str]
  1057. bad_key_list = ['bad..example.com:SFuWd/q99SzF8Yzd1QbB9g==']
  1058. self.unix.update_config_data({'transfers_out':10 })
  1059. self.assertEqual(self.unix._max_transfers_out, 10)
  1060. self.assertTrue(self.unix.tsig_key_ring is not None)
  1061. self.check_default_ACL()
  1062. self.unix.update_config_data({'transfers_out':9,
  1063. 'tsig_key_ring':tsig_key_list})
  1064. self.assertEqual(self.unix._max_transfers_out, 9)
  1065. self.assertEqual(self.unix.tsig_key_ring.size(), 1)
  1066. self.unix.tsig_key_ring.remove(Name("example.com."))
  1067. self.assertEqual(self.unix.tsig_key_ring.size(), 0)
  1068. # bad tsig key
  1069. config_data = {'transfers_out':9, 'tsig_key_ring': bad_key_list}
  1070. self.assertRaises(None, self.unix.update_config_data(config_data))
  1071. self.assertEqual(self.unix.tsig_key_ring.size(), 0)
  1072. # Load the ACL
  1073. self.unix.update_config_data({'transfer_acl': [{'from': '127.0.0.1',
  1074. 'action': 'ACCEPT'}]})
  1075. self.check_loaded_ACL(self.unix._acl)
  1076. # Pass a wrong data there and check it does not replace the old one
  1077. self.assertRaises(XfroutConfigError,
  1078. self.unix.update_config_data,
  1079. {'transfer_acl': ['Something bad']})
  1080. self.check_loaded_ACL(self.unix._acl)
  1081. def test_zone_config_data(self):
  1082. # By default, there's no specific zone config
  1083. self.assertEqual({}, self.unix._zone_config)
  1084. # Adding config for a specific zone. The config is empty unless
  1085. # explicitly specified.
  1086. self.unix.update_config_data({'zone_config':
  1087. [{'origin': 'example.com',
  1088. 'class': 'IN'}]})
  1089. self.assertEqual({}, self.unix._zone_config[('IN', 'example.com.')])
  1090. # zone class can be omitted
  1091. self.unix.update_config_data({'zone_config':
  1092. [{'origin': 'example.com'}]})
  1093. self.assertEqual({}, self.unix._zone_config[('IN', 'example.com.')])
  1094. # zone class, name are stored in the "normalized" form. class
  1095. # strings are upper cased, names are down cased.
  1096. self.unix.update_config_data({'zone_config':
  1097. [{'origin': 'EXAMPLE.com'}]})
  1098. self.assertEqual({}, self.unix._zone_config[('IN', 'example.com.')])
  1099. # invalid zone class, name will result in exceptions
  1100. self.assertRaises(EmptyLabel,
  1101. self.unix.update_config_data,
  1102. {'zone_config': [{'origin': 'bad..example'}]})
  1103. self.assertRaises(InvalidRRClass,
  1104. self.unix.update_config_data,
  1105. {'zone_config': [{'origin': 'example.com',
  1106. 'class': 'badclass'}]})
  1107. # Configuring a couple of more zones
  1108. self.unix.update_config_data({'zone_config':
  1109. [{'origin': 'example.com'},
  1110. {'origin': 'example.com',
  1111. 'class': 'CH'},
  1112. {'origin': 'example.org'}]})
  1113. self.assertEqual({}, self.unix._zone_config[('IN', 'example.com.')])
  1114. self.assertEqual({}, self.unix._zone_config[('CH', 'example.com.')])
  1115. self.assertEqual({}, self.unix._zone_config[('IN', 'example.org.')])
  1116. # Duplicate data: should be rejected with an exception
  1117. self.assertRaises(XfroutConfigError,
  1118. self.unix.update_config_data,
  1119. {'zone_config': [{'origin': 'example.com'},
  1120. {'origin': 'example.org'},
  1121. {'origin': 'example.com'}]})
  1122. def test_zone_config_data_with_acl(self):
  1123. # Similar to the previous test, but with transfer_acl config
  1124. self.unix.update_config_data({'zone_config':
  1125. [{'origin': 'example.com',
  1126. 'transfer_acl':
  1127. [{'from': '127.0.0.1',
  1128. 'action': 'ACCEPT'}]}]})
  1129. acl = self.unix._zone_config[('IN', 'example.com.')]['transfer_acl']
  1130. self.check_loaded_ACL(acl)
  1131. # invalid ACL syntax will be rejected with exception
  1132. self.assertRaises(XfroutConfigError,
  1133. self.unix.update_config_data,
  1134. {'zone_config': [{'origin': 'example.com',
  1135. 'transfer_acl':
  1136. [{'action': 'BADACTION'}]}]})
  1137. def test_get_db_file(self):
  1138. self.assertEqual(self.unix.get_db_file(), "initdb.file")
  1139. def test_increase_transfers_counter(self):
  1140. self.unix._max_transfers_out = 10
  1141. count = self.unix._transfers_counter
  1142. self.assertEqual(self.unix.increase_transfers_counter(), True)
  1143. self.assertEqual(count + 1, self.unix._transfers_counter)
  1144. self.unix._max_transfers_out = 0
  1145. count = self.unix._transfers_counter
  1146. self.assertEqual(self.unix.increase_transfers_counter(), False)
  1147. self.assertEqual(count, self.unix._transfers_counter)
  1148. def test_decrease_transfers_counter(self):
  1149. count = self.unix._transfers_counter
  1150. self.unix.decrease_transfers_counter()
  1151. self.assertEqual(count - 1, self.unix._transfers_counter)
  1152. def _remove_file(self, sock_file):
  1153. try:
  1154. os.remove(sock_file)
  1155. except OSError:
  1156. pass
  1157. def test_sock_file_in_use_file_exist(self):
  1158. sock_file = 'temp.sock.file'
  1159. self._remove_file(sock_file)
  1160. self.assertFalse(self.unix._sock_file_in_use(sock_file))
  1161. self.assertFalse(os.path.exists(sock_file))
  1162. def test_sock_file_in_use_file_not_exist(self):
  1163. self.assertFalse(self.unix._sock_file_in_use('temp.sock.file'))
  1164. def _start_unix_sock_server(self, sock_file):
  1165. serv = ThreadingUnixStreamServer(sock_file, BaseRequestHandler)
  1166. serv_thread = threading.Thread(target=serv.serve_forever)
  1167. serv_thread.setDaemon(True)
  1168. serv_thread.start()
  1169. def test_sock_file_in_use(self):
  1170. sock_file = 'temp.sock.file'
  1171. self._remove_file(sock_file)
  1172. self.assertFalse(self.unix._sock_file_in_use(sock_file))
  1173. self._start_unix_sock_server(sock_file)
  1174. old_stdout = sys.stdout
  1175. sys.stdout = open(os.devnull, 'w')
  1176. self.assertTrue(self.unix._sock_file_in_use(sock_file))
  1177. sys.stdout = old_stdout
  1178. def test_remove_unused_sock_file_in_use(self):
  1179. sock_file = 'temp.sock.file'
  1180. self._remove_file(sock_file)
  1181. self.assertFalse(self.unix._sock_file_in_use(sock_file))
  1182. self._start_unix_sock_server(sock_file)
  1183. old_stdout = sys.stdout
  1184. sys.stdout = open(os.devnull, 'w')
  1185. try:
  1186. self.unix._remove_unused_sock_file(sock_file)
  1187. except SystemExit:
  1188. pass
  1189. else:
  1190. # This should never happen
  1191. self.assertTrue(False)
  1192. sys.stdout = old_stdout
  1193. def test_remove_unused_sock_file_dir(self):
  1194. import tempfile
  1195. dir_name = tempfile.mkdtemp()
  1196. old_stdout = sys.stdout
  1197. sys.stdout = open(os.devnull, 'w')
  1198. try:
  1199. self.unix._remove_unused_sock_file(dir_name)
  1200. except SystemExit:
  1201. pass
  1202. else:
  1203. # This should never happen
  1204. self.assertTrue(False)
  1205. sys.stdout = old_stdout
  1206. os.rmdir(dir_name)
  1207. class TestInitialization(unittest.TestCase):
  1208. def setEnv(self, name, value):
  1209. if value is None:
  1210. if name in os.environ:
  1211. del os.environ[name]
  1212. else:
  1213. os.environ[name] = value
  1214. def setUp(self):
  1215. self._oldSocket = os.getenv("BIND10_XFROUT_SOCKET_FILE")
  1216. self._oldFromBuild = os.getenv("B10_FROM_BUILD")
  1217. def tearDown(self):
  1218. self.setEnv("B10_FROM_BUILD", self._oldFromBuild)
  1219. self.setEnv("BIND10_XFROUT_SOCKET_FILE", self._oldSocket)
  1220. # Make sure even the computed values are back
  1221. xfrout.init_paths()
  1222. def testNoEnv(self):
  1223. self.setEnv("B10_FROM_BUILD", None)
  1224. self.setEnv("BIND10_XFROUT_SOCKET_FILE", None)
  1225. xfrout.init_paths()
  1226. self.assertEqual(xfrout.UNIX_SOCKET_FILE,
  1227. "@@LOCALSTATEDIR@@/@PACKAGE_NAME@/auth_xfrout_conn")
  1228. def testProvidedSocket(self):
  1229. self.setEnv("B10_FROM_BUILD", None)
  1230. self.setEnv("BIND10_XFROUT_SOCKET_FILE", "The/Socket/File")
  1231. xfrout.init_paths()
  1232. self.assertEqual(xfrout.UNIX_SOCKET_FILE, "The/Socket/File")
  1233. if __name__== "__main__":
  1234. isc.log.resetUnitTestRootLogger()
  1235. unittest.main()