From e90184fbdaa2ac1c438548e98dd4953779cb3a60 Mon Sep 17 00:00:00 2001 From: Douglas Bagnall Date: Wed, 5 Nov 2025 12:50:31 +1300 Subject: [PATCH] pytest:krb5: errcode errors include names Before: > AssertionError: 6 not found in (20,) After: > AssertionError: 6 not found in (20,) : KDC_ERR_C_PRINCIPAL_UNKNOWN not in ['KDC_ERR_TGT_REVOKED'] Useful for people who don't know the codes off by heart. Signed-off-by: Douglas Bagnall Reviewed-by: Jennifer Sutton --- python/samba/tests/krb5/raw_testcase.py | 5 ++++- python/samba/tests/krb5/rfc4120_constants.py | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/python/samba/tests/krb5/raw_testcase.py b/python/samba/tests/krb5/raw_testcase.py index 07bf4490104..e36e8fce418 100644 --- a/python/samba/tests/krb5/raw_testcase.py +++ b/python/samba/tests/krb5/raw_testcase.py @@ -130,6 +130,7 @@ from samba.tests.krb5.rfc4120_constants import ( PADATA_REQ_ENC_PA_REP, PADATA_SUPPORTED_ETYPES, TD_CMS_DIGEST_ALGORITHMS, + errmap ) import samba.tests.krb5.kcrypto as kcrypto @@ -5080,7 +5081,9 @@ class RawKerberosTest(TestCase): self.assertElementEqual(rep, 'pvno', 5) self.assertElementEqual(rep, 'msg-type', KRB_ERROR) error_code = self.getElementValue(rep, 'error-code') - self.assertIn(error_code, expected_error_mode) + self.assertIn(error_code, expected_error_mode, + f"{errmap.get(error_code)} not in " + f"{[errmap.get(e) for e in expected_error_mode]}") if self.strict_checking: self.assertElementMissing(rep, 'ctime') self.assertElementMissing(rep, 'cusec') diff --git a/python/samba/tests/krb5/rfc4120_constants.py b/python/samba/tests/krb5/rfc4120_constants.py index c98f1c67b12..a643f40c4af 100644 --- a/python/samba/tests/krb5/rfc4120_constants.py +++ b/python/samba/tests/krb5/rfc4120_constants.py @@ -132,6 +132,8 @@ KDC_ERR_PUBLIC_KEY_ENCRYPTION_NOT_SUPPORTED = 81 KDC_ERR_PREAUTH_EXPIRED = 90 KDC_ERR_UNKNOWN_CRITICAL_FAST_OPTIONS = 93 +errmap = {v: k for k, v in globals().items() if k[:8] == 'KDC_ERR_'} + # Kpasswd error codes KPASSWD_SUCCESS = 0 KPASSWD_MALFORMED = 1 -- 2.47.3