-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix favicon download from URL with non-standard port.
Fixes #5001. The favicon download URL was constructed from scheme and host only. This is fixed by simply replacing the path of the original URL with "/favicon.ico", thus keeping scheme, host, auth and port intact. Further modification: URL's with a non-http schema are now rejected. Added TestIconDownloader.cpp covering corner cases.
- Loading branch information
Showing
5 changed files
with
125 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#include "TestIconDownloader.h" | ||
#include <QTest> | ||
#include <gui/IconDownloader.h> | ||
#include <iostream> | ||
#include <vector> | ||
|
||
QTEST_GUILESS_MAIN(TestIconDownloader) | ||
|
||
QList<QString> TestIconDownloader::resolve_favicon_url(const char* url) { | ||
IconDownloader downloader; | ||
downloader.setUrl(QString(url)); | ||
QList<QString> resolved_urls; | ||
for(const auto& resolved_url : downloader.m_urlsToTry) { | ||
resolved_urls.push_back(resolved_url.toString()); | ||
} | ||
return resolved_urls; | ||
} | ||
|
||
void TestIconDownloader::testFaviconResolve() | ||
{ | ||
// Create downloader | ||
IconDownloader downloader; | ||
|
||
const QString keepassxc_favicon("https://keepassxc.org/favicon.ico"); | ||
// Invalid URL | ||
QCOMPARE(resolve_favicon_url("http:sk/s.com"), {}); | ||
|
||
// Unsupported schema | ||
QCOMPARE(resolve_favicon_url("ftp://google.com"), {}); | ||
|
||
// Missing schema | ||
QCOMPARE(resolve_favicon_url("keepassxc.org"), {"http://keepassxc.org/favicon.ico"}); | ||
|
||
// Missing host | ||
QCOMPARE(resolve_favicon_url("https:///register"), {}); | ||
|
||
// URL with path | ||
QCOMPARE(resolve_favicon_url("https://keepassxc.org/register/here"), {keepassxc_favicon}); | ||
|
||
// URL with path and query | ||
QCOMPARE(resolve_favicon_url("https://keepassxc.org/register/here?login=me"), {keepassxc_favicon}); | ||
|
||
// URL with port | ||
QCOMPARE(resolve_favicon_url("https://keepassxc.org:8080"), {"https://keepassxc.org:8080/favicon.ico"}); | ||
|
||
// 2nd level domain | ||
QCOMPARE(resolve_favicon_url("https://login.keepassxc.org"), QList<QString>({"https://login.keepassxc.org/favicon.ico", keepassxc_favicon})); | ||
|
||
// 2nd level domain .co.uk special case | ||
QCOMPARE(resolve_favicon_url("https://login.keepassxc.co.uk"), QList<QString>({"https://login.keepassxc.co.uk/favicon.ico", "https://keepassxc.co.uk/favicon.ico"})); | ||
QCOMPARE(resolve_favicon_url("https://keepassxc.co.uk"), QList<QString>({"https://keepassxc.co.uk/favicon.ico"})); | ||
|
||
// 2nd level domain lots of subdomains | ||
QCOMPARE(resolve_favicon_url("https://de.login.keepassxc.org"), QList<QString>({"https://de.login.keepassxc.org/favicon.ico", keepassxc_favicon})); | ||
|
||
// IP | ||
QCOMPARE(resolve_favicon_url("https://134.130.155.184"), QList<QString>({"https://134.130.155.184/favicon.ico"})); | ||
QCOMPARE(resolve_favicon_url("134.130.155.184"), QList<QString>({"http://134.130.155.184/favicon.ico"})); | ||
|
||
// IP with path | ||
QCOMPARE(resolve_favicon_url("https://134.130.155.184/with/path"), QList<QString>({"https://134.130.155.184/favicon.ico"})); | ||
|
||
// IP with port | ||
QCOMPARE(resolve_favicon_url("https://134.130.155.184:8080/test"), QList<QString>({"https://134.130.155.184:8080/favicon.ico"})); | ||
QCOMPARE(resolve_favicon_url("134.130.155.184:8080/test"), QList<QString>({"http://134.130.155.184:8080/favicon.ico"})); | ||
|
||
// URL with Username + Password | ||
QCOMPARE(resolve_favicon_url("https://user:password@keepassxc.org"), QList<QString>({"https://user:password@keepassxc.org/favicon.ico"})); | ||
QCOMPARE(resolve_favicon_url("https://user:password@de.login.keepassxc.org"), QList<QString>({"https://user:password@de.login.keepassxc.org/favicon.ico", "https://user:password@keepassxc.org/favicon.ico"})); | ||
|
||
// IP with Username + Password | ||
QCOMPARE(resolve_favicon_url("https://user:password@134.130.155.184"), QList<QString>({"https://user:password@134.130.155.184/favicon.ico"})); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (C) 2011 Felix Geyer <debfx@fobos.de> | ||
* Copyright (C) 2019 KeePassXC Team <team@keepassxc.org> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 2 or (at your option) | ||
* version 3 of the License. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef KEEPASSXC_TESTICONDOWNLOADER_HPP | ||
#define KEEPASSXC_TESTICONDOWNLOADER_HPP | ||
|
||
#include <QObject> | ||
|
||
class TestIconDownloader : public QObject | ||
{ | ||
Q_OBJECT | ||
|
||
private slots: | ||
void testFaviconResolve(); | ||
|
||
private: | ||
QList<QString> resolve_favicon_url(const char* url); | ||
}; | ||
|
||
#endif // KEEPASSXC_TESTICONDOWNLOADER_HPP |