def testCDMDefaultSection(self):
     cr = ConfigReader()
     cr.setContentList(['[cdm]'])
     procConfig(cr)
     res = cr.config
     res['cdm']['DEFAULT']['depends'] = set(
         res['cdm']['DEFAULT']['depends'])
     self.assertEqual(defaultConfig, res)
예제 #2
0
 def testDHparamDefaultSection(self):
     cr = ConfigReader()
     cr.setContentList(['[dhparam]'])
     procConfig(cr)
     self.assertEqual(
         {
             'filename': '/etc/myssl/dhparam.pem',
             'keysize': 2048
         }, cr.config['dhparam']['DEFAULT'])
예제 #3
0
 def testServiceDefaultSection(self):
     cr = ConfigReader()
     cr.setContentList(['[service]'])
     procConfig(cr)
     # maybe trash - ToDo: check if needed
     self.assertEqual({
         'container': 'false',
         'depends': {}
     }, cr.config['service']['DEFAULT'])
 def testCDMDefaultSectionDefaultOverwrite(self):
     cr = ConfigReader()
     cr.setContentList([' [cdm] \n statedir = /blub \n '])
     procConfig(cr)
     ref = copy.deepcopy(defaultConfig)
     ref['cdm']['DEFAULT']['statedir'] = '/blub'
     res = cr.config
     res['cdm']['DEFAULT']['depends'] = set(
         res['cdm']['DEFAULT']['depends'])
     self.assertEqual(ref, res)
 def testCDMDefaultSectionSimpleVal2(self):
     cr = ConfigReader()
     cr.setContentList(['[cdm] \n x = 3 \n '])
     procConfig(cr)
     ref = copy.deepcopy(defaultConfig)
     ref['cdm']['DEFAULT']['x'] = '3'
     res = cr.config
     res['cdm']['DEFAULT']['depends'] = set(
         res['cdm']['DEFAULT']['depends'])
     self.assertEqual(ref, res)
 def testTestDefaultSection(self):
     cr = ConfigReader()
     cr.setContentList(['[test]'])
     procConfig(cr)
     self.assertEqual(
         {'test': {
             'DEFAULT': {
                 'defaultx': '23',
                 'defaulty': '42'
             }
         }}, cr.config)
예제 #7
0
 def testDHparamNamedSectionDehydratedLetsencryptset(self):
     cr = ConfigReader()
     cr.setContentList(
         ['[dhparam:name]\nhandler = openssl \nkeysize = 4096  '])
     procConfig(cr)
     self.assertEqual(
         {
             'keysize': 4096,
             'handler': 'openssl',
             'filename': '/etc/myssl/dh2048.pem'
         }, cr.config['dhparam']['name'])
 def testTestDefaultSectionDefaultOverwrite(self):
     cr = ConfigReader()
     cr.setContentList(['[test]\ndefaultx=3\n', '[test]\ndefaulty=4\n'])
     procConfig(cr)
     self.assertEqual(
         {'test': {
             'DEFAULT': {
                 'defaultx': '3',
                 'defaulty': '4'
             }
         }}, cr.config)
예제 #9
0
 def testDHparamDefaultSectionDehydratedLetsencryptset(self):
     cr = ConfigReader()
     cr.setContentList([
         '[dhparam]\nhandler = openssl \nfilename = /etc/myssl2/dhp.dh \nkeysize = 4096  '
     ])
     procConfig(cr)
     self.assertEqual(
         {
             'keysize': 4096,
             'handler': 'openssl',
             'filename': '/etc/myssl2/dhp.dh'
         }, cr.config['dhparam']['DEFAULT'])
