On 06/10/2013 01:13 PM, Tomas Babej wrote:
Hi,

Hardcoded values for range parameters such as base RID or range
size could be the reason the tests produced incorrect results,
as the ranges could get in conflict with already existing ranges
on the server.

Patch dynamically chooses ID and RID range space at the end of
all ranges already present on the server.

https://fedorahosted.org/freeipa/ticket/3662

Tomas

Patch altered to incorporate minor fixes for recent idrange objectclass changes.

Tomas
From b35b10f1356c9714776f16aadec7ffbe95e2f41e Mon Sep 17 00:00:00 2001
From: Tomas Babej <tba...@redhat.com>
Date: Mon, 10 Jun 2013 13:08:50 +0200
Subject: [PATCH] Remove hardcoded values from idrange plugin tests

Hardcoded values for range parameters such as base RID or range
size could be the reason the tests produced incorrect results,
as the ranges could get in conflict with already existing ranges
on the server.

Patch dynamically chooses ID and RID range space at the end of
all ranges already present on the server.

https://fedorahosted.org/freeipa/ticket/3662
---
 ipalib/plugins/idrange.py              |  2 +-
 tests/test_xmlrpc/test_range_plugin.py | 90 ++++++++++++++++++++++------------
 2 files changed, 60 insertions(+), 32 deletions(-)

diff --git a/ipalib/plugins/idrange.py b/ipalib/plugins/idrange.py
index abca492978d04c71b78a89df8e5c2d1d51c06398..54b835e244fb60ee212a9c00223d4294ff8f4363 100644
--- a/ipalib/plugins/idrange.py
+++ b/ipalib/plugins/idrange.py
@@ -224,7 +224,7 @@ class idrange(LDAPObject):
         if not any((options.get('pkey_only', False),
                     options.get('raw', False))):
             range_type = entry_attrs['iparangetype'][0]
-            entry_attrs['iparangetype'] = self.range_types.get(range_type, None)
+            entry_attrs['iparangetype'] = [self.range_types.get(range_type, None)]
 
         # Remove the objectclass
         if not keep_objectclass:
diff --git a/tests/test_xmlrpc/test_range_plugin.py b/tests/test_xmlrpc/test_range_plugin.py
index ce70433112b3216304356b520026d79be66543cf..f0f881ab914b8c8ff84737be607cd709cceee377 100644
--- a/tests/test_xmlrpc/test_range_plugin.py
+++ b/tests/test_xmlrpc/test_range_plugin.py
@@ -29,62 +29,86 @@ from ipapython.dn import *
 
 import ldap, ldap.sasl, ldap.modlist
 
+id_shift = 0
+rid_shift = 0
+
+for idrange in api.Command['idrange_find']()['result']:
+    size = int(idrange['ipaidrangesize'][0])
+    base_id = int(idrange['ipabaseid'][0])
+
+    id_end = base_id + size
+    rid_end = 0
+
+    if 'ipabaserid' in idrange:
+        base_rid = int(idrange['ipabaserid'][0])
+        rid_end = base_rid + size
+
+    if 'ipasecondarybaserid' in idrange:
+        secondary_base_rid = int(idrange['ipasecondarybaserid'][0])
+        rid_end = max(base_rid, secondary_base_rid) + size
+
+    if id_shift < id_end:
+        id_shift = id_end + 1000000
+
+    if rid_shift < rid_end:
+        rid_shift = rid_end + 1000000
+
 testrange1 = u'testrange1'
-testrange1_base_id = 900000
+testrange1_base_id = id_shift + 900000
 testrange1_size = 99999
-testrange1_base_rid = 10000
-testrange1_secondary_base_rid = 200000
+testrange1_base_rid = rid_shift + 10000
+testrange1_secondary_base_rid = rid_shift + 200000
 
 testrange2 = u'testrange2'
-testrange2_base_id = 100
+testrange2_base_id = id_shift + 100
 testrange2_size = 50
-testrange2_base_rid = 100
-testrange2_secondary_base_rid = 1000
+testrange2_base_rid = rid_shift + 100
+testrange2_secondary_base_rid = rid_shift + 1000
 
 testrange3 = u'testrange3'
-testrange3_base_id = 200
+testrange3_base_id = id_shift + 200
 testrange3_size = 50
-testrange3_base_rid = 70
-testrange3_secondary_base_rid = 1100
+testrange3_base_rid = rid_shift + 70
+testrange3_secondary_base_rid = rid_shift + 1100
 
 testrange4 = u'testrange4'
