[Kimchi-devel] [PATCHv7 4/4] Update test model for authentication and authorization

lvroyce at linux.vnet.ibm.com lvroyce at linux.vnet.ibm.com
Thu Nov 20 06:45:43 UTC 2014


From: Royce Lv <lvroyce at linux.vnet.ibm.com>

As test model includes test against pam user/group listing,
using pam authentication instead of fake authentication.
Also change test cases which used fake user/group update
to use pam user validation and update.

Signed-off-by: Royce Lv <lvroyce at linux.vnet.ibm.com>
---
 src/kimchi/mockmodel.py     | 4 ++++
 tests/test_authorization.py | 3 ++-
 tests/test_model.py         | 3 ++-
 tests/utils.py              | 3 ++-
 4 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py
index 9089ef6..fa93fab 100644
--- a/src/kimchi/mockmodel.py
+++ b/src/kimchi/mockmodel.py
@@ -33,6 +33,8 @@ from kimchi.model.host import DeviceModel
 from kimchi.model.model import Model
 from kimchi.model.storagevolumes import StorageVolumesModel
 from kimchi.model.templates import LibvirtVMTemplate
+from kimchi.model.users import PAMUsersModel
+from kimchi.model.groups import PAMGroupsModel
 from kimchi.objectstore import ObjectStore
 from kimchi.utils import add_task, get_next_clone_name
 from kimchi.vmtemplate import VMTemplate
@@ -73,6 +75,8 @@ class MockModel(Model):
         libvirt.virDomain.updateDeviceFlags = MockModel.updateDeviceFlags
         libvirt.virStorageVol.resize = MockModel.volResize
         libvirt.virStorageVol.wipePattern = MockModel.volWipePattern
+        PAMUsersModel.auth_type = 'fake'
+        PAMGroupsModel.auth_type = 'fake'
 
         super(MockModel, self).__init__('test:///default', objstore_loc)
         self.objstore_loc = objstore_loc
diff --git a/tests/test_authorization.py b/tests/test_authorization.py
index a8a94fe..4fcc496 100644
--- a/tests/test_authorization.py
+++ b/tests/test_authorization.py
@@ -131,7 +131,8 @@ class AuthorizationTests(unittest.TestCase):
 
         model.vms_create({'name': u'test-groupa',
                           'template': '/templates/test'})
-        model.vm_update(u'test-groupa', {'groups': ['wheel']})
+        a_group = model.groups_get_list()[0]
+        model.vm_update(u'test-groupa', {'groups': [a_group]})
 
         resp = self.request('/vms', '{}', 'GET')
         self.assertEquals(200, resp.status)
diff --git a/tests/test_model.py b/tests/test_model.py
index c68b01f..0b91edc 100644
--- a/tests/test_model.py
+++ b/tests/test_model.py
@@ -38,7 +38,7 @@ import iso_gen
 import kimchi.objectstore
 import utils
 from kimchi import netinfo
-from kimchi.config import paths
+from kimchi.config import config, paths
 from kimchi.exception import ImageFormatError, InvalidOperation
 from kimchi.exception import InvalidParameter, NotFoundError, OperationFailed
 from kimchi.iscsi import TargetClient
@@ -934,6 +934,7 @@ class ModelTests(unittest.TestCase):
                               'new-test', params)
 
     def test_vm_edit(self):
+        config.set("authentication", "method", "pam")
         inst = model.Model(None,
                            objstore_loc=self.tmp_store)
 
diff --git a/tests/utils.py b/tests/utils.py
index f846d48..c692041 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -20,6 +20,7 @@
 
 import base64
 import cherrypy
+import grp
 import httplib
 import json
 import os
@@ -181,7 +182,7 @@ class FakeUser(User):
         self.user[USER_ROLES] = dict.fromkeys(tabs, 'user')
 
     def get_groups(self):
-        return ['groupA', 'groupB', 'wheel']
+        return sorted([group.gr_name for group in grp.getgrall()])[0:3]
 
     def get_roles(self):
         if self.sudo:
-- 
1.8.3.2




More information about the Kimchi-devel mailing list