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
	CookieRow(BColumnListView* list, const BNetworkCookie& cookie)
		:
		BRow(),
		fCookie(cookie)
	{
		list->AddRow(this);
		SetField(new BStringField(cookie.Name().String()), 0);
		SetField(new BStringField(cookie.Path().String()), 1);
		time_t expiration = cookie.ExpirationDate();
		SetField(new BDateField(&expiration), 2);
		SetField(new BStringField(cookie.Value().String()), 3);

		BString flags;
		if (cookie.Secure())
			flags = "https ";
		if (cookie.HttpOnly())
			flags = "http ";

		if (cookie.IsHostOnly())
			flags += "hostOnly";
		SetField(new BStringField(flags.String()), 4);
	}
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());
	}
}