-testrange4_base_id = 300
+testrange4_base_id = id_shift + 300
 testrange4_size = 50
-testrange4_base_rid = 200
-testrange4_secondary_base_rid = 1030
+testrange4_base_rid = rid_shift + 200
+testrange4_secondary_base_rid = rid_shift + 1030
 
 testrange5 = u'testrange5'
-testrange5_base_id = 400
+testrange5_base_id = id_shift + 400
 testrange5_size = 50
-testrange5_base_rid = 1020
-testrange5_secondary_base_rid = 1200
+testrange5_base_rid = rid_shift + 1020
+testrange5_secondary_base_rid = rid_shift + 1200
 
 testrange6 = u'testrange6'
-testrange6_base_id = 130
+testrange6_base_id = id_shift + 130
 testrange6_size = 50
-testrange6_base_rid = 500
-testrange6_secondary_base_rid = 1300
+testrange6_base_rid = rid_shift + 500
+testrange6_secondary_base_rid = rid_shift + 1300
 
 testrange7 = u'testrange7'
-testrange7_base_id = 600
+testrange7_base_id = id_shift + 600
 testrange7_size = 50
-testrange7_base_rid = 600
-testrange7_secondary_base_rid = 649
+testrange7_base_rid = rid_shift + 600
+testrange7_secondary_base_rid = rid_shift + 649
 
 testrange8 = u'testrange8'
-testrange8_base_id = 700
+testrange8_base_id = id_shift + 700
 testrange8_size = 50
-testrange8_base_rid = 700
+testrange8_base_rid = rid_shift + 700
 
 testrange9 = u'testrange9'
-testrange9_base_id = 800
+testrange9_base_id = id_shift + 800
 testrange9_size = 50
-testrange9_base_rid = 800
+testrange9_base_rid = rid_shift + 800
 
 testrange10 = u'testrange10'
-testrange10_base_id = 900
+testrange10_base_id = id_shift + 900
 testrange10_size = 50
-testrange10_base_rid = 900
+testrange10_base_rid = rid_shift + 900
 
 testrange9_dn = "cn={name},cn=ranges,cn=etc,{basedn}".format(name=testrange9,
                                                       basedn=api.env.basedn)
@@ -95,6 +119,7 @@ testrange9_add = dict(
     ipaBaseRID="{base_rid}".format(base_rid=testrange9_base_rid),
     ipaIDRangeSize="{size}".format(size=testrange9_size),
     ipaNTTrustedDomainSID="S-1-5-21-259319770-2312917334-591429603",
+    ipaRangeType="ipa-ad-trust",
     )
 
 testrange10_dn = "cn={name},cn=ranges,cn=etc,{basedn}".format(name=testrange10,
@@ -106,6 +131,7 @@ testrange10_add = dict(
     ipaBaseRID="{base_rid}".format(base_rid=testrange10_base_rid),
     ipaIDRangeSize="{size}".format(size=testrange10_size),
     ipaNTTrustedDomainSID="S-1-5-21-2997650941-1802118864-3094776726",
+    ipaRangeType="ipa-ad-trust",
     )
 
 testtrust = u'testtrust'
@@ -123,9 +149,9 @@ testtrust_add = dict(
     )
 
 user1 = u'tuser1'
-user1_uid = 900000
+user1_uid = id_shift + 900000
 group1 = u'group1'
-group1_gid = 900100
+group1_gid = id_shift + 900100
 
 
 class test_range(Declarative):
@@ -295,7 +321,9 @@ class test_range(Declarative):
 
         dict(
             desc='Try to modify ID range %r to get out bounds object #1' % (testrange1),
-            command=('idrange_mod', [testrange1], dict(ipabaseid=90001)),
+            command=(
+                'idrange_mod', [testrange1], dict(ipabaseid=user1_uid + 1)
+            ),
             expected=errors.ValidationError(name='ipabaseid,ipaidrangesize',
                 error=u'range modification leaving objects with ID out of the'
                       u' defined range is not allowed'),
@@ -406,7 +434,7 @@ class test_range(Declarative):
         dict(
             desc='Try to modify ID range %r so that its rid ranges are overlapping themselves' % (testrange2),
             command=('idrange_mod', [testrange2],
-                      dict(ipabaserid=(testrange2_base_rid*10))),
+                      dict(ipabaserid=(testrange2_secondary_base_rid))),
             expected=errors.ValidationError(
                 name='ID Range setup', error='Primary RID range and secondary RID range cannot overlap'),
         ),
-- 
1.8.1.4

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to