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)
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)
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)
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)
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)
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)