diff --git a/lbrynet/metadata/Metadata.py b/lbrynet/metadata/Metadata.py index 1af4b2d6f..2e602b109 100644 --- a/lbrynet/metadata/Metadata.py +++ b/lbrynet/metadata/Metadata.py @@ -8,6 +8,7 @@ NAME_ALLOWED_CHARSET = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0987 def verify_name_characters(name): + assert len(name) > 0, "Empty uri" for c in name: assert c in NAME_ALLOWED_CHARSET, "Invalid character" return True diff --git a/tests/unit/core/test_Metadata.py b/tests/unit/core/test_Metadata.py index b13456968..5c50bb63e 100644 --- a/tests/unit/core/test_Metadata.py +++ b/tests/unit/core/test_Metadata.py @@ -2,7 +2,21 @@ from lbrynet.metadata import Metadata from twisted.trial import unittest from jsonschema import ValidationError + class MetadataTest(unittest.TestCase): + def test_name_error_if_blank(self): + with self.assertRaises(AssertionError): + Metadata.verify_name_characters("") + + def test_name_error_if_contains_bad_chrs(self): + with self.assertRaises(AssertionError): + Metadata.verify_name_characters("wu tang") + with self.assertRaises(AssertionError): + Metadata.verify_name_characters("$wutang") + with self.assertRaises(AssertionError): + Metadata.verify_name_characters("#wutang") + + def test_validation_error_if_no_metadata(self): metadata = {} with self.assertRaises(ValidationError):