From 971d26abbfdee302681b2fa832ef6a069a19a267 Mon Sep 17 00:00:00 2001 From: Calina Cenan Date: Wed, 6 Apr 2022 08:55:30 +0000 Subject: [PATCH] Adds single filter. --- aquarius/app/util.py | 10 ++++++++++ tests/test_util.py | 15 ++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/aquarius/app/util.py b/aquarius/app/util.py index 62c9eb86..5d835c00 100644 --- a/aquarius/app/util.py +++ b/aquarius/app/util.py @@ -11,6 +11,7 @@ from json import JSONDecodeError import logging import os +import requests from web3.main import Web3 from aquarius.app.auth_util import sanitize_addresses @@ -23,6 +24,15 @@ def sanitize_record(data_record): if "_id" in data_record: data_record.pop("_id") + if os.getenv("RBAC_SERVER_URL"): + payload = { + "eventType": "filter_single_result", + "component": "metadatacache", + "ddo": data_record, + } + + return requests.post(os.getenv("RBAC_SERVER_URL"), json=payload).json() + return json.dumps(data_record, default=datetime_converter) diff --git a/tests/test_util.py b/tests/test_util.py index 7911909f..7b9a61fd 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -6,8 +6,9 @@ import json import logging import os +from requests.models import Response from datetime import datetime -from unittest.mock import patch +from unittest.mock import patch, Mock import pytest @@ -112,6 +113,18 @@ def test_sanitize_record(): assert result["other_value"] == "something else" +def test_sanitize_record_through_rbac(monkeypatch): + monkeypatch.setenv("RBAC_SERVER_URL", "test") + + with patch("requests.post") as mock: + response = Mock(spec=Response) + response.json.return_value = {"this_is": "SPARTAAA!"} + mock.return_value = response + + result = sanitize_record({}) + assert result["this_is"] == "SPARTAAA!" + + class BlockProcessingClassChild(BlockProcessingClass): def get_last_processed_block(self): raise Exception("BAD!")