use of com.thoughtworks.go.http.mocks.MockHttpServletRequest 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();
}
use of com.thoughtworks.go.http.mocks.MockHttpServletRequest in project gocd by gocd.
the class AgentRemoteInvokerServiceExporterTest method setup.
@BeforeEach
void setup() throws Exception {
when(env.get(AGENT_EXTRA_PROPERTIES)).thenReturn("gocd.agent.remoting.legacy=true");
req = new MockHttpServletRequest();
req.addHeader("X-Agent-GUID", AGENT_UUID);
res = new MockHttpServletResponse();
}
use of com.thoughtworks.go.http.mocks.MockHttpServletRequest in project gocd by gocd.
the class BackupFilterTest method shouldReturn503WhenJsonAPICallIsMadeAndBackupBeingTaken.
@Test
public void shouldReturn503WhenJsonAPICallIsMadeAndBackupBeingTaken() throws Exception {
when(backupService.isBackingUp()).thenReturn(true);
when(backupService.backupRunningSinceISO8601()).thenReturn(BACKUP_STARTED_AT);
when(backupService.backupStartedBy()).thenReturn(BACKUP_STARTED_BY);
MockHttpServletRequest request = HttpRequestBuilder.GET("/api/agents").withHeader("Accept", "application/json").build();
backupFilter.doFilter(request, res, chain);
verify(res, times(1)).setContentType("application/json");
JsonObject json = new JsonObject();
assertResponse(json);
}
use of com.thoughtworks.go.http.mocks.MockHttpServletRequest in project gocd by gocd.
the class GenericAccessDeniedHandlerTest method shouldRedirectToLoginPageWhenSecurityIsEnabledAndUserIsNotAuthenticated.
@Test
void shouldRedirectToLoginPageWhenSecurityIsEnabledAndUserIsNotAuthenticated() throws IOException {
final MockHttpServletRequest request = HttpRequestBuilder.GET("/foo").build();
final MockHttpServletResponse response = new MockHttpServletResponse();
SecurityService securityService = mock(SecurityService.class);
SessionUtilsHelper.loginAsAnonymous(request);
when(securityService.isSecurityEnabled()).thenReturn(true);
new GenericAccessDeniedHandler(securityService).handle(request, response, SC_FORBIDDEN, "Some error");
MockHttpServletResponseAssert.assertThat(response).redirectsTo("/go/auth/login");
}
use of com.thoughtworks.go.http.mocks.MockHttpServletRequest in project gocd by gocd.
the class GenericAccessDeniedHandlerTest method shouldAccessDeniedWhenUserIsAuthenticated.
@Test
void shouldAccessDeniedWhenUserIsAuthenticated() throws IOException {
final MockHttpServletRequest request = HttpRequestBuilder.GET("/admin/").build();
final MockHttpServletResponse response = new MockHttpServletResponse();
SecurityService securityService = mock(SecurityService.class);
SessionUtilsHelper.loginAsRandomUser(request, GoAuthority.ROLE_USER.asAuthority());
when(securityService.isSecurityEnabled()).thenReturn(true);
new GenericAccessDeniedHandler(securityService).handle(request, response, SC_FORBIDDEN, "Some error");
MockHttpServletResponseAssert.assertThat(response).isForbidden();
}
Aggregations