| 1 |
# --- BEGIN COPYRIGHT BLOCK --- |
| 2 |
# Copyright (C) 2016 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 |
''' |
| 10 |
Created on Nov 27th, 2018 |
| 11 |
|
| 12 |
@author: tbordaz |
| 13 |
''' |
| 14 |
import logging |
| 15 |
import subprocess |
| 16 |
import pytest |
| 17 |
from lib389 import Entry |
| 18 |
from lib389.utils import * |
| 19 |
from lib389.plugins import * |
| 20 |
from lib389._constants import * |
| 21 |
from test389.topologies import topology_st as topo |
| 22 |
|
| 23 |
pytestmark = pytest.mark.tier1 |
| 24 |
|
| 25 |
def add_user(server, uid, testbase, locality=None, tel=None, title=None): |
| 26 |
dn = 'uid=%s,%s' % (uid, testbase) |
| 27 |
log.fatal('Adding user (%s): ' % dn) |
| 28 |
server.add_s(Entry((dn, {'objectclass': ['top', 'person', 'organizationalPerson', 'inetOrgPerson'], |
| 29 |
'cn': 'user_%s' % uid, |
| 30 |
'sn': 'user_%s' % uid, |
| 31 |
'uid': uid, |
| 32 |
'l': locality, |
| 33 |
'title': title, |
| 34 |
'telephoneNumber': tel, |
| 35 |
'description': 'description real'}))) |
| 36 |
|
| 37 |
def test_cos_operational_default(topo): |
| 38 |
"""operational-default cosAttribute should not overwrite an existing value |
| 39 |
|
| 40 |
:id: 12fadff9-e14a-4c64-a3ee-51152cb8fcfb |
| 41 |
:setup: Standalone Instance |
| 42 |
:steps: |
| 43 |
1. Create a user entry with attribute 'l' and 'telephonenumber' (real attribute with real value) |
| 44 |
2. Create cos that defines 'l' as operational-default (virt. attr. with value != real value) |
| 45 |
3. Create cos that defines 'telephone' as default (virt. attr. with value != real value) |
| 46 |
4. Check that telephone is retrieved with real value |
| 47 |
5. Check that 'l' is retrieved with real value |
| 48 |
:expectedresults: |
| 49 |
1. should succeed |
| 50 |
2. should succeed |
| 51 |
3. should succeed |
| 52 |
""" |
| 53 |
|
| 54 |
REAL = 'real' |
| 55 |
VIRTUAL = 'virtual' |
| 56 |
TEL_REAL = '1234 is %s' % REAL |
| 57 |
TEL_VIRT = '4321 is %s' % VIRTUAL |
| 58 |
|
| 59 |
LOC_REAL = 'here is %s' % REAL |
| 60 |
LOC_VIRT = 'there is %s' % VIRTUAL |
| 61 |
|
| 62 |
TITLE_REAL = 'title is %s' % REAL |
| 63 |
|
| 64 |
inst = topo[0] |
| 65 |
|
| 66 |
PEOPLE = 'ou=people,%s' % SUFFIX |
| 67 |
add_user(inst, 'user_0', PEOPLE, locality=LOC_REAL, tel=TEL_REAL, title=TITLE_REAL) |
| 68 |
|
| 69 |
# locality cos operational-default |
| 70 |
LOC_COS_TEMPLATE = "cn=locality_template,%s" % PEOPLE |
| 71 |
LOC_COS_DEFINITION = "cn=locality_definition,%s" % PEOPLE |
| 72 |
inst.add_s(Entry((LOC_COS_TEMPLATE, { |
| 73 |
'objectclass': ['top', 'extensibleObject', 'costemplate', |
| 74 |
'ldapsubentry'], |
| 75 |
'l': LOC_VIRT}))) |
| 76 |
|
| 77 |
inst.add_s(Entry((LOC_COS_DEFINITION, { |
| 78 |
'objectclass': ['top', 'LdapSubEntry', 'cosSuperDefinition', |
| 79 |
'cosPointerDefinition'], |
| 80 |
'cosTemplateDn': LOC_COS_TEMPLATE, |
| 81 |
'cosAttribute': 'l operational-default'}))) |
| 82 |
|
| 83 |
# telephone cos default |
| 84 |
TEL_COS_TEMPLATE = "cn=telephone_template,%s" % PEOPLE |
| 85 |
TEL_COS_DEFINITION = "cn=telephone_definition,%s" % PEOPLE |
| 86 |
inst.add_s(Entry((TEL_COS_TEMPLATE, { |
| 87 |
'objectclass': ['top', 'extensibleObject', 'costemplate', |
| 88 |
'ldapsubentry'], |
| 89 |
'telephonenumber': TEL_VIRT}))) |
| 90 |
|
| 91 |
inst.add_s(Entry((TEL_COS_DEFINITION, { |
| 92 |
'objectclass': ['top', 'LdapSubEntry', 'cosSuperDefinition', |
| 93 |
'cosPointerDefinition'], |
| 94 |
'cosTemplateDn': TEL_COS_TEMPLATE, |
| 95 |
'cosAttribute': 'telephonenumber default'}))) |
| 96 |
|
| 97 |
# seeAlso cos operational |
| 98 |
SEEALSO_VIRT = "dc=%s,dc=example,dc=com" % VIRTUAL |
| 99 |
SEEALSO_COS_TEMPLATE = "cn=seealso_template,%s" % PEOPLE |
| 100 |
SEEALSO_COS_DEFINITION = "cn=seealso_definition,%s" % PEOPLE |
| 101 |
inst.add_s(Entry((SEEALSO_COS_TEMPLATE, { |
| 102 |
'objectclass': ['top', 'extensibleObject', 'costemplate', |
| 103 |
'ldapsubentry'], |
| 104 |
'seealso': SEEALSO_VIRT}))) |
| 105 |
|
| 106 |
inst.add_s(Entry((SEEALSO_COS_DEFINITION, { |
| 107 |
'objectclass': ['top', 'LdapSubEntry', 'cosSuperDefinition', |
| 108 |
'cosPointerDefinition'], |
| 109 |
'cosTemplateDn': SEEALSO_COS_TEMPLATE, |
| 110 |
'cosAttribute': 'seealso operational'}))) |
| 111 |
|
| 112 |
# description cos override |
| 113 |
DESC_VIRT = "desc is %s" % VIRTUAL |
| 114 |
DESC_COS_TEMPLATE = "cn=desc_template,%s" % PEOPLE |
| 115 |
DESC_COS_DEFINITION = "cn=desc_definition,%s" % PEOPLE |
| 116 |
inst.add_s(Entry((DESC_COS_TEMPLATE, { |
| 117 |
'objectclass': ['top', 'extensibleObject', 'costemplate', |
| 118 |
'ldapsubentry'], |
| 119 |
'description': DESC_VIRT}))) |
| 120 |
|
| 121 |
inst.add_s(Entry((DESC_COS_DEFINITION, { |
| 122 |
'objectclass': ['top', 'LdapSubEntry', 'cosSuperDefinition', |
| 123 |
'cosPointerDefinition'], |
| 124 |
'cosTemplateDn': DESC_COS_TEMPLATE, |
| 125 |
'cosAttribute': 'description override'}))) |
| 126 |
|
| 127 |
# title cos override |
| 128 |
TITLE_VIRT = [] |
| 129 |
for i in range(2): |
| 130 |
TITLE_VIRT.append("title is %s %d" % (VIRTUAL, i)) |
| 131 |
TITLE_COS_TEMPLATE = "cn=title_template,%s" % PEOPLE |
| 132 |
TITLE_COS_DEFINITION = "cn=title_definition,%s" % PEOPLE |
| 133 |
inst.add_s(Entry((TITLE_COS_TEMPLATE, { |
| 134 |
'objectclass': ['top', 'extensibleObject', 'costemplate', |
| 135 |
'ldapsubentry'], |
| 136 |
'title': TITLE_VIRT}))) |
| 137 |
|
| 138 |
inst.add_s(Entry((TITLE_COS_DEFINITION, { |
| 139 |
'objectclass': ['top', 'LdapSubEntry', 'cosSuperDefinition', |
| 140 |
'cosPointerDefinition'], |
| 141 |
'cosTemplateDn': TITLE_COS_TEMPLATE, |
| 142 |
'cosAttribute': 'title merge-schemes'}))) |
| 143 |
|
| 144 |
# note that the search requests both attributes (it is required for operational*) |
| 145 |
ents = inst.search_s(SUFFIX, ldap.SCOPE_SUBTREE, "uid=user_0", ["telephonenumber", "l"]) |
| 146 |
assert len(ents) == 1 |
| 147 |
ent = ents[0] |
| 148 |
|
| 149 |
# Check telephonenumber (specifier default) with real value => real |
| 150 |
assert ent.hasAttr('telephonenumber') |
| 151 |
value = ent.getValue('telephonenumber') |
| 152 |
log.info('Returned telephonenumber (exp. real): %s' % value) |
| 153 |
log.info('Returned telephonenumber: %d' % value.find(REAL.encode())) |
| 154 |
assert value.find(REAL.encode()) != -1 |
| 155 |
|
| 156 |
# Check 'locality' (specifier operational-default) with real value => real |
| 157 |
assert ent.hasAttr('l') |
| 158 |
value = ent.getValue('l') |
| 159 |
log.info('Returned l (exp. real): %s ' % value) |
| 160 |
log.info('Returned l: %d' % value.find(REAL.encode())) |
| 161 |
assert value.find(REAL.encode()) != -1 |
| 162 |
|
| 163 |
# Check 'seealso' (specifier operational) without real value => virtual |
| 164 |
assert not ent.hasAttr('seealso') |
| 165 |
ents = inst.search_s(SUFFIX, ldap.SCOPE_SUBTREE, "uid=user_0", ["seealso"]) |
| 166 |
assert len(ents) == 1 |
| 167 |
ent = ents[0] |
| 168 |
value = ent.getValue('seealso') |
| 169 |
log.info('Returned seealso (exp. virtual): %s' % value) |
| 170 |
log.info('Returned seealso: %d' % value.find(VIRTUAL.encode())) |
| 171 |
assert value.find(VIRTUAL.encode()) != -1 |
| 172 |
|
| 173 |
# Check 'description' (specifier override) with real value => virtual |
| 174 |
assert not ent.hasAttr('description') |
| 175 |
ents = inst.search_s(SUFFIX, ldap.SCOPE_SUBTREE, "uid=user_0") |
| 176 |
assert len(ents) == 1 |
| 177 |
ent = ents[0] |
| 178 |
value = ent.getValue('description') |
| 179 |
log.info('Returned description (exp. virtual): %s' % value) |
| 180 |
log.info('Returned description: %d' % value.find(VIRTUAL.encode())) |
| 181 |
assert value.find(VIRTUAL.encode()) != -1 |
| 182 |
|
| 183 |
# Check 'title' (specifier merge-schemes) with real value => real value returned |
| 184 |
ents = inst.search_s(SUFFIX, ldap.SCOPE_SUBTREE, "uid=user_0") |
| 185 |
assert len(ents) == 1 |
| 186 |
ent = ents[0] |
| 187 |
found_real = False |
| 188 |
found_virtual = False |
| 189 |
for value in ent.getValues('title'): |
| 190 |
log.info('Returned title (exp. real): %s' % value) |
| 191 |
if value.find(VIRTUAL.encode()) != -1: |
| 192 |
found_virtual = True |
| 193 |
if value.find(REAL.encode()) != -1: |
| 194 |
found_real = True |
| 195 |
assert not found_virtual |
| 196 |
assert found_real |
| 197 |
|
| 198 |
# Check 'title ((specifier merge-schemes) without real value => real value returned |
| 199 |
ents = inst.search_s(SUFFIX, ldap.SCOPE_SUBTREE, "uid=user_0") |
| 200 |
assert len(ents) == 1 |
| 201 |
inst.modify_s(ents[0].dn,[(ldap.MOD_DELETE, 'title', None)]) |
| 202 |
|
| 203 |
inst.restart() |
| 204 |
ents = inst.search_s(SUFFIX, ldap.SCOPE_SUBTREE, "uid=user_0") |
| 205 |
assert len(ents) == 1 |
| 206 |
ent = ents[0] |
| 207 |
found_real = False |
| 208 |
found_virtual = False |
| 209 |
count = 0 |
| 210 |
for value in ent.getValues('title'): |
| 211 |
log.info('Returned title(exp. virt): %s' % value) |
| 212 |
count = count + 1 |
| 213 |
if value.find(VIRTUAL.encode()) != -1: |
| 214 |
found_virtual = True |
| 215 |
if value.find(REAL.encode()) != -1: |
| 216 |
found_real = True |
| 217 |
assert not found_real |
| 218 |
assert found_virtual |
| 219 |
assert count == 2 |