Skip to content

Commit

Permalink
add test coverage for read_resume_data() when v1 or v2 hashes do not …
Browse files Browse the repository at this point in the history
…match the torrent metadata
  • Loading branch information
arvidn committed Feb 17, 2024
1 parent 4128849 commit b13a573
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions test/test_read_resume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,46 @@ TORRENT_TEST(read_resume_torrent)
TEST_EQUAL(atp.ti->name(), ti->name());
}

TORRENT_TEST(mismatching_v1_hash)
{
std::shared_ptr<torrent_info> ti = generate_torrent();

entry rd;
rd["file-format"] = "libtorrent resume file";
rd["file-version"] = 1;
rd["info-hash"] = "abababababababababab";
rd["info"] = bdecode(ti->info_section());

std::vector<char> resume_data;
bencode(std::back_inserter(resume_data), rd);

// the info-hash field does not match the torrent in the "info" field, so it
// will be ignored
error_code ec;
add_torrent_params atp = read_resume_data(resume_data, ec);
TEST_CHECK(ec == errors::mismatching_info_hash);
}

TORRENT_TEST(mismatching_v2_hash)
{
std::shared_ptr<torrent_info> ti = generate_torrent();

entry rd;
rd["file-format"] = "libtorrent resume file";
rd["file-version"] = 1;
rd["info-hash2"] = "abababababababababababababababab";
rd["info"] = bdecode(ti->info_section());

std::vector<char> resume_data;
bencode(std::back_inserter(resume_data), rd);

// the info-hash field does not match the torrent in the "info" field, so it
// will be ignored
error_code ec;
add_torrent_params atp = read_resume_data(resume_data, ec);
TEST_CHECK(ec == errors::mismatching_info_hash);
}

namespace {

void test_roundtrip(add_torrent_params input)
Expand Down

0 comments on commit b13a573

Please sign in to comment.