use of com.thoughtworks.go.http.mocks.MockHttpServletResponse in project gocd by gocd.
the class DenyAllAccessFilterTest method denyAllAccessWhenFilterIsCalled.
@Test
void denyAllAccessWhenFilterIsCalled() throws ServletException, IOException {
final MockHttpServletResponse response = new MockHttpServletResponse();
final MockHttpServletRequest request = new MockHttpServletRequest();
new DenyAllAccessFilter().doFilter(request, response, mock(FilterChain.class));
MockHttpServletResponseAssert.assertThat(response).isForbidden();
}
use of com.thoughtworks.go.http.mocks.MockHttpServletResponse in project gocd by gocd.
the class ThreadLocalUserFilterTest method shouldSetUserToThreadLocalWhenFilterIsCalledAndRemoveUserFromThreadLocalOnceRequestIsCompleted.
@Test
void shouldSetUserToThreadLocalWhenFilterIsCalledAndRemoveUserFromThreadLocalOnceRequestIsCompleted() throws ServletException, IOException {
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockHttpServletResponse response = new MockHttpServletResponse();
final AuthenticationToken<UsernamePassword> authenticationToken = SessionUtilsHelper.createUsernamePasswordAuthentication("bob", "p@ssw0rd", 0L);
SessionUtils.setAuthenticationTokenAfterRecreatingSession(authenticationToken, request);
final GoUserPrinciple[] currentUserInFilter = { null };
final FilterChain filterChain = new MockFilterChain(mock(Servlet.class), spy(new OncePerRequestFilter() {
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
currentUserInFilter[0] = SessionUtils.getCurrentUser();
}
}));
new ThreadLocalUserFilter().doFilter(request, response, filterChain);
assertThat(currentUserInFilter[0]).isNotNull();
assertThat(SessionUtils.getCurrentUser().getUsername()).isEqualTo("anonymous");
assertThat(SessionUtils.getCurrentUser().getAuthorities()).containsExactly(GoAuthority.ROLE_ANONYMOUS.asAuthority());
}
use of com.thoughtworks.go.http.mocks.MockHttpServletResponse in project gocd by gocd.
the class UserEnabledCheckFilterWithRedirectToLoginPageTest method setUp.
@BeforeEach
void setUp() {
filter = new UserEnabledCheckFilterWithRedirectToLoginPage(null, null);
request = new MockHttpServletRequest();
response = new MockHttpServletResponse();
}
use of com.thoughtworks.go.http.mocks.MockHttpServletResponse in project gocd by gocd.
the class BasicAuthenticationWithChallengeFailureResponseHandlerTest method setUp.
@BeforeEach
void setUp() {
securityService = mock(SecurityService.class);
response = new MockHttpServletResponse();
}
use of com.thoughtworks.go.http.mocks.MockHttpServletResponse in project gocd by gocd.
the class RequestRejectedExceptionHandlerTest method shouldReturn404WithHtmlResponse.
@Test
void shouldReturn404WithHtmlResponse() throws IOException {
final MockHttpServletRequest request = HttpRequestBuilder.GET("foo/bar").withHeader("Accept", "application/json").build();
final MockHttpServletResponse response = new MockHttpServletResponse();
new RequestRejectedExceptionHandler().handle(request, response, "Something went wrong", HttpStatus.BAD_REQUEST);
assertThat(response).isBadRequest().hasNoBody();
}
Aggregations