def test_auth_rule_static_validation_failed_with_excess_field( get_auth_rule_request, get_auth_rule_handler: GetAuthRuleHandler): get_auth_rule_request.operation[OLD_VALUE] = "old_value" get_auth_rule_request.operation[AUTH_ACTION] = ADD_PREFIX with pytest.raises(InvalidClientRequest, match="ADD must not contain field old_value"): get_auth_rule_handler.static_validation(get_auth_rule_request)
def test_auth_rule_static_validation_failed_without_old_value( get_auth_rule_request, get_auth_rule_handler: GetAuthRuleHandler): if OLD_VALUE in get_auth_rule_request.operation: del get_auth_rule_request.operation[OLD_VALUE] get_auth_rule_request.operation[AUTH_ACTION] = EDIT_PREFIX with pytest.raises(InvalidClientRequest, match="EDIT must contain field old_value"): get_auth_rule_handler.static_validation(get_auth_rule_request)
def test_auth_rule_static_validation_failed_with_incorrect_key( get_auth_rule_request, get_auth_rule_handler: GetAuthRuleHandler): get_auth_rule_request.operation.update( generate_key(auth_action=EDIT_PREFIX, auth_type="wrong_type", field=ROLE, new_value=ENDORSER, old_value="*")) with pytest.raises(InvalidClientRequest, match="is not found in authorization map"): get_auth_rule_handler.static_validation(get_auth_rule_request)
def _register_config_req_handlers(self): # Read handlers get_auth_rule_handler = GetAuthRuleHandler(database_manager=self.node.db_manager, write_req_validator=self.node.write_req_validator) # Write handlers auth_rule_handler = AuthRuleHandler(database_manager=self.node.db_manager, write_req_validator=self.node.write_req_validator) auth_rule_handler_1_9_1 = AuthRuleHandler191(database_manager=self.node.db_manager, write_req_validator=self.node.write_req_validator) auth_rules_handler = AuthRulesHandler(database_manager=self.node.db_manager, write_req_validator=self.node.write_req_validator) pool_config_handler = PoolConfigHandler(database_manager=self.node.db_manager, write_req_validator=self.node.write_req_validator, pool_config=self.node.poolCfg) pool_upgrade_handler = PoolUpgradeHandler(database_manager=self.node.db_manager, upgrader=self.node.upgrader, write_req_validator=self.node.write_req_validator, pool_manager=self.node.poolManager) taa_aml_handler = TxnAuthorAgreementAmlHandler(database_manager=self.node.db_manager, write_req_validator=self.node.write_req_validator) taa_handler = TxnAuthorAgreementHandler(database_manager=self.node.db_manager, write_req_validator=self.node.write_req_validator) taa_handler_v1 = TxnAuthorAgreementHandlerV1(database_manager=self.node.db_manager, write_req_validator=self.node.write_req_validator) taa_disable_handler = TxnAuthorAgreementDisableHandler(database_manager=self.node.db_manager, write_req_validator=self.node.write_req_validator) get_taa_aml_handler = GetTxnAuthorAgreementAmlHandler(database_manager=self.node.db_manager) get_taa_handler = GetTxnAuthorAgreementHandler(database_manager=self.node.db_manager) node_upgrade_handler = NodeUpgradeHandler(database_manager=self.node.db_manager) ledgers_freeze_handler = LedgersFreezeHandler(database_manager=self.node.db_manager, write_req_validator=self.node.write_req_validator) get_frozen_ledgers_handler = GetFrozenLedgersHandler(database_manager=self.node.db_manager) # Register write handlers self.node.write_manager.register_req_handler(auth_rule_handler) self.node.write_manager.register_req_handler(auth_rules_handler) self.node.write_manager.register_req_handler(pool_config_handler) self.node.write_manager.register_req_handler(pool_upgrade_handler) self.node.write_manager.register_req_handler(taa_aml_handler) self.node.write_manager.register_req_handler(taa_handler) self.node.write_manager.register_req_handler(taa_disable_handler) self.node.write_manager.register_req_handler(node_upgrade_handler) self.node.write_manager.register_req_handler(ledgers_freeze_handler) # Register read handlers self.node.read_manager.register_req_handler(get_auth_rule_handler) self.node.read_manager.register_req_handler(get_taa_aml_handler) self.node.read_manager.register_req_handler(get_taa_handler) self.node.read_manager.register_req_handler(get_frozen_ledgers_handler) # Register write handlers for a version self.node.write_manager.register_req_handler_with_version(auth_rule_handler_1_9_1, version="1.9.1") self.node.write_manager.register_req_handler_with_version(taa_handler_v1, version="1")
def register_config_req_handlers(self): # Read handlers get_auth_rule_handler = GetAuthRuleHandler( database_manager=self.node.db_manager, write_req_validator=self.node.write_req_validator) # Write handlers auth_rule_handler = AuthRuleHandler( database_manager=self.node.db_manager, write_req_validator=self.node.write_req_validator) auth_rules_handler = AuthRulesHandler( database_manager=self.node.db_manager, write_req_validator=self.node.write_req_validator) pool_config_handler = PoolConfigHandler( database_manager=self.node.db_manager, write_req_validator=self.node.write_req_validator, pool_config=self.node.poolCfg) pool_upgrade_handler = PoolUpgradeHandler( database_manager=self.node.db_manager, upgrader=self.node.upgrader, write_req_validator=self.node.write_req_validator, pool_manager=self.node.poolManager) taa_aml_handler = TxnAuthorAgreementAmlHandler( database_manager=self.node.db_manager, bls_crypto_verifier=self.node.bls_bft.bls_crypto_verifier, write_req_validator=self.node.write_req_validator) taa_handler = TxnAuthorAgreementHandler( database_manager=self.node.db_manager, bls_crypto_verifier=self.node.bls_bft.bls_crypto_verifier, write_req_validator=self.node.write_req_validator) get_taa_aml_handler = GetTxnAuthorAgreementAmlHandler( database_manager=self.node.db_manager) get_taa_handler = GetTxnAuthorAgreementHandler( database_manager=self.node.db_manager) node_upgrade_handler = NodeUpgradeHandler( database_manager=self.node.db_manager) # Register write handlers self.node.write_manager.register_req_handler(auth_rule_handler) self.node.write_manager.register_req_handler(auth_rules_handler) self.node.write_manager.register_req_handler(pool_config_handler) self.node.write_manager.register_req_handler(pool_upgrade_handler) self.node.write_manager.register_req_handler(taa_aml_handler) self.node.write_manager.register_req_handler(taa_handler) self.node.write_manager.register_req_handler(node_upgrade_handler) # Register read handlers self.node.read_manager.register_req_handler(get_auth_rule_handler) self.node.read_manager.register_req_handler(get_taa_aml_handler) self.node.read_manager.register_req_handler(get_taa_handler)
def register_config_req_handlers(self): # Read handlers get_auth_rule_handler = GetAuthRuleHandler(database_manager=self.db_manager, write_req_validator=self.write_req_validator) # Write handlers auth_rule_handler = AuthRuleHandler(database_manager=self.db_manager, write_req_validator=self.write_req_validator) auth_rules_handler = AuthRulesHandler(database_manager=self.db_manager, write_req_validator=self.write_req_validator) pool_config_handler = PoolConfigHandler(database_manager=self.db_manager, write_req_validator=self.write_req_validator, pool_config=self.poolCfg) pool_upgrade_handler = PoolUpgradeHandler(database_manager=self.db_manager, upgrader=self.upgrader, write_req_validator=self.write_req_validator, pool_manager=self.poolManager) # Register write handlers self.write_manager.register_req_handler(auth_rule_handler) self.write_manager.register_req_handler(auth_rules_handler) self.write_manager.register_req_handler(pool_config_handler) self.write_manager.register_req_handler(pool_upgrade_handler) # Register read handlers self.read_manager.register_req_handler(get_auth_rule_handler)
def test_all_auth_rules_static_validation( get_all_auth_rules_request, get_auth_rule_handler: GetAuthRuleHandler): get_auth_rule_handler.static_validation(get_all_auth_rules_request)
def get_auth_rule_handler(db_manager): f = FakeSomething() f.validate = lambda request, action_list: True f.auth_map = auth_map return GetAuthRuleHandler(db_manager, f)