8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek#
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek# SSSD integration test - operations on UNIX user and group database
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek#
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek# Copyright (c) 2016 Red Hat, Inc.
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek#
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek# This is free software; you can redistribute it and/or modify it
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek# under the terms of the GNU General Public License as published by
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek# the Free Software Foundation; version 2 only
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek#
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek# This program is distributed in the hope that it will be useful, but
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek# WITHOUT ANY WARRANTY; without even the implied warranty of
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek# General Public License for more details.
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek#
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek# You should have received a copy of the GNU General Public License
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek# along with this program. If not, see <http://www.gnu.org/licenses/>.
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek#
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozekimport pwd
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozekimport grp
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozekimport pytest
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozekimport ent
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozekfrom files_ops import passwd_ops_setup, group_ops_setup
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub HrozekUSER1 = dict(name='user1', passwd='*', uid=10001, gid=20001,
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek gecos='User for tests',
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek dir='/home/user1',
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek shell='/bin/bash')
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub HrozekGROUP1 = dict(name='group1',
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek gid=30001,
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek mem=['user1'])
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozekdef test_useradd(passwd_ops_setup):
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek with pytest.raises(KeyError):
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek pwd.getpwnam("user1")
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek passwd_ops_setup.useradd(**USER1)
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek ent.assert_passwd_by_name("user1", USER1)
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozekdef test_usermod(passwd_ops_setup):
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek passwd_ops_setup.useradd(**USER1)
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek ent.assert_passwd_by_name("user1", USER1)
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek USER1['shell'] = '/bin/zsh'
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek passwd_ops_setup.usermod(**USER1)
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek ent.assert_passwd_by_name("user1", USER1)
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozekdef test_userdel(passwd_ops_setup):
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek passwd_ops_setup.useradd(**USER1)
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek ent.assert_passwd_by_name("user1", USER1)
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek passwd_ops_setup.userdel("user1")
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek with pytest.raises(KeyError):
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek pwd.getpwnam("user1")
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozekdef test_groupadd(group_ops_setup):
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek with pytest.raises(KeyError):
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek grp.getgrnam("group1")
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek group_ops_setup.groupadd(**GROUP1)
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek ent.assert_group_by_name("group1", GROUP1)
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozekdef test_groupmod(group_ops_setup):
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek group_ops_setup.groupadd(**GROUP1)
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek ent.assert_group_by_name("group1", GROUP1)
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek modgroup = dict(GROUP1)
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek modgroup['mem'] = []
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek group_ops_setup.groupmod(old_name=GROUP1["name"], **modgroup)
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek ent.assert_group_by_name("group1", modgroup)
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozekdef test_groupdel(group_ops_setup):
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek group_ops_setup.groupadd(**GROUP1)
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek ent.assert_group_by_name("group1", GROUP1)
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek group_ops_setup.groupdel("group1")
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek with pytest.raises(KeyError):
8bdb8c0970dc9acb5b0a54dab0bae306ca964944Jakub Hrozek grp.getgrnam("group1")