-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
21b6f3f
commit 0dce70b
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
...re/src/test/java/org/sonarsource/sonarlint/core/embedded/server/RateLimitFilterTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.sonarsource.sonarlint.core.embedded.server; | ||
|
||
import org.apache.hc.core5.http.ClassicHttpRequest; | ||
import org.apache.hc.core5.http.HttpException; | ||
import org.apache.hc.core5.http.io.HttpFilterChain; | ||
import org.apache.hc.core5.http.message.BasicHeader; | ||
import org.apache.hc.core5.http.protocol.HttpContext; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.mockito.Mockito.*; | ||
|
||
class RateLimitFilterTests { | ||
|
||
private final ClassicHttpRequest request = mock(ClassicHttpRequest.class); | ||
private final HttpFilterChain.ResponseTrigger responseTrigger = mock(HttpFilterChain.ResponseTrigger.class); | ||
private final HttpContext context = mock(HttpContext.class); | ||
private final HttpFilterChain chain = mock(HttpFilterChain.class); | ||
private RateLimitFilter filter; | ||
|
||
@BeforeEach | ||
void init() { | ||
filter = new RateLimitFilter(); | ||
} | ||
|
||
@Test | ||
void should_not_proceed_with_request_if_origin_is_null() throws HttpException, IOException { | ||
when(request.getHeader("Origin")).thenReturn(null); | ||
|
||
filter.handle(request, responseTrigger, context, chain); | ||
|
||
verify(responseTrigger).submitResponse(any()); | ||
verify(chain, never()).proceed(any(), any(), any()); | ||
} | ||
|
||
@Test | ||
void should_proceed_when_request_is_valid() throws HttpException, IOException { | ||
when(request.getHeader("Origin")).thenReturn(new BasicHeader("Origin", "https://example.com")); | ||
|
||
filter.handle(request, responseTrigger, context, chain); | ||
|
||
verify(responseTrigger, never()).submitResponse(any()); | ||
verify(chain).proceed(any(), any(), any()); | ||
} | ||
|
||
} |