Merge pull request #1662 from Smartling/KEYCLOAK-1892
WrappedHttpServletRequest may throw an exception returning cookies
This commit is contained in:
commit
7a3b4823b0
2 changed files with 15 additions and 1 deletions
|
@ -64,6 +64,12 @@ class WrappedHttpServletRequest implements Request {
|
|||
@Override
|
||||
public Cookie getCookie(String cookieName) {
|
||||
|
||||
javax.servlet.http.Cookie[] cookies = request.getCookies();
|
||||
|
||||
if (cookies == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (javax.servlet.http.Cookie cookie : request.getCookies()) {
|
||||
if (cookie.getName().equals(cookieName)) {
|
||||
return new Cookie(cookie.getName(), cookie.getValue(), cookie.getVersion(), cookie.getDomain(), cookie.getPath());
|
||||
|
|
|
@ -24,10 +24,11 @@ public class WrappedHttpServletRequestTest {
|
|||
private static final String QUERY_PARM_2 = "code2";
|
||||
|
||||
private WrappedHttpServletRequest request;
|
||||
private MockHttpServletRequest mockHttpServletRequest;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest();
|
||||
mockHttpServletRequest = new MockHttpServletRequest();
|
||||
request = new WrappedHttpServletRequest(mockHttpServletRequest);
|
||||
|
||||
mockHttpServletRequest.setMethod(REQUEST_METHOD);
|
||||
|
@ -75,6 +76,13 @@ public class WrappedHttpServletRequestTest {
|
|||
assertNotNull(request.getCookie(COOKIE_NAME));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCookieCookiesNull() throws Exception
|
||||
{
|
||||
mockHttpServletRequest.setCookies(null);
|
||||
request.getCookie(COOKIE_NAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetHeader() throws Exception {
|
||||
String header = request.getHeader(HEADER_SINGLE_VALUE);
|
||||
|
|
Loading…
Reference in a new issue