def test_create_group(mocker): with message(mocker, "group_created", group="adminsys"): user_group_create("adminsys") group_res = user_group_list()["groups"] assert "adminsys" in group_res assert "members" in group_res["adminsys"].keys() assert group_res["adminsys"]["members"] == []
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_create_group_already_exists(mocker): # Check groups already exist (regular groups) with raiseYunohostError(mocker, "group_already_exist"): user_group_create("dev")
def test_create_group_all_users(mocker): # Check groups already exist with special group "all_users" with raiseYunohostError(mocker, "group_already_exist"): user_group_create("all_users")
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 )