ProxyServletService extends HttpServlet { void maybeAppendAuthHeader(URI uri, Request request) { if (uri != null && uri.getUserInfo() != null) { String[] userInfo = uri.getUserInfo().split(":"); if (userInfo.length >= 1) { String user = userInfo[0]; String password = userInfo.length >= 2 ? userInfo[1] : null; String authString = password != null ? user + ":" + password : user + ":"; String basicAuthentication = "Basic " + B64Code.encode(authString, StringUtil.__ISO_8859_1); request.header(HttpHeader.AUTHORIZATION, basicAuthentication); } } }   static final String PROXY_ALIAS; static final String ATTR_URI; static final String ATTR_SERVLET_EXCEPTION; }
@Test public void testMaybeAppendAuthHeaderWithFullCredentials() throws URISyntaxException { Request request = mock(Request.class); URI uri = new URI("http: service.maybeAppendAuthHeader(uri, request); verify(request).header(HttpHeader.AUTHORIZATION, "Basic " + B64Code.encode("testuser:testpassword", StringUtil.__ISO_8859_1)); }
@Test public void testMaybeAppendAuthHeaderWithoutPassword() throws URISyntaxException { Request request = mock(Request.class); URI uri = new URI("http: service.maybeAppendAuthHeader(uri, request); verify(request).header(HttpHeader.AUTHORIZATION, "Basic " + B64Code.encode("testuser:", StringUtil.__ISO_8859_1)); }
@Test public void testMaybeAppendAuthHeaderWithoutCredentials() throws URISyntaxException { Request request = mock(Request.class); URI uri = new URI("http: service.maybeAppendAuthHeader(uri, request); verify(request, never()).header(any(HttpHeader.class), anyString()); }