1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
from kafka.admin.acl_resource import ACL
from kafka.admin.acl_resource import ACLOperation
from kafka.admin.acl_resource import ACLPermissionType
from kafka.admin.acl_resource import ResourcePattern
from kafka.admin.acl_resource import ResourceType
from kafka.admin.acl_resource import ACLResourcePatternType
def test_different_acls_are_different():
one = ACL(
principal='User:A',
host='*',
operation=ACLOperation.ALL,
permission_type=ACLPermissionType.ALLOW,
resource_pattern=ResourcePattern(
resource_type=ResourceType.TOPIC,
resource_name='some-topic',
pattern_type=ACLResourcePatternType.LITERAL
)
)
two = ACL(
principal='User:B', # Different principal
host='*',
operation=ACLOperation.ALL,
permission_type=ACLPermissionType.ALLOW,
resource_pattern=ResourcePattern(
resource_type=ResourceType.TOPIC,
resource_name='some-topic',
pattern_type=ACLResourcePatternType.LITERAL
)
)
assert one != two
assert hash(one) != hash(two)
def test_different_acls_are_different_with_glob_topics():
one = ACL(
principal='User:A',
host='*',
operation=ACLOperation.ALL,
permission_type=ACLPermissionType.ALLOW,
resource_pattern=ResourcePattern(
resource_type=ResourceType.TOPIC,
resource_name='*',
pattern_type=ACLResourcePatternType.LITERAL
)
)
two = ACL(
principal='User:B', # Different principal
host='*',
operation=ACLOperation.ALL,
permission_type=ACLPermissionType.ALLOW,
resource_pattern=ResourcePattern(
resource_type=ResourceType.TOPIC,
resource_name='*',
pattern_type=ACLResourcePatternType.LITERAL
)
)
assert one != two
assert hash(one) != hash(two)
def test_same_acls_are_same():
one = ACL(
principal='User:A',
host='*',
operation=ACLOperation.ALL,
permission_type=ACLPermissionType.ALLOW,
resource_pattern=ResourcePattern(
resource_type=ResourceType.TOPIC,
resource_name='some-topic',
pattern_type=ACLResourcePatternType.LITERAL
)
)
two = ACL(
principal='User:A',
host='*',
operation=ACLOperation.ALL,
permission_type=ACLPermissionType.ALLOW,
resource_pattern=ResourcePattern(
resource_type=ResourceType.TOPIC,
resource_name='some-topic',
pattern_type=ACLResourcePatternType.LITERAL
)
)
assert one == two
assert hash(one) == hash(two)
assert len(set((one, two))) == 1
|