mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-05-15 01:53:09 +00:00
Make matching login form credentials case-sensitive
The keys of the form.data dictionary are case-sensitive and therefore a KeyError was possible if the configured values are not identical to the input element name attributes.
This commit is contained in:
parent
7a6ef938cc
commit
8fc0dcc055
2 changed files with 4 additions and 6 deletions
|
|
@ -42,16 +42,14 @@ def search_form(content, cgiuser, cgipassword):
|
|||
CGI fields. If no form is found return None.
|
||||
"""
|
||||
soup = htmlsoup.make_soup(content)
|
||||
# The value of the name attribute is case-insensitive
|
||||
# https://www.w3.org/TR/html401/interact/forms.html#adef-name-INPUT
|
||||
cginames = {cgiuser.lower(), cgipassword.lower()}
|
||||
cginames = {cgiuser, cgipassword}
|
||||
for form_element in soup.find_all("form", action=True):
|
||||
form = Form(form_element["action"])
|
||||
for input_element in form_element.find_all("input",
|
||||
attrs={"name": True}):
|
||||
form.add_value(
|
||||
input_element["name"], input_element.attrs.get("value"))
|
||||
if cginames <= {x.lower() for x in form.data}:
|
||||
if cginames <= set(form.data):
|
||||
log.debug(LOG_CHECK, "Found form %s", form)
|
||||
return form
|
||||
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ class TestFormSearch(unittest.TestCase):
|
|||
|
||||
def test_search_form(self):
|
||||
form = loginformsearch.search_form(login_form,
|
||||
"USER_FIELD", "password_field")
|
||||
"User_Field", "Password_Field")
|
||||
self.assertIsNotNone(form)
|
||||
self.assertEqual(form.url, "/log_me_in")
|
||||
self.assertIn("User_Field", form.data)
|
||||
|
|
@ -51,5 +51,5 @@ class TestFormSearch(unittest.TestCase):
|
|||
|
||||
def test_search_form_none(self):
|
||||
form = loginformsearch.search_form(login_form,
|
||||
"nouser", "nopassword")
|
||||
"user_field", "password_field")
|
||||
self.assertIsNone(form)
|
||||
|
|
|
|||
Loading…
Reference in a new issue