def test_update_group_add_user_already_in(mocker): with message(mocker, "group_user_already_in_group", user="******", group="apps"): user_group_update("apps", add=["bob"]) group_res = user_group_list()["groups"] assert group_res["apps"]["members"] == ["bob"]
def migrate_LDAP_db(): logger.info(m18n.n("migration_0011_update_LDAP_database")) from yunohost.utils.ldap import _get_ldap_interface ldap = _get_ldap_interface() ldap_map = read_yaml( '/usr/share/yunohost/yunohost-config/moulinette/ldap_scheme.yml') try: SetupGroupPermissions.remove_if_exists("ou=permission") SetupGroupPermissions.remove_if_exists('ou=groups') attr_dict = ldap_map['parents']['ou=permission'] ldap.add('ou=permission', attr_dict) attr_dict = ldap_map['parents']['ou=groups'] ldap.add('ou=groups', attr_dict) attr_dict = ldap_map['children']['cn=all_users,ou=groups'] ldap.add('cn=all_users,ou=groups', attr_dict) attr_dict = ldap_map['children']['cn=visitors,ou=groups'] ldap.add('cn=visitors,ou=groups', attr_dict) for rdn, attr_dict in ldap_map['depends_children'].items(): ldap.add(rdn, attr_dict) except Exception as e: raise YunohostError("migration_0011_LDAP_update_failed", error=e) logger.info(m18n.n("migration_0011_create_group")) # Create a group for each yunohost user user_list = ldap.search( 'ou=users,dc=yunohost,dc=org', '(&(objectclass=person)(!(uid=root))(!(uid=nobody)))', ['uid', 'uidNumber']) for user_info in user_list: username = user_info['uid'][0] ldap.update( 'uid=%s,ou=users' % username, { 'objectClass': [ 'mailAccount', 'inetOrgPerson', 'posixAccount', 'userPermissionYnh' ] }) user_group_create(username, gid=user_info['uidNumber'][0], primary_group=True, sync_perm=False) user_group_update(groupname='all_users', add=username, force=True, sync_perm=False)
def setup_function(function): clean_user_groups() global maindomain maindomain = _get_maindomain() user_create("alice", "Alice", "White", maindomain, "test123Ynh") user_create("bob", "Bob", "Snow", maindomain, "test123Ynh") user_create("jack", "Jack", "Black", maindomain, "test123Ynh") user_group_create("dev") user_group_create("apps") user_group_update("dev", add=["alice"]) user_group_update("apps", add=["bob"])
def test_update_group_add_user_that_doesnt_exist(mocker): with raiseYunohostError(mocker, "user_unknown"): user_group_update("dev", add=["doesnt_exist"]) assert "doesnt_exist" not in user_group_list()["groups"]["dev"]["members"]
def test_update_group_primary_manually(mocker): with raiseYunohostError(mocker, "group_cannot_edit_primary_group"): user_group_update("alice", remove=["alice"]) assert "alice" in user_group_list()["groups"]["alice"]["members"]
def test_update_group_that_doesnt_exist(mocker): with raiseYunohostError(mocker, "group_unknown"): user_group_update("doesnt_exist", add=["alice"])
def test_update_group_remove_user_not_already_in(mocker): with message(mocker, "group_user_not_in_group", user="******", group="apps"): user_group_update("apps", remove=["jack"]) group_res = user_group_list()["groups"] assert group_res["apps"]["members"] == ["bob"]
def test_update_group_remove_user(mocker): with message(mocker, "group_updated", group="apps"): user_group_update("apps", remove=["bob"]) group_res = user_group_list()["groups"] assert group_res["apps"]["members"] == []
def test_update_group_add_user(mocker): with message(mocker, "group_updated", group="dev"): user_group_update("dev", add=["bob"]) group_res = user_group_list()["groups"] assert set(group_res["dev"]["members"]) == set(["alice", "bob"])
def migrate_LDAP_db(): logger.info(m18n.n("migration_0011_update_LDAP_database")) from yunohost.utils.ldap import _get_ldap_interface ldap = _get_ldap_interface() ldap_map = read_yaml( "/usr/share/yunohost/yunohost-config/moulinette/ldap_scheme.yml" ) try: SetupGroupPermissions.remove_if_exists("ou=permission") SetupGroupPermissions.remove_if_exists("ou=groups") attr_dict = ldap_map["parents"]["ou=permission"] ldap.add("ou=permission", attr_dict) attr_dict = ldap_map["parents"]["ou=groups"] ldap.add("ou=groups", attr_dict) attr_dict = ldap_map["children"]["cn=all_users,ou=groups"] ldap.add("cn=all_users,ou=groups", attr_dict) attr_dict = ldap_map["children"]["cn=visitors,ou=groups"] ldap.add("cn=visitors,ou=groups", attr_dict) for rdn, attr_dict in ldap_map["depends_children"].items(): ldap.add(rdn, attr_dict) except Exception as e: raise YunohostError("migration_0011_LDAP_update_failed", error=e) logger.info(m18n.n("migration_0011_create_group")) # Create a group for each yunohost user user_list = ldap.search( "ou=users,dc=yunohost,dc=org", "(&(objectclass=person)(!(uid=root))(!(uid=nobody)))", ["uid", "uidNumber"], ) for user_info in user_list: username = user_info["uid"][0] ldap.update( "uid=%s,ou=users" % username, { "objectClass": [ "mailAccount", "inetOrgPerson", "posixAccount", "userPermissionYnh", ] }, ) user_group_create( username, gid=user_info["uidNumber"][0], primary_group=True, sync_perm=False, ) user_group_update( groupname="all_users", add=username, force=True, sync_perm=False )