Ejemplo n.º 1
0
    def setUp(self):
        """Create and configure a new app instance for each test."""
        self.maxDiff = None
        # create the app with common test config
        self.set_scoped_session()
        self.app = create_app('test')
        if self.db_uris:
            self.app.config['SQLALCHEMY_DATABASE_URI'] = self.db_uris[0]
            remove_db_file(self.db_uris[0])
        self.app.config['SERVER_NAME'] = 'node1'
        self.app_context = self.app.app_context()
        self.client = self.app.test_client()
        self.app_context.push()

        self.app2 = create_app('test')
        if self.db_uris:
            self.app2.config['SQLALCHEMY_DATABASE_URI'] = self.db_uris[1]
            remove_db_file(self.db_uris[1])
        self.app2.config['SERVER_NAME'] = 'node2'
        self.app2_context = self.app2.app_context()
        self.client2 = self.app2.test_client()

        self._fill_database(self.app)

        self._fill_database(self.app2)
        self.generate_auth()
        super().setUp()
Ejemplo n.º 2
0
    def setUp(self) -> None:
        self.file1 = os.path.join(DEST_FOLDER, 'server1.tempfile.log')
        self.file2 = os.path.join(DEST_FOLDER, 'server2.tempfile.log')
        self.remove_files()

        self.app1 = create_app(Server1())
        self.app2 = create_app(Server2())

        self.client1 = self.app1.test_client()
        self.client2 = self.app2.test_client()
        self.lines = ['line 1\nline 2\n', 'line 3\n', 'line 4\nline 5\n']
        self.i = 0
        self.append_data()
Ejemplo n.º 3
0
    def setUp(self):
        """Create and configure a new app instance for each test."""
        # create the app with common test config
        self.app = create_app('test')
        self.app.config['SECURIZER'] = True

        @self.app.route('/', methods=['GET', 'POST'])
        @securizer
        def home():
            return {'msg': 'default response'}

        self.app_context = self.app.app_context()
        self.app_context.push()
        self.client = self.app.test_client()
        db.init_app(self.app)
        db.create_all()
        self.server = Server('me', port=5000, me=True)
        db.session.add(self.server)

        self.dim = generate_dimension('dimension')
        self.dim.current = True
        db.session.add(self.dim)

        self.token = create_access_token('test')
        self.auth = HTTPBearerAuth(self.token)
        self.url = 'https://me:5000/'
Ejemplo n.º 4
0
 def setUp(self):
     """Create and configure a new app instance for each test."""
     # create the app with common test config
     self.app = create_app('test')
     self.app_context = self.app.app_context()
     self.app_context.push()
     db.create_all()
Ejemplo n.º 5
0
    def setUp(self):
        """Create and configure a new app instance for each test."""
        # create the app with common test config
        self.app = create_app('test')
        self.app_context = self.app.app_context()
        self.app_context.push()
        self.client = self.app.test_client()
        self.headers = {
            "Authorization":
            f"Bearer {create_access_token('00000000-0000-0000-0000-000000000001')}"
        }

        db.create_all()
        set_initial()

        self.soft = Software(id='aaaaaaaa-1234-5678-1234-56781234aaa1',
                             name='test',
                             version='1',
                             filename='file')
        self.soft2 = Software(id='aaaaaaaa-1234-5678-1234-56781234aaa2',
                              name='test',
                              version='2',
                              filename='file')
        self.ssa = SoftwareServerAssociation(software=self.soft,
                                             server=Server.get_current(),
                                             path='/root')
        db.session.add_all([self.soft, self.soft2, self.ssa])
        db.session.commit()
Ejemplo n.º 6
0
    def setUp(self):
        self.maxDiff = None
        self.app_join = create_app('test')
        self.app_join.config['SERVER_NAME'] = 'join'
        self.app_join_context = self.app_join.app_context()
        self.client_join = self.app_join.test_client()
        with self.app_join.app_context():
            db.create_all()
            set_initial(server=False)
            self.join_server_id = Server.set_initial()
            db.session.commit()
            self.mock_dm = mock.MagicMock()
            self.mock_dm.flask_app = self.app_join
            self.mock_dm.engine = db.engine
            self.mock_dm.catalog_manager.db_update_catalog = update_db_catalog

        super().setUp()
        self.app.config['SECURIZER'] = True
        self.app_join.config['SECURIZER'] = True
        self.token = create_access_token(JOIN,
                                         additional_claims={'applicant': 'me'})
        self.setUpPyfakefs()

        open('/origin_key', 'w').write('keyfile')
        open('/origin_cert', 'w').write('certfile')
