1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# -*- encoding: utf-8 -*-
# Copyright (C) 2012-2013 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 <rrakus@redhat.com>
#
from common import AccountBase
from methods import *
from lmi.shell import LMIInstance
import subprocess
class TestAccount(AccountBase):
"""
Class for testing LMI_Account class
"""
CLASS_NAME = "LMI_Account"
def tearDown(self):
clean_account(self.user_name)
def test_account_properties(self):
"""
Account: Test if there are key and main properties in LMI_Account
"""
inst = self.cim_class.first_instance()
self.assertIsInstance(inst, LMIInstance)
# check if it provides key properties
for attr in ['CreationClassName', 'Name', 'SystemCreationClassName',
'SystemName']:
self.assertIsNotNone(inst.properties_dict()[attr])
# check if it provides other properties, which should be set
for attr in ['host', 'UserID', 'UserPassword', 'UserPasswordEncoding']:
self.assertIsNotNone(inst.properties_dict()[attr])
def test_create_account(self):
"""
Account: Test to create user account
"""
# make sure the account will not exist
clean_account(self.user_name)
lams = self.ns.LMI_AccountManagementService.first_instance()
self.assertIsInstance(lams, LMIInstance)
(retval, rparam, errorstr) = lams.CreateAccount({'Name': self.user_name,
'System': self.system_iname})
self.assertEqual(retval, 0)
# The user now should be created, check it
self.assertTrue(user_exists(self.user_name))
def test_delete_account(self):
"""
Account: Test to delete account
"""
# make sure the account will exist
create_account(self.user_name)
inst = self.cim_class.first_instance({"Name": self.user_name})
self.assertIsInstance(inst, LMIInstance)
r = inst.delete()
self.assertTrue(r)
# check if it was really deleted
self.assertFalse(user_exists(self.user_name))
def test_modify_account(self):
"""
Account: Test several modifications
"""
create_account(self.user_name)
inst = self.cim_class.first_instance({"Name": self.user_name})
self.assertIsInstance(inst, LMIInstance)
# gecos
inst.ElementName = "GECOS"
(retval, rparam, errorstr) = inst.push()
self.assertEqual(retval, 0)
self.assertEqual(field_in_passwd(self.user_name, 4), "GECOS")
# login shell
inst.LoginShell = "/modified"
(retval, rparam, errorstr) = inst.push()
self.assertEqual(retval, 0)
self.assertEqual(field_in_passwd(self.user_name, 6), "/modified")
# password
inst.UserPassword = ['$6$9Ky8vI6f$ipRcdc7rgMrtDh.sWOaRSoBck2cLz4eUom8Eze.NaY2DoMmNimuFBrXpJjlPCjMoeFTYC.FdZwj488JZcohyw1']
(retval, rparam, errorstr) = inst.push()
self.assertEqual(retval, 0)
self.assertEqual(field_in_shadow(self.user_name, 1),
'$6$9Ky8vI6f$ipRcdc7rgMrtDh.sWOaRSoBck2cLz4eUom8Eze.NaY2DoMmNimuFBrXpJjlPCjMoeFTYC.FdZwj488JZcohyw1')
|