1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-11-20 13:50:12 +01:00

improve bitcoin validation regex + testcases

This commit is contained in:
Michael Pöhn 2019-05-07 22:43:05 +02:00
parent 64275356e4
commit 06cec2041d
2 changed files with 32 additions and 1 deletions

View File

@ -453,7 +453,7 @@ valuetypes = {
["AuthorEmail"]), ["AuthorEmail"]),
FieldValidator("Bitcoin address", FieldValidator("Bitcoin address",
r'^[a-zA-Z0-9]{27,34}$', r'^(bc1|[13])[a-zA-HJ-NP-Z0-9]{25,39}$',
["Bitcoin"]), ["Bitcoin"]),
FieldValidator("Litecoin address", FieldValidator("Litecoin address",

View File

@ -39,6 +39,35 @@ class MetadataTest(unittest.TestCase):
os.makedirs(self.tmpdir) os.makedirs(self.tmpdir)
os.chdir(self.basedir) os.chdir(self.basedir)
def test_FieldValidator(self):
validator = None
for vali in fdroidserver.metadata.valuetypes:
if vali.name == 'Bitcoin address':
validator = vali
break
self.assertIsNotNone(validator, "could not find 'Bitcoin address' validator")
fdroidserver.metadata.warnings_action = 'error'
# some valid addresses (P2PKH, P2SH, Bech32)
self.assertIsNone(validator.check('1BrrrrErsrWetrTrnrrrrm4GFg7xJaNVN2', 'fake.app.id'))
self.assertIsNone(validator.check('3JrrrrWrEZr3rNrrvrecrnyirrnqRhWNLy', 'fake.app.id'))
self.assertIsNone(validator.check('bc1qar0srrr7xrkvr5lr43lrdnwrre5rgtrzrf5rrq', 'fake.app.id'))
# some invalid addresses (various special use/testnet addresses)
self.assertRaises(fdroidserver.exception.MetaDataException, validator.check,
'21BvMrSYsrWrtrrrn5Au4m4GFr7rrarrN2', 'fake.app.id')
self.assertRaises(fdroidserver.exception.MetaDataException, validator.check,
'5Hrgr3ur5rGLrfKrrrrrrHSrqJrroGrrzrQrrrrrrLNrsrDrrrA', 'fake.app.id')
self.assertRaises(fdroidserver.exception.MetaDataException, validator.check,
'92rr46rUrgTrrromrVrirW6r1rrrdrerrdbJrrrhrCsYrrrrrrc', 'fake.app.id')
self.assertRaises(fdroidserver.exception.MetaDataException, validator.check,
'K1BvMrSYsrWrtrrrn5Au4m4GFr7rrarrN2', 'fake.app.id')
self.assertRaises(fdroidserver.exception.MetaDataException, validator.check,
'L1BvMrSYsrWrtrrrn5Au4m4GFr7rrarrN2', 'fake.app.id')
self.assertRaises(fdroidserver.exception.MetaDataException, validator.check,
'tb1qw5r8drrejxrrg4y5rrrrrraryrrrrwrkxrjrsx', 'fake.app.id')
def test_read_metadata(self): def test_read_metadata(self):
def _build_yaml_representer(dumper, data): def _build_yaml_representer(dumper, data):
@ -54,6 +83,7 @@ class MetadataTest(unittest.TestCase):
config['ndk_paths'] = dict() config['ndk_paths'] = dict()
config['accepted_formats'] = ['json', 'txt', 'yml'] config['accepted_formats'] = ['json', 'txt', 'yml']
fdroidserver.common.config = config fdroidserver.common.config = config
fdroidserver.metadata.warnings_action = None
apps = fdroidserver.metadata.read_metadata(xref=True) apps = fdroidserver.metadata.read_metadata(xref=True)
for appid in ('org.smssecure.smssecure', 'org.adaway', for appid in ('org.smssecure.smssecure', 'org.adaway',
@ -73,6 +103,7 @@ class MetadataTest(unittest.TestCase):
def test_rewrite_yaml_fakeotaupdate(self): def test_rewrite_yaml_fakeotaupdate(self):
testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir) testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
fdroidserver.common.config = {'accepted_formats': ['txt', 'yml']} fdroidserver.common.config = {'accepted_formats': ['txt', 'yml']}
fdroidserver.metadata.warnings_action = None
# rewrite metadata # rewrite metadata
allapps = fdroidserver.metadata.read_metadata(xref=True) allapps = fdroidserver.metadata.read_metadata(xref=True)