diff --git a/webenginepart/autotests/webenginepartcookiejar_test.cpp b/webenginepart/autotests/webenginepartcookiejar_test.cpp --- a/webenginepart/autotests/webenginepartcookiejar_test.cpp +++ b/webenginepart/autotests/webenginepartcookiejar_test.cpp @@ -108,14 +108,16 @@ "persistent cookie with domain and path", "session cookie with domain and path", "persistent cookie with domain and no path", + "persistent cookie with domain and / as path", "persistent cookie with path and no domain", "persistent cookie without secure", }; const QList input{ {m_cookieName + "-persistent", "test-value", ".yyy.xxx.com", "/abc/def/", "zzz.yyy.xxx.com", QDateTime::currentDateTime().addYears(1), true}, {m_cookieName + "-session", "test-value", ".yyy.xxx.com", "/abc/def/", "zzz.yyy.xxx.com", QDateTime(), true}, {m_cookieName + "-no-path", "test-value", ".yyy.xxx.com", "", "zzz.yyy.xxx.com", QDateTime::currentDateTime().addYears(1), true}, + {m_cookieName + "-slash-as-path", "test-value", ".yyy.xxx.com", "", "zzz.yyy.xxx.com", QDateTime::currentDateTime().addYears(1), true}, {m_cookieName + "-no-domain", "test-value", "", "/abc/def/", "zzz.yyy.xxx.com", QDateTime::currentDateTime().addYears(1), true}, {m_cookieName + "-no-secure", "test-value", ".yyy.xxx.com", "/abc/def/", "zzz.yyy.xxx.com", QDateTime::currentDateTime().addYears(1), false} }; @@ -229,22 +231,25 @@ QTest::addColumn("cookie"); QTest::addColumn("name"); QTest::addColumn("domain"); + QTest::addColumn("path"); QTest::addColumn("host"); const QStringList labels{ "remove persistent cookie with domain and path", "remove session cookie with domain and path", "remove persistent cookie with domain and no path", + "remove persistent cookie with domain and / as path", "remove persistent cookie with path and no domain", - "remove persistent cookie without secure", + "remove persistent cookie without secure" }; const QList input{ {m_cookieName + "-persistent-remove", "test-remove-value", ".yyy.xxx.com", "/abc/def/", "zzz.yyy.xxx.com", QDateTime::currentDateTime().addYears(1), true}, {m_cookieName + "-session-remove", "test-remove-value", ".yyy.xxx.com", "/abc/def/", "zzz.yyy.xxx.com", QDateTime(), true}, {m_cookieName + "-no-path-remove", "test-remove-value", ".yyy.xxx.com", "", "zzz.yyy.xxx.com", QDateTime::currentDateTime().addYears(1), true}, + {m_cookieName + "-slash-as-path-remove", "test-remove-value", ".yyy.xxx.com", "/", "zzz.yyy.xxx.com", QDateTime::currentDateTime().addYears(1), true}, {m_cookieName + "-no-domain-remove", "test-remove-value", "", "/abc/def/", "zzz.yyy.xxx.com", QDateTime::currentDateTime().addYears(1), true}, - {m_cookieName + "-no-secure-remove", "test-remove-value", ".yyy.xxx.com", "/abc/def/", "zzz.yyy.xxx.com", QDateTime::currentDateTime().addYears(1), false} + {m_cookieName + "-no-secure-remove", "test-remove-value", ".yyy.xxx.com", "/abc/def/", "zzz.yyy.xxx.com", QDateTime::currentDateTime().addYears(1), false}, }; QList expected(input); @@ -256,32 +261,38 @@ if (in.domain.isEmpty()) { c.normalize(QUrl("https://" + in.host)); } - QTest::newRow(labels.at(i).toLatin1()) << c << ex.name << ex.domain << ex.host; + QTest::newRow(labels.at(i).toLatin1()) << c << ex.name << ex.domain << ex.path << ex.host; }} void TestWebEnginePartCookieJar::testCookieRemovedFromStoreAreRemovedFromKCookieServer() { QFETCH(const QNetworkCookie, cookie); QFETCH(const QString, name); QFETCH(const QString, domain); + QFETCH(const QString, path); QFETCH(const QString, host); //Add cookie to KCookieServer QDBusError e = addCookieToKCookieServer(cookie, host); QVERIFY2(!e.isValid(), qPrintable(m_server->lastError().message())); + auto findCookies=[this, &domain, &host, &path, &name](){ + QDBusReply reply = m_server->call(QDBus::Block, "findCookies", QVariant::fromValue(QList{2}), domain, host, path, name); + return reply; + }; + //Ensure cookie has been added to KCookieServer - QDBusReply reply = m_server->call(QDBus::Block, "findCookies", QVariant::fromValue(QList{2}), domain, host, "", ""); + QDBusReply reply = findCookies(); QVERIFY2(reply.isValid(), qPrintable(reply.error().message())); - QStringList cookies = reply.value(); - QVERIFY2(cookies.contains(name), "Cookie wasn't added to server"); - + QVERIFY2(reply.value().contains(name), "Cookie wasn't added to server"); + //Emit QWebEngineCookieStore::cookieRemoved signal and check that cookie has indeed been removed emit m_store->cookieRemoved(cookie); - reply = m_server->call(QDBus::Block, "findCookies", QVariant::fromValue(QList{2}), domain, "", "", ""); + + //Check that cookie is no longer in KCookieServer + reply = findCookies(); QVERIFY2(reply.isValid(), qPrintable(reply.error().message())); - cookies = reply.value(); - QVERIFY2(!cookies.contains(name), "Cookie wasn't removed from server"); + QVERIFY2(!reply.value().contains(name), "Cookie wasn't removed from server"); } QDBusError TestWebEnginePartCookieJar::addCookieToKCookieServer(const QNetworkCookie& _cookie, const QString& host) diff --git a/webenginepart/src/webenginepartcookiejar.cpp b/webenginepart/src/webenginepartcookiejar.cpp --- a/webenginepart/src/webenginepartcookiejar.cpp +++ b/webenginepart/src/webenginepartcookiejar.cpp @@ -269,7 +269,7 @@ } removeCookieDomain(cookie); - QDBusPendingCall pcall = m_cookieServer.asyncCall("deleteCookie", cookie.domain(), url.toString(), cookie.path(), QString(cookie.name())); + QDBusPendingCall pcall = m_cookieServer.asyncCall("deleteCookie", cookie.domain(), url.host(), cookie.path(), QString(cookie.name())); QDBusPendingCallWatcher *w = new QDBusPendingCallWatcher(pcall, this); connect(w, &QDBusPendingCallWatcher::finished, this, &WebEnginePartCookieJar::cookieRemovalFailed); } @@ -331,7 +331,7 @@ { QNetworkCookie c; auto extractField = [data, start](CookieDetails field){return data.at(start + static_cast(field));}; - c.setDomain(data.at(start+static_cast(CookieDetails::domain)).toUtf8()); + c.setDomain(extractField(CookieDetails::domain).toUtf8()); c.setExpirationDate(QDateTime::fromSecsSinceEpoch(extractField(CookieDetails::expirationDate).toInt())); c.setName(extractField(CookieDetails::name).toUtf8()); c.setPath(extractField(CookieDetails::path).toUtf8());