opennel-pymanager/tests/test_client_manager.py

84 lines
3.3 KiB
Python
Raw Normal View History

#!/usr/bin/python3
# -*- coding: utf-8 -*-
#
# create certificate (use for test)
# Copyright (C) 2017 AleaJactaEst
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import unittest
import tempfile
import os
import configparser
from unittest.mock import patch
try:
import pymanager.client as Client
except ImportError:
import sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import pymanager.client as Client
try:
import pymanager.certificate as cert
except ImportError:
import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import pymanager.certificate as cert
try:
import pymanager.manager as Manager
except ImportError:
import sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import pymanager.manager as Manager
class TestManager(unittest.TestCase):
def setUp(self):
pass
def test_client_send_json(self):
workdir = tempfile.mkdtemp(prefix='test_client_send_json')
workdir_cert_root = tempfile.mkdtemp(prefix='pymanager-certificate-root-')
workdir_cert_appli = tempfile.mkdtemp(prefix='pymanager-certificate-application-')
args=['--workdir-cert-root', workdir_cert_root, '--workdir-cert-appli', workdir_cert_appli]
cert.main(args)
config = configparser.ConfigParser()
config.add_section('config:server')
config.set('config:server', 'port', '8000')
config.set('config:server', 'keyfile', os.path.join(workdir_cert_appli, 'private', 'serverkey.pem'))
config.set('config:server', 'certfile', os.path.join(workdir_cert_appli, 'certs', 'servercert.pem'))
config.set('config:server', 'ca_cert', os.path.join(workdir_cert_appli, 'certs', 'cachaincert.pem'))
config.add_section('config:client')
config.set('config:client', 'port', '8000')
config.set('config:client', 'keyfile', os.path.join(workdir_cert_appli, 'private', 'clientkey.pem'))
config.set('config:client', 'certfile', os.path.join(workdir_cert_appli, 'certs', 'clientcert.pem'))
config.set('config:client', 'ca_cert', os.path.join(workdir_cert_appli, 'certs', 'cachaincert.pem'))
config.set('config:client', 'address', '127.0.0.1')
config.add_section('command:test')
config.set('command:test', 'path', workdir)
config.set('command:test', 'command', os.path.join(os.path.abspath(__file__), 'simulate_program.py'))
try:
client = Client.Client(None, None, None)
client._load_config(config)
self.assertTrue(True)
except:
self.fail('Error detected on load config')
if __name__ == '__main__':
unittest.main()