예제 #10
0
class ManagedDomain:
    def __init__(self):
        self.cr = ConfigReader()
        self.sh = StateHandler()

    def readConfig(self, confFiles=[], confContent=''):
        self.cr.setFilenames(confFiles)
        self.cr.setContentList(confContent)
        self.cr.open()
        if 'cdm' not in self.cr.cp:
            self.cr.cp['cdm'] = {}
        self.cr.interprete(self.sh)
        self.sh.registerConfig(self.cr.config['cdm'])

    def run(self, confFile=None, forcePhase='next', confContent=''):
        if confFile is not None or 0 < len(confContent):
            self.readConfig(confFile, confContent)
        self.sh.load()
        self.sh.delete()  # --next starts with prepare, if failed
        self.sh.resetOpStateRecursive()
        currentPhase = getCurrentPhase(self.sh, forcePhase)
        log.info('Running phase: {}'.format(currentPhase))
        runPhase(self.cr, self.sh, currentPhase)
        nextphase = getNextPhase(currentPhase)
        self.sh.registerResult({'nextphase': nextphase})
        self.sh.save()
 def testCertDefaultSection(self):
     cr = ConfigReader()
     cr.setContentList(['[cert]'])
     procConfig(cr)
     self.assertEqual(
         {
             'caa': {
                 'flag': '0',
                 'tag': 'issue',
                 'url': 'letsencrypt.org'
             },
             'extraflags': [],
             'handler': 'dehydrated/letsencrypt',
             'keysize': 4096
         }, cr.config['cert']['DEFAULT'])
예제 #12
0
 def testServiceDefaultPostfixset(self):
     cr = ConfigReader()
     cr.setContentList(['[service:postfix]'])
     procConfig(cr)
     # maybe trash - ToDo: check if needed
     self.assertEqual(
         {
             'cert': [],
             'dhparam': [],
             'handler': 'postfix',
             'container': 'false',
             'depends': {'cert', 'dhparam'},
             'requires': {
                 'cert': set(),
                 'dhparam': set()
             }
         }, cr.config['service']['postfix'])
 def testTestSectionDefaults(self):
     cr = ConfigReader()
     cr.setContentList(
         ['[test]\ndefaultx=3\n[test:testsection]\ndefaulty=4\n'])
     procConfig(cr)
     self.assertEqual(
         {
             'test': {
                 'DEFAULT': {
                     'defaultx': '3',
                     'defaulty': '42'
                 },
                 'testsection': {
                     'defaultx': '3',
                     'defaulty': '4'
                 }
             }
         }, cr.config)
 def testCertDefaultSectionDehydratedLetsencryptset(self):
     cr = ConfigReader()
     cr.setContentList([
         '[cert]\nhandler = dehydrated/letsencrypt \nemail = [email protected] \nkeysize = 4096 \ndestination = /etc/ssl2 \nextraflags = -x , --hsts \ncertname = full.crt '
     ])
     procConfig(cr)
     self.assertEqual(
         {
             'keysize': 4096,
             'extraflags': ['-x', '--hsts'],
             'handler': 'dehydrated/letsencrypt',
             'email': '*****@*****.**',
             'destination': '/etc/ssl2',
             'certname': 'full.crt',
             'caa': {
                 'url': 'letsencrypt.org',
                 'flag': '0',
                 'tag': 'issue'
             }
         }, cr.config['cert']['DEFAULT'])
 def testSetContentList(self):
     cr = ConfigReader()
     cr.setContentList(['a', 'b', 'c'])
     cr.setContentList(['d', 'e', 'f'])
     cr.setContentList(['g', 'h\nr', 'i'])
     self.assertEqual(cr.contentList, ['g', 'h\nr', 'i'])
 def testSetFilenames(self):
     cr = ConfigReader()
     cr.addFilenames(['a', 'b', 'c'])
     cr.addFilenames(['d', 'e', 'f'])
     cr.setFilenames(['g', 'h', 'i'])
     self.assertEqual(cr.filenameList, ['g', 'h', 'i'])
 def testEmptyConfigContentListEntry(self):
     cr = ConfigReader()
     cr.setContentList([''])
     procConfig(cr)
     self.assertEqual(cr.config, {})
 def testEmptyConfig(self):
     cr = ConfigReader()
     procConfig(cr)
     self.assertEqual(cr.config, {})
예제 #19
0
 def __init__(self):
     self.cr = ConfigReader()
     self.sh = StateHandler()
예제 #20
0
 def testNoSection(self):
     cr = ConfigReader()
     cr.setContentList([''])
     procConfig(cr)
     self.assertEqual(cr.config, {})