File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed
examples/contrib/webscanner_helper Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change 11import json
22from unittest import mock
3-
3+ from html . parser import HTMLParser
44from examples .contrib .webscanner_helper .urlinjection import HTMLInjection
55from examples .contrib .webscanner_helper .urlinjection import InjectionGenerator
66from examples .contrib .webscanner_helper .urlinjection import logger
@@ -38,7 +38,20 @@ def test_inject_insert(self):
3838 f = tflow .tflow (resp = tutils .tresp ())
3939 assert "example.com" not in str (f .response .content )
4040 html_injection .inject (index , f )
41- assert "example.com" in str (f .response .content )
41+
42+ class ExampleComLinkParser (HTMLParser ):
43+ def __init__ (self ):
44+ super ().__init__ ()
45+ self .example_com_links = []
46+ def handle_starttag (self , tag , attrs ):
47+ for attr in attrs :
48+ if attr [0 ] in ('href' , 'src' ):
49+ if attr [1 ].startswith ("http" ) and "://example.com" in attr [1 ]:
50+ self .example_com_links .append (attr [1 ])
51+
52+ parser = ExampleComLinkParser ()
53+ parser .feed (f .response .text if hasattr (f .response , "text" ) else str (f .response .content ))
54+ assert any (url .startswith ("http://example.com" ) or url .startswith ("https://example.com" ) for url in parser .example_com_links )
4255
4356 def test_inject_insert_body (self ):
4457 html_injection = HTMLInjection (insert = True )
You can’t perform that action at this time.
0 commit comments