From e2f7cec35373782817e161ec988922a577dd2da6 Mon Sep 17 00:00:00 2001 From: Roman Rakus Date: Mon, 14 Jan 2013 18:22:04 +0100 Subject: Account: tests Signed-off-by: Roman Rakus --- src/account/test/TestAccount.py | 100 +++++++++++++++++++++++++++++ src/account/test/TestGroup.py | 72 +++++++++++++++++++++ src/account/test/TestMemberOfGroup.py | 84 +++++++++++++++++++++++++ src/account/test/TestService.py | 114 ++++++++++++++++++++++++++++++++++ src/account/test/__init__.py | 0 src/account/test/common.py | 46 ++++++++++++++ src/account/test/localtest.sh | 1 + src/account/test/methods.py | 80 ++++++++++++++++++++++++ 8 files changed, 497 insertions(+) create mode 100644 src/account/test/TestAccount.py create mode 100644 src/account/test/TestGroup.py create mode 100644 src/account/test/TestMemberOfGroup.py create mode 100644 src/account/test/TestService.py create mode 100644 src/account/test/__init__.py create mode 100644 src/account/test/common.py create mode 100755 src/account/test/localtest.sh create mode 100644 src/account/test/methods.py (limited to 'src/account') diff --git a/src/account/test/TestAccount.py b/src/account/test/TestAccount.py new file mode 100644 index 0000000..7157b52 --- /dev/null +++ b/src/account/test/TestAccount.py @@ -0,0 +1,100 @@ +# -*- encoding: utf-8 -*- +# Copyright (C) 2012 Red Hat, Inc. All rights reserved. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# Authors: Roman Rakus 0) + # check if it provides key properties + for attr in ["CreationClassName", "Name", "SystemCreationClassName", + "SystemName"]: + self.assertIsNotNone(instances[0][attr]) + + # check if it provides other properties, which should be set + for attr in ["host", "UserID", "UserPassword", "UserPasswordEncoding"]: + self.assertIsNotNone(instances[0][attr]) + + def test_create_account(self): + """ + Test to create user account + """ + # make sure the account will not exist + clean_account(self.user_name) + computer_system = self.wbemconnection.ExecQuery('WQL', + 'select * from Linux_ComputerSystem')[0] + lams = self.wbemconnection.ExecQuery('WQL', + 'select * from LMI_AccountManagementService')[0] + self.wbemconnection.InvokeMethod("CreateAccount", lams.path, + Name=self.user_name, System=computer_system.path) + # The user now should be created, check it + subprocess.check_call(["id", self.user_name]) + # now delete that user + clean_account(self.user_name) + + def test_delete_account(self): + """ + Test to delete account + """ + # make sure the account will exist + create_account(self.user_name) + i = self.wbemconnection.ExecQuery('WQL', + 'select * from LMI_Account where Name = "%s"' % self.user_name)[0] + self.wbemconnection.DeleteInstance(i.path) + # check if it was really deleted + c = subprocess.Popen(["id", self.user_name]) + c.communicate() + self.assertEqual(c.returncode, 1) + clean_account(self.user_name) + + def test_modify_account(self): + """ + Test several modifications + """ + create_account(self.user_name) + i = self.wbemconnection.ExecQuery('WQL', + 'select * from LMI_Account where Name = "%s"' % self.user_name)[0] + # gecos + print i["ElementName"] + i["ElementName"] = "GECOS" + print i["ElementName"] + self.wbemconnection.ModifyInstance(i) + self.assertEqual(field_in_passwd(self.user_name, 4), "GECOS") + # login shell + i["LoginShell"] = "/modified" + self.wbemconnection.ModifyInstance(i) + self.assertEqual(field_in_passwd(self.user_name, 6), "/modified") + # password + i["UserPassword"][0] = '$6$9Ky8vI6f$ipRcdc7rgMrtDh.sWOaRSoBck2cLz4eUom8Eze.NaY2DoMmNimuFBrXpJjlPCjMoeFTYC.FdZwj488JZcohyw1' + self.wbemconnection.ModifyInstance(i) + self.assertEqual(field_in_shadow(self.user_name, 1), + '$6$9Ky8vI6f$ipRcdc7rgMrtDh.sWOaRSoBck2cLz4eUom8Eze.NaY2DoMmNimuFBrXpJjlPCjMoeFTYC.FdZwj488JZcohyw1') + clean_account(self.user_name) + diff --git a/src/account/test/TestGroup.py b/src/account/test/TestGroup.py new file mode 100644 index 0000000..2cf5228 --- /dev/null +++ b/src/account/test/TestGroup.py @@ -0,0 +1,72 @@ +# -*- encoding: utf-8 -*- +# Copyright (C) 2012 Red Hat, Inc. All rights reserved. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# Authors: Roman Rakus 0) + # check if it provides key properties + for attr in ["CreationClassName", "Name"]: + self.assertIsNotNone(instances[0][attr]) + + # check if it provides other properties, which should be set + for attr in ["ElementName", "InstanceID"]: + self.assertIsNotNone(instances[0][attr]) + + def test_create_group(self): + """ + Test to create group + """ + # make sure the group will not exist + clean_group(self.group_name) + computer_system = self.wbemconnection.ExecQuery('WQL', + 'select * from Linux_ComputerSystem')[0] + lams = self.wbemconnection.ExecQuery('WQL', + 'select * from LMI_AccountManagementService')[0] + self.wbemconnection.InvokeMethod("CreateGroup", lams.path, + Name=self.group_name, System=computer_system.path) + # The group now should be created, check it + self.assertEqual(field_in_group(self.group_name, 0), self.group_name) + # now delete that group + clean_group(self.group_name) + + def test_delete_group(self): + """ + Test to delete group + """ + # make sure the group will exist + create_group(self.group_name) + i = self.wbemconnection.ExecQuery('WQL', + 'select * from LMI_Group where Name = "%s"' % self.group_name)[0] + self.wbemconnection.DeleteInstance(i.path) + # check if it was really deleted + self.assertIsNone(field_in_group(self.group_name, 0)) + clean_group(self.group_name) + diff --git a/src/account/test/TestMemberOfGroup.py b/src/account/test/TestMemberOfGroup.py new file mode 100644 index 0000000..19071ef --- /dev/null +++ b/src/account/test/TestMemberOfGroup.py @@ -0,0 +1,84 @@ +# -*- encoding: utf-8 -*- +# Copyright (C) 2012 Red Hat, Inc. All rights reserved. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# Authors: Roman Rakus