Ejemplo n.º 7
0
    def setUp(self):
        """Create and configure a new app instance for each test."""
        # create the app with common test config
        self.app = create_app('test')
        self.app_context = self.app.app_context()
        self.app_context.push()
        self.client = self.app.test_client()
        self.headers = {
            "Authorization":
            f"Bearer {create_access_token('00000000-0000-0000-0000-000000000001')}"
        }

        db.create_all()
        # set_initial(server=False)

        self.srv1 = Server('node1',
                           id='00000000-0000-0000-0000-000000000001',
                           me=True)
        self.file = File(source_server=self.srv1,
                         target='/etc/ssh/sshd_config',
                         id='00000000-0000-0000-0000-000000000002')
        self.fsa = FileServerAssociation(file=self.file,
                                         destination_server=self.srv1)

        db.session.add_all([self.srv1, self.file, self.fsa])
        db.session.commit()
Ejemplo n.º 8
0
 def setUp(self) -> None:
     self.maxDiff = None
     self.app = create_app('test')
     self.app.config['SECURIZER'] = False
     # user sqlite in a file as flush does not emits states in an inmemory database
     # self.app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///'+os.path.join(basedir, 'test.db')
     self.app_context = self.app.app_context()
     self.app_context.push()
     db.create_all()
Ejemplo n.º 9
0
 def setUp(self):
     self.maxDiff = None
     self.set_scoped_session()
     self.app = create_app('test')
     self.app.config['SERVER_NAME'] = 'me'
     self.app_context = self.app.app_context()
     self.client = self.app.test_client()
     self.app_context.push()
     db.create_all()
Ejemplo n.º 10
0
 def setUp(self):
     """Create and configure a new app instance for each test."""
     # create the app with common test config
     self.app = create_app('test')
     self.app_context = self.app.app_context()
     self.app_context.push()
     self.client = self.app.test_client()
     self.auth = HTTPBearerAuth(create_access_token('00000000-0000-0000-0000-000000000001'))
     db.create_all()
Ejemplo n.º 11
0
    def setUp(self) -> None:
        self.maxDiff = None
        set_test_scoped_session(db)
        self.app1 = create_app('test')
        self.app1.config['SERVER_NAME'] = 'node1'
        self.app_context = self.app1.app_context()
        self.app_context.push()
        self.app2 = create_app('test')
        self.app2.config['SERVER_NAME'] = 'node2'
        self.app3 = create_app('test')
        self.app3.config['SERVER_NAME'] = 'node3'

        self.fill_database('node1')

        with self.app2.app_context():
            self.fill_database('node2')

        with self.app3.app_context():
            self.fill_database('node3')
Ejemplo n.º 12
0
 def setUp(self):
     """Create and configure a new app instance for each test."""
     # create the app with common test config
     self.app = create_app('test')
     self.app_context = self.app.app_context()
     self.app_context.push()
     self.client = self.app.test_client()
     db.create_all()
     set_initial()
     self.auth = HTTPBearerAuth(
         create_access_token(User.get_by_name('root').id))
Ejemplo n.º 13
0
 def setUp(self):
     """Create and configure a new app instance for each test."""
     # create the app with common test config
     self.app = create_app('test')
     self.app_context = self.app.app_context()
     self.app_context.push()
     self.client = self.app.test_client()
     self.auth = HTTPBearerAuth(create_access_token('00000000-0000-0000-0000-000000000001'))
     db.create_all()
     self.src = Server('source', port=5000)
     self.dst = Server('destination', port=5000)
Ejemplo n.º 14
0
 def setUp(self):
     """Create and configure a new app instance for each test."""
     # create the app with common test config
     self.app = create_app('test')
     self.app_context = self.app.app_context()
     self.app_context.push()
     self.client = self.app.test_client()
     self.auth = HTTPBearerAuth(create_access_token('00000000-0000-0000-0000-000000000001'))
     db.create_all()
     self.me = Server('me', port=5000, _me=True)
     self.remote = Server('remote', port=5000)
     db.session.add_all([self.remote, self.me])
     self.maxDiff = None
Ejemplo n.º 15
0
    def setUp(self, mock_now):
        """Create and configure a new app instance for each test."""
        mock_now.return_value = dt.datetime(2019, 4, 1, tzinfo=dt.timezone.utc)

        # create the app with common test config
        self.app = create_app('test')
        self.app_context = self.app.app_context()
        self.app_context.push()
        self.client = self.app.test_client()

        db.create_all()
        Locker.set_initial()
        Server.set_initial()
        db.session.commit()
Ejemplo n.º 16
0
    def setUp(self):
        """Create and configure a new app instance for each test."""
        # create the app with common test config
        self.app = create_app('test')
        self.app_context = self.app.app_context()
        self.app_context.push()
        self.client = self.app.test_client()
        self.headers = {
            "Authorization":
            f"Bearer {create_access_token('00000000-0000-0000-0000-000000000001')}"
        }

        db.create_all()
        db.session.commit()
Ejemplo n.º 17
0
    def setUp(self) -> None:
        self.maxDiff = None
        self.set_scoped_session()
        self.app = create_app('test')
        if self.db_uris:
            self.app.config['SQLALCHEMY_DATABASE_URI'] = self.db_uris[0]
            remove_db_file(self.db_uris[0])
        self.app.config['SERVER_NAME'] = 'node1'
        self.app_context = self.app.app_context()
        self.client = self.app.test_client()
        self.app_context.push()

        self._fill_database()
        self.generate_auth()
        super().setUp()
