tests/krb5: Use __slots__ to indicate which attributes are used by classes
authorJoseph Sutton <josephsutton@catalyst.net.nz>
Mon, 30 Oct 2023 01:05:17 +0000 (14:05 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 1 Nov 2023 20:10:45 +0000 (20:10 +0000)
These should help to catch mistaken attempts to set invalid attributes.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/tests/krb5/kdc_base_test.py
python/samba/tests/krb5/raw_testcase.py

index afbdc056d479586772f1a3ef5a99eeaa22da36ac..98a64a33041300c161f7c322ca5e6f50f870eaec 100644 (file)
@@ -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')
index 347874fc99a599e822cf9abd03fc2b77d9856c05..b163fc01856f8f423ac4c9cbd3819b6bdc400cfb 100644 (file)
@@ -249,6 +249,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,
@@ -305,6 +312,8 @@ class Krb5EncryptionKey:
 
 
 class RodcPacEncryptionKey(Krb5EncryptionKey):
+    __slots__ = ['rodc_id']
+
     def __init__(self, key, kvno, rodc_id=None):
         super().__init__(key, kvno)
 
@@ -352,6 +361,8 @@ class ZeroedChecksumKey(RodcPacEncryptionKey):
 
 
 class WrongLengthChecksumKey(RodcPacEncryptionKey):
+    __slots__ = ['_length']
+
     def __init__(self, key, kvno, length):
         super().__init__(key, kvno)
 
@@ -383,6 +394,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) | (
@@ -586,6 +611,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,