Debian Codegraph @

dirsrvtests/tests/suites/cos/cos_test.py

raw
1 # --- BEGIN COPYRIGHT BLOCK ---
2 # Copyright (C) 2019 Red Hat, Inc.
3 # All rights reserved.
4 #
5 # License: GPL (version 3 or any later version).
6 # See LICENSE for details.
7 # --- END COPYRIGHT BLOCK ---
8
9 import logging
10 import time
11 import pytest, os, ldap
12 from lib389.cos import CosClassicDefinition, CosClassicDefinitions, CosTemplate
13 from lib389._constants import DEFAULT_SUFFIX
14 from test389.topologies import topology_st as topo
15 from lib389.idm.role import FilteredRoles
16 from lib389.idm.nscontainer import nsContainer
17 from lib389.idm.user import UserAccount
18
19 logging.getLogger(__name__).setLevel(logging.INFO)
20 log = logging.getLogger(__name__)
21
22 pytestmark = pytest.mark.tier1
23 @pytest.fixture(scope="function")
24 def reset_ignore_vattr(topo, request):
25 default_ignore_vattr_value = topo.standalone.config.get_attr_val_utf8('nsslapd-ignore-virtual-attrs')
26 def fin():
27 topo.standalone.config.set('nsslapd-ignore-virtual-attrs', default_ignore_vattr_value)
28
29 request.addfinalizer(fin)
30
31 def test_positive(topo, reset_ignore_vattr):
32 """CoS positive tests
33
34 :id: a5a74235-597f-4fe8-8c38-826860927472
35 :setup: server
36 :steps:
37 1. Add filter role entry
38 2. Add ns container
39 3. Add cos template
40 4. Add CosClassic Definition
41 5. Cos entries should be added and searchable
42 6. employeeType attribute should be there in user entry as per the cos plugin property
43 :expectedresults:
44 1. Operation should success
45 2. Operation should success
46 3. Operation should success
47 4. Operation should success
48 5. Operation should success
49 6. Operation should success
50 """
51 # Adding ns filter role
52 roles = FilteredRoles(topo.standalone, DEFAULT_SUFFIX)
53 roles.create(properties={'cn': 'FILTERROLEENGROLE',
54 'nsRoleFilter': 'cn=eng*'})
55 # adding ns container
56 nsContainer(topo.standalone,'cn=cosClassicGenerateEmployeeTypeUsingnsroleTemplates,{}'.format(DEFAULT_SUFFIX))\
57 .create(properties={'cn': 'cosTemplates'})
58
59 # creating cos template
60 properties = {'employeeType': 'EngType',
61 'cn': '"cn=filterRoleEngRole,dc=example,dc=com",cn=cosClassicGenerateEmployeeTypeUsingnsroleTemplates,dc=example,dc=com'
62 }
63 CosTemplate(topo.standalone, 'cn="cn=filterRoleEngRole,dc=example,dc=com",cn=cosClassicGenerateEmployeeTypeUsingnsroleTemplates,{}'.format(DEFAULT_SUFFIX))\
64 .create(properties=properties)
65
66 # creating CosClassicDefinition
67 properties = {'cosTemplateDn': 'cn=cosClassicGenerateEmployeeTypeUsingnsroleTemplates,{}'.format(DEFAULT_SUFFIX),
68 'cosAttribute': 'employeeType',
69 'cosSpecifier': 'nsrole',
70 'cn': 'cosClassicGenerateEmployeeTypeUsingnsrole'}
71 CosClassicDefinition(topo.standalone,'cn=cosClassicGenerateEmployeeTypeUsingnsrole,{}'.format(DEFAULT_SUFFIX))\
72 .create(properties=properties)
73
74 # Adding User entry
75 properties = {
76 'uid': 'enguser1',
77 'cn': 'enguser1',
78 'sn': 'user',
79 'uidNumber': '1000',
80 'gidNumber': '2000',
81 'homeDirectory': '/home/' + 'enguser1'
82 }
83 user = UserAccount(topo.standalone, 'cn=enguser1,{}'.format(DEFAULT_SUFFIX))
84 user.create(properties=properties)
85
86 # Asserting Cos should be added and searchable
87 cosdef = CosClassicDefinitions(topo.standalone, DEFAULT_SUFFIX).get('cosClassicGenerateEmployeeTypeUsingnsrole')
88 assert cosdef.dn == 'cn=cosClassicGenerateEmployeeTypeUsingnsrole,dc=example,dc=com'
89 assert cosdef.get_attr_val_utf8('cn') == 'cosClassicGenerateEmployeeTypeUsingnsrole'
90
91 # CoS definition entry's cosSpecifier attribute specifies the employeeType attribute
92 assert user.present('employeeType')
93 cosdef.delete()
94
95 def test_vattr_on_cos_definition(topo, reset_ignore_vattr):
96 """Test nsslapd-ignore-virtual-attrs configuration attribute
97 The attribute is ON by default. If a cos definition is
98 added it is moved to OFF
99
100 :id: e7ef5254-386f-4362-bbb4-9409f3f51b08
101 :customerscenario: True
102 :setup: Standalone instance
103 :steps:
104 1. Check the attribute nsslapd-ignore-virtual-attrs is present in cn=config
105 2. Check the default value of attribute nsslapd-ignore-virtual-attrs should be ON
106 3. Create a cos definition for employeeType
107 4. Check the value of nsslapd-ignore-virtual-attrs should be OFF (with a delay for postop processing)
108 5. Check a message "slapi_vattrspi_regattr - Because employeeType,.." in error logs
109 6. Check after deleting cos definition value of attribute nsslapd-ignore-virtual-attrs is set back to ON
110 :expectedresults:
111 1. This should be successful
112 2. This should be successful
113 3. This should be successful
114 4. This should be successful
115 5. This should be successful
116 6. This should be successful
117 """
118
119 log.info("Check the attribute nsslapd-ignore-virtual-attrs is present in cn=config")
120 assert topo.standalone.config.present('nsslapd-ignore-virtual-attrs')
121
122 log.info("Check the default value of attribute nsslapd-ignore-virtual-attrs should be ON")
123 assert topo.standalone.config.get_attr_val_utf8('nsslapd-ignore-virtual-attrs') == "on"
124
125 # creating CosClassicDefinition
126 log.info("Create a cos definition")
127 properties = {'cosTemplateDn': 'cn=cosClassicGenerateEmployeeTypeUsingnsroleTemplates,{}'.format(DEFAULT_SUFFIX),
128 'cosAttribute': 'employeeType',
129 'cosSpecifier': 'nsrole',
130 'cn': 'cosClassicGenerateEmployeeTypeUsingnsrole'}
131 cosdef = CosClassicDefinition(topo.standalone,'cn=cosClassicGenerateEmployeeTypeUsingnsrole,{}'.format(DEFAULT_SUFFIX))\
132 .create(properties=properties)
133
134 log.info("Check the default value of attribute nsslapd-ignore-virtual-attrs should be OFF")
135 time.sleep(2)
136 assert topo.standalone.config.present('nsslapd-ignore-virtual-attrs', 'off')
137
138 topo.standalone.stop()
139 assert topo.standalone.searchErrorsLog("slapi_vattrspi_regattr - Because employeeType is a new registered virtual attribute , nsslapd-ignore-virtual-attrs was set to \'off\'")
140 topo.standalone.start()
141 log.info("Delete a cos definition")
142 cosdef.delete()
143 log.info("Check the default value of attribute nsslapd-ignore-virtual-attrs is back to ON")
144 topo.standalone.restart()
145 assert topo.standalone.config.get_attr_val_utf8('nsslapd-ignore-virtual-attrs') == "on"
146
147 if __name__ == "__main__":
148 CURRENT_FILE = os.path.realpath(__file__)
149 pytest.main("-s -v %s" % CURRENT_FILE)