Merge pull request #283 from lbryio/fail-blank-uri

fail verify_name_characters for blank uri
This commit is contained in:
Jack Robison 2016-11-22 13:55:12 -05:00 committed by GitHub
commit 82f9cc57fd
2 changed files with 15 additions and 0 deletions

View file

@ -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

View file

@ -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):