def test_auth_rule_static_validation_failed_with_incorrect_key(auth_rules_request, auth_rules_handler: AuthRulesHandler): auth_rules_request.operation[RULES].append(generate_auth_rule(auth_action=ADD_PREFIX, auth_type="wrong_type", field=ROLE, new_value=ENDORSER)) with pytest.raises(InvalidClientRequest, match="key .* is not found in authorization map"): auth_rules_handler.static_validation(auth_rules_request)
def test_auth_rule_static_validation_failed_with_excess_field(auth_rules_request, auth_rules_handler: AuthRulesHandler): rule = auth_rules_request.operation[RULES][0] rule[OLD_VALUE] = "old_value" rule[AUTH_TYPE] = ADD_PREFIX with pytest.raises(InvalidClientRequest, match="ADD must not contain field old_value"): auth_rules_handler.static_validation(auth_rules_request)
def test_auth_rule_static_validation_failed_without_old_value(auth_rules_request, auth_rules_handler: AuthRulesHandler): rule = auth_rules_request.operation[RULES][0] if OLD_VALUE in rule: del rule[OLD_VALUE] rule[AUTH_ACTION] = EDIT_PREFIX with pytest.raises(InvalidClientRequest, match="EDIT must contain field old_value"): auth_rules_handler.static_validation(auth_rules_request)
def test_update_state(auth_rules_request, auth_rules_handler: AuthRulesHandler): txn = reqToTxn(auth_rules_request) payload = get_payload_data(txn) for rule in payload[RULES]: constraint = StaticAuthRuleHelper.get_auth_constraint(rule) auth_key = StaticAuthRuleHelper.get_auth_key(rule) path = AbstractAuthRuleHandler.make_state_path_for_auth_rule(auth_key) auth_rules_handler.update_state(txn, None, auth_rules_request) assert auth_rules_handler.get_from_state(path) == constraint.as_dict
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_auth_rule_dynamic_validation_without_permission( auth_rules_request, auth_rules_handler: AuthRulesHandler, creator): add_to_idr(auth_rules_handler.database_manager.idr_cache, creator, STEWARD) with pytest.raises(UnauthorizedClientRequest): auth_rules_handler.dynamic_validation(auth_rules_request)
def test_auth_rule_static_validation(auth_rules_request, auth_rules_handler: AuthRulesHandler): auth_rules_handler.static_validation(auth_rules_request)
def auth_rules_handler(db_manager, write_auth_req_validator): return AuthRulesHandler(db_manager, write_auth_req_validator)
def auth_rule_handler(db_manager): f = FakeSomething() f.validate = lambda request, action_list: True f.auth_map = auth_map return AuthRulesHandler(db_manager, f)