void
BNetworkCookieJar::_DoFlatten() const
{
    fFlattened.Truncate(0);

    BNetworkCookie* cookiePtr;
    for (Iterator it = GetIterator(); (cookiePtr = it.Next()) != NULL;) {
        fFlattened 	<< cookiePtr->Domain() << '\t' << "TRUE" << '\t'
                    << cookiePtr->Path() << '\t'
                    << (cookiePtr->Secure()?"TRUE":"FALSE") << '\t'
                    << (int32)cookiePtr->ExpirationDate() << '\t'
                    << cookiePtr->Name() << '\t' << cookiePtr->Value() << '\n';
    }
}
Ejemplo n.º 2
0
void explodeImplodeTest()
{
	uint8 testIndex;
	BNetworkCookie cookie;

	for (testIndex = 0; testIndex < (sizeof(kTestExplode) / sizeof(ExplodeTest)); testIndex++)
	{
		cookie.ParseCookieString(kTestExplode[testIndex].cookieString);

		ASSERT(testIndex, BString(kTestExplode[testIndex].expected.name) == BString(cookie.Name()));
		ASSERT(testIndex, BString(kTestExplode[testIndex].expected.value) == BString(cookie.Value()));
		ASSERT(testIndex, BString(kTestExplode[testIndex].expected.domain) == BString(cookie.Domain()));
		ASSERT(testIndex, BString(kTestExplode[testIndex].expected.path) == BString(cookie.Path()));
		ASSERT(testIndex, kTestExplode[testIndex].expected.secure == cookie.Secure());
		ASSERT(testIndex, kTestExplode[testIndex].expected.discard == cookie.Discard());
		ASSERT(testIndex, kTestExplode[testIndex].expected.session == cookie.IsSessionCookie());

		if (!cookie.IsSessionCookie())
			ASSERT(testIndex, kTestExplode[testIndex].expected.maxAge == cookie.MaxAge());
	}
}
Ejemplo n.º 3
0
void
CookieTest::ExplodeTest()
{
	struct Test {
		const char* cookieString;
		const char*	url;
		struct
		{
			bool		valid;
			const char* name;
			const char* value;
			const char* domain;
			const char* path;
			bool 		secure;
			bool 		httponly;
			bool		session;
			BDateTime	expire;
		} expected;
	};

	Test tests[] = {
	//     Cookie string      URL
	//     ------------- -------------
	//		   Valid     Name     Value	       Domain         Path      Secure  HttpOnly Session  Expiration
	//       --------- -------- --------- ----------------- ---------  -------- -------- -------  ----------
		// Normal cookies
		{ "name=value", "http://www.example.com/path/path",
			{  true,    "name",  "value", "www.example.com", "/path",   false,   false,   true,   BDateTime() } },
		{ "name=value; domain=example.com; path=/; secure", "http://www.example.com/path/path",
			{  true,    "name",  "value",   "example.com",   "/"    ,   true,    false,   true,   BDateTime() } },
		{ "name=value; httponly; secure", "http://www.example.com/path/path",
			{  true,    "name",  "value", "www.example.com", "/path",   true,    true,    true,   BDateTime() } },
		{ "name=value; expires=Wed, 20-Feb-2013 20:00:00 UTC", "http://www.example.com/path/path",
			{  true,    "name",  "value", "www.example.com", "/path",   false,   false,   false,
				BDateTime(BDate(2013, 2, 20), BTime(20, 0, 0, 0)) } },
		// Valid cookie with bad form
		{ "name=  ;  domain   =example.com  ;path=/;  secure = yup  ; blahblah ;)", "http://www.example.com/path/path",
			{  true,    "name",  "",   "example.com",   "/"    ,   true,    false,   true,   BDateTime() } },
		// Invalid path
		{ "name=value; path=invalid", "http://www.example.com/path/path",
			{  false,    "name",  "value", "www.example.com", "/path",   false,   false,   true,   BDateTime() } },
		// Setting for other subdomain (invalid)
		{ "name=value; domain=subdomain.example.com", "http://www.example.com/path/path",
			{  false,   "name",  "value", "www.example.com", "/path",   false,   false,   true,   BDateTime() } },
		// Various invalid cookies
		{ "name", "http://www.example.com/path/path",
			{  false,   "name",  "value", "www.example.com", "/path",   false,   false,   true,   BDateTime() } },
		{ "; domain=example.com", "http://www.example.com/path/path",
			{  false,   "name",  "value", "www.example.com", "/path",   false,   false,   true,   BDateTime() } }
	};
	
	BNetworkCookie cookie;

	for (uint32 i = 0; i < (sizeof(tests) / sizeof(Test)); i++) {
		NextSubTest();

		BUrl url(tests[i].url);
		cookie.ParseCookieString(tests[i].cookieString, url);

		CPPUNIT_ASSERT(tests[i].expected.valid == cookie.IsValid());

		if (!tests[i].expected.valid)
			continue;

		CPPUNIT_ASSERT_EQUAL(BString(tests[i].expected.name), cookie.Name());
		CPPUNIT_ASSERT_EQUAL(BString(tests[i].expected.value), cookie.Value());
		CPPUNIT_ASSERT_EQUAL(BString(tests[i].expected.domain),
			cookie.Domain());
		CPPUNIT_ASSERT_EQUAL(BString(tests[i].expected.path), cookie.Path());
		CPPUNIT_ASSERT(tests[i].expected.secure == cookie.Secure());
		CPPUNIT_ASSERT(tests[i].expected.httponly == cookie.HttpOnly());
		CPPUNIT_ASSERT(tests[i].expected.session == cookie.IsSessionCookie());

		if (!cookie.IsSessionCookie())
			CPPUNIT_ASSERT_EQUAL(tests[i].expected.expire.Time_t(),
				cookie.ExpirationDate());
	}
}