Example #1
0
class BackupInstanceFaulty(MessageBase):
    typename = BACKUP_INSTANCE_FAULTY
    schema = ((f.VIEW_NO.nm, NonNegativeNumberField()),
              (f.INSTANCES.nm, IterableField(NonNegativeNumberField())),
              (f.REASON.nm, NonNegativeNumberField()))
Example #2
0
class OldViewPrePrepareReply(MessageBase):
    typename = OLD_VIEW_PREPREPARE_REP
    schema = (
        (f.INST_ID.nm, NonNegativeNumberField()),
        (f.PREPREPARES.nm, IterableField(AnyField())),
    )
Example #3
0
class InstanceChange(MessageBase):
    typename = INSTANCE_CHANGE
    schema = ((f.VIEW_NO.nm, NonNegativeNumberField()),
              (f.REASON.nm, NonNegativeNumberField()))
Example #4
0
class ClientMessageValidator(MessageValidator):
    schema = (
        (f.IDENTIFIER.nm, IdentifierField(optional=True, nullable=True)),
        (f.REQ_ID.nm, NonNegativeNumberField()),
        (OPERATION, ClientOperationField()),
        (f.SIG.nm,
         SignatureField(max_length=SIGNATURE_FIELD_LIMIT, optional=True)),
        (f.DIGEST.nm,
         LimitedLengthStringField(max_length=DIGEST_FIELD_LIMIT,
                                  optional=True)),
        (f.PROTOCOL_VERSION.nm, ProtocolVersionField()),
        (f.TAA_ACCEPTANCE.nm, ClientTAAAcceptance(optional=True)),
        (f.SIGS.nm,
         MapField(IdentifierField(),
                  SignatureField(max_length=SIGNATURE_FIELD_LIMIT),
                  optional=True,
                  nullable=True)),
        (f.ENDORSER.nm, IdentifierField(optional=True)),
    )

    def __init__(self, operation_schema_is_strict, *args, **kwargs):
        super().__init__(*args, **kwargs)
        # Following code is for support of non-strict schema
        # TODO: refactor this
        # TODO: this (and all related functionality) can be removed when
        # when fixed problem with transaction serialization (INDY-338)
        # Adding fields from enabled plugins to schema.
        self.schema = self.schema + tuple(PLUGIN_CLIENT_REQUEST_FIELDS.items())
        if operation_schema_is_strict:
            operation_field_index = 2
            op = ClientOperationField(
                schema_is_strict=operation_schema_is_strict)
            schema = list(self.schema)
            schema[operation_field_index] = (OPERATION, op)
            self.schema = tuple(schema)

    def validate(self, dct):
        super().validate(dct)
        identifier = dct.get(f.IDENTIFIER.nm, None)
        signatures = dct.get(f.SIGS.nm, None)
        signature = dct.get(f.SIG.nm, None)
        endorser = dct.get(f.ENDORSER.nm, None)
        if signatures and signature:
            self._raise_invalid_message(
                'Request can not contain both fields "signatures" and "signature"'
            )
        if endorser is not None:
            if not signatures or endorser not in signatures:
                self._raise_invalid_message("Endorser must sign the request")
            if identifier is None:
                self._raise_invalid_message(
                    "Author's Identifier must be present when sending via Endorser"
                )
            if not signatures or identifier not in signatures:
                self._raise_invalid_message(
                    "Author must sign the request when sending via Endorser")
        if identifier and signatures and identifier not in signatures:
            self._raise_invalid_message(
                'The identifier is not contained in signatures')
        if not (identifier or signatures):
            self._raise_invalid_message(
                'Missing both signatures and identifier')
Example #5
0
class OldViewPrePrepareRequest(MessageBase):
    typename = OLD_VIEW_PREPREPARE_REQ
    schema = (
        (f.INST_ID.nm, NonNegativeNumberField()),
        (f.BATCH_IDS.nm, IterableField(BatchIDField())),
    )
Example #6
0
class ClientGetTxnAuthorAgreementAMLOperation(MessageValidator):
    schema = ((TXN_TYPE, ConstantField(GET_TXN_AUTHOR_AGREEMENT_AML)),
              (GET_TXN_AUTHOR_AGREEMENT_AML_VERSION,
               NonEmptyStringField(optional=True)),
              (GET_TXN_AUTHOR_AGREEMENT_AML_TIMESTAMP,
               NonNegativeNumberField(optional=True)))
 class ANewMessageClass(MessageBase):
     typename = 'NewMessage'
     schema = (('a', NonNegativeNumberField()), )
Example #8
0
def test_valid_inner_type():
    validator = IterableField(NonNegativeNumberField())
    assert not validator.validate([1, 2, 3])
    assert validator.validate([1, 2, -3])
Example #9
0
 def __init__(self, **kwargs):
     super().__init__(NonEmptyStringField(), NonNegativeNumberField(),
                      **kwargs)
Example #10
0
class MessageTest(MessageBase):
    typename = 'MessageTest'
    schema = (
        ('a', NonNegativeNumberField()),
        ('b', NonNegativeNumberField()),
    )