use of org.springframework.mock.web.MockHttpServletResponse in project gocd by gocd.
the class BasicAuthenticationFilterTest method setUp.
@Before
public void setUp() throws Exception {
errorMessage = "There was an error authenticating you. Please check the go server logs, or contact the go server administrator.";
httpRequest = new MockHttpServletRequest();
httpResponse = new MockHttpServletResponse();
localizer = mock(Localizer.class);
filter = new BasicAuthenticationFilter(localizer);
when(localizer.localize("AUTHENTICATION_ERROR")).thenReturn(errorMessage);
}
use of org.springframework.mock.web.MockHttpServletResponse in project gocd by gocd.
the class BasicAuthenticationFilterTest method shouldConvey_itsBasicProcessingFilter.
@Test
public void shouldConvey_itsBasicProcessingFilter() throws IOException, ServletException {
BasicAuthenticationFilter filter = new BasicAuthenticationFilter(localizer);
final Boolean[] hadBasicMarkOnInsideAuthenticationManager = new Boolean[] { false };
filter.setAuthenticationManager(new AuthenticationManager() {
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
hadBasicMarkOnInsideAuthenticationManager[0] = BasicAuthenticationFilter.isProcessingBasicAuth();
return new UsernamePasswordAuthenticationToken("school-principal", "u can be principal if you know this!");
}
});
assertThat(BasicAuthenticationFilter.isProcessingBasicAuth(), is(false));
MockHttpServletRequest httpRequest = new MockHttpServletRequest();
httpRequest.addHeader("Authorization", "Basic " + Base64.getEncoder().encodeToString("loser:boozer".getBytes()));
filter.doFilterHttp(httpRequest, new MockHttpServletResponse(), new FilterChain() {
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse) throws IOException, ServletException {
}
});
assertThat(BasicAuthenticationFilter.isProcessingBasicAuth(), is(false));
assertThat(hadBasicMarkOnInsideAuthenticationManager[0], is(true));
}
use of org.springframework.mock.web.MockHttpServletResponse in project gocd by gocd.
the class BasicProcessingFilterEntryPointTest method testShouldRender401WithWithHTMLWithNoAcceptHeader.
@Test
public void testShouldRender401WithWithHTMLWithNoAcceptHeader() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
new BasicProcessingFilterEntryPoint().commence(request, response, new BadCredentialsException("foo"));
assertEquals("Basic realm=\"GoCD\"", response.getHeader("WWW-Authenticate"));
assertEquals(401, response.getStatus());
assertEquals("foo", response.getErrorMessage());
}
use of org.springframework.mock.web.MockHttpServletResponse in project gocd by gocd.
the class GoExceptionTranslationFilterTest method setUp.
@Before
public void setUp() {
request = new MockHttpServletRequest();
response = new MockHttpServletResponse();
filterChain = mock(FilterChain.class);
authenticationException = mock(AuthenticationException.class);
basicAuth = mock(BasicProcessingFilterEntryPoint.class);
cruiseLoginFormAuth = mock(AuthenticationEntryPoint.class);
securityService = mock(SecurityService.class);
filter = new GoExceptionTranslationFilter();
filter.setUrlPatternsThatShouldNotBeRedirectedToAfterLogin("(\\.json)|(/images/)");
filter.setAuthenticationEntryPoint(cruiseLoginFormAuth);
filter.setBasicAuthenticationEntryPoint(basicAuth);
filter.setSecurityService(securityService);
}
use of org.springframework.mock.web.MockHttpServletResponse in project gocd by gocd.
the class StageControllerIntegrationTest method setUp.
@Before
public void setUp() throws Exception {
fixture = new PipelineWithMultipleStages(3, materialRepository, transactionTemplate, temporaryFolder);
this.configHelper = new GoConfigFileHelper();
configHelper.usingCruiseConfigDao(goConfigDao);
configHelper.onSetUp();
fixture.usingConfigHelper(configHelper).usingDbHelper(dbHelper).onSetUp();
request = new MockHttpServletRequest();
response = new MockHttpServletResponse();
request.addHeader("Confirm", "true");
}
Aggregations