Minor bug fixes; more test coverage
git-svn-id: https://svn.apache.org/repos/asf/jakarta/httpcomponents/httpclient/trunk@409996 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7d7da3d68b
commit
cd657a4939
|
@ -68,9 +68,6 @@ public class BasicPathHandler implements CookieAttributeHandler {
|
|||
throw new IllegalArgumentException("Cookie origin may not be null");
|
||||
}
|
||||
String targetpath = origin.getPath();
|
||||
if (targetpath == null) {
|
||||
targetpath = "/";
|
||||
}
|
||||
String topmostPath = cookie.getPath();
|
||||
if (topmostPath == null) {
|
||||
topmostPath = "/";
|
||||
|
|
|
@ -83,7 +83,7 @@ public class BrowserCompatSpec extends CookieSpecBase {
|
|||
if (header == null) {
|
||||
throw new IllegalArgumentException("Header may not be null");
|
||||
}
|
||||
if (header == null) {
|
||||
if (origin == null) {
|
||||
throw new IllegalArgumentException("Cookie origin may not be null");
|
||||
}
|
||||
String headervalue = header.getValue();
|
||||
|
|
|
@ -103,9 +103,6 @@ public abstract class CookieSpecBase extends AbstractCookieSpec {
|
|||
if (origin == null) {
|
||||
throw new IllegalArgumentException("Cookie origin may not be null");
|
||||
}
|
||||
if (cookie.getName() == null || cookie.getName().trim().equals("")) {
|
||||
throw new MalformedCookieException("Cookie name may not be blank");
|
||||
}
|
||||
for (Iterator i = getAttribHandlerIterator(); i.hasNext();) {
|
||||
CookieAttributeHandler handler = (CookieAttributeHandler) i.next();
|
||||
handler.validate(cookie, origin);
|
||||
|
|
|
@ -553,6 +553,23 @@ public class TestBrowserCompatSpec extends TestCase {
|
|||
assertEquals(1, parsed.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if cookie constructor rejects cookie name containing blanks.
|
||||
*/
|
||||
public void testCookieNameBlank() throws Exception {
|
||||
Header header = new Header("Set-Cookie", "=stuff");
|
||||
CookieSpec cookiespec = new BrowserCompatSpec();
|
||||
CookieOrigin origin = new CookieOrigin("127.0.0.1", 80, "/", false);
|
||||
try {
|
||||
Cookie[] parsed = cookiespec.parse(header, origin);
|
||||
for (int i = 0; i < parsed.length; i++) {
|
||||
cookiespec.validate(parsed[i], origin);
|
||||
}
|
||||
fail("MalformedCookieException should have been thrown");
|
||||
} catch (MalformedCookieException expected) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if cookie constructor rejects cookie name starting with $.
|
||||
*/
|
||||
|
@ -885,5 +902,56 @@ public class TestBrowserCompatSpec extends TestCase {
|
|||
new MalformedCookieException("whatever", null);
|
||||
}
|
||||
|
||||
public void testInvalidInput() throws Exception {
|
||||
CookieSpec cookiespec = new BrowserCompatSpec();
|
||||
try {
|
||||
cookiespec.parse(null, null);
|
||||
fail("IllegalArgumentException must have been thrown");
|
||||
} catch (IllegalArgumentException ex) {
|
||||
// expected
|
||||
}
|
||||
try {
|
||||
cookiespec.parse(new Header("Set-Cookie", "name=value"), null);
|
||||
fail("IllegalArgumentException must have been thrown");
|
||||
} catch (IllegalArgumentException ex) {
|
||||
// expected
|
||||
}
|
||||
try {
|
||||
cookiespec.validate(null, null);
|
||||
fail("IllegalArgumentException must have been thrown");
|
||||
} catch (IllegalArgumentException ex) {
|
||||
// expected
|
||||
}
|
||||
try {
|
||||
cookiespec.validate(new Cookie("name", null), null);
|
||||
fail("IllegalArgumentException must have been thrown");
|
||||
} catch (IllegalArgumentException ex) {
|
||||
// expected
|
||||
}
|
||||
try {
|
||||
cookiespec.match(null, null);
|
||||
fail("IllegalArgumentException must have been thrown");
|
||||
} catch (IllegalArgumentException ex) {
|
||||
// expected
|
||||
}
|
||||
try {
|
||||
cookiespec.match(new Cookie("name", null), null);
|
||||
fail("IllegalArgumentException must have been thrown");
|
||||
} catch (IllegalArgumentException ex) {
|
||||
// expected
|
||||
}
|
||||
try {
|
||||
cookiespec.formatCookies(null);
|
||||
fail("IllegalArgumentException must have been thrown");
|
||||
} catch (IllegalArgumentException ex) {
|
||||
// expected
|
||||
}
|
||||
try {
|
||||
cookiespec.formatCookies(new Cookie[] {});
|
||||
fail("IllegalArgumentException must have been thrown");
|
||||
} catch (IllegalArgumentException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue