Commit 6b8cdfa3 authored by 's avatar

Add Unit Test for CookieJar

Adds a unit test in "tests/cookie_test.cc" for "CookieJar.addFromRaw".
Additionally, "CookieJar.addFromRaw" now skips all whitespace between cookies.
Not sure what the HTTP standard requires, but this seems to be the safest bet
in the case of no whitespace or multiple whitespace delimiting cookies.
parent befdba10
......@@ -234,7 +234,8 @@ CookieJar::addFromRaw(const char *str, size_t len) {
Cookie cookie(std::move(name), std::move(value));
add(cookie);
cursor.advance(2);
cursor.advance(1);
skip_whitespaces(cursor);
}
}
......
......@@ -129,3 +129,22 @@ TEST(cookie_test, invalid_test) {
ASSERT_THROW(Cookie::fromString("lang=en-US; Max-Age=12ab"), std::invalid_argument);
}
void addCookies(const char* str, std::function<void (const CookieJar&)> testFunc) {
CookieJar jar;
jar.addFromRaw(str, strlen(str));
testFunc(jar);
}
TEST(cookie_test, cookiejar_test) {
addCookies("key1=value1", [](const CookieJar& jar) {
ASSERT_EQ(jar.get("key1").value, "value1");
});
addCookies("key2=value2; key3=value3", [](const CookieJar& jar) {
ASSERT_EQ(jar.get("key2").value, "value2");
ASSERT_EQ(jar.get("key3").value, "value3");
});
CookieJar jar;
ASSERT_THROW(jar.addFromRaw("key4", strlen("key4")), std::runtime_error);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment