Пример #1
0
 def test_identifiers(self):
     """
     """
     auth_plugin = GASimpleAuthenticationPlugin()
     self.assertEquals(auth_plugin.__class__.manifest().identifier,
                       'garuda.plugin.authentication.simple')
     self.assertEquals(auth_plugin.manifest().identifier,
                       'garuda.plugin.authentication.simple')
Пример #2
0
    def test_extract_session_identifier(self):
        """
        """
        request = GARequest(action=GARequest.ACTION_READ)
        request.token = 'token'

        auth_plugin = GASimpleAuthenticationPlugin()

        self.assertEquals(auth_plugin.extract_session_identifier(request=request), 'token')
Пример #3
0
    def test_extract_session_identifier(self):
        """
        """
        request = GARequest(action=GARequest.ACTION_READ)
        request.token = 'token'

        auth_plugin = GASimpleAuthenticationPlugin()

        self.assertEquals(
            auth_plugin.extract_session_identifier(request=request), 'token')
Пример #4
0
    def test_authenticate_with_wrong_access(self):
        """
        """
        GASDKLibrary().register_sdk('default', tstdk)

        request = GARequest(action=GARequest.ACTION_READ)
        request.resources = [GAResource('note-good', None)]
        request.token = 'token'
        session = GASession()
        auth_plugin = GASimpleAuthenticationPlugin()
        auth_info = auth_plugin.authenticate(request=request, session=session)

        self.assertIsNone(auth_info)
Пример #5
0
    def test_authenticate_without_auth_function(self):
        """
        """
        GASDKLibrary().register_sdk('default', tstdk)

        request = GARequest(action=GARequest.ACTION_READ)
        request.resources = [GAResource('root', None)]
        request.token = 'token'
        session = GASession()
        auth_plugin = GASimpleAuthenticationPlugin()
        auth_info = auth_plugin.authenticate(request=request, session=session)

        self.assertEquals(auth_info.__class__, tstdk.GARoot)
Пример #6
0
    def test_authenticate_with_wrong_access(self):
        """
        """
        GASDKLibrary().register_sdk('default', tstdk)

        request = GARequest(action=GARequest.ACTION_READ)
        request.resources = [GAResource('note-good', None)]
        request.token = 'token'
        session = GASession()
        auth_plugin = GASimpleAuthenticationPlugin()
        auth_info = auth_plugin.authenticate(request=request, session=session)

        self.assertIsNone(auth_info)
Пример #7
0
    def test_authenticate_without_auth_function(self):
        """
        """
        GASDKLibrary().register_sdk('default', tstdk)

        request = GARequest(action=GARequest.ACTION_READ)
        request.resources = [GAResource('root', None)]
        request.token = 'token'
        session = GASession()
        auth_plugin = GASimpleAuthenticationPlugin()
        auth_info = auth_plugin.authenticate(request=request, session=session)

        self.assertEquals(auth_info.__class__, tstdk.GARoot)
Пример #8
0
    def test_authenticate_with_auth_function(self):
        """
        """
        GASDKLibrary().register_sdk('default', tstdk)

        o_request = GARequest(action=GARequest.ACTION_READ)
        o_request.resources = [GAResource('root', None)]
        o_request.token = 'token'
        o_session = GASession()

        def auth_function(request, session, root_object_class, storage_controller):
            self.assertEquals(request, o_request)
            self.assertEquals(session, o_session)
            self.assertEquals(root_object_class, tstdk.GARoot)
            self.assertEquals(storage_controller, 'fake_storage_controller')

        auth_plugin = GASimpleAuthenticationPlugin()
        auth_plugin.core_controller = FakeCoreController()
        auth_plugin._auth_function = auth_function
        auth_plugin.authenticate(request=o_request, session=o_session)
