def test_managed_global_internal(monkeypatch): # this test uses the internal mechanics of the user endpoint monkeypatch.setattr( "cmk.gui.watolib.global_settings.rulebased_notifications_enabled", lambda: True) edit_users({ "user": { "attributes": { "ui_theme": None, "ui_sidebar_position": None, "nav_hide_icons_title": None, "icons_per_item": None, "show_mode": None, "start_url": None, "force_authuser": False, "enforce_pw_change": False, "alias": "User Name", "locked": False, "pager": "", "roles": [], "contactgroups": [], "customer": None, # None represents global internally "email": "", "fallback_contact": False, "disable_notifications": {}, }, "is_new_user": True, } }) user_internal = _load_user("user") user_endpoint_attrs = complement_customer( _internal_to_api_format(user_internal)) assert user_endpoint_attrs["customer"] == "global"
def serialize_password(ident, details): return constructors.domain_object( domain_type="password", identifier=ident, title=details["title"], members={ "title": constructors.object_property( name="title", value=details["title"], prop_format="string", base=constructors.object_href("password", ident), ) }, extensions={ k: v for k, v in complement_customer(details).items() if k in ( "comment", "docu_url", "password", "owned_by", "shared_with", "customer", ) }, )
def serve_user(user_id): response = Response() user_attributes_internal = _load_user(user_id) user_attributes = _internal_to_api_format(user_attributes_internal) response.set_data(json.dumps(serialize_user(user_id, complement_customer(user_attributes)))) response.set_content_type("application/json") response.headers.add("ETag", constructors.etag_of_dict(user_attributes).to_header()) return response
def _serve_password(ident, password_details): response = Response() response.set_data( json.dumps( serialize_password(ident, complement_customer(password_details)))) response.set_content_type("application/json") response.headers.add( "ETag", constructors.etag_of_dict(password_details).to_header()) return response
def list_users(params): """Show all users""" users = [] for user_id, attrs in userdb.load_users(False).items(): user_attributes = _internal_to_api_format(attrs) users.append( serialize_user(user_id, complement_customer(user_attributes))) return constructors.serve_json( constructors.collection_object(domain_type="user_config", value=users))
def test_managed_idle_internal(wsgi_app, with_automation_user, monkeypatch): # this test uses the internal mechanics of the user endpoint monkeypatch.setattr( "cmk.gui.watolib.global_settings.rulebased_notifications_enabled", lambda: True) username, secret = with_automation_user wsgi_app.set_authorization(('Bearer', username + " " + secret)) edit_users({ 'user': { 'attributes': { 'ui_theme': None, 'ui_sidebar_position': None, 'nav_hide_icons_title': None, 'icons_per_item': None, 'show_mode': None, 'start_url': None, 'force_authuser': False, 'enforce_pw_change': False, 'alias': 'User Name', 'locked': False, 'pager': '', 'roles': [], 'contactgroups': [], 'customer': None, # None represents global internally 'email': '', 'fallback_contact': False, 'disable_notifications': {} }, 'is_new_user': True } }) user_internal = _load_user("user") user_endpoint_attrs = complement_customer( _internal_to_api_format(user_internal)) assert "idle_timeout" not in _load_user(username) assert user_endpoint_attrs["idle_timeout"] == {"option": "global"}
def _load_internal_attributes(username): return complement_customer(_internal_attributes(_load_user(username)))