Search in sources :

Example 26 with MockHttpServletResponse

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

the class AuthenticationFilterChainTest method setUp.

@BeforeEach
void setUp() throws IOException {
    response = new MockHttpServletResponse();
    filterChain = mock(FilterChain.class);
    securityService = mock(SecurityService.class);
    clock = new TestingClock();
    systemEnvironment = new SystemEnvironment();
    final AnonymousAuthenticationProvider anonymousAuthenticationProvider = new AnonymousAuthenticationProvider(clock, new AuthorityGranter(securityService));
    assumeAnonymousUserFilter = new AssumeAnonymousUserFilter(securityService, anonymousAuthenticationProvider);
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) AuthorityGranter(com.thoughtworks.go.server.security.AuthorityGranter) 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)

Example 27 with MockHttpServletResponse

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

the class AlwaysCreateSessionFilterTest method setUp.

@BeforeEach
void setUp() throws Exception {
    response = new MockHttpServletResponse();
    request = new MockHttpServletRequest();
    alwaysCreateSessionFilter = new AlwaysCreateSessionFilter();
}
Also used : MockHttpServletRequest(com.thoughtworks.go.http.mocks.MockHttpServletRequest) MockHttpServletResponse(com.thoughtworks.go.http.mocks.MockHttpServletResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 28 with MockHttpServletResponse

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

the class InvalidateAuthenticationOnSecurityConfigChangeFilterTest method setUp.

@BeforeEach
void setUp() {
    // request = new MockHttpServletRequest();
    response = new MockHttpServletResponse();
    clock = new TestingClock();
    systemEnvironment = new SystemEnvironment();
    filterChain = mock(FilterChain.class);
    cruiseConfig = new BasicCruiseConfig();
    GoConfigMother.enableSecurityWithPasswordFilePlugin(cruiseConfig);
    filter = new InvalidateAuthenticationOnSecurityConfigChangeFilter(goConfigService, clock, cacheService, pluginRoleService);
    filter.initialize();
    filter.onPluginRoleChange();
    filter.onConfigChange(GoConfigMother.deepClone(cruiseConfig));
    reset(cacheService);
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) FilterChain(javax.servlet.FilterChain) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) TestingClock(com.thoughtworks.go.util.TestingClock) MockHttpServletResponse(com.thoughtworks.go.http.mocks.MockHttpServletResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 29 with MockHttpServletResponse

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

the class AgentSessionReduceIdleTimeoutFilterTest method shouldReduceSessionTimeoutWhenAppliedAndNewSessionIsCreatedAfterApplyingFilter.

@Test
public void shouldReduceSessionTimeoutWhenAppliedAndNewSessionIsCreatedAfterApplyingFilter() throws IOException, ServletException {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockHttpServletResponse response = new MockHttpServletResponse();
    final SystemEnvironment systemEnvironment = mock(SystemEnvironment.class);
    when(systemEnvironment.get(SystemEnvironment.AGENT_REQUEST_IDLE_TIMEOUT_IN_SECONDS)).thenReturn(30);
    assertThat(request.getSession(false)).isNull();
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            request.getSession(true);
            return null;
        }
    }).when(filterChain).doFilter(request, response);
    new AgentSessionReduceIdleTimeoutFilter(systemEnvironment).doFilter(request, response, filterChain);
    verify(filterChain).doFilter(request, response);
    assertThat(request.getSession(false).getMaxInactiveInterval()).isEqualTo(30);
    assertThat(request.getSession(false)).isNotNull();
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) Answer(org.mockito.stubbing.Answer) MockHttpServletRequest(com.thoughtworks.go.http.mocks.MockHttpServletRequest) InvocationOnMock(org.mockito.invocation.InvocationOnMock) MockHttpServletResponse(com.thoughtworks.go.http.mocks.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 30 with MockHttpServletResponse

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

the class DashBoardControllerTest method shouldProvideDashboardContentsForStandby.

@Test
void shouldProvideDashboardContentsForStandby() {
    when(authToken.isValid()).thenReturn(true);
    when(authToken.toUsernamePassword()).thenReturn(new UsernamePassword(USERNAME, PASSWORD));
    when(authToken.forHttp()).thenReturn(CREDENTIALS);
    HttpServletRequest request = HttpRequestBuilder.GET("").withBasicAuth(USERNAME, PASSWORD).build();
    httpClientMock.onGet("https://localhost:8154/go/add-on/business-continuity/api/health-check").withHeader("Authorization", AUTHORIZATION_HEADER_VALUE).doReturnStatus(200);
    httpClientMock.onGet("https://localhost:8154/go/add-on/business-continuity/api/latest_database_wal_location").withHeader("Authorization", AUTHORIZATION_HEADER_VALUE).doReturn(200, "/logs/location");
    httpClientMock.onGet("https://localhost:8154/go/add-on/business-continuity/api/config_files_status").withHeader("Authorization", AUTHORIZATION_HEADER_VALUE).doReturn(200, "{\"configFilesUpdateInterval\":10,\"fileDetailsMap\":{\"CRUISE_CONFIG_XML\":{\"md5\":\"a\"}}}");
    httpClientMock.onGet("https://localhost:8154/go/add-on/business-continuity/api/plugin_files_status").withHeader("Authorization", AUTHORIZATION_HEADER_VALUE).doReturn(200, "{\"bundled\":[{\"name\":\"yum.jar\",\"md5\":\"LAVBbwaDykricDnAP57klg\\u003d\\u003d\"}],\"external\":[{\"name\":\"external1.jar\",\"md5\":\"+yWDK4+tYQtfqyh3tmT95A\\u003d\\u003d\"},{\"name\":\"external2.jar\",\"md5\":\"DS/Oa0vv5URteXfzSU7mvQ\\u003d\\u003d\"}]}");
    when(addOnConfiguration.isServerInStandby()).thenReturn(true);
    MockHttpServletResponse response = new MockHttpServletResponse();
    String dashboardData = controller.dashboardData(request, response);
    MockHttpServletResponseAssert.assertThat(response).hasStatus(200);
    JsonFluentAssert.assertThatJson(dashboardData).isEqualTo("{\n" + "  \"setupStatus\": \"success\",\n" + "  \"userName\": \"bob\",\n" + "  \"standbyServerDetails\": {\n" + "    \"primaryStatusCheckInterval\": 0,\n" + "    \"pluginStatus\": \"\",\n" + "    \"lastUpdateTime\": " + new GsonBuilder().setDateFormat("MMM d, YYYY HH:mm:ss").create().toJson(new Date(0)) + "\n" + "  },\n" + "  \"primaryServerDetails\": {\n" + "    \"latestDatabaseWalLocation\": \"/logs/location\",\n" + "    \"configFilesUpdateInterval\": 10,\n" + "    \"lastConfigUpdateTime\": " + new GsonBuilder().setDateFormat("MMM d, YYYY HH:mm:ss").create().toJson(new Date(0)) + ",\n" + "    \"CRUISE_CONFIG_XML\": {\n" + "      \"md5\": \"a\"\n" + "    },\n" + "    \"pluginStatus\": \"external1.jar\\u003d+yWDK4+tYQtfqyh3tmT95A\\u003d\\u003d, external2.jar\\u003dDS/Oa0vv5URteXfzSU7mvQ\\u003d\\u003d\",\n" + "    \"url\": \"https://localhost:8154\"\n" + "  },\n" + "  \"syncErrors\": []\n" + "}");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) GsonBuilder(com.google.gson.GsonBuilder) MockHttpServletResponse(com.thoughtworks.go.http.mocks.MockHttpServletResponse) Date(java.util.Date) UsernamePassword(com.thoughtworks.go.server.newsecurity.models.UsernamePassword) Test(org.junit.jupiter.api.Test)

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