Search in sources :

Example 16 with MockHttpServletResponse

use of com.thoughtworks.go.http.mocks.MockHttpServletResponse in project gocd by gocd.

the class RequestRejectedExceptionHandlerTest method shouldHandleUrlsAsApiRequest.

@ParameterizedTest
@ValueSource(strings = { "/remoting/foo", "/add-on/bar/api/foo", "/api/foo", "/cctray.xml" })
void shouldHandleUrlsAsApiRequest(String url) throws IOException {
    final MockHttpServletRequest request = HttpRequestBuilder.GET(url).withHeader("Accept", "application/json").build();
    final MockHttpServletResponse response = new MockHttpServletResponse();
    new RequestRejectedExceptionHandler().handle(request, response, "Something went wrong", HttpStatus.BAD_REQUEST);
    assertThat(response).isBadRequest().hasBody("{\n" + "  \"message\": \"Something went wrong\"\n" + "}");
}
Also used : MockHttpServletRequest(com.thoughtworks.go.http.mocks.MockHttpServletRequest) MockHttpServletResponse(com.thoughtworks.go.http.mocks.MockHttpServletResponse) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 17 with MockHttpServletResponse

use of com.thoughtworks.go.http.mocks.MockHttpServletResponse in project gocd by gocd.

the class DenyGoCDAccessForArtifactsFilterChainTest method setUp.

@BeforeEach
void setUp() {
    response = new MockHttpServletResponse();
    filter = new DenyGoCDAccessForArtifactsFilterChain();
    filterChain = mock(FilterChain.class);
}
Also used : MockHttpServletResponse(com.thoughtworks.go.http.mocks.MockHttpServletResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 18 with MockHttpServletResponse

use of com.thoughtworks.go.http.mocks.MockHttpServletResponse in project gocd by gocd.

the class AbstractBasicAuthenticationFilterTest method setUp.

@BeforeEach
void setUp() {
    clock = new TestingClock();
    securityService = mock(SecurityService.class);
    authenticationProvider = mock(PasswordBasedPluginAuthenticationProvider.class);
    response = new MockHttpServletResponse();
    filterChain = mock(FilterChain.class);
    filter = spy(new AbstractBasicAuthenticationFilter(securityService, authenticationProvider) {

        @Override
        protected void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, String errorMessage) throws IOException {
        }
    });
}
Also used : MockHttpServletRequest(com.thoughtworks.go.http.mocks.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) PasswordBasedPluginAuthenticationProvider(com.thoughtworks.go.server.newsecurity.providers.PasswordBasedPluginAuthenticationProvider) SecurityService(com.thoughtworks.go.server.service.SecurityService) FilterChain(javax.servlet.FilterChain) MockHttpServletResponse(com.thoughtworks.go.http.mocks.MockHttpServletResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) TestingClock(com.thoughtworks.go.util.TestingClock) MockHttpServletResponse(com.thoughtworks.go.http.mocks.MockHttpServletResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 19 with MockHttpServletResponse

use of com.thoughtworks.go.http.mocks.MockHttpServletResponse in project gocd by gocd.

the class AbstractUserEnabledCheckFilterTest method setUp.

@BeforeEach
void setUp() throws Exception {
    userService = mock(UserService.class);
    securityService = mock(SecurityService.class);
    filter = spy(new AbstractUserEnabledCheckFilter(userService, securityService) {

        @Override
        void handleFailure(HttpServletRequest request, HttpServletResponse response, String errorMessage) throws IOException {
        }
    });
    request = new MockHttpServletRequest();
    response = new MockHttpServletResponse();
    filterChain = mock(FilterChain.class);
}
Also used : MockHttpServletRequest(com.thoughtworks.go.http.mocks.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) UserService(com.thoughtworks.go.server.service.UserService) SecurityService(com.thoughtworks.go.server.service.SecurityService) MockHttpServletRequest(com.thoughtworks.go.http.mocks.MockHttpServletRequest) FilterChain(javax.servlet.FilterChain) MockHttpServletResponse(com.thoughtworks.go.http.mocks.MockHttpServletResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) MockHttpServletResponse(com.thoughtworks.go.http.mocks.MockHttpServletResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 20 with MockHttpServletResponse

use of com.thoughtworks.go.http.mocks.MockHttpServletResponse in project gocd by gocd.

the class AssumeAnonymousUserFilterTest method setUp.

@BeforeEach
void setUp() {
    clock = new TestingClock();
    securityService = mock(SecurityService.class);
    anonymousAuthenticationProvider = new AnonymousAuthenticationProvider(clock, new AuthorityGranter(securityService));
    filterChain = mock(FilterChain.class);
    response = new MockHttpServletResponse();
    request = new MockHttpServletRequest();
}
Also used : AuthorityGranter(com.thoughtworks.go.server.security.AuthorityGranter) SecurityService(com.thoughtworks.go.server.service.SecurityService) MockHttpServletRequest(com.thoughtworks.go.http.mocks.MockHttpServletRequest) FilterChain(javax.servlet.FilterChain) TestingClock(com.thoughtworks.go.util.TestingClock) AnonymousAuthenticationProvider(com.thoughtworks.go.server.newsecurity.providers.AnonymousAuthenticationProvider) MockHttpServletResponse(com.thoughtworks.go.http.mocks.MockHttpServletResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

MockHttpServletResponse (com.thoughtworks.go.http.mocks.MockHttpServletResponse)30 MockHttpServletRequest (com.thoughtworks.go.http.mocks.MockHttpServletRequest)20 BeforeEach (org.junit.jupiter.api.BeforeEach)16 Test (org.junit.jupiter.api.Test)13 FilterChain (javax.servlet.FilterChain)11 SecurityService (com.thoughtworks.go.server.service.SecurityService)7 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)7 TestingClock (com.thoughtworks.go.util.TestingClock)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 UsernamePassword (com.thoughtworks.go.server.newsecurity.models.UsernamePassword)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 AnonymousAuthenticationProvider (com.thoughtworks.go.server.newsecurity.providers.AnonymousAuthenticationProvider)2 AuthorityGranter (com.thoughtworks.go.server.security.AuthorityGranter)2 HttpSession (javax.servlet.http.HttpSession)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Answer (org.mockito.stubbing.Answer)2 SavedRequest (org.springframework.security.web.savedrequest.SavedRequest)2 GsonBuilder (com.google.gson.GsonBuilder)1 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)1