Verified Commit fc99b20f authored by Grigorii Demidov's avatar Grigorii Demidov Committed by Tomas Krizek

scenario: possibility to ignore selected queries was added

parent f011d004
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
" au BufRead,BufNewFile *.rpl set filetype=deckard " au BufRead,BufNewFile *.rpl set filetype=deckard
" au BufRead,BufNewFile *.stc set foldmethod=syntax " au BufRead,BufNewFile *.stc set foldmethod=syntax
syntax keyword Keyword MATCH STEP ADJUST MANDATORY RAW syntax keyword Keyword MATCH STEP ADJUST MANDATORY RAW IGNORE
syntax keyword Structure CONFIG_END syntax keyword Structure CONFIG_END
syntax keyword Function CHECK_ANSWER QUERY TIME_PASSES syntax keyword Function CHECK_ANSWER QUERY TIME_PASSES
......
...@@ -37,12 +37,13 @@ let adjust_option = "copy_id" | "copy_query" | "raw_id" ...@@ -37,12 +37,13 @@ let adjust_option = "copy_id" | "copy_query" | "raw_id"
let reply_option = "QR" | "TC" | "AA" | "AD" | "RD" | "RA" | "CD" | "DO" | "NOERROR" | "FORMERR" | "SERVFAIL" | "NXDOMAIN" | "NOTIMP" | "REFUSED" | "YXDOMAIN" | "YXRRSET" | "NXRRSET" | "NOTAUTH" | "NOTZONE" | "BADVERS" | "BADSIG" | "BADKEY" | "BADTIME" | "BADMODE" | "BADNAME" | "BADALG" | "BADTRUNC" | "BADCOOKIE" let reply_option = "QR" | "TC" | "AA" | "AD" | "RD" | "RA" | "CD" | "DO" | "NOERROR" | "FORMERR" | "SERVFAIL" | "NXDOMAIN" | "NOTIMP" | "REFUSED" | "YXDOMAIN" | "YXRRSET" | "NXRRSET" | "NOTAUTH" | "NOTZONE" | "BADVERS" | "BADSIG" | "BADKEY" | "BADTIME" | "BADMODE" | "BADNAME" | "BADALG" | "BADTRUNC" | "BADCOOKIE"
let step_option = "REPLY" | "QUERY" | "CHECK_ANSWER" | "CHECK_OUT_QUERY" | /TIME_PASSES[ \t]+ELAPSE/ let step_option = "REPLY" | "QUERY" | "CHECK_ANSWER" | "CHECK_OUT_QUERY" | /TIME_PASSES[ \t]+ELAPSE/
let ignore = [del_str "IGNORE" . label "ignore" . value "true" . comment_or_eol]
let mandatory = [del_str "MANDATORY" . label "mandatory" . value "true" . comment_or_eol] let mandatory = [del_str "MANDATORY" . label "mandatory" . value "true" . comment_or_eol]
let tsig = [del_str "TSIG" . label "tsig" . space . [label "keyname" . store word] . space . [label "secret" . store word] . comment_or_eol] let tsig = [del_str "TSIG" . label "tsig" . space . [label "keyname" . store word] . space . [label "secret" . store word] . comment_or_eol]
let match = (mandatory | tsig)* . [ label "match_present" . value "true" . del_str "MATCH" ] . [space . label "match" . store match_option ]+ . comment_or_eol let match = (ignore | mandatory | tsig)* . [ label "match_present" . value "true" . del_str "MATCH" ] . [space . label "match" . store match_option ]+ . comment_or_eol
let adjust = (mandatory | tsig)* . del_str "ADJUST" . [space . label "adjust" . store adjust_option ]+ . comment_or_eol let adjust = (ignore | mandatory | tsig)* . del_str "ADJUST" . [space . label "adjust" . store adjust_option ]+ . comment_or_eol
let reply = (mandatory | tsig)* . del ("REPLY" | "FLAGS") "REPLY" . [space . label "reply" . store reply_option ]+ . comment_or_eol let reply = (ignore | mandatory | tsig)* . del ("REPLY" | "FLAGS") "REPLY" . [space . label "reply" . store reply_option ]+ . comment_or_eol
let question = [label "record" . domain . tab . (class . tab)? . type . comment_or_eol ] let question = [label "record" . domain . tab . (class . tab)? . type . comment_or_eol ]
......
...@@ -173,6 +173,12 @@ class Entry: ...@@ -173,6 +173,12 @@ class Entry:
except (KeyError, IndexError): except (KeyError, IndexError):
self.mandatory = None self.mandatory = None
# IGNORE
try:
self.ignore = list(node.match("/ignore"))[0]
except (KeyError, IndexError):
self.ignore = None
# TSIG # TSIG
self.process_tsig() self.process_tsig()
...@@ -395,6 +401,8 @@ class Entry: ...@@ -395,6 +401,8 @@ class Entry:
return self.raw_data return self.raw_data
def reply(self, query): def reply(self, query):
if self.ignore:
return None, True
if self.is_raw_data_entry: if self.is_raw_data_entry:
return self._adjust_raw_reply(query), True return self._adjust_raw_reply(query), True
return self._adjust_reply(query), False return self._adjust_reply(query), False
...@@ -788,7 +796,7 @@ class Scenario: ...@@ -788,7 +796,7 @@ class Scenario:
return candidate.reply(query) return candidate.reply(query)
except (IndexError, ValueError): except (IndexError, ValueError):
pass pass
return None, True return None, False
def play(self, paddr): def play(self, paddr):
""" Play given scenario. """ """ Play given scenario. """
......
...@@ -91,15 +91,16 @@ class TestServer: ...@@ -91,15 +91,16 @@ class TestServer:
if query is None: if query is None:
return False return False
log.debug('server %s received query from %s: %s', server_addr, client_addr, query) log.debug('server %s received query from %s: %s', server_addr, client_addr, query)
response, is_raw_data = self.scenario.reply(query, server_addr) response, second = self.scenario.reply(query, server_addr)
if response: if response:
is_raw_data = second
if not is_raw_data: if not is_raw_data:
data_to_wire = response.to_wire(max_size=65535) data_to_wire = response.to_wire(max_size=65535)
log.debug('response: %s', response) log.debug('response: %s', response)
else: else:
data_to_wire = response data_to_wire = response
log.debug('raw response not printed') log.debug('raw response not printed')
else: elif not second:
response = dns.message.make_response(query) response = dns.message.make_response(query)
response.set_rcode(dns.rcode.SERVFAIL) response.set_rcode(dns.rcode.SERVFAIL)
data_to_wire = response.to_wire() data_to_wire = response.to_wire()
...@@ -108,6 +109,10 @@ class TestServer: ...@@ -108,6 +109,10 @@ class TestServer:
'server %s has no response for question %s, answering with SERVFAIL', 'server %s has no response for question %s, answering with SERVFAIL',
server_addr, server_addr,
'; '.join([str(rr) for rr in query.question])) '; '.join([str(rr) for rr in query.question]))
else:
# Just ignore
log.debug('ignoring')
return True
scenario.sendto_msg(client, data_to_wire, client_addr) scenario.sendto_msg(client, data_to_wire, client_addr)
return True return True
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment