mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-01-11 00:31:56 -06:00
UI tests for "ID Range": check range name and base ID duplication
https://pagure.io/freeipa/issue/7709 Reviewed-By: Mohammad Rizwan Yusuf <myusuf@redhat.com> Reviewed-By: Petr Vobornik <pvoborni@redhat.com>
This commit is contained in:
parent
3eac88a433
commit
e55d17d609
@ -21,16 +21,19 @@
|
||||
Range tasks
|
||||
"""
|
||||
|
||||
import uuid
|
||||
|
||||
from ipatests.test_webui.ui_driver import UI_driver
|
||||
|
||||
LOCAL_ID_RANGE = 'ipa-local'
|
||||
TRUSTED_ID_RANGE = 'ipa-ad-trust'
|
||||
|
||||
|
||||
class range_tasks(UI_driver):
|
||||
|
||||
def get_shifts(self, idranges=None):
|
||||
|
||||
if not idranges:
|
||||
result = self.execute_api_from_ui('idrange_find', [], {})
|
||||
idranges = result['result']['result']
|
||||
def get_shifts(self):
|
||||
result = self.execute_api_from_ui('idrange_find', [], {})
|
||||
idranges = result['result']['result']
|
||||
|
||||
max_id = 0
|
||||
max_rid = 0
|
||||
@ -67,50 +70,101 @@ class range_tasks(UI_driver):
|
||||
domain = trusts[0]['cn']
|
||||
return domain
|
||||
|
||||
def get_data(self, pkey, size=50, add_data=None):
|
||||
def get_data(self, pkey=None, form_data=None, **kwargs):
|
||||
|
||||
if not add_data:
|
||||
add_data = self.get_add_data(pkey, size=size)
|
||||
if not pkey:
|
||||
pkey = 'itest-range-{}'.format(uuid.uuid4().hex[:8])
|
||||
|
||||
if form_data:
|
||||
form_data.cn = pkey
|
||||
else:
|
||||
form_data = self.get_add_form_data(pkey, **kwargs)
|
||||
|
||||
data = {
|
||||
'pkey': pkey,
|
||||
'add': add_data,
|
||||
'add': form_data.serialize(),
|
||||
'mod': [
|
||||
('textbox', 'ipaidrangesize', str(size + 1)),
|
||||
('textbox', 'ipaidrangesize', str(form_data.size + 1)),
|
||||
],
|
||||
}
|
||||
return data
|
||||
|
||||
def get_add_data(self, pkey, range_type='ipa-local', size=50, shift=100, domain=None):
|
||||
def get_add_form_data(self, pkey, range_type=LOCAL_ID_RANGE, size=50,
|
||||
domain=None, **kwargs):
|
||||
"""
|
||||
Generate RangeAddFormData instance with initial data based on existing
|
||||
ID ranges.
|
||||
"""
|
||||
|
||||
base_id = self.max_id + shift
|
||||
shift = 100
|
||||
base_id = kwargs.get('base_id', self.max_id + shift)
|
||||
self.max_id = base_id + size
|
||||
|
||||
base_rid = self.max_rid + shift
|
||||
self.max_rid = base_rid + size
|
||||
|
||||
add = [
|
||||
('textbox', 'cn', pkey),
|
||||
('textbox', 'ipabaseid', str(base_id)),
|
||||
('textbox', 'ipaidrangesize', str(size)),
|
||||
('textbox', 'ipabaserid', str(base_rid)),
|
||||
('radio', 'iparangetype', range_type),
|
||||
('callback', self.check_range_type_mod, range_type)
|
||||
]
|
||||
|
||||
secondary_base_rid = None
|
||||
if not domain:
|
||||
base_rid = self.max_rid + shift
|
||||
self.max_rid = base_rid + size
|
||||
add.append(('textbox', 'ipasecondarybaserid', str(base_rid)))
|
||||
if domain:
|
||||
add.append(('textbox', 'ipanttrusteddomainname', domain))
|
||||
secondary_base_rid = base_rid + size + shift
|
||||
self.max_rid = secondary_base_rid + size
|
||||
|
||||
return add
|
||||
return RangeAddFormData(
|
||||
pkey, base_id, base_rid,
|
||||
secondary_base_rid=secondary_base_rid,
|
||||
range_type=range_type,
|
||||
size=size,
|
||||
domain=domain,
|
||||
callback=self.check_range_type_mod
|
||||
)
|
||||
|
||||
def check_range_type_mod(self, range_type):
|
||||
if range_type == 'ipa-local':
|
||||
if range_type == LOCAL_ID_RANGE:
|
||||
self.assert_disabled("[name=ipanttrusteddomainname]")
|
||||
self.assert_disabled("[name=ipasecondarybaserid]", negative=True)
|
||||
elif range_type == 'ipa-ad-trust':
|
||||
self.assert_disabled("[name=ipanttrusteddomainname]", negative=True)
|
||||
elif range_type == TRUSTED_ID_RANGE:
|
||||
self.assert_disabled("[name=ipanttrusteddomainname]",
|
||||
negative=True)
|
||||
self.assert_disabled("[name=ipasecondarybaserid]")
|
||||
|
||||
|
||||
class RangeAddFormData(object):
|
||||
"""
|
||||
Class for ID Range form data storing and serializing.
|
||||
|
||||
Warning: Only for data transformation.
|
||||
Do not put any additional logic here!
|
||||
"""
|
||||
|
||||
def __init__(self, cn, base_id, base_rid, secondary_base_rid=None,
|
||||
range_type=LOCAL_ID_RANGE, size=50, domain=None,
|
||||
callback=None):
|
||||
self.cn = cn
|
||||
self.base_id = base_id
|
||||
self.base_rid = base_rid
|
||||
self.secondary_base_rid = secondary_base_rid
|
||||
self.range_type = range_type
|
||||
self.size = size
|
||||
self.domain = domain
|
||||
self.callback = callback
|
||||
|
||||
def serialize(self):
|
||||
|
||||
serialized = [
|
||||
('textbox', 'cn', self.cn),
|
||||
('textbox', 'ipabaseid', str(self.base_id)),
|
||||
('textbox', 'ipaidrangesize', str(self.size)),
|
||||
('textbox', 'ipabaserid', str(self.base_rid)),
|
||||
('radio', 'iparangetype', self.range_type),
|
||||
('callback', self.callback, self.range_type),
|
||||
]
|
||||
|
||||
if self.domain:
|
||||
serialized.append(('textbox',
|
||||
'ipanttrusteddomainname',
|
||||
self.domain))
|
||||
else:
|
||||
serialized.append(('textbox',
|
||||
'ipasecondarybaserid',
|
||||
str(self.secondary_base_rid)))
|
||||
|
||||
return serialized
|
||||
|
@ -21,10 +21,15 @@
|
||||
Range tests
|
||||
"""
|
||||
|
||||
import pytest
|
||||
|
||||
import ipatests.test_webui.test_trust as trust_mod
|
||||
from ipatests.test_webui.ui_driver import screenshot
|
||||
from ipatests.test_webui.task_range import range_tasks
|
||||
import pytest
|
||||
from ipatests.test_webui.task_range import (
|
||||
range_tasks,
|
||||
LOCAL_ID_RANGE,
|
||||
TRUSTED_ID_RANGE,
|
||||
)
|
||||
|
||||
ENTITY = 'idrange'
|
||||
PKEY = 'itest-range'
|
||||
@ -33,13 +38,20 @@ PKEY = 'itest-range'
|
||||
@pytest.mark.tier1
|
||||
class test_range(range_tasks):
|
||||
|
||||
def setup(self):
|
||||
super(test_range, self).setup()
|
||||
self.init_app()
|
||||
self.get_shifts()
|
||||
|
||||
self.range_types = [LOCAL_ID_RANGE]
|
||||
if self.has_trusts():
|
||||
self.range_types.append(TRUSTED_ID_RANGE)
|
||||
|
||||
@screenshot
|
||||
def test_crud(self):
|
||||
"""
|
||||
Basic CRUD: range
|
||||
"""
|
||||
self.init_app()
|
||||
self.get_shifts()
|
||||
self.basic_crud(ENTITY, self.get_data(PKEY), mod=False)
|
||||
|
||||
@screenshot
|
||||
@ -48,16 +60,11 @@ class test_range(range_tasks):
|
||||
Test mod operating in a new range
|
||||
"""
|
||||
|
||||
self.init_app()
|
||||
self.navigate_to_entity(ENTITY)
|
||||
self.get_shifts()
|
||||
|
||||
add = self.get_add_data(PKEY)
|
||||
data = self.get_data(PKEY, add_data=add)
|
||||
data = self.get_data(PKEY)
|
||||
|
||||
self.add_record(ENTITY, data, facet='search', navigate=False,
|
||||
facet_btn='add', dialog_name='add',
|
||||
dialog_btn='add')
|
||||
self.add_record(ENTITY, data, navigate=False)
|
||||
self.navigate_to_record(PKEY)
|
||||
|
||||
# changes idrange and tries to save it
|
||||
@ -88,15 +95,12 @@ class test_range(range_tasks):
|
||||
- 'ipa-ad-winsync' and 'ipa-ipa-trust' and are not supported yet
|
||||
https://fedorahosted.org/freeipa/ticket/4323
|
||||
"""
|
||||
self.init_app()
|
||||
self.get_shifts()
|
||||
|
||||
pkey_local = 'itest-local'
|
||||
pkey_ad = 'itest-ad'
|
||||
column = 'iparangetype'
|
||||
|
||||
add = self.get_add_data(pkey_local)
|
||||
data = self.get_data(pkey_local, add_data=add)
|
||||
data = self.get_data(pkey_local)
|
||||
self.add_record(ENTITY, data)
|
||||
self.assert_record_value('local domain range', pkey_local, column)
|
||||
|
||||
@ -111,13 +115,64 @@ class test_range(range_tasks):
|
||||
|
||||
self.navigate_to_entity(ENTITY)
|
||||
|
||||
add = self.get_add_data(pkey_ad, range_type='ipa-ad-trust', domain=domain)
|
||||
data = self.get_data(pkey_ad, add_data=add)
|
||||
data = self.get_data(pkey_ad, range_type=TRUSTED_ID_RANGE,
|
||||
domain=domain)
|
||||
self.add_record(ENTITY, data, navigate=False)
|
||||
self.assert_record_value('Active Directory domain range', pkey_ad, column)
|
||||
self.assert_record_value('Active Directory domain range', pkey_ad,
|
||||
column)
|
||||
|
||||
self.delete(trust_mod.ENTITY, [trust_data])
|
||||
self.navigate_to_entity(ENTITY)
|
||||
self.delete_record(pkey_ad)
|
||||
|
||||
self.delete_record(pkey_local)
|
||||
|
||||
@screenshot
|
||||
def test_add_range_with_existing_name(self):
|
||||
"""
|
||||
Test creating ID Range with existing range name
|
||||
"""
|
||||
self.navigate_to_entity(ENTITY)
|
||||
|
||||
for range_type in self.range_types:
|
||||
pkey = 'itest-range-{}'.format(range_type)
|
||||
data = self.get_data(pkey, range_type=range_type)
|
||||
|
||||
self.add_record(ENTITY, data, navigate=False)
|
||||
self.add_record(ENTITY, data, navigate=False, negative=True,
|
||||
pre_delete=False)
|
||||
|
||||
dialog = self.get_last_error_dialog()
|
||||
|
||||
try:
|
||||
assert ('range with name "{}" already exists'.format(pkey)
|
||||
in dialog.text)
|
||||
finally:
|
||||
self.delete_record(pkey)
|
||||
|
||||
@screenshot
|
||||
def test_add_range_with_existing_base_id(self):
|
||||
"""
|
||||
Test creating ID Range with existing base ID
|
||||
"""
|
||||
self.navigate_to_entity(ENTITY)
|
||||
|
||||
for range_type in self.range_types:
|
||||
pkey = 'itest-range-original'
|
||||
form_data = self.get_add_form_data(pkey)
|
||||
data = self.get_data(pkey, form_data=form_data)
|
||||
form_data.range_type = range_type
|
||||
duplicated_data = self.get_data(form_data=form_data)
|
||||
|
||||
self.add_record(ENTITY, data, navigate=False)
|
||||
self.add_record(ENTITY, duplicated_data, navigate=False,
|
||||
negative=True, pre_delete=False)
|
||||
|
||||
dialog = self.get_last_error_dialog()
|
||||
|
||||
try:
|
||||
assert ('Constraint violation: '
|
||||
'New base range overlaps with existing base range.'
|
||||
in dialog.text)
|
||||
finally:
|
||||
self.delete_record(pkey)
|
||||
|
@ -127,9 +127,9 @@ class test_trust(trust_tasks):
|
||||
r_tasks.driver = self.driver
|
||||
r_tasks.config = self.config
|
||||
r_tasks.get_shifts()
|
||||
range_add = r_tasks.get_add_data('')
|
||||
base_id = range_add[2][2]
|
||||
range_size = range_add[3][2]
|
||||
range_form = r_tasks.get_add_form_data('')
|
||||
base_id = range_form.base_id
|
||||
range_size = range_form.size
|
||||
range_pkey = self.get_range_name()
|
||||
column = 'iparangetype'
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user