Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AlekSIS-Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AlekSIS®
Official
AlekSIS-Core
Commits
c203ea6f
Verified
Commit
c203ea6f
authored
3 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
Add tests to ensure LDAP authentication for vanished accoutns fails
parent
8e7e86b7
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!847
Resolve "Login with local Django accounts and LDAP password changes are mutually exclusive"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
aleksis/core/tests/views/test_account.py
+44
-0
44 additions, 0 deletions
aleksis/core/tests/views/test_account.py
tox.ini
+1
-1
1 addition, 1 deletion
tox.ini
with
45 additions
and
1 deletion
aleksis/core/tests/views/test_account.py
+
44
−
0
View file @
c203ea6f
from
django.conf
import
settings
from
django.conf
import
settings
from
django.test
import
override_settings
from
django.urls
import
reverse
from
django.urls
import
reverse
import
ldap
import
pytest
import
pytest
from
django_auth_ldap.config
import
LDAPSearch
from
aleksis.core.models
import
UserAdditionalAttributes
pytestmark
=
pytest
.
mark
.
django_db
pytestmark
=
pytest
.
mark
.
django_db
LDAP_BASE
=
"
dc=example,dc=com
"
LDAP_SETTINGS
=
{
"
AUTH_LDAP_GLOBAL_OPTIONS
"
:
{
ldap
.
OPT_NETWORK_TIMEOUT
:
1
,
},
"
AUTH_LDAP_USER_SEARCH
"
:
LDAPSearch
(
LDAP_BASE
,
ldap
.
SCOPE_SUBTREE
),
}
def
test_index_not_logged_in
(
client
):
def
test_index_not_logged_in
(
client
):
response
=
client
.
get
(
"
/
"
)
response
=
client
.
get
(
"
/
"
)
...
@@ -40,3 +53,34 @@ def test_logout(client, django_user_model):
...
@@ -40,3 +53,34 @@ def test_logout(client, django_user_model):
assert
response
.
status_code
==
200
assert
response
.
status_code
==
200
assert
"
Please login to see this page.
"
in
response
.
content
.
decode
(
"
utf-8
"
)
assert
"
Please login to see this page.
"
in
response
.
content
.
decode
(
"
utf-8
"
)
@override_settings
(
AUTHENTICATION_BACKENDS
=
[
"
aleksis.core.util.ldap.LDAPBackend
"
,
"
django.contrib.auth.backends.ModelBackend
"
,
],
AUTH_LDAP_SERVER_URI
=
"
ldap://[100::0]
"
,
AUTH_LDAP_SET_USABLE_PASSWORD
=
True
,
**
LDAP_SETTINGS
)
def
test_login_ldap_fail_if_previously_ldap_authenticated
(
client
,
django_user_model
):
username
=
"
foo
"
password
=
"
bar
"
django_user_model
.
objects
.
create_user
(
username
=
username
,
password
=
password
)
# Logging in with a fresh account should success
res
=
client
.
login
(
username
=
username
,
password
=
password
)
assert
res
client
.
get
(
reverse
(
"
logout
"
),
follow
=
True
)
# Logging in with a previously LDAP-authenticated account should fail
UserAdditionalAttributes
.
set_user_attribute
(
username
,
"
ldap_authenticated
"
,
True
)
res
=
client
.
login
(
username
=
username
,
password
=
password
)
assert
not
res
# Explicitly noting account has not been used with LDAP should succeed
UserAdditionalAttributes
.
set_user_attribute
(
username
,
"
ldap_authenticated
"
,
False
)
res
=
client
.
login
(
username
=
username
,
password
=
password
)
assert
res
This diff is collapsed.
Click to expand it.
tox.ini
+
1
−
1
View file @
c203ea6f
...
@@ -9,7 +9,7 @@ whitelist_externals = poetry
...
@@ -9,7 +9,7 @@ whitelist_externals = poetry
skip_install
=
true
skip_install
=
true
envdir
=
{toxworkdir}/globalenv
envdir
=
{toxworkdir}/globalenv
commands_pre
=
commands_pre
=
poetry
install
poetry
install
-E
ldap
poetry
run
aleksis-admin
yarn
install
poetry
run
aleksis-admin
yarn
install
poetry
run
aleksis-admin
collectstatic
--no-input
poetry
run
aleksis-admin
collectstatic
--no-input
commands
=
commands
=
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment