Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed 14 unnecessary stubbings in AutoLoginFilterTest.java #73

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ public class AutoLoginFilterTest {
@Test
public void testFilter() throws Exception {
ServletContext servletContext = mock(ServletContext.class);
when(servletContext.getContextPath()).thenReturn("/sonar");
FilterConfig filterConfig = mock(FilterConfig.class);
when(filterConfig.getServletContext()).thenReturn(servletContext);

Configuration configurationMock = mock(Configuration.class);
when(configurationMock.getBoolean("sonar.auth." + OidcIdentityProvider.KEY + ".enabled"))
.thenReturn(Optional.of(true));
Expand All @@ -63,9 +60,6 @@ public void testFilter() throws Exception {
filter.doGetPattern();

HttpServletRequest request = mock(HttpServletRequest.class);
when(request.getRequestURL()).thenReturn(new StringBuffer(SONAR_URL + "/sessions/new"));
when(request.getServerName()).thenReturn("acme.com");

HttpServletResponse response = mock(HttpServletResponse.class);

FilterChain chain = mock(FilterChain.class);
Expand All @@ -79,10 +73,7 @@ public void testFilter() throws Exception {
@Test
public void testFilterDisbled() throws Exception {
ServletContext servletContext = mock(ServletContext.class);
when(servletContext.getContextPath()).thenReturn("/sonar");
FilterConfig filterConfig = mock(FilterConfig.class);
when(filterConfig.getServletContext()).thenReturn(servletContext);

Configuration configurationMock = mock(Configuration.class);
when(configurationMock.getBoolean("sonar.auth." + OidcIdentityProvider.KEY + ".enabled"))
.thenReturn(Optional.of(true));
Expand All @@ -92,16 +83,11 @@ public void testFilterDisbled() throws Exception {
.thenReturn(Optional.of("id"));
when(configurationMock.getBoolean("sonar.auth." + OidcIdentityProvider.KEY + ".autoLogin"))
.thenReturn(Optional.of(false));
when(configurationMock.get(CoreProperties.SERVER_BASE_URL)).thenReturn(Optional.of(SONAR_URL));

ServletFilter filter = new AutoLoginFilter(new OidcConfiguration(configurationMock));
filter.init(filterConfig);
filter.doGetPattern();

HttpServletRequest request = mock(HttpServletRequest.class);
when(request.getRequestURL()).thenReturn(new StringBuffer(SONAR_URL + "/sessions/new"));
when(request.getServerName()).thenReturn("acme.com");

HttpServletResponse response = mock(HttpServletResponse.class);

FilterChain chain = mock(FilterChain.class);
Expand All @@ -115,24 +101,17 @@ public void testFilterDisbled() throws Exception {
@Test
public void testFilterTemporarilyDisbled() throws Exception {
ServletContext servletContext = mock(ServletContext.class);
when(servletContext.getContextPath()).thenReturn("/sonar");
FilterConfig filterConfig = mock(FilterConfig.class);
when(filterConfig.getServletContext()).thenReturn(servletContext);

Configuration configurationMock = mock(Configuration.class);
when(configurationMock.getBoolean(OidcConfiguration.ENABLED)).thenReturn(Optional.of(true));
when(configurationMock.get(OidcConfiguration.ISSUER_URI)).thenReturn(Optional.of("http://idp.com"));
when(configurationMock.get(OidcConfiguration.CLIENT_ID)).thenReturn(Optional.of("id"));
when(configurationMock.getBoolean(OidcConfiguration.AUTO_LOGIN)).thenReturn(Optional.of(true));
when(configurationMock.get(CoreProperties.SERVER_BASE_URL)).thenReturn(Optional.of(SONAR_URL));

ServletFilter filter = new AutoLoginFilter(new OidcConfiguration(configurationMock));
filter.init(filterConfig);
filter.doGetPattern();

HttpServletRequest request = mock(HttpServletRequest.class);
when(request.getRequestURL()).thenReturn(new StringBuffer(SONAR_URL + "/sessions/new"));
when(request.getServerName()).thenReturn("acme.com");
when(request.getHeader("referer")).thenReturn(SONAR_URL + "/?auto-login=false");

HttpServletResponse response = mock(HttpServletResponse.class);
Expand Down