Skip to content

Commit

Permalink
Tweak 2fa form def in forms.py. Fix tests (#1804)
Browse files Browse the repository at this point in the history
  • Loading branch information
amazingphilippe authored Apr 16, 2024
1 parent 61ff00e commit b077235
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/main/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class TwoFactorCode(StringField):
]

def __call__(self, **kwargs):
return super().__call__(type="tel", pattern="[0-9]*", **kwargs)
return super().__call__(type="text", inputmode="numeric", autocomplete="one-time-code", pattern="[0-9]*", **kwargs)


class ForgivingIntegerField(StringField):
Expand Down
1 change: 0 additions & 1 deletion app/templates/views/two-factor-email.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ <h1 class="heading-large">{{ _(title) }}</h1>
form.two_factor_code,
width='form-control-5em',
autofocus=True,
autocomplete='one-time-code'
) }}
{{ page_footer(
continue,
Expand Down
8 changes: 6 additions & 2 deletions tests/app/main/views/test_two_factor.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ def test_should_render_sms_two_factor_page(
page = BeautifulSoup(response.data.decode("utf-8"), "html.parser")
assert page.select_one("main p").text.strip() == ("We’ve sent you a text message with a security code.")
assert page.select_one("label").text.strip("Text message code")
assert page.select_one("input")["type"] == "tel"
assert page.select_one("input")["type"] == "text"
assert page.select_one("input")["autocomplete"] == "one-time-code"
assert page.select_one("input")["inputmode"] == "numeric"
assert page.select_one("input")["pattern"] == "[0-9]*"


Expand Down Expand Up @@ -80,7 +82,9 @@ def test_should_render_email_two_factor_page(
page = BeautifulSoup(response.data.decode("utf-8"), "html.parser")
assert page.select_one("main p").text.strip() == ("We’ve sent you an email with a security code.")
assert page.select_one("label").text.strip("Text message code")
assert page.select_one("input")["type"] == "tel"
assert page.select_one("input")["type"] == "text"
assert page.select_one("input")["autocomplete"] == "one-time-code"
assert page.select_one("input")["inputmode"] == "numeric"
assert page.select_one("input")["pattern"] == "[0-9]*"


Expand Down

0 comments on commit b077235

Please sign in to comment.