improve unit test coverage and fix handling of some invalid .torrent files and invalid utf-8 sequences
This commit is contained in:
@@ -53,7 +53,23 @@ EXTRA_DIST = Jamfile \
|
||||
test_torrents/empty_httpseed.torrent \
|
||||
test_torrents/long_name.torrent \
|
||||
test_torrents/whitespace_url.torrent \
|
||||
test_torrents/duplicate_files.torrent
|
||||
test_torrents/duplicate_files.torrent \
|
||||
test_torrents/invalid_piece_len.torrent \
|
||||
test_torrents/missing_piece_len.torrent \
|
||||
test_torrents/negative_piece_len.torrent \
|
||||
test_torrents/no_name.torrent \
|
||||
test_torrents/invalid_name.torrent \
|
||||
test_torrents/invalid_name2.torrent \
|
||||
test_torrents/invalid_info.torrent \
|
||||
test_torrents/string.torrent \
|
||||
test_torrents/negative_size.torrent \
|
||||
test_torrents/negative_file_size.torrent \
|
||||
test_torrents/pad_file.torrent \
|
||||
test_torrents/invalid_path_list.torrent \
|
||||
test_torrents/missing_path_list.torrent \
|
||||
test_torrents/invalid_pieces.torrent \
|
||||
test_torrents/unaligned_pieces.torrent \
|
||||
test_torrents/creation_date.torrent
|
||||
|
||||
EXTRA_PROGRAMS = $(test_programs)
|
||||
|
||||
|
@@ -1314,14 +1314,14 @@ int test_main()
|
||||
// valid 2-byte sequence
|
||||
test = "filename\xc2\xa1";
|
||||
TEST_CHECK(verify_encoding(test));
|
||||
fprintf(stderr, "%s %x %x\n", test.c_str(), test[test.size()-2], test[test.size()-1]);
|
||||
fprintf(stderr, "%s\n", test.c_str());
|
||||
TEST_CHECK(test == "filename\xc2\xa1");
|
||||
|
||||
// truncated 2-byte sequence
|
||||
test = "filename\xc2";
|
||||
TEST_CHECK(!verify_encoding(test));
|
||||
fprintf(stderr, "%s %x %x\n", test.c_str(), test[test.size()-2], test[test.size()-1]);
|
||||
TEST_CHECK(test == "filename\xc3\x82");
|
||||
fprintf(stderr, "%s\n", test.c_str());
|
||||
TEST_CHECK(test == "filename_");
|
||||
|
||||
// valid 3-byte sequence
|
||||
test = "filename\xe2\x9f\xb9";
|
||||
@@ -1332,26 +1332,32 @@ int test_main()
|
||||
// truncated 3-byte sequence
|
||||
test = "filename\xe2\x9f";
|
||||
TEST_CHECK(!verify_encoding(test));
|
||||
fprintf(stderr, "%s %x %x\n", test.c_str(), test[test.size()-2], test[test.size()-1]);
|
||||
TEST_CHECK(test == "filename\xc3\xa2");
|
||||
fprintf(stderr, "%s\n", test.c_str());
|
||||
TEST_CHECK(test == "filename_");
|
||||
|
||||
// truncated 3-byte sequence
|
||||
test = "filename\xe2";
|
||||
TEST_CHECK(!verify_encoding(test));
|
||||
fprintf(stderr, "%s %x %x\n", test.c_str(), test[test.size()-2], test[test.size()-1]);
|
||||
TEST_CHECK(test == "filename\xc3\xa2");
|
||||
fprintf(stderr, "%s\n", test.c_str());
|
||||
TEST_CHECK(test == "filename_");
|
||||
|
||||
// valid 4-byte sequence
|
||||
test = "filename\xf0\x9f\x92\x88";
|
||||
TEST_CHECK(verify_encoding(test));
|
||||
fprintf(stderr, "%s %x %x\n", test.c_str(), test[test.size()-2], test[test.size()-1]);
|
||||
fprintf(stderr, "%s\n", test.c_str());
|
||||
TEST_CHECK(test == "filename\xf0\x9f\x92\x88");
|
||||
|
||||
// truncated 4-byte sequence
|
||||
test = "filename\xf0\x9f\x92";
|
||||
TEST_CHECK(!verify_encoding(test));
|
||||
fprintf(stderr, "%s %x %x\n", test.c_str(), test[test.size()-2], test[test.size()-1]);
|
||||
TEST_CHECK(test == "filename\xc3\xb0");
|
||||
fprintf(stderr, "%s\n", test.c_str());
|
||||
TEST_CHECK(test == "filename_");
|
||||
|
||||
// 5-byte utf-8 sequence (not allowed)
|
||||
test = "filename\xf8\x9f\x9f\x9f\x9f""foobar";
|
||||
TEST_CHECK(!verify_encoding(test));
|
||||
fprintf(stderr, "%s\n", test.c_str());
|
||||
TEST_CHECK(test == "filename_____foobar");
|
||||
|
||||
// trim_path_element
|
||||
|
||||
|
@@ -58,30 +58,45 @@ test_torrent_t test_torrents[] =
|
||||
{ "long_name.torrent" },
|
||||
{ "whitespace_url.torrent" },
|
||||
{ "duplicate_files.torrent" },
|
||||
// { "" },
|
||||
{ "pad_file.torrent" },
|
||||
{ "creation_date.torrent" },
|
||||
};
|
||||
|
||||
struct test_failing_torrent_t
|
||||
{
|
||||
char const* file;
|
||||
error_code error; // the expected error
|
||||
};
|
||||
|
||||
test_failing_torrent_t test_error_torrents[] =
|
||||
{
|
||||
{ "missing_piece_len.torrent", errors::torrent_missing_piece_length },
|
||||
{ "invalid_piece_len.torrent", errors::torrent_missing_piece_length },
|
||||
{ "negative_piece_len.torrent", errors::torrent_missing_piece_length },
|
||||
{ "no_name.torrent", errors::torrent_missing_name },
|
||||
{ "invalid_name.torrent", errors::torrent_missing_name },
|
||||
{ "invalid_name2.torrent", errors::torrent_invalid_name },
|
||||
{ "invalid_info.torrent", errors::torrent_missing_info },
|
||||
{ "string.torrent", errors::torrent_is_no_dict },
|
||||
{ "negative_size.torrent", errors::torrent_file_parse_failed},
|
||||
{ "negative_file_size.torrent", errors::torrent_file_parse_failed },
|
||||
{ "invalid_path_list.torrent", errors::torrent_file_parse_failed },
|
||||
{ "missing_path_list.torrent", errors::torrent_file_parse_failed },
|
||||
{ "invalid_pieces.torrent", errors::torrent_missing_pieces },
|
||||
{ "unaligned_pieces.torrent", errors::torrent_invalid_hashes },
|
||||
};
|
||||
|
||||
// TODO: create a separate list of all torrents that should
|
||||
// fail to parse, and include the expected error code in that list
|
||||
|
||||
// TODO: merkle torrents. specifically torrent_info::add_merkle_nodes and torrent with "root hash"
|
||||
// TODO: torrent where info-section is not a dict
|
||||
// TODO: torrent with "piece length" <= 0
|
||||
// TODO: torrent with no "name" nor "name.utf8"
|
||||
// TODO: torrent with "name" refering to an invalid path
|
||||
// TODO: torrent with 'p' (padfile) attribute
|
||||
// TODO: torrent with 'h' (hidden) attribute
|
||||
// TODO: torrent with 'x' (executable) attribute
|
||||
// TODO: torrent with 'l' (symlink) attribute
|
||||
// TODO: torrent with bitcomet style padfiles (name convention)
|
||||
// TODO: torrent with a negative file size
|
||||
// TODO: torrent with a negative total size
|
||||
// TODO: torrent with a pieces field that's not a string
|
||||
// TODO: torrent with a pieces field whose length is not divisible by 20
|
||||
// TODO: creating a merkle torrent (torrent_info::build_merkle_list)
|
||||
// TODO: torrent with multiple trackers in multiple tiers, making sure we shuffle them (how do you test shuffling?, load it multiple times and make sure it's in different order at least once)
|
||||
// TODO: torrent with web seed. make sure we append '/' for multifile torrents
|
||||
// TODO: test that creation date is parsed correctly
|
||||
|
||||
int test_main()
|
||||
{
|
||||
@@ -105,6 +120,16 @@ int test_main()
|
||||
TEST_CHECK(ti->file_at(0).path == "temp/foo/bar.txt");
|
||||
TEST_CHECK(ti->file_at(1).path == "temp/foo/bar.1.txt");
|
||||
}
|
||||
else if (std::string(test_torrents[i].file) == "pad_file.torrent")
|
||||
{
|
||||
TEST_EQUAL(ti->num_files(), 2);
|
||||
TEST_CHECK(ti->file_at(0).pad_file == false);
|
||||
TEST_CHECK(ti->file_at(1).pad_file == true);
|
||||
}
|
||||
else if (std::string(test_torrents[i].file) == "creation_date.torrent")
|
||||
{
|
||||
TEST_CHECK(*ti->creation_date() == 1234567);
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
for (torrent_info::file_iterator i = ti->begin_files();
|
||||
@@ -127,6 +152,16 @@ int test_main()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (int i = 0; i < sizeof(test_error_torrents)/sizeof(test_error_torrents[0]); ++i)
|
||||
{
|
||||
error_code ec;
|
||||
fprintf(stderr, "loading %s\n", test_error_torrents[i].file);
|
||||
boost::intrusive_ptr<torrent_info> ti(new torrent_info(combine_path("test_torrents", test_error_torrents[i].file), ec));
|
||||
fprintf(stderr, "E: %s\nexpected: %s\n", ec.message().c_str(), test_error_torrents[i].error.message().c_str());
|
||||
TEST_EQUAL(ec, test_error_torrents[i].error);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
1
test/test_torrents/creation_date.torrent
Normal file
1
test/test_torrents/creation_date.torrent
Normal file
@@ -0,0 +1 @@
|
||||
d10:created by10:libtorrent13:creation datei1234567e4:infod5:filesld6:lengthi425e4:pathl3:foo7:bar.txteed6:lengthi425e4:pathl3:foo7:var.txteee4:name4:temp12:piece lengthi16384e6:pieces20:01234567890123456789ee
|
1
test/test_torrents/invalid_info.torrent
Normal file
1
test/test_torrents/invalid_info.torrent
Normal file
@@ -0,0 +1 @@
|
||||
d10:created by10:libtorrent13:creation datei1359599503e4:info5:filese
|
1
test/test_torrents/invalid_name.torrent
Normal file
1
test/test_torrents/invalid_name.torrent
Normal file
@@ -0,0 +1 @@
|
||||
d10:created by10:libtorrent13:creation datei1359599503e4:infod5:filesld6:lengthi425e4:pathl3:foo7:bar.txteed6:lengthi425e4:pathl3:foo7:var.txteee4:namei1348e12:piece lengthi16384e6:pieces20:<3A><><EFBFBD><EFBFBD>&<26><>JW<4A>}<7D>A4u,<2C><><EFBFBD><EFBFBD>ee
|
1
test/test_torrents/invalid_name2.torrent
Normal file
1
test/test_torrents/invalid_name2.torrent
Normal file
@@ -0,0 +1 @@
|
||||
d10:created by10:libtorrent13:creation datei1359599503e4:infod5:filesld6:lengthi425e4:pathl3:foo7:bar.txteed6:lengthi425e4:pathl3:foo7:var.txteee4:name2:..12:piece lengthi16384e6:pieces20:<3A><><EFBFBD><EFBFBD>&<26><>JW<4A>}<7D>A4u,<2C><><EFBFBD><EFBFBD>ee
|
1
test/test_torrents/invalid_path_list.torrent
Normal file
1
test/test_torrents/invalid_path_list.torrent
Normal file
@@ -0,0 +1 @@
|
||||
d10:created by10:libtorrent13:creation datei1359599503e4:infod5:filesld6:lengthi425e4:pathli1242e3:foo7:bar.txteed6:lengthi425e4:pathl3:foo7:var.txteee4:name4:temp12:piece lengthi16384e6:pieces20:<3A><><EFBFBD><EFBFBD>&<26><>JW<4A>}<7D>A4u,<2C><><EFBFBD><EFBFBD>ee
|
1
test/test_torrents/invalid_piece_len.torrent
Normal file
1
test/test_torrents/invalid_piece_len.torrent
Normal file
@@ -0,0 +1 @@
|
||||
d10:created by10:libtorrent13:creation datei1359599503e4:infod5:filesld6:lengthi425e4:pathl3:foo7:bar.txteed6:lengthi425e4:pathl3:foo7:var.txteee4:name4:temp12:piece length5:163846:pieces20:<3A><><EFBFBD><EFBFBD>&<26><>JW<4A>}<7D>A4u,<2C><><EFBFBD><EFBFBD>ee
|
1
test/test_torrents/invalid_pieces.torrent
Normal file
1
test/test_torrents/invalid_pieces.torrent
Normal file
@@ -0,0 +1 @@
|
||||
d10:created by10:libtorrent13:creation datei1359599503e4:infod5:filesld6:lengthi425e4:pathl3:foo7:bar.txteed6:lengthi425e4:pathl3:foo7:var.txteee4:name4:temp12:piece lengthi16384e6:piecesi-23eee
|
1
test/test_torrents/missing_path_list.torrent
Normal file
1
test/test_torrents/missing_path_list.torrent
Normal file
@@ -0,0 +1 @@
|
||||
d10:created by10:libtorrent13:creation datei1359599503e4:infod5:filesld6:lengthi425eed6:lengthi425e4:pathl3:foo7:var.txteee4:name4:temp12:piece lengthi16384e6:pieces20:<3A><><EFBFBD><EFBFBD>&<26><>JW<4A>}<7D>A4u,<2C><><EFBFBD><EFBFBD>ee
|
1
test/test_torrents/missing_piece_len.torrent
Normal file
1
test/test_torrents/missing_piece_len.torrent
Normal file
@@ -0,0 +1 @@
|
||||
d10:created by10:libtorrent13:creation datei1359599503e4:infod5:filesld6:lengthi425e4:pathl3:foo7:bar.txteed6:lengthi425e4:pathl3:foo7:var.txteee4:name4:temp6:pieces20:<3A><><EFBFBD><EFBFBD>&<26><>JW<4A>}<7D>A4u,<2C><><EFBFBD><EFBFBD>ee
|
1
test/test_torrents/negative_file_size.torrent
Normal file
1
test/test_torrents/negative_file_size.torrent
Normal file
@@ -0,0 +1 @@
|
||||
d10:created by10:libtorrent13:creation datei1359599503e4:infod5:filesld4:pathl3:foo7:bar.txte6:lengthi-45eed4:pathl3:foo7:var.txte6:lengthi24124eee4:name4:temp12:piece lengthi16384e6:pieces20:<3A><><EFBFBD><EFBFBD>&<26><>JW<4A>}<7D>A4u,<2C><><EFBFBD><EFBFBD>ee
|
1
test/test_torrents/negative_piece_len.torrent
Normal file
1
test/test_torrents/negative_piece_len.torrent
Normal file
@@ -0,0 +1 @@
|
||||
d10:created by10:libtorrent13:creation datei1359599503e4:infod5:filesld6:lengthi425e4:pathl3:foo7:bar.txteed6:lengthi425e4:pathl3:foo7:var.txteee4:name4:temp12:piece lengthi-16384e6:pieces20:<3A><><EFBFBD><EFBFBD>&<26><>JW<4A>}<7D>A4u,<2C><><EFBFBD><EFBFBD>ee
|
1
test/test_torrents/negative_size.torrent
Normal file
1
test/test_torrents/negative_size.torrent
Normal file
@@ -0,0 +1 @@
|
||||
d10:created by10:libtorrent13:creation datei1359599503e4:infod6:lengthi-425e4:name4:temp12:piece lengthi16384e6:pieces20:cdcdcdcdcdcdcdcdcdcdee
|
1
test/test_torrents/no_name.torrent
Normal file
1
test/test_torrents/no_name.torrent
Normal file
@@ -0,0 +1 @@
|
||||
d10:created by10:libtorrent13:creation datei1359599503e4:infod5:filesld6:lengthi425e4:pathl3:foo7:bar.txteed6:lengthi425e4:pathl3:foo7:var.txteee12:piece lengthi16384e6:pieces20:<3A><><EFBFBD><EFBFBD>&<26><>JW<4A>}<7D>A4u,<2C><><EFBFBD><EFBFBD>ee
|
1
test/test_torrents/pad_file.torrent
Normal file
1
test/test_torrents/pad_file.torrent
Normal file
@@ -0,0 +1 @@
|
||||
d10:created by10:libtorrent13:creation datei1359599503e4:infod5:filesld4:pathl3:foo7:bar.txte6:lengthi45eed4:pathl18:_____padding_file_e6:lengthi2124eee4:name4:temp12:piece lengthi16384e6:pieces20:<3A><><EFBFBD><EFBFBD>&<26><>JW<4A>}<7D>A4u,<2C><><EFBFBD><EFBFBD>ee
|
1
test/test_torrents/string.torrent
Normal file
1
test/test_torrents/string.torrent
Normal file
@@ -0,0 +1 @@
|
||||
10:libtorrent
|
1
test/test_torrents/unaligned_pieces.torrent
Normal file
1
test/test_torrents/unaligned_pieces.torrent
Normal file
@@ -0,0 +1 @@
|
||||
d10:created by10:libtorrent13:creation datei1359599503e4:infod5:filesld6:lengthi425e4:pathl3:foo7:bar.txteed6:lengthi425e4:pathl3:foo7:var.txteee4:name4:temp12:piece lengthi16384e6:pieces24:012345678901234567890123ee
|
Reference in New Issue
Block a user