From 66105de83308d72670ba643e0495c14185e50398 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20P=C3=B6hn?= Date: Fri, 10 May 2019 12:02:13 +0200 Subject: [PATCH] improve litecoin validation + tests --- fdroidserver/metadata.py | 2 +- tests/metadata.TestCase | 35 ++++++++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/fdroidserver/metadata.py b/fdroidserver/metadata.py index 9f67b20e..17a3e739 100644 --- a/fdroidserver/metadata.py +++ b/fdroidserver/metadata.py @@ -457,7 +457,7 @@ valuetypes = { ["Bitcoin"]), FieldValidator("Litecoin address", - r'^L[a-zA-Z0-9]{33}$', + r'^[LM3][a-km-zA-HJ-NP-Z1-9]{26,33}$', ["Litecoin"]), FieldValidator("Repo Type", diff --git a/tests/metadata.TestCase b/tests/metadata.TestCase index dc786095..d7b72f71 100755 --- a/tests/metadata.TestCase +++ b/tests/metadata.TestCase @@ -39,7 +39,7 @@ class MetadataTest(unittest.TestCase): os.makedirs(self.tmpdir) os.chdir(self.basedir) - def test_FieldValidator(self): + def test_FieldValidator_BitcoinAddress(self): validator = None for vali in fdroidserver.metadata.valuetypes: if vali.name == 'Bitcoin address': @@ -54,9 +54,9 @@ class MetadataTest(unittest.TestCase): self.assertIsNone(validator.check('3JrrrrWrEZr3rNrrvrecrnyirrnqRhWNLy', 'fake.app.id')) self.assertIsNone(validator.check('bc1qar0srrr7xrkvr5lr43lrdnwrre5rgtrzrf5rrq', 'fake.app.id')) - # some invalid addresses (various special use/testnet addresses) + # some invalid addresses self.assertRaises(fdroidserver.exception.MetaDataException, validator.check, - '21BvMrSYsrWrtrrrn5Au4m4GFr7rrarrN2', 'fake.app.id') + '21BvMrSYsrWrtrrlL5A10mlGFr7rrarrN2', 'fake.app.id') self.assertRaises(fdroidserver.exception.MetaDataException, validator.check, '5Hrgr3ur5rGLrfKrrrrrrHSrqJrroGrrzrQrrrrrrLNrsrDrrrA', 'fake.app.id') self.assertRaises(fdroidserver.exception.MetaDataException, validator.check, @@ -68,6 +68,35 @@ class MetadataTest(unittest.TestCase): self.assertRaises(fdroidserver.exception.MetaDataException, validator.check, 'tb1qw5r8drrejxrrg4y5rrrrrraryrrrrwrkxrjrsx', 'fake.app.id') + def test_FieldValidator_LitecoinAddress(self): + validator = None + for vali in fdroidserver.metadata.valuetypes: + if vali.name == 'Litecoin address': + validator = vali + break + self.assertIsNotNone(validator, "could not find 'Litecoin address' validator") + + fdroidserver.metadata.warnings_action = 'error' + + # some valid addresses (L, M, 3) + self.assertIsNone(validator.check('LgeGrrrrJAxyXprrPrrBrrX5Qrrrrrrrrd', 'fake.app.id')) + self.assertIsNone(validator.check('MrrrrrrrJAxyXpanPtrrRAX5QHxvUJo8id', 'fake.app.id')) + self.assertIsNone(validator.check('3rereVr9rAryrranrrrrrAXrrHx', 'fake.app.id')) + + # some invalid addresses (various special use/testnet addresses, invalid chars) + self.assertRaises(fdroidserver.exception.MetaDataException, validator.check, + '21BvMrSYsrWrtrrrn5Au4l4GFr7rrarrN2', 'fake.app.id') + self.assertRaises(fdroidserver.exception.MetaDataException, validator.check, + '5Hrgr3ur5rGLrfKrrrrrr1SrqJrroGrrzrQrrrrrrLNrsrDrrrA', '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, + 'L0000rSYsrWrtrrrn5Au4m4GFr7rrarrN2', 'fake.app.id') + self.assertRaises(fdroidserver.exception.MetaDataException, validator.check, + 'tb1qw5r8drrejxrrg4y5rrrrrraryrrrrwrkxrjrsx', 'fake.app.id') + def test_read_metadata(self): def _build_yaml_representer(dumper, data):