summaryrefslogtreecommitdiffstats
path: root/deluge/tests/test_ui_common.py
diff options
context:
space:
mode:
authorCalum Lind <calumlind+deluge@gmail.com>2020-06-14 19:04:29 +0100
committerCalum Lind <calumlind+deluge@gmail.com>2021-03-24 10:26:08 +0000
commit3ec23ad96bfa205c8ae23b662c6da153efbfed3a (patch)
tree880c8efcea5253b330b443f3d99e7118a9da11ca /deluge/tests/test_ui_common.py
parentdcd3918f3626403e32f00993d0a6e7014be3cbf3 (diff)
downloaddeluge-3ec23ad96bfa205c8ae23b662c6da153efbfed3a.tar.gz
deluge-3ec23ad96bfa205c8ae23b662c6da153efbfed3a.tar.bz2
deluge-3ec23ad96bfa205c8ae23b662c6da153efbfed3a.zip
[#3388|WebUI] Fix md5sums in torrent files breaking file listing
Torrents containing md5sum optional hashes are not being decoded and so causes errors in the json_api when the TorrentInfo is returned: Object of type bytes is not JSON serializable Fixed by removing all optional hashes from the paths returned from TorrentInfo and only including the required path keys. The optional hashes are unused by Deluge so simplify by removing. Fixed Windows path issue in TorrentInfo by ensuring conversion to posix paths. Refs: http://wiki.bitcomet.com/inside_bitcomet http://wiki.depthstrike.com/index.php/P2P:Protocol:Specifications:Optional_Hashes https://wiki.theory.org/index.php/BitTorrentSpecification
Diffstat (limited to 'deluge/tests/test_ui_common.py')
-rw-r--r--deluge/tests/test_ui_common.py96
1 files changed, 96 insertions, 0 deletions
diff --git a/deluge/tests/test_ui_common.py b/deluge/tests/test_ui_common.py
index dffd8840b..b0c311183 100644
--- a/deluge/tests/test_ui_common.py
+++ b/deluge/tests/test_ui_common.py
@@ -24,6 +24,102 @@ class UICommonTestCase(unittest.TestCase):
def tearDown(self): # NOQA: N803
pass
+ def test_hash_optional_single_file(self):
+ """Ensure single file with `ed2k` and `sha1` keys are not in filetree output."""
+ filename = common.get_test_data_file('test.torrent')
+ files_tree = {'azcvsupdater_2.6.2.jar': (0, 307949, True)}
+ ti = TorrentInfo(filename, filetree=1)
+ self.assertEqual(ti.files_tree, files_tree)
+
+ files_tree2 = {
+ 'contents': {
+ 'azcvsupdater_2.6.2.jar': {
+ 'type': 'file',
+ 'index': 0,
+ 'length': 307949,
+ 'download': True,
+ }
+ }
+ }
+ ti = TorrentInfo(filename, filetree=2)
+ self.assertEqual(ti.files_tree, files_tree2)
+
+ def test_hash_optional_multi_file(self):
+ """Ensure multi-file with `filehash` and `ed2k` are keys not in filetree output."""
+ filename = common.get_test_data_file('filehash_field.torrent')
+ files_tree = {
+ 'torrent_filehash': {
+ 'tull.txt': (0, 54, True),
+ '還在一個人無聊嗎~還不趕緊上來聊天美.txt': (1, 54, True),
+ }
+ }
+ ti = TorrentInfo(filename, filetree=1)
+ self.assertEqual(ti.files_tree, files_tree)
+
+ filestree2 = {
+ 'contents': {
+ 'torrent_filehash': {
+ 'type': 'dir',
+ 'contents': {
+ 'tull.txt': {
+ 'type': 'file',
+ 'path': 'torrent_filehash/tull.txt',
+ 'length': 54,
+ 'index': 0,
+ 'download': True,
+ },
+ '還在一個人無聊嗎~還不趕緊上來聊天美.txt': {
+ 'type': 'file',
+ 'path': 'torrent_filehash/還在一個人無聊嗎~還不趕緊上來聊天美.txt',
+ 'length': 54,
+ 'index': 1,
+ 'download': True,
+ },
+ },
+ 'length': 108,
+ 'download': True,
+ }
+ },
+ 'type': 'dir',
+ }
+ ti = TorrentInfo(filename, filetree=2)
+ self.assertEqual(ti.files_tree, filestree2)
+
+ def test_hash_optional_md5sum(self):
+ # Ensure `md5sum` key is not included in filetree output
+ filename = common.get_test_data_file('md5sum.torrent')
+ files_tree = {'test': {'lol': (0, 4, True), 'rofl': (1, 5, True)}}
+ ti = TorrentInfo(filename, filetree=1)
+ self.assertEqual(ti.files_tree, files_tree)
+ ti = TorrentInfo(filename, filetree=2)
+ files_tree2 = {
+ 'contents': {
+ 'test': {
+ 'type': 'dir',
+ 'contents': {
+ 'lol': {
+ 'type': 'file',
+ 'path': 'test/lol',
+ 'index': 0,
+ 'length': 4,
+ 'download': True,
+ },
+ 'rofl': {
+ 'type': 'file',
+ 'path': 'test/rofl',
+ 'index': 1,
+ 'length': 5,
+ 'download': True,
+ },
+ },
+ 'length': 9,
+ 'download': True,
+ }
+ },
+ 'type': 'dir',
+ }
+ self.assertEqual(ti.files_tree, files_tree2)
+
def test_utf8_encoded_paths(self):
filename = common.get_test_data_file('test.torrent')
ti = TorrentInfo(filename)