コード例 #1
0
ファイル: securities.py プロジェクト: zippyy/program-y
class BrainSecuritiesConfiguration(BaseSectionConfigurationData):
    def __init__(self):
        BaseSectionConfigurationData.__init__(self, "security")
        self._authorisation = None
        self._authentication = None
        self._account_linker = None

    @property
    def authorisation(self):
        return self._authorisation

    @property
    def authentication(self):
        return self._authentication

    @property
    def account_linker(self):
        return self._account_linker

    def load_config_section(self, configuration_file, configuration, bot_root):
        securities = configuration_file.get_section(self.section_name, configuration)
        if securities is not None:
            self._authentication = BrainSecurityAuthenticationConfiguration()
            self._authentication.load_config_section(configuration_file, securities, bot_root)

            self._authorisation = BrainSecurityAuthorisationConfiguration()
            self._authorisation.load_config_section(configuration_file, securities, bot_root)

            self._account_linker = BrainSecurityAccountLinkerConfiguration()
            self._account_linker.load_config_section(configuration_file, securities, bot_root)

    def to_yaml(self, data, defaults=True):
        self.config_to_yaml(data, BrainSecurityAuthenticationConfiguration(), defaults)
        self.config_to_yaml(data, BrainSecurityAuthorisationConfiguration(), defaults)
        self.config_to_yaml(data, BrainSecurityAccountLinkerConfiguration(), defaults)
コード例 #2
0
ファイル: securities.py プロジェクト: lilnana00/3ddd
    def load_config_section(self,
                            configuration_file,
                            configuration,
                            bot_root,
                            subs: Substitutions = None):
        securities = configuration_file.get_section(self.section_name,
                                                    configuration)
        if securities is not None:
            self._authentication = BrainSecurityAuthenticationConfiguration()
            self._authentication.load_config_section(configuration_file,
                                                     securities,
                                                     bot_root,
                                                     subs=subs)

            self._authorisation = BrainSecurityAuthorisationConfiguration()
            self._authorisation.load_config_section(configuration_file,
                                                    securities,
                                                    bot_root,
                                                    subs=subs)

            self._account_linker = BrainSecurityAccountLinkerConfiguration()
            self._account_linker.load_config_section(configuration_file,
                                                     securities,
                                                     bot_root,
                                                     subs=subs)
コード例 #3
0
ファイル: securities.py プロジェクト: lilnana00/3ddd
 def to_yaml(self, data, defaults=True):
     self.config_to_yaml(data, BrainSecurityAuthenticationConfiguration(),
                         defaults)
     self.config_to_yaml(data, BrainSecurityAuthorisationConfiguration(),
                         defaults)
     self.config_to_yaml(data, BrainSecurityAccountLinkerConfiguration(),
                         defaults)
コード例 #4
0
ファイル: test_security.py プロジェクト: lilnana00/3ddd
    def test_defaults(self):
        authenticate_config = BrainSecurityAuthenticationConfiguration()
        data = {}
        authenticate_config.to_yaml(data, True)

        BrainSecurityConfigurationTests.assert_authenticate_defaults(
            self, data)

        authorise_config = BrainSecurityAuthorisationConfiguration()
        data = {}
        authorise_config.to_yaml(data, True)

        BrainSecurityConfigurationTests.assert_authorise_defaults(self, data)

        accountlinker_config = BrainSecurityAccountLinkerConfiguration()
        data = {}
        accountlinker_config.to_yaml(data, True)

        BrainSecurityConfigurationTests.assert_accountlinker_defaults(
            self, data)
コード例 #5
0
ファイル: test_manager.py プロジェクト: lilnana00/3ddd
    def test_fail_load_authorisation_class(self):
        config = BrainSecuritiesConfiguration()
        config._authorisation = BrainSecurityAuthorisationConfiguration()
        config._authentication = BrainSecurityAuthenticationConfiguration()
        config._account_linker = BrainSecurityAccountLinkerConfiguration()

        mgr = MockSecurityManager(config, fail_authorise=True)
        self.assertIsNotNone(mgr)

        client = TestClient()
        mgr.load_security_services(client)

        self.assertIsNone(mgr.authorisation)
        self.assertIsNotNone(mgr.authentication)
        self.assertIsNotNone(mgr.account_linker)
コード例 #6
0
ファイル: test_manager.py プロジェクト: lilnana00/3ddd
    def test_fail_load_account_linking_class_missing(self):
        config = BrainSecuritiesConfiguration()
        config._authorisation = BrainSecurityAuthorisationConfiguration()
        config._authentication = BrainSecurityAuthenticationConfiguration()
        config._account_linker = BrainSecurityAccountLinkerConfiguration()
        config._account_linker._classname = None

        mgr = SecurityManager(config)
        self.assertIsNotNone(mgr)

        client = TestClient()
        mgr.load_security_services(client)

        self.assertIsNotNone(mgr.authorisation)
        self.assertIsNotNone(mgr.authentication)
        self.assertIsNone(mgr.account_linker)