forked from halo-dev/halo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DefaultServerAuthenticationEntryPointTest.java
35 lines (29 loc) · 1.3 KB
/
DefaultServerAuthenticationEntryPointTest.java
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
package run.halo.app.security;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.springframework.http.HttpHeaders.WWW_AUTHENTICATE;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
import org.springframework.mock.web.server.MockServerWebExchange;
import org.springframework.security.authentication.AuthenticationCredentialsNotFoundException;
import reactor.test.StepVerifier;
@ExtendWith(MockitoExtension.class)
class DefaultServerAuthenticationEntryPointTest {
@InjectMocks
DefaultServerAuthenticationEntryPoint entryPoint;
@Test
void commence() {
var mockReq = MockServerHttpRequest.get("/protected")
.build();
var mockExchange = MockServerWebExchange.builder(mockReq)
.build();
var commenceMono = entryPoint.commence(mockExchange,
new AuthenticationCredentialsNotFoundException("Not Found"));
StepVerifier.create(commenceMono)
.verifyComplete();
var headers = mockExchange.getResponse().getHeaders();
assertEquals("FormLogin realm=\"console\"", headers.getFirst(WWW_AUTHENTICATE));
}
}