mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-11-04 22:40:29 +03:00
Merge branch 'fix-1125' into 'master'
index: fail if user sets mirrors:isPrimary wrong Closes #1125 See merge request fdroid/fdroidserver!1617
This commit is contained in:
commit
f09d859281
2 changed files with 24 additions and 0 deletions
|
|
@ -1516,6 +1516,7 @@ def add_mirrors_to_repodict(repo_section, repodict):
|
|||
repodict['mirrors'] = []
|
||||
canonical_url = repodict['address']
|
||||
found_primary = False
|
||||
errors = 0
|
||||
for mirror in mirrors:
|
||||
if canonical_url == mirror['url']:
|
||||
found_primary = True
|
||||
|
|
@ -1524,9 +1525,19 @@ def add_mirrors_to_repodict(repo_section, repodict):
|
|||
for k in sorted(mirror.keys()):
|
||||
sortedmirror[k] = mirror[k]
|
||||
repodict['mirrors'].insert(0, sortedmirror)
|
||||
elif mirror.get('isPrimary'):
|
||||
errors += 1
|
||||
logging.error(
|
||||
_('Mirror config for {url} contains "isPrimary" key!').format(
|
||||
url=mirror['url']
|
||||
)
|
||||
)
|
||||
else:
|
||||
repodict['mirrors'].append(mirror)
|
||||
|
||||
if errors:
|
||||
raise FDroidException(_('"isPrimary" key should not be added to mirrors!'))
|
||||
|
||||
if repodict['mirrors'] and not found_primary:
|
||||
repodict['mirrors'].insert(0, {'isPrimary': True, 'url': repodict['address']})
|
||||
|
||||
|
|
|
|||
|
|
@ -814,6 +814,19 @@ class IndexTest(unittest.TestCase):
|
|||
with self.assertRaises(fdroidserver.exception.FDroidException):
|
||||
index.add_mirrors_to_repodict('repo', repodict)
|
||||
|
||||
def test_erroneous_isPrimary_in_mirrors_config(self):
|
||||
"""There can be only one primary mirror aka canonical URL"""
|
||||
common.config = {
|
||||
'repo_url': 'http://one/fdroid',
|
||||
'mirrors': [
|
||||
{'url': 'http://one/fdroid', 'countryCode': 'SA'},
|
||||
{'url': 'http://two/fdroid', 'isPrimary': True},
|
||||
],
|
||||
}
|
||||
repodict = {'address': common.config['repo_url']}
|
||||
with self.assertRaises(fdroidserver.exception.FDroidException):
|
||||
index.add_mirrors_to_repodict('repo', repodict)
|
||||
|
||||
|
||||
class AltstoreIndexTest(unittest.TestCase):
|
||||
def test_make_altstore(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue