def test_user_created(self, details_data): assert model.User.get(details_data["name"]) is None details = utils.Details(**details_data) utils.get_or_create_from_details(details) user = model.User.get(details_data["name"]) assert user.name == details_data["name"] assert user.plugin_extras["drupal_idp"] == details_data
def test_user_sync(self, details_data, monkeypatch, ckan_config): details = utils.Details(**details_data) userdict = utils.get_or_create_from_details(details) user = model.User.get(userdict["id"]) user.email = "hello@world" user.name = "hello" model.Session.commit() userdict = utils.get_or_create_from_details(details) assert userdict["name"] != details_data["name"] assert userdict["name"] == "hello" user = model.User.get(userdict["id"]) assert user.email != details_data["email"] assert user.email == "hello@world" utils.synchronize(userdict, details) userdict = utils.get_or_create_from_details(details) assert userdict["name"] == details_data["name"] user = model.User.get(userdict["id"]) assert user.email == details_data["email"] assert (model.Session.query( model.User).filter_by(name="hello").count() == 0) assert (model.Session.query( model.User).filter_by(name=details_data["name"]).count() == 1)
def test_plugin_extras_not_erased(self, details_data): details = utils.Details(**details_data) userdict = utils.get_or_create_from_details(details) user = model.User.get(userdict["id"]) user.plugin_extras = {"test": {"key": "value"}} utils.synchronize(userdict, details, force=True) user = model.User.get(userdict["id"]) assert "drupal_idp" in user.plugin_extras assert "test" in user.plugin_extras
def identify(self): """This does drupal authorization. The drupal session contains the drupal id of the logged in user. We need to convert this to represent the ckan user.""" static = { ("static", "index"), ("webassets", "index"), } if tk.asbool(tk.config.get( CONFIG_SKIP_STATIC, DEFAULT_SKIP_STATIC)) and tk.get_endpoint() in static: log.debug("Skip static route") return cookie_sid = tk.request.cookies.get(utils.session_cookie_name()) if not cookie_sid: log.debug("No session cookie found") return sid = utils.decode_sid(cookie_sid) details = utils.get_user_details(sid) if not details: log.debug("No user details for SID %s", sid) return try: user = utils.get_or_create_from_details(details) except tk.ValidationError as e: log.error(f"Cannot create user {details.name}<{details.email}>:" f" {e.error_summary}") return if utils.is_synchronization_enabled(): force = tk.asbool( tk.config.get(CONFIG_FOCE_SYNC, DEFAULT_FORCE_SYNC)) try: user = utils.synchronize(user, details, force) except tk.ValidationError as e: log.error( f"Cannot synchronize user details {details.name}<{details.email}>:" f" {e.error_summary}") return tk.c.user = user["name"]
def test_same_id(self, details_data): details = utils.Details(**details_data) userdict = utils.get_or_create_from_details(details) assert userdict["id"] == str(details_data["id"])
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"]
def test_no_user_raises_an_error(self, details_data): details = utils.Details(**details_data) userdict = utils.get_or_create_from_details(details) user = call_action('drupal_idp_user_show', id=details.id) assert user["id"] == userdict["id"]