mirror of
				https://github.com/f-droid/fdroidserver.git
				synced 2025-11-03 22:20:28 +03:00 
			
		
		
		
	Add check for repo/archive_url
This commit is contained in:
		
							parent
							
								
									f4cb3bbfb4
								
							
						
					
					
						commit
						5f3eb601df
					
				
					 3 changed files with 67 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -48,6 +48,8 @@
 | 
			
		|||
# The same policy is applied to the archive repo, if there is one.
 | 
			
		||||
# repo_maxage: 0
 | 
			
		||||
 | 
			
		||||
# Canonical URL of the repositoy, needs to end in /repo. Is is used to identity
 | 
			
		||||
# the repo in the client, as well.
 | 
			
		||||
# repo_url: https://MyFirstFDroidRepo.org/fdroid/repo
 | 
			
		||||
# repo_name: My First F-Droid Repo Demo
 | 
			
		||||
# repo_description: >-
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -433,6 +433,14 @@ def read_config(opts=None):
 | 
			
		|||
        limit = config['git_mirror_size_limit']
 | 
			
		||||
        config['git_mirror_size_limit'] = parse_human_readable_size(limit)
 | 
			
		||||
 | 
			
		||||
    if 'repo_url' in config:
 | 
			
		||||
        if not config['repo_url'].endswith('/repo'):
 | 
			
		||||
            raise FDroidException(_('repo_url needs to end with /repo'))
 | 
			
		||||
 | 
			
		||||
    if 'archive_url' in config:
 | 
			
		||||
        if not config['archive_url'].endswith('/archive'):
 | 
			
		||||
            raise FDroidException(_('archive_url needs to end with /archive'))
 | 
			
		||||
 | 
			
		||||
    confignames_to_delete = set()
 | 
			
		||||
    for configname, dictvalue in config.items():
 | 
			
		||||
        if configname == 'java_paths':
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1845,6 +1845,63 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
        config = fdroidserver.common.read_config(fdroidserver.common.options)
 | 
			
		||||
        self.assertEqual('yml', config.get('apksigner'))
 | 
			
		||||
 | 
			
		||||
    def test_config_repo_url(self):
 | 
			
		||||
        """repo_url ends in /repo, archive_url ends in /archive."""
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        os.chdir(testdir)
 | 
			
		||||
        with open('config.yml', 'w') as fp:
 | 
			
		||||
            fp.write('repo_url: https://MyFirstFDroidRepo.org/fdroid/repo\n')
 | 
			
		||||
            fp.write('archive_url: https://MyFirstFDroidRepo.org/fdroid/archive')
 | 
			
		||||
        config = fdroidserver.common.read_config()
 | 
			
		||||
        self.assertEqual('https://MyFirstFDroidRepo.org/fdroid/repo', config.get('repo_url'))
 | 
			
		||||
        self.assertEqual('https://MyFirstFDroidRepo.org/fdroid/archive', config.get('archive_url'))
 | 
			
		||||
 | 
			
		||||
    def test_config_repo_url_extra_slash(self):
 | 
			
		||||
        """repo_url ends in /repo, archive_url ends in /archive."""
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        os.chdir(testdir)
 | 
			
		||||
        with open('config.yml', 'w') as fp:
 | 
			
		||||
            fp.write('repo_url: https://MyFirstFDroidRepo.org/fdroid/repo/')
 | 
			
		||||
        with self.assertRaises(FDroidException):
 | 
			
		||||
            fdroidserver.common.read_config()
 | 
			
		||||
 | 
			
		||||
    def test_config_repo_url_not_repo(self):
 | 
			
		||||
        """repo_url ends in /repo, archive_url ends in /archive."""
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        os.chdir(testdir)
 | 
			
		||||
        with open('config.yml', 'w') as fp:
 | 
			
		||||
            fp.write('repo_url: https://MyFirstFDroidRepo.org/fdroid/foo')
 | 
			
		||||
        with self.assertRaises(FDroidException):
 | 
			
		||||
            fdroidserver.common.read_config()
 | 
			
		||||
 | 
			
		||||
    def test_config_archive_url_extra_slash(self):
 | 
			
		||||
        """repo_url ends in /repo, archive_url ends in /archive."""
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        os.chdir(testdir)
 | 
			
		||||
        with open('config.yml', 'w') as fp:
 | 
			
		||||
            fp.write('archive_url: https://MyFirstFDroidRepo.org/fdroid/archive/')
 | 
			
		||||
        with self.assertRaises(FDroidException):
 | 
			
		||||
            fdroidserver.common.read_config()
 | 
			
		||||
 | 
			
		||||
    def test_config_archive_url_not_repo(self):
 | 
			
		||||
        """repo_url ends in /repo, archive_url ends in /archive."""
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        os.chdir(testdir)
 | 
			
		||||
        with open('config.yml', 'w') as fp:
 | 
			
		||||
            fp.write('archive_url: https://MyFirstFDroidRepo.org/fdroid/foo')
 | 
			
		||||
        with self.assertRaises(FDroidException):
 | 
			
		||||
            fdroidserver.common.read_config()
 | 
			
		||||
 | 
			
		||||
    def test_write_to_config_yml(self):
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue