-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathacls_test.go
More file actions
124 lines (119 loc) · 3.87 KB
/
acls_test.go
File metadata and controls
124 lines (119 loc) · 3.87 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package confluent
import (
"io"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
func TestAcls_ListAclsSuccess(t *testing.T) {
mock := MockHttpClient{}
mk := MockKafkaClient{}
mock.DoRequestFn = func(method string, uri string, reqBody io.Reader) (responseBody []byte, statusCode int, status string, err error) {
assert.Equal(t, http.MethodGet, method, "Expected method 'GET', got %s", method)
assert.Equal(t, "/clusters/cluster-1/acls", uri)
return []byte(`
{
"kind": "KafkaAclList",
"metadata": {
"self": "http://localhost:9391/v3/clusters/cluster-1/acls?principal=alice"
},
"data": [
{
"kind": "KafkaAcl",
"metadata": {
"self": "http://localhost:9391/v3/clusters/cluster-1/acls?resource_type=TOPIC&resource_name=topic-&pattern_type=PREFIXED&principal=alice&host=*&operation=ALL&permission=ALLOW"
},
"cluster_id": "cluster-1",
"resource_type": "TOPIC",
"resource_name": "topic-",
"pattern_type": "PREFIXED",
"principal": "alice",
"host": "*",
"operation": "ALL",
"permission": "ALLOW"
},
{
"kind": "KafkaAcl",
"metadata": {
"self": "http://localhost:9391/v3/clusters/cluster-1/acls?resource_type=CLUSTER&resource_name=cluster-1&pattern_type=LITERAL&principal=bob&host=*&operation=DESCRIBE&permission=DENY"
},
"cluster_id": "cluster-1",
"resource_type": "CLUSTER",
"resource_name": "cluster-2",
"pattern_type": "LITERAL",
"principal": "alice",
"host": "*",
"operation": "DESCRIBE",
"permission": "DENY"
}
]
}
`), 200, "200 OK", nil
}
clusterAdmin, _ := mk.NewSaramaClusterAdmin()
c := NewClient(&mock, &mk, clusterAdmin)
acls, err := c.ListAcls("cluster-1")
assert.NoError(t, err)
assert.Equal(t, 2, len(acls))
assert.Equal(t, "alice", acls[0].Principal)
}
func TestAcls_CreateAclsSuccess(t *testing.T) {
mock := MockHttpClient{}
mk := MockKafkaClient{}
mock.DoRequestFn = func(method string, uri string, reqBody io.Reader) (responseBody []byte, statusCode int, status string, err error) {
assert.Equal(t, http.MethodPost, method, "Expected method 'POST', got %s", method)
assert.Equal(t, "/clusters/cluster-1/acls", uri)
return []byte(``), 201, "201", nil
}
clusterAdmin, _ := mk.NewSaramaClusterAdmin()
c := NewClient(&mock, &mk, clusterAdmin)
aclConfig := Acl{}
err := c.CreateAcl("cluster-1", &aclConfig)
assert.NoError(t, err)
}
func TestAcls_DeleteAclSuccess(t *testing.T) {
mock := MockHttpClient{}
mk := MockKafkaClient{}
mock.DoRequestFn = func(method string, uri string, reqBody io.Reader) (responseBody []byte, statusCode int, status string, err error) {
assert.Equal(t, http.MethodDelete, method, "Expected method 'Delete', got %s", method)
assert.Equal(t, "/clusters/cluster-1/acls", uri)
return []byte(`
{
"data": [
{
"kind": "KafkaAcl",
"metadata": {
"self": "http://localhost:9391/v3/clusters/cluster-1/acls?resource_type=TOPIC&resource_name=topic-&pattern_type=PREFIXED&principal=alice&host=*&operation=ALL&permission=ALLOW"
},
"cluster_id": "cluster-1",
"resource_type": "TOPIC",
"resource_name": "topic-",
"pattern_type": "PREFIXED",
"principal": "alice",
"host": "*",
"operation": "ALL",
"permission": "ALLOW"
},
{
"kind": "KafkaAcl",
"metadata": {
"self": "http://localhost:9391/v3/clusters/cluster-1/acls?resource_type=CLUSTER&resource_name=cluster-1&pattern_type=LITERAL&principal=bob&host=*&operation=DESCRIBE&permission=DENY"
},
"cluster_id": "cluster-1",
"resource_type": "CLUSTER",
"resource_name": "cluster-2",
"pattern_type": "LITERAL",
"principal": "alice",
"host": "*",
"operation": "DESCRIBE",
"permission": "DENY"
}
]
}
`), 200, "200", nil
}
clusterAdmin, _ := mk.NewSaramaClusterAdmin()
c := NewClient(&mock, &mk, clusterAdmin)
err := c.DeleteAcl("cluster-1", "")
assert.NoError(t, err)
}