acl_delete_request_test.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. package sarama
  2. import "testing"
  3. var (
  4. aclDeleteRequestNullsv1 = []byte{
  5. 0, 0, 0, 1,
  6. 1,
  7. 255, 255,
  8. 1, // Any
  9. 255, 255,
  10. 255, 255,
  11. 11,
  12. 3,
  13. }
  14. aclDeleteRequestv1 = []byte{
  15. 0, 0, 0, 1,
  16. 1, // any
  17. 0, 6, 'f', 'i', 'l', 't', 'e', 'r',
  18. 1, // Any Filter
  19. 0, 9, 'p', 'r', 'i', 'n', 'c', 'i', 'p', 'a', 'l',
  20. 0, 4, 'h', 'o', 's', 't',
  21. 4, // write
  22. 3, // allow
  23. }
  24. aclDeleteRequestNulls = []byte{
  25. 0, 0, 0, 1,
  26. 1,
  27. 255, 255,
  28. 255, 255,
  29. 255, 255,
  30. 11,
  31. 3,
  32. }
  33. aclDeleteRequest = []byte{
  34. 0, 0, 0, 1,
  35. 1, // any
  36. 0, 6, 'f', 'i', 'l', 't', 'e', 'r',
  37. 0, 9, 'p', 'r', 'i', 'n', 'c', 'i', 'p', 'a', 'l',
  38. 0, 4, 'h', 'o', 's', 't',
  39. 4, // write
  40. 3, // allow
  41. }
  42. aclDeleteRequestArray = []byte{
  43. 0, 0, 0, 2,
  44. 1,
  45. 0, 6, 'f', 'i', 'l', 't', 'e', 'r',
  46. 0, 9, 'p', 'r', 'i', 'n', 'c', 'i', 'p', 'a', 'l',
  47. 0, 4, 'h', 'o', 's', 't',
  48. 4, // write
  49. 3, // allow
  50. 2,
  51. 0, 5, 't', 'o', 'p', 'i', 'c',
  52. 255, 255,
  53. 255, 255,
  54. 6,
  55. 2,
  56. }
  57. )
  58. func TestDeleteAclsRequest(t *testing.T) {
  59. req := &DeleteAclsRequest{
  60. Filters: []*AclFilter{{
  61. ResourceType: AclResourceAny,
  62. Operation: AclOperationAlterConfigs,
  63. PermissionType: AclPermissionAllow,
  64. }},
  65. }
  66. testRequest(t, "delete request nulls", req, aclDeleteRequestNulls)
  67. req.Filters[0].ResourceName = nullString("filter")
  68. req.Filters[0].Principal = nullString("principal")
  69. req.Filters[0].Host = nullString("host")
  70. req.Filters[0].Operation = AclOperationWrite
  71. testRequest(t, "delete request", req, aclDeleteRequest)
  72. req.Filters = append(req.Filters, &AclFilter{
  73. ResourceType: AclResourceTopic,
  74. ResourceName: nullString("topic"),
  75. Operation: AclOperationDelete,
  76. PermissionType: AclPermissionDeny,
  77. })
  78. testRequest(t, "delete request array", req, aclDeleteRequestArray)
  79. }
  80. func TestDeleteAclsRequestV1(t *testing.T) {
  81. req := &DeleteAclsRequest{
  82. Version: 1,
  83. Filters: []*AclFilter{{
  84. ResourceType: AclResourceAny,
  85. Operation: AclOperationAlterConfigs,
  86. PermissionType: AclPermissionAllow,
  87. ResourcePatternTypeFilter: AclPatternAny,
  88. }},
  89. }
  90. testRequest(t, "delete request nulls", req, aclDeleteRequestNullsv1)
  91. req.Filters[0].ResourceName = nullString("filter")
  92. req.Filters[0].Principal = nullString("principal")
  93. req.Filters[0].Host = nullString("host")
  94. req.Filters[0].Operation = AclOperationWrite
  95. testRequest(t, "delete request", req, aclDeleteRequestv1)
  96. }