Skip to content

Commit a9abf9c

Browse files
committed
fix broken tests in ShouldBlockRequest
1 parent 133fb7c commit a9abf9c

1 file changed

Lines changed: 24 additions & 3 deletions

File tree

agent_api/src/test/java/ShouldBlockRequestTest.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import dev.aikido.agent_api.context.Context;
55
import dev.aikido.agent_api.context.ContextObject;
66
import dev.aikido.agent_api.context.User;
7+
import dev.aikido.agent_api.storage.RateLimiterStore;
78
import dev.aikido.agent_api.storage.ServiceConfigStore;
89
import dev.aikido.agent_api.storage.statistics.StatisticsStore;
910
import org.junit.jupiter.api.AfterEach;
@@ -40,12 +41,15 @@ public static void clean() {
4041
Context.set(null);
4142
ServiceConfigStore.updateFromAPIResponse(emptyAPIResponse);
4243
StatisticsStore.clear();
44+
RateLimiterStore.clear();
4345
};
4446

4547
@AfterEach
4648
public void tearDown() throws SQLException {
4749
Context.set(null);
4850
ServiceConfigStore.updateFromAPIResponse(emptyAPIResponse);
51+
StatisticsStore.clear();
52+
RateLimiterStore.clear();
4953
}
5054

5155
@Test
@@ -135,22 +139,39 @@ public void testEndpointsExistButNoMatch() throws SQLException {
135139

136140
@Test
137141
public void testEndpointsExistWithMatch() throws SQLException {
138-
Context.set(new SampleContextObject());
142+
Context.set(null);
139143
setEmptyConfigWithEndpointList(List.of(
140-
new Endpoint("GET", "/api/*", 1, 1000, Collections.emptyList(), false, false, false)
144+
new Endpoint("GET", "/api/*", 1, 1000, Collections.emptyList(), false, false, false)
141145
));
142146

143147
// Test with match & rate-limiting disabled :
144148
var res1 = ShouldBlockRequest.shouldBlockRequest();
145149
assertFalse(res1.block());
146150

151+
Context.set(null);
147152
setEmptyConfigWithEndpointList(List.of(
148-
new Endpoint("GET", "/api/*", 1, 1000, Collections.emptyList(), false, false, true)
153+
new Endpoint("GET", "/api/*", 1, 1000, Collections.emptyList(), false, false, true)
149154
));
150155

151156
// Test with match & rate-limiting enabled :
152157
var res2 = ShouldBlockRequest.shouldBlockRequest();
153158
assertFalse(res2.block());
159+
}
160+
161+
@Test
162+
public void testEndpointsExistAndGetsRateLimited() throws SQLException {
163+
setEmptyConfigWithEndpointList(List.of(
164+
new Endpoint("GET", "/api/*", 2, 1000, Collections.emptyList(), false, false, true)
165+
));
166+
167+
// Test with match
168+
Context.set(new SampleContextObject());
169+
var res1 = ShouldBlockRequest.shouldBlockRequest();
170+
assertFalse(res1.block());
171+
172+
// Test with match
173+
var res2 = ShouldBlockRequest.shouldBlockRequest();
174+
assertFalse(res2.block());
154175
assertEquals(0, StatisticsStore.getStatsRecord().requests().rateLimited());
155176

156177
var res3 = ShouldBlockRequest.shouldBlockRequest();

0 commit comments

Comments
 (0)