mirror of https://github.com/nucypher/nucypher.git
Implement a redundant validation of JsonApiCondition scheme (RFC)
parent
06af880616
commit
40b7b65508
|
@ -323,6 +323,15 @@ class ReturnValueTest:
|
|||
value = _resolve_context_variable(self.value, **context)
|
||||
return ReturnValueTest(self.comparator, value=value, index=self.index)
|
||||
|
||||
def as_dict(self):
|
||||
result = {
|
||||
"comparator": self.comparator,
|
||||
"value": self.value,
|
||||
}
|
||||
if self.index is not None:
|
||||
result["index"] = self.index
|
||||
return result
|
||||
|
||||
|
||||
class ConditionLingo(_Serializable):
|
||||
VERSION = "1.0.0"
|
||||
|
|
|
@ -10,6 +10,7 @@ from nucypher.policy.conditions.base import AccessControlCondition
|
|||
from nucypher.policy.conditions.exceptions import (
|
||||
ConditionEvaluationFailed,
|
||||
InvalidCondition,
|
||||
InvalidConditionLingo,
|
||||
)
|
||||
from nucypher.policy.conditions.lingo import ConditionType, ReturnValueTest
|
||||
from nucypher.policy.conditions.utils import CamelCaseSchema
|
||||
|
@ -83,6 +84,20 @@ class JsonApiCondition(AccessControlCondition):
|
|||
f"{self.__class__.__name__} must be instantiated with the {self.CONDITION_TYPE} type."
|
||||
)
|
||||
|
||||
# validate inputs using marshmallow schema
|
||||
data = {
|
||||
"conditionType": condition_type,
|
||||
"endpoint": endpoint,
|
||||
"query": query,
|
||||
"returnValueTest": return_value_test.as_dict(),
|
||||
}
|
||||
if parameters:
|
||||
data["parameters"] = parameters
|
||||
schema = self.Schema()
|
||||
errors = schema.validate(data)
|
||||
if errors:
|
||||
raise InvalidConditionLingo(errors)
|
||||
|
||||
self.endpoint = endpoint
|
||||
self.parameters = parameters
|
||||
self.query = query
|
||||
|
|
Loading…
Reference in New Issue