summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2015-07-30 14:29:54 +1200
committerStefan Metzmacher <metze@samba.org>2015-09-03 09:11:35 +0200
commit43c6f8cf69b4d49824e601480ca51c105fa9932f (patch)
tree3682dd8af86f9fb515b0077b442d6ef6fd64138d
parentc9b80d79ec2d8f453dabac495b611fe9b04ba318 (diff)
downloadsamba-43c6f8cf69b4d49824e601480ca51c105fa9932f.tar.gz
python/tests: Add tests for integer overflow handling
This also documents an issue with our python bindings and lists, as changes to integers in a list of integers are not preserved BUG: https://bugzilla.samba.org/show_bug.cgi?id=11429 Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org> (cherry picked from commit 336d41155e94303d0e1fa0530874539339439fed)
-rw-r--r--python/samba/tests/dcerpc/integer.py203
-rw-r--r--selftest/knownfail5
-rw-r--r--selftest/tests.py1
3 files changed, 209 insertions, 0 deletions
diff --git a/python/samba/tests/dcerpc/integer.py b/python/samba/tests/dcerpc/integer.py
new file mode 100644
index 00000000000..1a392ee6bea
--- /dev/null
+++ b/python/samba/tests/dcerpc/integer.py
@@ -0,0 +1,203 @@
+# Unix SMB/CIFS implementation.
+# Copyright (C) Andrew Bartlett <abartlet@samba.org> 2015
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+"""Tests for integer handling in PIDL generated bindings samba.dcerpc.*"""
+
+from samba.dcerpc import server_id, misc, srvsvc
+import samba.tests
+
+class IntegerTests(samba.tests.TestCase):
+
+ def test_uint32_into_hyper(self):
+ s = server_id.server_id()
+ s.unique_id = server_id.NONCLUSTER_VNN
+ self.assertEquals(s.unique_id, 0xFFFFFFFFL)
+
+ def test_int_into_hyper(self):
+ s = server_id.server_id()
+ s.unique_id = 1
+
+ def test_negative_int_into_hyper(self):
+ s = server_id.server_id()
+ def assign():
+ s.unique_id = -1
+ self.assertRaises(OverflowError, assign)
+
+ def test_hyper_into_uint32(self):
+ s = server_id.server_id()
+ def assign():
+ s.vnn = server_id.SERVERID_UNIQUE_ID_NOT_TO_VERIFY
+ self.assertRaises(OverflowError, assign)
+
+ def test_hyper_into_int32(self):
+ s = srvsvc.NetRemoteTODInfo()
+ def assign():
+ s.timezone = server_id.SERVERID_UNIQUE_ID_NOT_TO_VERIFY
+ self.assertRaises(OverflowError, assign)
+
+ def test_int_into_int32(self):
+ s = srvsvc.NetRemoteTODInfo()
+ s.timezone = 5
+
+ def test_uint32_into_int32(self):
+ s = srvsvc.NetRemoteTODInfo()
+ def assign():
+ s.timezone = server_id.NONCLUSTER_VNN
+ self.assertRaises(OverflowError, assign)
+
+ def test_long_into_int32(self):
+ s = srvsvc.NetRemoteTODInfo()
+ s.timezone = 5L
+
+ def test_larger_long_int_into_int32(self):
+ s = srvsvc.NetRemoteTODInfo()
+ def assign():
+ s.timezone = 2147483648
+ self.assertRaises(OverflowError, assign)
+
+ def test_larger_int_into_int32(self):
+ s = srvsvc.NetRemoteTODInfo()
+ s.timezone = 2147483647
+
+ def test_float_into_int32(self):
+ s = srvsvc.NetRemoteTODInfo()
+ def assign():
+ s.timezone = 2.5
+ self.assertRaises(TypeError, assign)
+
+ def test_int_float_into_int32(self):
+ s = srvsvc.NetRemoteTODInfo()
+ def assign():
+ s.timezone = 2.0
+ self.assertRaises(TypeError, assign)
+
+ def test_negative_int_into_int32(self):
+ s = srvsvc.NetRemoteTODInfo()
+ s.timezone = -2147483648
+
+ def test_negative_into_uint32(self):
+ s = server_id.server_id()
+ def assign():
+ s.vnn = -1
+ self.assertRaises(OverflowError, assign)
+
+ def test_hyper_into_uint16(self):
+ g = misc.GUID()
+ def assign():
+ g.time_mid = server_id.SERVERID_UNIQUE_ID_NOT_TO_VERIFY
+ self.assertRaises(OverflowError, assign)
+
+ def test_int_into_uint16(self):
+ g = misc.GUID()
+ def assign():
+ g.time_mid = 200000
+ self.assertRaises(OverflowError, assign)
+
+ def test_negative_int_into_uint16(self):
+ g = misc.GUID()
+ def assign():
+ g.time_mid = -2
+ self.assertRaises(OverflowError, assign)
+
+ def test_int_into_uint16(self):
+ g = misc.GUID()
+ def assign():
+ g.time_mid = 200000
+ self.assertRaises(OverflowError, assign)
+
+ def test_negative_int_into_uint16(self):
+ g = misc.GUID()
+ def assign():
+ g.time_mid = -2
+ self.assertRaises(OverflowError, assign)
+
+ def test_enum_into_uint16(self):
+ g = misc.GUID()
+ g.time_mid = misc.SEC_CHAN_DOMAIN
+
+ def test_bitmap_into_uint16(self):
+ g = misc.GUID()
+ g.time_mid = misc.SV_TYPE_WFW
+ self.assertEqual(g.time_mid, misc.SV_TYPE_WFW)
+
+ def test_overflow_bitmap_into_uint16(self):
+ g = misc.GUID()
+ def assign():
+ g.time_mid = misc.SV_TYPE_LOCAL_LIST_ONLY
+ self.assertRaises(OverflowError, assign)
+
+ def test_overflow_bitmap_into_uint16_2(self):
+ g = misc.GUID()
+ def assign():
+ g.time_mid = misc.SV_TYPE_DOMAIN_ENUM
+ self.assertRaises(OverflowError, assign)
+
+ def test_int_list_over_list(self):
+ g = misc.GUID()
+ g.node = [5, 0, 5, 0, 7, 4]
+ self.assertEqual(g.node[0], 5)
+
+ def test_long_int_list_over_uint8_list(self):
+ g = misc.GUID()
+ g.node = [5L, 0, 5, 0, 7, 4]
+ self.assertEqual(g.node[0], 5)
+
+ def test_negative_list_over_uint8_list(self):
+ g = misc.GUID()
+ def assign():
+ g.node = [-1, 0, 5, 0, 7, 4]
+ self.assertRaises(OverflowError, assign)
+
+ def test_overflow_list_over_uint8_list(self):
+ g = misc.GUID()
+ def assign():
+ g.node = [256, 0, 5, 0, 7, 4]
+ self.assertRaises(OverflowError, assign)
+
+ def test_short_list_over_uint8_list(self):
+ g = misc.GUID()
+ def assign():
+ g.node = [5, 0, 5]
+ self.assertRaises(TypeError, assign)
+
+ def test_long_list_over_uint8_list(self):
+ g = misc.GUID()
+ def assign():
+ g.node = [5, 0, 5, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]
+ self.assertRaises(TypeError, assign)
+
+ # Due to our PIDL bindings generating a python List, modifications
+ # to a list of non-objects are not reflected in the C list
+ # (modifications objects in lists of objects work because the
+ # objects are modified), so changes essentially vanish and are not
+ # type checked either.
+ def test_assign_into_uint8_list(self):
+ g = misc.GUID()
+ g.node[1] = 5
+ self.assertEqual(g.node[1], 5)
+
+ def test_negative_into_uint8_list(self):
+ g = misc.GUID()
+ def assign():
+ g.node[1] = -1
+ self.assertRaises(OverflowError, assign)
+
+ def test_overflow_into_uint8_list(self):
+ g = misc.GUID()
+ def assign():
+ g.node[1] = 256
+ self.assertRaises(OverflowError, assign)
diff --git a/selftest/knownfail b/selftest/knownfail
index b7320ade8d1..447544ea07c 100644
--- a/selftest/knownfail
+++ b/selftest/knownfail
@@ -303,3 +303,8 @@
^samba4.ldap.match_rules.python.__main__.MatchRulesTests.test_u2_groups
^samba4.ldap.match_rules.python.__main__.MatchRulesTests.test_u3_groups
^samba4.ldap.match_rules.python.__main__.MatchRulesTests.test_u4_groups
+#
+# This fails because our python bindings create python Lists, not a type
+# we can watch for set methods on.
+#
+^samba.tests.dcerpc.integer.samba.tests.dcerpc.integer.IntegerTests.test_.*_into_uint8_list
diff --git a/selftest/tests.py b/selftest/tests.py
index ef2f6a4bc0b..872fbaf0094 100644
--- a/selftest/tests.py
+++ b/selftest/tests.py
@@ -51,6 +51,7 @@ planpythontestsuite("none", "samba.tests.auth")
planpythontestsuite("none", "samba.tests.getopt")
planpythontestsuite("none", "samba.tests.security")
planpythontestsuite("none", "samba.tests.dcerpc.misc")
+planpythontestsuite("none", "samba.tests.dcerpc.integer")
planpythontestsuite("none", "samba.tests.param")
planpythontestsuite("none", "samba.tests.upgrade")
planpythontestsuite("none", "samba.tests.core")