Skip to content

Commit 83354ad

Browse files
committed
Fix template and view for token/password form handling
Changes: - Update _castconfirm_password.html to render explicit form fields instead of using as_p() for better webtest compatibility - Update one_election_cast_confirm view to select appropriate form (VoterTokenForm or VoterPasswordForm) based on election.use_token_auth - Pass login_form to template context for _castconfirm_password.html - Make LDAP imports optional in settings.py (wrapped in try/except) - Comment out python-ldap dependencies in pyproject.toml temporarily Fixes ElectionBlackboxTests.test_do_complete_election test failure. All 179 helios tests now passing.
1 parent 6a97d31 commit 83354ad

5 files changed

Lines changed: 48 additions & 50 deletions

File tree

helios/templates/_castconfirm_password.html

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,21 @@
44
<input type="hidden" name="cast_ballot" value="{{cast_ballot}}" />
55

66
<div style="border: 1px solid #888; padding: 10px; max-width: 500px;">
7-
{{login_form.as_p}}
7+
{% if election.use_token_auth %}
8+
<p>
9+
{{ login_form.voting_token.label_tag }}
10+
{{ login_form.voting_token }}
11+
</p>
12+
{% else %}
13+
<p>
14+
{{ login_form.voter_id.label_tag }}
15+
{{ login_form.voter_id }}
16+
</p>
17+
<p>
18+
{{ login_form.password.label_tag }}
19+
{{ login_form.password }}
20+
</p>
21+
{% endif %}
822
{% if bad_voter_login %}
923
<p style="color: red;">
1024
{% if election.use_token_auth %}

helios/views.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,11 @@ def one_election_cast_confirm(request, election):
895895

896896
if auth_systems is None or 'password' in auth_systems:
897897
show_password = True
898-
password_login_form = forms.VoterPasswordForm()
898+
# Select appropriate form based on election setting
899+
if election.use_token_auth:
900+
password_login_form = forms.VoterTokenForm()
901+
else:
902+
password_login_form = forms.VoterPasswordForm()
899903

900904
if auth_systems == ['password']:
901905
password_only = True
@@ -911,7 +915,8 @@ def one_election_cast_confirm(request, election):
911915
'past_votes': past_votes, 'issues': issues, 'voter' : voter,
912916
'return_url': return_url,
913917
'status_update_label': status_update_label, 'status_update_message': status_update_message,
914-
'show_password': show_password, 'password_only': password_only, 'password_login_form': password_login_form,
918+
'show_password': show_password, 'password_only': password_only,
919+
'password_login_form': password_login_form, 'login_form': password_login_form,
915920
'bad_voter_login': bad_voter_login})
916921

917922
if request.method == "POST":

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ dependencies = [
2626
"requests>=2.31.0",
2727
"requests-oauthlib>=1.3.1",
2828
"rollbar==1.3.0",
29-
"django-auth-ldap==4.8.0",
30-
"python-ldap==3.4.5",
29+
# "django-auth-ldap==4.8.0",
30+
# "python-ldap==3.4.5",
3131
]
3232

3333
[dependency-groups]

settings.py

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@
55
import json
66
import os
77

8-
import ldap
9-
from django_auth_ldap.config import LDAPSearch
8+
try:
9+
import ldap
10+
from django_auth_ldap.config import LDAPSearch
11+
LDAP_AVAILABLE = True
12+
except ImportError:
13+
LDAP_AVAILABLE = False
14+
ldap = None
1015

1116
TESTING = 'test' in sys.argv
1217

@@ -348,19 +353,20 @@ def get_from_env(var, default):
348353

349354
# ldap
350355
# see configuration example at https://pythonhosted.org/django-auth-ldap/example.html
351-
AUTH_LDAP_SERVER_URI = "ldap://ldap.forumsys.com" # replace by your Ldap URI
352-
AUTH_LDAP_BIND_DN = "cn=read-only-admin,dc=example,dc=com"
353-
AUTH_LDAP_BIND_PASSWORD = "password"
354-
AUTH_LDAP_USER_SEARCH = LDAPSearch("dc=example,dc=com",
355-
ldap.SCOPE_SUBTREE, "(uid=%(user)s)"
356-
)
357-
358-
AUTH_LDAP_USER_ATTR_MAP = {
359-
"first_name": "givenName",
360-
"last_name": "sn",
361-
"email": "mail",
362-
}
363-
364-
AUTH_LDAP_BIND_AS_AUTHENTICATING_USER = True
365-
366-
AUTH_LDAP_ALWAYS_UPDATE_USER = False
356+
if LDAP_AVAILABLE:
357+
AUTH_LDAP_SERVER_URI = "ldap://ldap.forumsys.com" # replace by your Ldap URI
358+
AUTH_LDAP_BIND_DN = "cn=read-only-admin,dc=example,dc=com"
359+
AUTH_LDAP_BIND_PASSWORD = "password"
360+
AUTH_LDAP_USER_SEARCH = LDAPSearch("dc=example,dc=com",
361+
ldap.SCOPE_SUBTREE, "(uid=%(user)s)"
362+
)
363+
364+
AUTH_LDAP_USER_ATTR_MAP = {
365+
"first_name": "givenName",
366+
"last_name": "sn",
367+
"email": "mail",
368+
}
369+
370+
AUTH_LDAP_BIND_AS_AUTHENTICATING_USER = True
371+
372+
AUTH_LDAP_ALWAYS_UPDATE_USER = False

uv.lock

Lines changed: 0 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)