Ejemplo n.º 18
0
 def setUp(self):
     """Create and configure a new app instance for each test."""
     # create the app with common test config
     self.app = create_app('test')
     self.app_context = self.app.app_context()
     self.app_context.push()
     self.client = self.app.test_client()
     self.auth = HTTPBearerAuth(
         create_access_token('00000000-0000-0000-0000-000000000001'))
     db.create_all()
     self.at = ActionTemplate(name='action',
                              version=1,
                              action_type=ActionType.SHELL,
                              code='code to run',
                              expected_stdout='expected output',
                              expected_rc=0,
                              system_kwargs={})
     ActionTemplate.set_initial()
Ejemplo n.º 19
0
    def setUp(self):
        """Create and configure a new app instance for each test."""
        # create the app with common test config
        self.app = create_app('test')
        self.app_context = self.app.app_context()
        self.app_context.push()
        self.client = self.app.test_client()
        self.headers = {
            "Authorization":
            f"Bearer {create_access_token('00000000-0000-0000-0000-000000000001')}"
        }

        db.create_all()
        set_initial()

        self.n1 = Server("node1", port=8000)
        Route(self.n1, cost=0)
        self.n2 = Server("node2", port=8000)
        Route(self.n2, cost=0)
        db.session.add_all([self.n1, self.n2])
        db.session.commit()
        self.datamark = Catalog.max_catalog(str)
Ejemplo n.º 20
0
    def setUp(self):
        """Create and configure a new app instance for each test."""
        # create the app with common test config
        self.app = create_app('test')
        self.app_context = self.app.app_context()
        self.app_context.push()
        self.client = self.app.test_client()
        self.headers = {"Authorization": f"Bearer {create_access_token('00000000-0000-0000-0000-000000000001')}"}

        db.create_all()

        self.at1 = ActionTemplate(id='11111111-2222-3333-4444-555555550001', name='action1', version=1,
                                  action_type=ActionType.SHELL, code='code to run',
                                  expected_stdout='expected output', expected_stderr='stderr', expected_rc=0,
                                  system_kwargs={})

        self.at2 = ActionTemplate(id='11111111-2222-3333-4444-555555550002', name='action2', version=1,
                                  action_type=ActionType.SHELL, code='code to run',
                                  expected_stdout='expected output', expected_stderr='stderr', expected_rc=0,
                                  system_kwargs={})

        self.o = Orchestration(id='11111111-2222-3333-4444-666666660001', name='orchestration_name',
                               version=1, description='desc')
Ejemplo n.º 21
0
 def setUp(self):
     self.maxDiff = None
     """Create and configure a new app instance for each test."""
     # create the app with common test config
     self.app = create_app('test')
     self.app_context = self.app.app_context()
     self.app_context.push()
     self.client = self.app.test_client()
     self.auth = HTTPBearerAuth(
         create_access_token('00000000-0000-0000-0000-000000000001'))
     db.create_all()
     self.src = Server('source',
                       port=5000,
                       id='00000000-0000-0000-0000-000000000000')
     self.dst1 = Server('destination1',
                        port=5000,
                        id='00000000-0000-0000-0000-000000000001')
     self.dst2 = Server('destination2',
                        port=5000,
                        id='00000000-0000-0000-0000-000000000002')
     self.dst3 = Server('destination3',
                        port=5000,
                        id='00000000-0000-0000-0000-000000000003')
     db.session.add_all([self.src, self.dst1, self.dst2, self.dst3])
Ejemplo n.º 22
0
from sqlalchemy import exc, sql

from dimensigon import defaults
from dimensigon.core import Dimensigon
from dimensigon.dshell.output import dprint

basedir = os.path.abspath(os.path.dirname(__file__))

PLATFORM = platform.system()

from dimensigon.domain.entities import *
from dimensigon.web.network import pack_msg2, unpack_msg2
from dimensigon.web import create_app, db, get_root_auth
from dimensigon.utils.helpers import generate_symmetric_key, generate_dimension, get_now

app: Flask = create_app(os.getenv('FLASK_CONFIG') or 'default')


def new(dm: Dimensigon, name: str):
    dm.create_flask_instance()
    with dm.flask_app.app_context():
        from cryptography import x509
        from cryptography.hazmat.backends import default_backend
        from cryptography.hazmat.primitives import hashes, serialization
        from cryptography.x509.oid import NameOID
        import datetime
        Server.set_initial()
        count = Dimension.query.count()

        if count > 0:
            exit("Only one dimension can be created")
Ejemplo n.º 23
0
 def create_flask_instance(self):
     if self.flask_app is None:
         self.flask_app = create_app(self.config.flask_conf)
         self.flask_app.dm = self
Ejemplo n.º 24
0
 def setUp(self) -> None:
     self.app = create_app('test')