def start(falcon_port, mongo_host, mongo_port, mongo_db, redis_host,
          redis_port, redis_db):
    """
    """
    # redis
    redis_info = {'host': redis_host, 'port': redis_port, 'db': redis_db}

    # mongo
    mongo_uri = 'mongodb://%s:%d' % (mongo_host, mongo_port)

    if os.path.exists("/certificates"):
        channel = GAFalconChannel(port=falcon_port,
                                  ssl_certificate='/certificates/server.pem',
                                  ssl_key='/certificates/server.key')
    else:
        channel = GAFalconChannel(port=falcon_port)

    storage_plugin = GAMongoStoragePlugin(db_name=mongo_db,
                                          mongo_uri=mongo_uri,
                                          db_initialization_function=db_init)
    authentication_plugin = GASimpleAuthenticationPlugin(
        auth_function=auth_function)
    permissions_plugin = GAOwnerPermissionsPlugin()
    sdk_infos = [{'identifier': 'default', 'module': 'specdk.v1_0'}]

    plugins = [
        storage_plugin, authentication_plugin, permissions_plugin,
        SDJobLogicPlugin(),
        SDAPILogicPlugin(),
        SDSpecificationLogicPlugin(),
        SDAbstractLogicPlugin(),
        SDAttributeLogicPlugin(),
        SDAPIInfoLogicPlugin(),
        SDRepositoryLogicPlugin(),
        SDMonolitheConfigLogicPlugin(),
        SDTokenLogicPlugin()
    ]

    garuda = Garuda(
        sdks_info=sdk_infos,
        redis_info=redis_info,
        channels=[channel],
        additional_controller_classes=[SDGitHubOperationsClient],
        additional_master_controller_classes=[SDGitHubOperationsController],
        plugins=plugins,
        log_level=logging.DEBUG)

    logger.info('starting specification director')
    garuda.start()
    def setUpClass(cls):
        """
        """
        def auth_function(request, session, root_object_class, storage_controller):
            pass

        cls.falcon_channel = GAFalconChannel(port=5454)
        cls.authentication_plugin = GASimpleAuthenticationPlugin(auth_function=auth_function)
        cls.storage_plugin = GAMongoStoragePlugin(db_name='test-db')
        cls.redis_info = {'host': '127.0.0.1', 'port': 6379, 'db': 6}

        cls.channels_controller = GAChannelsController(garuda_uuid='garuda-uuid',
                                                       channels=[cls.falcon_channel],
                                                       redis_info=cls.redis_info,
                                                       additional_controller_classes=[],
                                                       logic_plugins=[],
                                                       authentication_plugins=[cls.authentication_plugin],
                                                       storage_plugins=[cls.storage_plugin],
                                                       permission_plugins=[])
Пример #11
0
    def test_authenticate_with_auth_function(self):
        """
        """
        GASDKLibrary().register_sdk('default', tstdk)

        o_request = GARequest(action=GARequest.ACTION_READ)
        o_request.resources = [GAResource('root', None)]
        o_request.token = 'token'
        o_session = GASession()

        def auth_function(request, session, root_object_class,
                          storage_controller):
            self.assertEquals(request, o_request)
            self.assertEquals(session, o_session)
            self.assertEquals(root_object_class, tstdk.GARoot)
            self.assertEquals(storage_controller, 'fake_storage_controller')

        auth_plugin = GASimpleAuthenticationPlugin()
        auth_plugin.core_controller = FakeCoreController()
        auth_plugin._auth_function = auth_function
        auth_plugin.authenticate(request=o_request, session=o_session)
Пример #12
0
 def test_should_manage(self):
     """
     """
     auth_plugin = GASimpleAuthenticationPlugin()
     self.assertTrue(auth_plugin.should_manage(request='fake'))
Пример #13
0
 def test_identifiers(self):
     """
     """
     auth_plugin = GASimpleAuthenticationPlugin()
     self.assertEquals(auth_plugin.__class__.manifest().identifier, 'garuda.plugin.authentication.simple')
     self.assertEquals(auth_plugin.manifest().identifier, 'garuda.plugin.authentication.simple')
Пример #14
0
 def test_should_manage(self):
     """
     """
     auth_plugin = GASimpleAuthenticationPlugin()
     self.assertTrue(auth_plugin.should_manage(request='fake'))