summaryrefslogtreecommitdiff
path: root/python/samba/tests/__init__.py
AgeCommit message (Collapse)AuthorFilesLines
2025-11-20pytests: add TestCase.get_server_param() methodDouglas Bagnall1-0/+16
This makes it easier to get a loadparm value from the server smb.conf (rather than the client smb.conf), so you can alter test behaviour accordingly. The class._server_lp attribute is lazily loaded when first needed. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Jennifer Sutton <jennifersutton@catalyst.net.nz>
2025-05-26python:tests: Decode stdout and stderr for greater readabilityJennifer Sutton1-1/+9
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15852 Signed-off-by: Jennifer Sutton <jennifersutton@catalyst.net.nz> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2025-03-29pytest: source_tree_topdir() checks more thoroughlyDouglas Bagnall1-8/+12
We are more certain of how many ../ steps we are from top than we are that the existence of a thing called 'source4' is a definite sign that this is a full source tree. So we check fewer depths and more subdirectories. This also modernises the return type to be a pathlib.Path, which works without change for current callers. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Ralph Boehme <slow@samba.org>
2025-03-29python: make source_tree_topdir() test-onlyDouglas Bagnall1-0/+10
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Ralph Boehme <slow@samba.org>
2025-03-12pytest:samba-tool: .check_output() can set environmentDouglas Bagnall1-2/+2
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Rowland Penny <rpenny@samba.org>
2024-06-12pytest: simplify and fix HEXDUMP_FILTER used in hexdumpsDouglas Bagnall1-1/+2
The old test x if ((len(repr(chr(x))) == 3) and (x < 127)) else ord('.') went through some contortions to see if the character was printable, and it got it slightly wrong. The idea was that `repr(chr(97)` is "'a'", while `repr(chr(167)` is "'\xa7'", which we can distinguish using the length. But that miscategorised the backslash character, which is represented as "'\\'", a string of length 4, so it was show as '.' instead. Instead we notice that the characters we want to print in a hexdump are exactly those between 32 and 126, inclusive. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-01-26python/tests: add TestCase.get_loadparm(s3=True) supportStefan Metzmacher1-5/+9
This will be used for tests with registry shares, as the top level loadparm system doesn't support them. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Günther Deschner <gd@samba.org>
2023-12-21python:tests: Raise exception of more specific type NotImplementedErrorJoseph Sutton1-1/+1
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-12-21python:tests: Use ‘False’ in boolean expression rather than ‘None’Joseph Sutton1-1/+1
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-12-21selftest: require named parameters for callers of connect_samdb() and ↵Rob van der Linde1-4/+5
connect_samdb_ex() Signed-off-by: Rob van der Linde <rob@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2023-12-21selftest: add get_env_credentials()Rob van der Linde1-0/+19
This is like get_credentials but works for tests that are based on environment variable for usernames and passwords. Signed-off-by: Rob van der Linde <rob@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2023-12-21selftest: make get_loadparm a classmethodRob van der Linde1-1/+2
Signed-off-by: Rob van der Linde <rob@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2023-11-30python: tests: update all super calls to python 3 style in testsRob van der Linde1-3/+3
Signed-off-by: Rob van der Linde <rob@catalyst.net.nz> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> [abartlet@samba.org Some python2 style super() calls remain due to being an actual, even if reasonable, behaviour change]
2023-11-29python/tests: Import samba.gensec, not gensecAndrew Bartlett1-2/+2
This allows this function to be used by gensec.py (a test) without collision. Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2023-10-26python: tests: function to generate a unique name from callerRob van der Linde1-0/+19
Uses the caller function to generate a unique name from the test function name. Unique name is converted to camel case Signed-off-by: Rob van der Linde <rob@catalyst.net.nz> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-10-24netcmd: tests: make check_run and related methods classmethod for consistencyRob van der Linde1-6/+9
Before that only run_command was turned into a @classmethod, but not the other related methods which were left unchanged, this made it inconsistent. Some of these methods need to be called from setUpTestData so they really need to be @classmethod anyway. Signed-off-by: Rob van der Linde <rob@catalyst.net.nz> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-10-24tests: minor indentation and whitespace fixesRob van der Linde1-9/+11
Signed-off-by: Rob van der Linde <rob@catalyst.net.nz> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-10-13python:tests: Fix exception messageJoseph Sutton1-1/+1
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-09-29python: tests: implement setUpTestData overridable class methodRob van der Linde1-0/+54
On Python 3.6 and 3.7 the addClassCleanup method needs to be implemented, and tearDownClass must be called by setupClass if any exception is raised. On Python 3.8 and higher, unittest already calls tearDownClass, even if it raises an exception in setUpClass. Signed-off-by: Rob van der Linde <rob@catalyst.net.nz> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-09-27python:tests: Remove unused importJoseph Sutton1-1/+0
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-08-30python: Fix spellingJoseph Sutton1-3/+3
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-08-24pytests: add helper to grab a directory from environmentDouglas Bagnall1-0/+16
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-06-14python/tests: Make helpful, stateless methods @classmethod and @staticmethodAndrew Bartlett1-3/+5
This allows them to be used in setUpClass in tests. Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2023-02-23python: fix mutable default argumentsRob van der Linde1-1/+3
Signed-off-by: Rob van der Linde <rob@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz> Autobuild-User(master): Andrew Bartlett <abartlet@samba.org> Autobuild-Date(master): Thu Feb 23 23:33:46 UTC 2023 on atb-devel-224
2022-11-22tests: Fix an incorrect commentVolker Lendecke1-1/+1
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2022-09-16pytests: remove backwards compat workaround for python 2.6Douglas Bagnall1-5/+2
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2022-09-06pytests: move ValidNetbiosNameTests to samba.tests.netbiosDouglas Bagnall1-12/+0
These were the only tests in __init__.py. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Noel Power <npower@samba.org>
2022-09-06pytest: add file removal helpers for TestCaseInTempDirDouglas Bagnall1-0/+35
In several places we end a test by deleting a number of files and directories, but we do it rather haphazardly with unintentionally differing error handling. For example, in some tests we currently have something like: try: shutil.rmtree(os.path.join(self.tempdir, "a")) os.remove(os.path.join(self.tempdir, "b")) shutil.rmtree(os.path.join(self.tempdir, "c")) except Exception: pass where if, for example, the removal of "b" fails, the removal of "c" will not be attempted. That will result in the tearDown method raising an exception, and we're no better off. If the above code is replaced with self.rm_files('b') self.rm_dirs('a', 'c') the failure to remove 'b' will cause a test error, *unless* the failure was due to a FileNotFoundError (a.k.a. an OSError with errno ENOENT), in which case we ignore it, as was probably the original intention. If on the other hand, we have self.rm_files('b', must_exist=True) self.rm_dirs('a', 'c') then the FileNotFoundError causes a failure (not an error). We take a little bit of care to stay within self.tempdir, to protect test authors who accidentally write something like `self.rm_dirs('/')`. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Noel Power <npower@samba.org>
2022-03-10python:tests: let insta_creds() also copy the bind_dn from the templateStefan Metzmacher1-0/+4
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13879 Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2021-11-09CVE-2020-25722 pytest: Raise an error when adding a dynamic test that would ↵Joseph Sutton1-1/+4
overwrite an existing test BUG: https://bugzilla.samba.org/show_bug.cgi?id=14753 Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2021-11-09CVE-2020-25722 pytest: assertRaisesLdbError invents a message if you're lazyDouglas Bagnall1-0/+2
This makes it easier to convert tests that don't have good messages. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14564 Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2021-11-09CVE-2020-25722 pytests: add reverse lookup dict for LDB error codesDouglas Bagnall1-0/+16
You can give ldb_err() it a number, an LdbError, or a sequence of numbers, and it will return the corresponding strings. Examples: ldb_err(68) # "LDB_ERR_ENTRY_ALREADY_EXISTS" LDB_ERR_LUT[68] # "LDB_ERR_ENTRY_ALREADY_EXISTS" expected = (ldb.ERR_INSUFFICIENT_ACCESS_RIGHTS, ldb.ERR_INVALID_CREDENTIALS) try: foo() except ldb.LdbError as e: self.fail(f"got {ldb_err(e)}, expected one of {ldb_err(expected)}") BUG: https://bugzilla.samba.org/show_bug.cgi?id=14564 Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2021-11-09CVE-2020-25722 selftest: Allow self.assertRaisesLdbError() to take a list of ↵Andrew Bartlett1-10/+20
errors to match with BUG: https://bugzilla.samba.org/show_bug.cgi?id=14753 Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2021-10-20pytest: dynamic tests optionally add __doc__Douglas Bagnall1-1/+2
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14869 Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2021-10-04selftest: Move self.assertRaisesLdbError() to samba.tests.TestCaseAndrew Bartlett1-0/+25
This is easier to reason with regarding which cases should work and which cases should fail, avoiding issues where more success than expected would be OK because a self.fail() was missed in a try: block. Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2021-04-28python: remove all 'from __future__ import print_function'Douglas Bagnall1-1/+0
This made Python 2's print behave like Python 3's print(). In some cases, where we had: from __future__ import print_function """Intended module documentation...""" this will have the side effect of making the intended module documentation work as the actual module documentation (i.e. becoming __doc__), because it is once again the first statement in the module. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2020-10-21python/tests: add DynamicTestCase setUpDynamicTestCases() infrastructureStefan Metzmacher1-0/+27
This can be used in order to run a sepcific test (coded just once) with an autogenerated set of arguments. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14531 Pair-Programmed-With: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Signed-off-by: Stefan Metzmacher <metze@samba.org> Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2020-08-11python compat: remove text_typeDouglas Bagnall1-1/+0
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Noel Power <npower@samba.org>
2020-08-11python compat: remove string_typesDouglas Bagnall1-2/+1
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Noel Power <npower@samba.org>
2020-08-03python tests: drop python 2.6 compatibility functionsDouglas Bagnall1-106/+0
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Noel Power <npower@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2020-02-07pytests: heed assertEquals deprecation warning en-masseDouglas Bagnall1-1/+1
TestCase.assertEquals() is an alias for TestCase.assertEqual() and has been deprecated since Python 2.7. When we run our tests with in python developer mode (`PYTHONDEVMODE=1 make test`) we get 580 DeprecationWarnings about this. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Noel Power <npower@samba.org>
2019-11-20python: Return the stdout when also checking error codesAndrew Bartlett1-0/+1
This will aid in checking that ndrdump behaves as expected when failing to parse Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2019-07-31tests: Add samba_upgradedns to the list of possible cmdsGarming Sam1-0/+1
This will be used to test the replication scenario with no DNS partitions BUG: https://bugzilla.samba.org/show_bug.cgi?id=14051 Signed-off-by: Garming Sam <garming@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2019-07-05python/tests: helper function for checking --help consistencyDouglas Bagnall1-0/+118
Check that --help output doesn't contradict itself by assigning the same option string to different meanings (which *does* happen in the ldb tools). This will be used in the samba-tool help tests and the usage tests. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2019-07-02provision tests: Add --backend-store-size option.Gary Lockyer1-0/+17
Tests for the new "samba-tool domain provision" option "backend-store-size". This allows the lmdb map size to be set during a provision, instead of hard-wiring it to 8Gb Signed-off-by: Gary Lockyer <gary@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2019-06-07Revert TestCaseInSubDir parts of "downgradedatabase: blackbox test"Andrew Bartlett1-7/+2
This reverts part of commit 74d15c9bf76f0a2fb5fa7b7b1d80971d10c4fe45. TestCaseInSubDir should not have been modified in this way, instead the downgradedatabase test should have removed the files it created specifically (this is part of the test, it shows the right files were created). BUG: https://bugzilla.samba.org/show_bug.cgi?id=13978 Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Autobuild-User(master): Andrew Bartlett <abartlet@samba.org> Autobuild-Date(master): Fri Jun 7 21:08:12 UTC 2019 on sn-devel-184
2019-05-29downgradedatabase: blackbox testAaron Haslett1-2/+7
This test confirms that running downgradedatabase causes all GUID keys to be replaced with DN keys at the KV level Signed-off-by: Aaron Haslett <aaronhaslett@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Garming Sam <garming@catalyst.net.nz>
2019-05-01pytests: slightly better errors in Testcase.insta_creds()Douglas Bagnall1-3/+4
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2019-01-08python/tests: add TestCaseInTempdir.mktemp()Douglas Bagnall1-1/+16
This gives you a name of a temporary file within the test case's tempdir. Use it like this: with self.mktemp() as filename: self.check_run("samba-tool foo --output %s" % filename) self.assertStringsEqual(open(filename).read(), expected) and filename will flick out of existence when the with block ends. This is based on an idea used in the traffic_runner tests, which will soon be adapted to use this method. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2019-01-08python/tests/blackbox: check_exit_code() explains by defaultDouglas Bagnall1-0/+2
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>