3939
4040ROWS = 96
4141SMALL = 15 # a real shop listing, far short of the 128 wide window
42- _WARN = multibit .singleTimeWarnMessage # restored after the cases that capture the nudge
42+ _SAID = ( multibit .singleTimeWarnMessage , multibit . singleTimeLogMessage ) # hint() speaks through both
4343
4444def tearDownModule ():
4545 reset_dbms ()
@@ -137,6 +137,7 @@ def tearDown(self):
137137 # kb.injection is restored by identity above, so its members have to be put back one by one
138138 kb .injection .place , kb .injection .parameter , kb .injection .data = self ._savedInjection
139139 multibit ._page = self ._savedPage
140+ multibit .singleTimeWarnMessage , multibit .singleTimeLogMessage = _SAID
140141
141142 def _attempt (self , secret , length = None , ** kwargs ):
142143 target = _Target (secret , ** kwargs )
@@ -354,21 +355,26 @@ def test_the_switch_takes_the_whole_table(self):
354355 self .assertEqual (value , secret )
355356 self .assertEqual (list (kb .multibit .values ())[0 ]["mode" ], MULTIBIT_WIDEN )
356357
358+ def _hint (self ):
359+ """hint() with everything it could say captured - a nudge is INFO, an unusable back-end a WARNING."""
360+
361+ said = []
362+ multibit .singleTimeWarnMessage = lambda message : said .append (message )
363+ multibit .singleTimeLogMessage = lambda message , level = None , flag = None : said .append (message )
364+ multibit .hint ()
365+
366+ return said
367+
357368 def test_hint_costs_nothing_and_states_the_width (self ):
358369 # the nudge towards the switch is drawn from the page sqlmap already has, never from a probe
359370 conf .multiBit = False # the nudge is for a run that did NOT ask for it
360371 kb .originalPage = "" .join ("<div class='item'><a href='/product.php?id=%d'>p</a></div>" % _ for _ in range (1 , 13 ))
361- warned = []
362- multibit .singleTimeWarnMessage = lambda message : warned .append (message )
363372
364- try :
365- multibit .hint ()
366- finally :
367- multibit .singleTimeWarnMessage = _WARN
373+ said = self ._hint ()
368374
369- self .assertEqual (len (warned ), 1 )
370- self .assertIn ("12 rows" , warned [0 ])
371- self .assertIn ("--multi-bit" , warned [0 ])
375+ self .assertEqual (len (said ), 1 )
376+ self .assertIn ("12 rows" , said [0 ])
377+ self .assertIn ("--multi-bit" , said [0 ])
372378
373379 def test_hint_stays_quiet_on_a_page_that_renders_no_rows (self ):
374380 # the old trigger announced "the target lists rows" on the nav menu of a single-product DETAIL
@@ -380,39 +386,26 @@ def test_hint_stays_quiet_on_a_page_that_renders_no_rows(self):
380386 "<a href='/category.php?cat=3'>C</a></nav>"
381387 "<main><div class='product'><h2>Quantum USB Cable</h2><p class='price'>$9.99</p>"
382388 "<input type='hidden' name='product_id' value='1'></div></main></body></html>" )
383- multibit .singleTimeWarnMessage = lambda message : self .fail ("hinted at a detail page: %s" % message )
384389
385- try :
386- multibit .hint ()
387- finally :
388- multibit .singleTimeWarnMessage = _WARN
390+ self .assertEqual (self ._hint (), [])
389391
390392 def test_switch_on_an_unsupported_backend_says_so (self ):
391393 # the bit arithmetic exists for five back-ends; asking for the switch on any other one has to
392394 # say why nothing happens instead of silently doing nothing
393395 set_dbms (DBMS .FIREBIRD )
394- warned = []
395- multibit .singleTimeWarnMessage = lambda message : warned .append (message )
396396
397- try :
398- multibit .hint ()
399- finally :
400- multibit .singleTimeWarnMessage = _WARN
397+ said = self ._hint ()
401398
402- self .assertEqual (len (warned ), 1 )
403- self .assertIn ("not supported" , warned [0 ])
399+ self .assertEqual (len (said ), 1 )
400+ self .assertIn ("not supported" , said [0 ])
404401
405402 def test_hint_stays_quiet_when_an_inband_channel_is_available (self ):
406403 # UNION or error-based beats any row channel, so nudging towards this one would be noise
407404 conf .multiBit = False
408405 kb .originalPage = "" .join ("<div class='item'><a href='/product.php?id=%d'>p</a></div>" % _ for _ in range (1 , 13 ))
409406 kb .injection .data [PAYLOAD .TECHNIQUE .UNION ] = {}
410- multibit .singleTimeWarnMessage = lambda message : self .fail ("hinted over an in-band channel: %s" % message )
411407
412- try :
413- multibit .hint ()
414- finally :
415- multibit .singleTimeWarnMessage = _WARN
408+ self .assertEqual (self ._hint (), [])
416409
417410if __name__ == "__main__" :
418411 unittest .main ()
0 commit comments