From: Joseph Sutton Date: Mon, 30 Oct 2023 01:05:17 +0000 (+1300) Subject: tests/krb5: Use __slots__ to indicate which attributes are used by classes X-Git-Tag: samba-4.19.8~42 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a35edbb5302fd83ec24eb731d3078e7a3d064ce8;p=thirdparty%2Fsamba.git tests/krb5: Use __slots__ to indicate which attributes are used by classes These should help to catch mistaken attempts to set invalid attributes. Signed-off-by: Joseph Sutton Reviewed-by: Andrew Bartlett (cherry picked from commit 2b69e1e7c316e634090aad1d97ecadf8cdf529f3) BUG: https://bugzilla.samba.org/show_bug.cgi?id=15655 --- diff --git a/python/samba/tests/krb5/kdc_base_test.py b/python/samba/tests/krb5/kdc_base_test.py index 96ae43a0937..76cea241d30 100644 --- a/python/samba/tests/krb5/kdc_base_test.py +++ b/python/samba/tests/krb5/kdc_base_test.py @@ -137,6 +137,8 @@ class GroupType(Enum): # This simple class encapsulates the DN and SID of a Principal. class Principal: + __slots__ = ['dn', 'sid'] + def __init__(self, dn, sid): if dn is not None and not isinstance(dn, ldb.Dn): raise AssertionError(f'expected {dn} to be an ldb.Dn') diff --git a/python/samba/tests/krb5/raw_testcase.py b/python/samba/tests/krb5/raw_testcase.py index 1507e4a9c5a..db4db9c9e85 100644 --- a/python/samba/tests/krb5/raw_testcase.py +++ b/python/samba/tests/krb5/raw_testcase.py @@ -248,6 +248,13 @@ krb5_asn1.KerbErrorDataType.prettyPrint =\ class Krb5EncryptionKey: + __slots__ = [ + 'ctype', + 'etype', + 'key', + 'kvno', + ] + def __init__(self, key, kvno): EncTypeChecksum = { kcrypto.Enctype.AES256: kcrypto.Cksumtype.SHA1_AES256, @@ -304,6 +311,8 @@ class Krb5EncryptionKey: class RodcPacEncryptionKey(Krb5EncryptionKey): + __slots__ = ['rodc_id'] + def __init__(self, key, kvno, rodc_id=None): super().__init__(key, kvno) @@ -351,6 +360,8 @@ class ZeroedChecksumKey(RodcPacEncryptionKey): class WrongLengthChecksumKey(RodcPacEncryptionKey): + __slots__ = ['_length'] + def __init__(self, key, kvno, length): super().__init__(key, kvno) @@ -382,6 +393,20 @@ class WrongLengthChecksumKey(RodcPacEncryptionKey): class KerberosCredentials(Credentials): + __slots__ = [ + '_private_key', + 'account_type', + 'ap_supported_enctypes', + 'as_supported_enctypes', + 'dn', + 'forced_keys', + 'forced_salt', + 'kvno', + 'sid', + 'spn', + 'tgs_supported_enctypes', + 'upn', + ] non_etype_bits = ( security.KERB_ENCTYPE_FAST_SUPPORTED) | ( @@ -577,6 +602,18 @@ class KerberosCredentials(Credentials): class KerberosTicketCreds: + __slots__ = [ + 'cname', + 'crealm', + 'decryption_key', + 'encpart_private', + 'session_key', + 'sname', + 'srealm', + 'ticket_private', + 'ticket', + ] + def __init__(self, ticket, session_key, crealm=None, cname=None, srealm=None, sname=None,