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);
}
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();
}
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);
}
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();
}
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" + "}");
}
Aggregations