Skip to content

Commit 9879213

Browse files
robobarioSamBarker
andauthored
Add further unit test coverage (kroxylicious#2936)
Signed-off-by: Robert Young <[email protected]> Co-authored-by: Sam Barker <[email protected]>
1 parent 189a7ce commit 9879213

File tree

16 files changed

+1067
-2
lines changed

16 files changed

+1067
-2
lines changed

kroxylicious-filters/kroxylicious-authorization/src/test/resources/scenarios/FETCH/12/baseline.yaml renamed to kroxylicious-filters/kroxylicious-authorization/src/test/resources/scenarios/FETCH/12/allowed-topic.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
metadata:
99
apiKeys: "FETCH"
1010
apiVersion: 12
11-
scenario: "baseline"
11+
scenario: "all topics in request are allowed"
1212
given:
1313
mockedUpstreamResponses:
1414
- expectedRequestKey: "FETCH"
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
#
2+
# Copyright Kroxylicious Authors.
3+
#
4+
# Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5+
#
6+
7+
---
8+
metadata:
9+
apiKeys: "FETCH"
10+
apiVersion: 12
11+
scenario: |
12+
request contains some allowed topics and some denied
13+
allowed topics are forwarded upstream
14+
denied topics are not forwarded upstream
15+
denied topic errors are augmented into response to client
16+
given:
17+
mockedUpstreamResponses:
18+
- expectedRequestKey: "FETCH"
19+
expectedRequestVersion: 12
20+
expectedRequestHeader:
21+
requestApiKey: 1
22+
requestApiVersion: 12
23+
correlationId: 1
24+
clientId: "clientId"
25+
expectedRequest:
26+
replicaId: 66
27+
maxWaitMs: 631
28+
minBytes: 576
29+
maxBytes: 658
30+
isolationLevel: 5
31+
sessionId: 267
32+
sessionEpoch: 603
33+
topics:
34+
- topic: "my-topic"
35+
partitions:
36+
- partition: 549
37+
currentLeaderEpoch: 609
38+
fetchOffset: 402
39+
lastFetchedEpoch: 645
40+
logStartOffset: 742
41+
partitionMaxBytes: 944
42+
forgottenTopicsData:
43+
- topic: "my-topic"
44+
partitions:
45+
- 563
46+
rackId: "random-string-474"
47+
upstreamResponseHeader:
48+
correlationId: 1
49+
upstreamResponse:
50+
throttleTimeMs: 15
51+
errorCode: 856
52+
sessionId: 885
53+
responses:
54+
- topic: "my-topic"
55+
partitions:
56+
- partitionIndex: 647
57+
errorCode: 575
58+
highWatermark: 339
59+
lastStableOffset: 551
60+
logStartOffset: 596
61+
abortedTransactions:
62+
- producerId: 287
63+
firstOffset: 914
64+
preferredReadReplica: 22
65+
records: !!binary ""
66+
authorizerRules:
67+
allowed:
68+
- subject: "alice"
69+
resourceName: "my-topic"
70+
resourceClass: "TOPIC"
71+
resourceType: "READ"
72+
topicNames: null
73+
when:
74+
subject: "alice"
75+
requestHeader:
76+
requestApiKey: 1
77+
requestApiVersion: 12
78+
correlationId: 1
79+
clientId: "clientId"
80+
request:
81+
replicaId: 66
82+
maxWaitMs: 631
83+
minBytes: 576
84+
maxBytes: 658
85+
isolationLevel: 5
86+
sessionId: 267
87+
sessionEpoch: 603
88+
topics:
89+
- topic: "my-topic"
90+
partitions:
91+
- partition: 549
92+
currentLeaderEpoch: 609
93+
fetchOffset: 402
94+
lastFetchedEpoch: 645
95+
logStartOffset: 742
96+
partitionMaxBytes: 944
97+
- topic: "unauthorized"
98+
partitions:
99+
- partition: 549
100+
currentLeaderEpoch: 609
101+
fetchOffset: 402
102+
lastFetchedEpoch: 645
103+
logStartOffset: 742
104+
partitionMaxBytes: 944
105+
forgottenTopicsData:
106+
- topic: "my-topic"
107+
partitions:
108+
- 563
109+
rackId: "random-string-474"
110+
then:
111+
expectedResponseHeader:
112+
correlationId: 1
113+
expectedResponse:
114+
throttleTimeMs: 15
115+
errorCode: 856
116+
sessionId: 885
117+
responses:
118+
- topic: "my-topic"
119+
partitions:
120+
- partitionIndex: 647
121+
errorCode: 575
122+
highWatermark: 339
123+
lastStableOffset: 551
124+
logStartOffset: 596
125+
abortedTransactions:
126+
- producerId: 287
127+
firstOffset: 914
128+
preferredReadReplica: 22
129+
records: !!binary ""
130+
- topic: "unauthorized"
131+
partitions:
132+
- partitionIndex: 549
133+
errorCode: 29
134+
highWatermark: -1
135+
lastStableOffset: -1
136+
logStartOffset: -1
137+
abortedTransactions: [ ]
138+
preferredReadReplica: -1
139+
records: !!binary ""
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#
2+
# Copyright Kroxylicious Authors.
3+
#
4+
# Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5+
#
6+
7+
---
8+
metadata:
9+
apiKeys: "FETCH"
10+
apiVersion: 12
11+
scenario: "all topics in request are denied. filter short circuit responds with error"
12+
given:
13+
mockedUpstreamResponses: []
14+
authorizerRules:
15+
allowed:
16+
- subject: "alice"
17+
resourceName: "my-topic"
18+
resourceClass: "TOPIC"
19+
resourceType: "READ"
20+
topicNames: null
21+
when:
22+
subject: "alice"
23+
requestHeader:
24+
requestApiKey: 1
25+
requestApiVersion: 12
26+
correlationId: 1
27+
clientId: "clientId"
28+
request:
29+
replicaId: 66
30+
maxWaitMs: 631
31+
minBytes: 576
32+
maxBytes: 658
33+
isolationLevel: 5
34+
sessionId: 267
35+
sessionEpoch: 603
36+
topics:
37+
- topic: "unauthorized"
38+
partitions:
39+
- partition: 549
40+
currentLeaderEpoch: 609
41+
fetchOffset: 402
42+
lastFetchedEpoch: 645
43+
logStartOffset: 742
44+
partitionMaxBytes: 944
45+
forgottenTopicsData:
46+
- topic: "my-topic"
47+
partitions:
48+
- 563
49+
rackId: "random-string-474"
50+
then:
51+
expectedResponseHeader:
52+
correlationId: 1
53+
expectedResponse:
54+
throttleTimeMs: 0
55+
errorCode: 0
56+
sessionId: 0
57+
responses:
58+
- topic: "unauthorized"
59+
partitions:
60+
- partitionIndex: 549
61+
errorCode: 29
62+
highWatermark: -1
63+
lastStableOffset: -1
64+
logStartOffset: -1
65+
abortedTransactions: [ ]
66+
preferredReadReplica: -1
67+
records: !!binary ""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#
2+
# Copyright Kroxylicious Authors.
3+
#
4+
# Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5+
#
6+
7+
---
8+
metadata:
9+
apiKeys: "LIST_OFFSETS"
10+
apiVersion: 10
11+
scenario: |
12+
request contains denied and allowed topics
13+
allowed topics are forwarded
14+
denied topics are not forwarded
15+
denied topic errors are augmented into response
16+
given:
17+
mockedUpstreamResponses:
18+
- expectedRequestKey: "LIST_OFFSETS"
19+
expectedRequestVersion: 10
20+
expectedRequestHeader:
21+
requestApiKey: 2
22+
requestApiVersion: 10
23+
correlationId: 1
24+
clientId: "clientId"
25+
expectedRequest:
26+
replicaId: 674
27+
isolationLevel: 119
28+
topics:
29+
- name: "my-topic"
30+
partitions:
31+
- partitionIndex: 342
32+
currentLeaderEpoch: 635
33+
timestamp: 903
34+
timeoutMs: 563
35+
upstreamResponseHeader:
36+
correlationId: 1
37+
upstreamResponse:
38+
throttleTimeMs: 803
39+
topics:
40+
- name: "my-topic"
41+
partitions:
42+
- partitionIndex: 955
43+
errorCode: 272
44+
timestamp: 535
45+
offset: 322
46+
leaderEpoch: 274
47+
authorizerRules:
48+
allowed:
49+
- subject: "alice"
50+
resourceName: "my-topic"
51+
resourceClass: "TOPIC"
52+
resourceType: "DESCRIBE"
53+
topicNames: null
54+
when:
55+
subject: "alice"
56+
requestHeader:
57+
requestApiKey: 2
58+
requestApiVersion: 10
59+
correlationId: 1
60+
clientId: "clientId"
61+
request:
62+
replicaId: 674
63+
isolationLevel: 119
64+
topics:
65+
- name: "my-topic"
66+
partitions:
67+
- partitionIndex: 342
68+
currentLeaderEpoch: 635
69+
timestamp: 903
70+
- name: "unauthorized"
71+
partitions:
72+
- partitionIndex: 342
73+
currentLeaderEpoch: 635
74+
timestamp: 903
75+
timeoutMs: 563
76+
then:
77+
expectedResponseHeader:
78+
correlationId: 1
79+
expectedResponse:
80+
throttleTimeMs: 803
81+
topics:
82+
- name: "my-topic"
83+
partitions:
84+
- partitionIndex: 955
85+
errorCode: 272
86+
timestamp: 535
87+
offset: 322
88+
leaderEpoch: 274
89+
- name: "unauthorized"
90+
partitions:
91+
- partitionIndex: 342
92+
errorCode: 29
93+
timestamp: -1
94+
offset: -1
95+
leaderEpoch: -1
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#
2+
# Copyright Kroxylicious Authors.
3+
#
4+
# Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5+
#
6+
7+
---
8+
metadata:
9+
apiKeys: "LIST_OFFSETS"
10+
apiVersion: 10
11+
scenario: "if all topics in request are denied we short circuit respond"
12+
given:
13+
mockedUpstreamResponses: [ ]
14+
authorizerRules:
15+
allowed:
16+
- subject: "alice"
17+
resourceName: "my-topic"
18+
resourceClass: "TOPIC"
19+
resourceType: "DESCRIBE"
20+
topicNames: null
21+
when:
22+
subject: "alice"
23+
requestHeader:
24+
requestApiKey: 2
25+
requestApiVersion: 10
26+
correlationId: 1
27+
clientId: "clientId"
28+
request:
29+
replicaId: 674
30+
isolationLevel: 119
31+
topics:
32+
- name: "unauthorized"
33+
partitions:
34+
- partitionIndex: 342
35+
currentLeaderEpoch: 635
36+
timestamp: 903
37+
timeoutMs: 563
38+
then:
39+
expectedResponseHeader:
40+
correlationId: 1
41+
expectedResponse:
42+
throttleTimeMs: 0
43+
topics:
44+
- name: "unauthorized"
45+
partitions:
46+
- partitionIndex: 342
47+
errorCode: 29
48+
timestamp: -1
49+
offset: -1
50+
leaderEpoch: -1

0 commit comments

Comments
 (0)