1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-11-19 21:30:10 +01:00

add test cases for parsing smartcardoptions config field

This commit is contained in:
Hans-Christoph Steiner 2022-05-25 10:09:52 +02:00
parent a4d0698628
commit 2639909f90

View File

@ -54,6 +54,8 @@ class CommonTest(unittest.TestCase):
os.makedirs(self.tmpdir)
os.chdir(self.basedir)
fdroidserver.common.config = None
fdroidserver.common.options = mock.Mock()
fdroidserver.common.options.verbose = False
self.path = os.environ['PATH']
self.android_home = os.environ.get('ANDROID_HOME')
@ -2438,6 +2440,98 @@ class CommonTest(unittest.TestCase):
self.assertTrue(os.path.exists(f), f + ' was created')
self.assertFalse(is_repo_file(f), f + ' not repo file')
def test_get_smartcardoptions_list(self):
os.chdir(self.tmpdir)
with open('config.yml', 'w') as fp:
fp.write(
textwrap.dedent(
"""
smartcardoptions:
- -storetype
- PKCS11
- -providerName
- SunPKCS11-OpenSC
- -providerClass
- sun.security.pkcs11.SunPKCS11
- -providerArg
- opensc-fdroid.cfg
"""
)
)
config = fdroidserver.common.read_config()
fdroidserver.common.config = config
self.assertTrue(isinstance(config['smartcardoptions'], list))
self.assertEqual(
[
'-storetype',
'PKCS11',
'-providerName',
'SunPKCS11-OpenSC',
'-providerClass',
'sun.security.pkcs11.SunPKCS11',
'-providerArg',
'opensc-fdroid.cfg',
],
config['smartcardoptions'],
)
def test_get_smartcardoptions_spaces(self):
os.chdir(self.tmpdir)
with open('config.yml', 'w') as fp:
fp.write(
textwrap.dedent(
"""smartcardoptions: |
-storetype PKCS11
-providerClass sun.security.pkcs11.SunPKCS11
-providerArg /etc/pkcs11_java.cfg
"""
)
)
config = fdroidserver.common.read_config()
fdroidserver.common.config = config
self.assertTrue(isinstance(config['smartcardoptions'], list))
self.assertEqual(
[
'-storetype',
'PKCS11',
'-providerClass',
'sun.security.pkcs11.SunPKCS11',
'-providerArg',
'/etc/pkcs11_java.cfg',
],
config['smartcardoptions'],
)
def test_get_smartcardoptions_config_py(self):
os.chdir(self.tmpdir)
with open('config.py', 'w') as fp:
fp.write(
textwrap.dedent(
"""
smartcardoptions = '''
\t-storetype\tPKCS11
\t-providerClass\tsun.security.pkcs11.SunPKCS11
\t-providerArg\t/etc/pkcs11_java.cfg
'''
"""
)
)
config = fdroidserver.common.read_config()
fdroidserver.common.config = config
self.assertEqual(
[
'-storetype',
'PKCS11',
'-providerClass',
'sun.security.pkcs11.SunPKCS11',
'-providerArg',
'/etc/pkcs11_java.cfg',
],
config['smartcardoptions'],
)
if __name__ == "__main__":
os.chdir(os.path.dirname(__file__))