use of com.google.gerrit.util.http.testutil.FakeHttpServletResponse in project gerrit by GerritCodeReview.
the class AllRequestFilterFilterProxyTest method dynamicUnloading.
@Test
public void dynamicUnloading() throws Exception {
FilterConfig config = mock(FilterConfig.class);
HttpServletRequest req1 = new FakeHttpServletRequest();
HttpServletRequest req2 = new FakeHttpServletRequest();
HttpServletRequest req3 = new FakeHttpServletRequest();
HttpServletResponse res1 = new FakeHttpServletResponse();
HttpServletResponse res2 = new FakeHttpServletResponse();
HttpServletResponse res3 = new FakeHttpServletResponse();
Plugin plugin = mock(Plugin.class);
FilterChain chain = mock(FilterChain.class);
ArgumentCaptor<FilterChain> capturedChainA1 = ArgumentCaptor.forClass(FilterChain.class);
ArgumentCaptor<FilterChain> capturedChainB1 = ArgumentCaptor.forClass(FilterChain.class);
ArgumentCaptor<FilterChain> capturedChainB2 = ArgumentCaptor.forClass(FilterChain.class);
AllRequestFilter filterA = mock(AllRequestFilter.class);
AllRequestFilter filterB = mock(AllRequestFilter.class);
AllRequestFilter.FilterProxy filterProxy = getFilterProxy();
ReloadableRegistrationHandle<AllRequestFilter> handleFilterA = addFilter(filterA);
ReloadableRegistrationHandle<AllRequestFilter> handleFilterB = addFilter(filterB);
InOrder inorder = inOrder(filterA, filterB, chain);
filterProxy.init(config);
inorder.verify(filterA).init(config);
inorder.verify(filterB).init(config);
// Request #1 with filterA and filterB
filterProxy.doFilter(req1, res1, chain);
inorder.verify(filterA).doFilter(eq(req1), eq(res1), capturedChainA1.capture());
capturedChainA1.getValue().doFilter(req1, res1);
inorder.verify(filterB).doFilter(eq(req1), eq(res1), capturedChainB1.capture());
capturedChainB1.getValue().doFilter(req1, res1);
inorder.verify(chain).doFilter(req1, res1);
// Unloading filterA
handleFilterA.remove();
filterProxy.onStopPlugin(plugin);
// Cleaning up of filterA after it got unloaded
inorder.verify(filterA).destroy();
// Request #2 only with filterB
filterProxy.doFilter(req2, res2, chain);
inorder.verify(filterB).doFilter(eq(req2), eq(res2), capturedChainB2.capture());
inorder.verify(filterA, never()).doFilter(eq(req2), eq(res2), any(FilterChain.class));
capturedChainB2.getValue().doFilter(req2, res2);
inorder.verify(chain).doFilter(req2, res2);
// Unloading filterB
handleFilterB.remove();
filterProxy.onStopPlugin(plugin);
// Cleaning up of filterA after it got unloaded
inorder.verify(filterB).destroy();
// Request #3 with no additional filters
filterProxy.doFilter(req3, res3, chain);
inorder.verify(chain).doFilter(req3, res3);
inorder.verify(filterA, never()).doFilter(eq(req2), eq(res2), any(FilterChain.class));
inorder.verify(filterB, never()).doFilter(eq(req2), eq(res2), any(FilterChain.class));
filterProxy.destroy();
}
use of com.google.gerrit.util.http.testutil.FakeHttpServletResponse in project gerrit by GerritCodeReview.
the class AllRequestFilterFilterProxyTest method twoFiltersNoBubbling.
@Test
public void twoFiltersNoBubbling() throws Exception {
FilterConfig config = mock(FilterConfig.class);
HttpServletRequest req = new FakeHttpServletRequest();
HttpServletResponse res = new FakeHttpServletResponse();
FilterChain chain = mock(FilterChain.class);
AllRequestFilter filterA = mock(AllRequestFilter.class);
AllRequestFilter filterB = mock(AllRequestFilter.class);
AllRequestFilter.FilterProxy filterProxy = getFilterProxy();
addFilter(filterA);
addFilter(filterB);
filterProxy.init(config);
filterProxy.doFilter(req, res, chain);
filterProxy.destroy();
InOrder inorder = inOrder(filterA, filterB);
inorder.verify(filterA).init(config);
inorder.verify(filterB).init(config);
inorder.verify(filterA).doFilter(eq(req), eq(res), any(FilterChain.class));
inorder.verify(filterA).destroy();
inorder.verify(filterB).destroy();
}
use of com.google.gerrit.util.http.testutil.FakeHttpServletResponse in project gerrit by GerritCodeReview.
the class AllRequestFilterFilterProxyTest method singleFilterNoBubbling.
@Test
public void singleFilterNoBubbling() throws Exception {
FilterConfig config = mock(FilterConfig.class);
HttpServletRequest req = new FakeHttpServletRequest();
HttpServletResponse res = new FakeHttpServletResponse();
FilterChain chain = mock(FilterChain.class);
AllRequestFilter filter = mock(AllRequestFilter.class);
AllRequestFilter.FilterProxy filterProxy = getFilterProxy();
addFilter(filter);
filterProxy.init(config);
filterProxy.doFilter(req, res, chain);
filterProxy.destroy();
InOrder inorder = inOrder(filter);
inorder.verify(filter).init(config);
inorder.verify(filter).doFilter(eq(req), eq(res), any(FilterChain.class));
inorder.verify(filter).destroy();
}
use of com.google.gerrit.util.http.testutil.FakeHttpServletResponse in project gerrit by GerritCodeReview.
the class ProjectBasicAuthFilterTest method setUp.
@Before
public void setUp() throws Exception {
req = new FakeHttpServletRequest("gerrit.example.com", 80, "", "");
res = new FakeHttpServletResponse();
extIdKeyFactory = new ExternalIdKeyFactory(new ExternalIdKeyFactory.ConfigImpl(authConfig));
extIdFactory = new ExternalIdFactory(extIdKeyFactory, authConfig);
authRequestFactory = new AuthRequest.Factory(extIdKeyFactory);
pwdVerifier = new PasswordVerifier(extIdKeyFactory, authConfig);
authSuccessful = new AuthResult(AUTH_ACCOUNT_ID, extIdKeyFactory.create("username", AUTH_USER), false);
doReturn(Optional.of(accountState)).when(accountCache).getByUsername(AUTH_USER);
doReturn(Optional.of(accountState)).when(accountCache).get(AUTH_ACCOUNT_ID);
doReturn(account).when(accountState).account();
doReturn(true).when(account).isActive();
doReturn(authSuccessful).when(accountManager).authenticate(any());
doReturn(new WebSessionManager.Key(AUTH_COOKIE_VALUE)).when(webSessionManager).createKey(any());
WebSessionManager.Val webSessionValue = new WebSessionManager.Val(AUTH_ACCOUNT_ID, 0L, false, null, 0L, "", "");
doReturn(webSessionValue).when(webSessionManager).createVal(any(), any(), eq(false), any(), any(), any());
}
use of com.google.gerrit.util.http.testutil.FakeHttpServletResponse in project gerrit by GerritCodeReview.
the class ResourceServletTest method largeFileWithGzip.
@Test
public void largeFileWithGzip() throws Exception {
Cache<Path, Resource> cache = newCache(1);
Servlet servlet = new Servlet(fs, cache, true, 3);
String content = Strings.repeat("a", 100);
writeFile("/foo", content);
FakeHttpServletRequest req = request("/foo").addHeader("Accept-Encoding", "gzip");
FakeHttpServletResponse res = new FakeHttpServletResponse();
servlet.doGet(req, res);
assertThat(res.getStatus()).isEqualTo(SC_OK);
assertThat(res.getHeader("Content-Encoding")).isEqualTo("gzip");
assertThat(gunzip(res.getActualBody())).isEqualTo(content);
assertHasLastModified(res);
assertCacheable(res, true);
}
Aggregations