Skip to content

Commit 13735da

Browse files
committed
[QA] Add unit test for validateURL()
1 parent a62f88a commit 13735da

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/test/util_tests.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,38 @@ BOOST_AUTO_TEST_CASE(test_Capitalize)
969969
BOOST_CHECK_EQUAL(Capitalize("\x00\xfe\xff"), "\x00\xfe\xff");
970970
}
971971

972+
BOOST_AUTO_TEST_CASE(test_validateURL)
973+
{
974+
// Must pass
975+
BOOST_CHECK(validateURL("http://foo.bar"));
976+
BOOST_CHECK(validateURL("https://foo.bar"));
977+
BOOST_CHECK(validateURL("https://foo.bar/"));
978+
BOOST_CHECK(validateURL("http://pivx.foo.bar"));
979+
BOOST_CHECK(validateURL("https://foo.bar/pivx"));
980+
BOOST_CHECK(validateURL("https://foo.bar/pivx/more/"));
981+
BOOST_CHECK(validateURL("https://142.2.3.1"));
982+
BOOST_CHECK(validateURL("https://foo_bar.pivx.com"));
983+
BOOST_CHECK(validateURL("http://foo.bar/?baz=some"));
984+
BOOST_CHECK(validateURL("http://foo.bar/?baz=some&p=364"));
985+
986+
// Must fail
987+
BOOST_CHECK(!validateURL("BlahBlah"));
988+
BOOST_CHECK(!validateURL("foo.bar"));
989+
BOOST_CHECK(!validateURL("://foo.bar"));
990+
BOOST_CHECK(!validateURL("www.foo.bar"));
991+
BOOST_CHECK(!validateURL("http://foo..bar"));
992+
BOOST_CHECK(!validateURL("http:///foo.bar"));
993+
BOOST_CHECK(!validateURL("http:// foo.bar"));
994+
BOOST_CHECK(!validateURL("http://foo .bar"));
995+
BOOST_CHECK(!validateURL("http://foo"));
996+
BOOST_CHECK(!validateURL("http://foo.bar."));
997+
BOOST_CHECK(!validateURL("http://foo.bar.."));
998+
BOOST_CHECK(!validateURL("http://"));
999+
BOOST_CHECK(!validateURL("http://.something.com"));
1000+
BOOST_CHECK(!validateURL("http://?something.com"));
1001+
BOOST_CHECK(!validateURL("https://foo.bar/?q=Spaces are not encoded"));
1002+
}
1003+
9721004
static void TestOtherThread(fs::path dirname, std::string lockname, bool *result)
9731005
{
9741006
*result = LockDirectory(dirname, lockname);

0 commit comments

Comments
 (0)