From: Gary Lockyer Date: Wed, 14 Jun 2017 19:57:23 +0000 (+1200) Subject: Tests lsa.String: add String constructor, str and repr X-Git-Tag: tevent-0.9.32~31 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4cc979aba71d5480b0db2dd421f0ccdc6893e693;p=thirdparty%2Fsamba.git Tests lsa.String: add String constructor, str and repr Tests for the String constructor, str and repr methods added to the samba.dcerpc.lsa.String python object Signed-off-by: Gary Lockyer Reviewed-by: Garming Sam Reviewed-by: Andrew Bartlett --- diff --git a/python/samba/tests/lsa_string.py b/python/samba/tests/lsa_string.py new file mode 100644 index 00000000000..130f8807a21 --- /dev/null +++ b/python/samba/tests/lsa_string.py @@ -0,0 +1,79 @@ +# Tests for lsa.String helpers in source4/librpc/ndr/py_lsa.c +# +# Copyright (C) Catalyst IT Ltd. 2017 +# +# 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 . +# + +from samba.tests import TestCase +from samba.dcerpc import lsa +from samba.ndr import ndr_pack, ndr_unpack +""" +Tests for the C helper functions in source4/librpc/ndr/py_lsa.c +for samba.dcerpc.lsa.String +""" + +class LsaStringTests(TestCase): + + def test_default_constructor(self): + s = lsa.String() + self.assertEqual(None, s.string) + self.assertEqual(0, s.size) + self.assertEqual(0, s.length) + + def test_string_constructor(self): + CONTENT = "The content string" + s = lsa.String(CONTENT) + self.assertEqual(CONTENT, s.string) + + # These should be zero, are set by ndr_pack and ndr_unpack + self.assertEqual(0, s.size) + self.assertEqual(0, s.length) + + def test_string_constructor(self): + CONTENT = "The content string" + s = lsa.String(CONTENT) + self.assertEqual(CONTENT, s.string) + + # These should be zero + self.assertEqual(0, s.size) + self.assertEqual(0, s.length) + + packed = ndr_pack(s) + unpacked = ndr_unpack(lsa.String, packed) + + # Original object should be unchanged + self.assertEqual(0, s.size) + self.assertEqual(0, s.length) + + # But they should be correct in the unpacked object + self.assertEqual(36, unpacked.size) + self.assertEqual(36, unpacked.length) + + def test_repr(self): + # test an empty string + self.assertEqual("lsaString(None)", repr(lsa.String())) + # and one with contents + self.assertEqual("lsaString('Hello world')", + repr(lsa.String("Hello world"))) + + def test_to_string(self): + # test an empty string + self.assertEqual("", str(lsa.String())) + # and one with contents + self.assertEqual("Hello world", + str(lsa.String("Hello world"))) + + + diff --git a/selftest/knownfail.d/lsa_string b/selftest/knownfail.d/lsa_string new file mode 100644 index 00000000000..10726b4b5e6 --- /dev/null +++ b/selftest/knownfail.d/lsa_string @@ -0,0 +1,5 @@ +# Tests for String constructor on lsa.String +# Currently failing as the constructor has not been implemented. +^samba.tests.lsa_string.samba.tests.lsa_string.LsaStringTests.test_repr\(ad_dc_ntvfs:local\) +^samba.tests.lsa_string.samba.tests.lsa_string.LsaStringTests.test_string_constructor\(ad_dc_ntvfs:local\) +^samba.tests.lsa_string.samba.tests.lsa_string.LsaStringTests.test_to_string\(ad_dc_ntvfs:local\) diff --git a/source4/selftest/tests.py b/source4/selftest/tests.py index f61c93f0f4e..b70faafa5e5 100755 --- a/source4/selftest/tests.py +++ b/source4/selftest/tests.py @@ -658,6 +658,8 @@ planoldpythontestsuite("ad_dc", "samba.tests.password_hash_ldap", extra_args=['-U"$USERNAME%$PASSWORD"']) +planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.lsa_string") + plantestsuite_loadlist("samba4.ldap.python(ad_dc_ntvfs)", "ad_dc_ntvfs", [python, os.path.join(samba4srcdir, "dsdb/tests/python/ldap.py"), '$SERVER', '-U"$USERNAME%$PASSWORD"', '--workgroup=$DOMAIN', '$LOADLIST', '$LISTOPT']) plantestsuite_loadlist("samba4.tokengroups.krb5.python(ad_dc_ntvfs)", "ad_dc_ntvfs:local", [python, os.path.join(samba4srcdir, "dsdb/tests/python/token_group.py"), '$SERVER', '-U"$USERNAME%$PASSWORD"', '--workgroup=$DOMAIN', '-k', 'yes', '$LOADLIST', '$LISTOPT']) plantestsuite_loadlist("samba4.tokengroups.ntlm.python(ad_dc_ntvfs)", "ad_dc_ntvfs:local", [python, os.path.join(samba4srcdir, "dsdb/tests/python/token_group.py"), '$SERVER', '-U"$USERNAME%$PASSWORD"', '--workgroup=$DOMAIN', '-k', 'no', '$LOADLIST', '$LISTOPT'])