Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F9312428
test_middlewares.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
test_middlewares.py
View Options
# Copyright (C) 2020 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU Affero General Public License version 3, or any later version
# See top-level LICENSE file for more information
import
pytest
from
django.core.cache
import
cache
from
django.test
import
modify_settings
from
swh.web.common.utils
import
reverse
from
swh.web.tests.utils
import
check_html_get_response
@pytest.mark.django_db
@modify_settings
(
MIDDLEWARE
=
{
"remove"
:
[
"swh.web.auth.middlewares.OIDCSessionExpiredMiddleware"
]}
)
def
test_oidc_session_expired_middleware_disabled
(
client
,
keycloak_mock
):
# authenticate user
client
.
login
(
code
=
""
,
code_verifier
=
""
,
redirect_uri
=
""
)
keycloak_mock
.
authorization_code
.
assert_called
()
url
=
reverse
(
"swh-web-homepage"
)
# visit url first to get user from response
response
=
check_html_get_response
(
client
,
url
,
status_code
=
200
)
# simulate OIDC session expiration
cache
.
delete
(
f
"oidc_user_{response.wsgi_request.user.id}"
)
# no redirection when session has expired
check_html_get_response
(
client
,
url
,
status_code
=
200
)
@pytest.mark.django_db
def
test_oidc_session_expired_middleware_enabled
(
client
,
keycloak_mock
):
# authenticate user
client
.
login
(
code
=
""
,
code_verifier
=
""
,
redirect_uri
=
""
)
keycloak_mock
.
authorization_code
.
assert_called
()
url
=
reverse
(
"swh-web-homepage"
)
# visit url first to get user from response
response
=
check_html_get_response
(
client
,
url
,
status_code
=
200
)
# simulate OIDC session expiration
cache
.
delete
(
f
"oidc_user_{response.wsgi_request.user.id}"
)
# should redirect to logout page
resp
=
check_html_get_response
(
client
,
url
,
status_code
=
302
)
silent_refresh_url
=
reverse
(
"logout"
,
query_params
=
{
"next_path"
:
url
,
"remote_user"
:
1
}
)
assert
resp
[
"location"
]
==
silent_refresh_url
File Metadata
Details
Attached
Mime Type
text/x-python
Expires
Thu, Jul 3, 10:52 AM (1 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3452096
Attached To
rDWAPPS Web applications
Event Timeline
Log In to Comment