CVE-2020-25722 pytests: add reverse lookup dict for LDB error codes
commita65866a6c73ebd3bc98faac57ce652c81f07d8e5
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Sun, 3 Oct 2021 23:56:42 +0000 (4 12:56 +1300)
committerJule Anger <janger@samba.org>
Mon, 8 Nov 2021 09:52:11 +0000 (8 10:52 +0100)
treeb9661b7817272f128f59cd17721028d20a5c456b
parentef7f582772a6c621205fd16a8a7f2b826b7397d7
CVE-2020-25722 pytests: add reverse lookup dict for LDB error codes

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>
python/samba/tests/__init__.py