Skip to content

Commit

Permalink
fix: kick_missing_sessin handles missing cookies
Browse files Browse the repository at this point in the history
  • Loading branch information
smotornyuk committed Sep 9, 2024
1 parent b2b69f2 commit 36f6f83
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
7 changes: 6 additions & 1 deletion ckanext/drupal_idp/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,20 @@ def identify(self):
log.debug("Skip static route")
return

kick_missing = tk.check_ckan_version("2.10") and config.kick_missing_session()
cookie_sid = tk.request.cookies.get(utils.session_cookie_name())
if not cookie_sid:
log.debug("No session cookie found")
if kick_missing:
tk.logout_user()
return

return

sid = utils.decode_sid(cookie_sid)
uid = utils.sid_into_uid(sid)
if not uid:
if tk.check_ckan_version("2.10") and config.kick_missing_session():
if kick_missing:
tk.logout_user()
return

Expand Down
2 changes: 1 addition & 1 deletion ckanext/drupal_idp/tests/logic/test_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import ckanext.drupal_idp.utils as utils


@pytest.mark.usefixtures("with_plugins", "clean_db")
class TestUserShow:
def test_id_is_mandatory(self):
with pytest.raises(tk.ValidationError):
Expand All @@ -15,7 +16,6 @@ def test_no_user_raises_an_error(self):
with pytest.raises(tk.ObjectNotFound):
call_action('drupal_idp_user_show', id=10)

@pytest.mark.usefixtures("clean_db")
def test_no_user_raises_an_error(self, details_data):
details = utils.Details(**details_data)
userdict = utils.get_or_create_from_details(details)
Expand Down
3 changes: 2 additions & 1 deletion ckanext/drupal_idp/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,15 @@ def test_user_created(self, details_data):
assert user.plugin_extras["drupal_idp"] == details_data


@pytest.mark.usefixtures("clean_db")
@pytest.mark.usefixtures("with_plugins", "clean_db")
class TestGetOrCreation:

def test_default_native_id(self, details_data):
details = utils.Details(**details_data)
userdict = utils.get_or_create_from_details(details)
assert userdict["id"] != details_data["id"]

@pytest.mark.xfail
@pytest.mark.ckan_config(config.CONFIG_SAME_ID, "true")
def test_same_id(self, details_data):
details = utils.Details(**details_data)
Expand Down
4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ profile = "black"
[tool.pytest.ini_options]
addopts = "--ckan-ini test.ini"
filterwarnings = [
"ignore::sqlalchemy.exc.SADeprecationWarning",
"ignore::sqlalchemy.exc.SAWarning",
"ignore::DeprecationWarning",
# "ignore::DeprecationWarning",
]

[tool.pyright]
Expand Down

0 comments on commit 36f6f83

Please sign in to comment.