コード例 #1
0
def test_claim_def_dynamic_validation_without_ref_to_not_schema(claim_def_request, schema_request,
                                                                claim_def_handler: ClaimDefHandler, creator):
    nym = reqToTxn(Request(identifier=creator, operation={'type': NYM}))
    claim_def_request.operation[REF] = get_seq_no(nym)
    claim_def_handler.ledger.appendTxns([nym])
    with pytest.raises(InvalidClientRequest) as e:
        claim_def_handler.dynamic_validation(claim_def_request)
    assert "Mentioned seqNo ({}) isn't seqNo of the schema.".format(claim_def_request.operation[REF]) \
           in e._excinfo[1].args[0]
コード例 #2
0
def test_claim_def_dynamic_validation_for_unknown_identifier(
        claim_def_request, schema, claim_def_handler: ClaimDefHandler):
    test_identifier = randomString()
    claim_def_handler.ledger.appendTxns([schema])
    request = Request(identifier=test_identifier,
                      reqId=claim_def_request.reqId,
                      operation=claim_def_request.operation)
    with pytest.raises(
            UnauthorizedClientRequest,
            match='DID {} is not found in the Ledger'.format(test_identifier)):
        claim_def_handler.dynamic_validation(request, 0)
コード例 #3
0
def test_update_state_with_incorrect_schema_seq_no(
        claim_def_request, claim_def_handler: ClaimDefHandler, schema_handler,
        schema_request):
    claim_def_seq_no = 1
    claim_def_txn_time = 1560241033
    claim_def_txn = reqToTxn(claim_def_request)
    append_txn_metadata(claim_def_txn, claim_def_seq_no, claim_def_txn_time)
    with pytest.raises(
            ValueError,
            match="'{}' field is absent, "
            "but it must contain schema seq no".format(CLAIM_DEF_SCHEMA_REF)):
        claim_def_handler.update_state(claim_def_txn, None, claim_def_request)
コード例 #4
0
def test_claim_def_dynamic_validation_for_unknown_identifier(claim_def_request, schema_request,
                                                             claim_def_handler: ClaimDefHandler):
    claim_def_handler.write_request_validator.validate = get_exception(True)
    test_identifier = randomString()
    schema = reqToTxn(schema_request)
    claim_def_request.operation[REF] = get_seq_no(schema)
    claim_def_handler.ledger.appendTxns([schema])
    request = Request(identifier=test_identifier,
                      reqId=claim_def_request.reqId,
                      operation=claim_def_request.operation)
    with pytest.raises(UnauthorizedClientRequest) as e:
        claim_def_handler.dynamic_validation(request)
コード例 #5
0
def test_claim_def_dynamic_validation_without_permission(
        claim_def_request, schema, claim_def_handler: ClaimDefHandler):
    claim_def_handler.ledger.appendTxns([schema])
    test_identifier = randomString()
    idr = claim_def_handler.database_manager.idr_cache
    add_to_idr(idr, test_identifier, "")

    request = Request(identifier=test_identifier,
                      reqId=claim_def_request.reqId,
                      signature="sig",
                      operation=claim_def_request.operation)
    with pytest.raises(UnauthorizedClientRequest,
                       match="Not enough .* signatures"):
        claim_def_handler.dynamic_validation(request, 0)
コード例 #6
0
def test_claim_def_dynamic_validation_without_permission(claim_def_request, schema_request,
                                                         claim_def_handler: ClaimDefHandler):
    claim_def_handler.write_request_validator.validate = get_exception(True)
    schema = reqToTxn(schema_request)
    claim_def_request.operation[REF] = get_seq_no(schema)
    claim_def_handler.ledger.appendTxns([schema])

    test_identifier = randomString()
    idr = claim_def_handler.database_manager.idr_cache
    add_to_idr(idr, test_identifier, "")

    request = Request(identifier=test_identifier,
                      reqId=claim_def_request.reqId,
                      operation=claim_def_request.operation)
    with pytest.raises(UnauthorizedClientRequest) as e:
        claim_def_handler.dynamic_validation(request)
コード例 #7
0
ファイル: node_bootstrap.py プロジェクト: shntnkd/indy-node
 def _register_domain_req_handlers(self):
     # Read handlers
     get_nym_handler = GetNymHandler(database_manager=self.node.db_manager)
     get_attribute_handler = GetAttributeHandler(
         database_manager=self.node.db_manager)
     get_schema_handler = GetSchemaHandler(
         database_manager=self.node.db_manager)
     get_claim_def_handler = GetClaimDefHandler(
         database_manager=self.node.db_manager)
     get_revoc_reg_def_handler = GetRevocRegDefHandler(
         database_manager=self.node.db_manager)
     get_revoc_reg_handler = GetRevocRegHandler(
         database_manager=self.node.db_manager)
     get_revoc_reg_delta_handler = GetRevocRegDeltaHandler(
         database_manager=self.node.db_manager,
         get_revocation_strategy=RevocRegDefHandler.get_revocation_strategy)
     # Write handlers
     nym_handler = NymHandler(
         config=self.node.config,
         database_manager=self.node.db_manager,
         write_req_validator=self.node.write_req_validator)
     attrib_handler = AttributeHandler(
         database_manager=self.node.db_manager,
         write_req_validator=self.node.write_req_validator)
     schema_handler = SchemaHandler(
         database_manager=self.node.db_manager,
         write_req_validator=self.node.write_req_validator)
     claim_def_handler = ClaimDefHandler(
         database_manager=self.node.db_manager,
         write_req_validator=self.node.write_req_validator)
     revoc_reg_def_handler = RevocRegDefHandler(
         database_manager=self.node.db_manager,
         write_req_validator=self.node.write_req_validator)
     revoc_reg_entry_handler = RevocRegEntryHandler(
         database_manager=self.node.db_manager,
         write_req_validator=self.node.write_req_validator,
         get_revocation_strategy=RevocRegDefHandler.get_revocation_strategy)
     # Register write handlers
     self.node.write_manager.register_req_handler(nym_handler)
     self.node.write_manager.register_req_handler(attrib_handler)
     self.node.write_manager.register_req_handler(schema_handler)
     self.node.write_manager.register_req_handler(claim_def_handler)
     self.node.write_manager.register_req_handler(revoc_reg_def_handler)
     self.node.write_manager.register_req_handler(revoc_reg_entry_handler)
     # Additional handler for idCache
     self.register_idr_cache_nym_handler()
     # Register read handlers
     self.node.read_manager.register_req_handler(get_nym_handler)
     self.node.read_manager.register_req_handler(get_attribute_handler)
     self.node.read_manager.register_req_handler(get_schema_handler)
     self.node.read_manager.register_req_handler(get_claim_def_handler)
     self.node.read_manager.register_req_handler(get_revoc_reg_def_handler)
     self.node.read_manager.register_req_handler(get_revoc_reg_handler)
     self.node.read_manager.register_req_handler(
         get_revoc_reg_delta_handler)
コード例 #8
0
def test_update_state(claim_def_request, claim_def_handler: ClaimDefHandler,
                      schema_handler, schema_request):
    # add schema to state
    schema_seq_no = 1
    schema_txn_time = 1560241000
    schema_txn = reqToTxn(schema_request)
    append_txn_metadata(schema_txn, schema_seq_no, schema_txn_time)
    schema_handler.update_state(schema_txn, None, schema_request)

    # prepare claim def data
    claim_def_request.operation[REF] = schema_seq_no
    claim_def_seq_no = 1
    claim_def_txn_time = 1560241033
    claim_def_txn = reqToTxn(claim_def_request)
    append_txn_metadata(claim_def_txn, claim_def_seq_no, claim_def_txn_time)
    path, value_bytes = ClaimDefHandler.prepare_claim_def_for_state(
        claim_def_txn)

    claim_def_handler.update_state(claim_def_txn, None, claim_def_request)
    assert claim_def_handler.get_from_state(path) == (
        claim_def_request.operation[CLAIM_DEF_PUBLIC_KEYS], claim_def_seq_no,
        claim_def_txn_time)
コード例 #9
0
def test_update_state_with_incorrect_data(claim_def_request,
                                          claim_def_handler: ClaimDefHandler,
                                          schema_handler, schema_request):
    # add schema to state
    schema_seq_no = 1
    schema_txn_time = 1560241000
    schema_txn = reqToTxn(schema_request)
    append_txn_metadata(schema_txn, schema_seq_no, schema_txn_time)
    schema_handler.update_state(schema_txn, None, schema_request)

    # set incorrect CLAIM_DEF_PUBLIC_KEYS
    claim_def_request.operation[CLAIM_DEF_PUBLIC_KEYS] = None
    # prepare claim def data
    claim_def_request.operation[REF] = schema_seq_no
    claim_def_seq_no = 1
    claim_def_txn_time = 1560241033
    claim_def_txn = reqToTxn(claim_def_request)
    append_txn_metadata(claim_def_txn, claim_def_seq_no, claim_def_txn_time)

    with pytest.raises(ValueError,
                       match="'{}' field is absent, but it must contain "
                       "components of keys".format(CLAIM_DEF_PUBLIC_KEYS)):
        claim_def_handler.update_state(claim_def_txn, None, claim_def_request)
コード例 #10
0
 def get_claim_def(self,
                   author: str,
                   schema_seq_no: str,
                   signature_type,
                   tag,
                   is_committed=True) -> (str, int, int, list):
     assert author is not None
     assert schema_seq_no is not None
     path = ClaimDefHandler.make_state_path_for_claim_def(
         author, schema_seq_no, signature_type, tag)
     try:
         keys, seq_no, last_update_time, proof = self.lookup(
             path, is_committed, with_proof=True)
         return keys, seq_no, last_update_time, proof
     except KeyError:
         return None, None, None, None
コード例 #11
0
def test_claim_def_dynamic_validation_for_new_claim_def(
        claim_def_request, schema, claim_def_handler: ClaimDefHandler):
    claim_def_handler.ledger.appendTxns([schema])
    claim_def_handler.dynamic_validation(claim_def_request, 0)
コード例 #12
0
def test_claim_def_dynamic_validation_without_schema(
        claim_def_request, claim_def_handler: ClaimDefHandler):
    with pytest.raises(InvalidClientRequest) as e:
        claim_def_handler.dynamic_validation(claim_def_request, 0)
    assert "Mentioned seqNo ({}) doesn't exist.".format(claim_def_request.operation[REF]) \
           in e._excinfo[1].reason
コード例 #13
0
def claim_def_handler(db_manager, write_auth_req_validator):
    return ClaimDefHandler(db_manager, write_auth_req_validator)
コード例 #14
0
    def _register_domain_req_handlers(self):
        # Read handlers
        get_nym_handler = GetNymHandler(database_manager=self.node.db_manager)
        get_attribute_handler = GetAttributeHandler(
            database_manager=self.node.db_manager)
        get_schema_handler = GetSchemaHandler(
            database_manager=self.node.db_manager)
        get_claim_def_handler = GetClaimDefHandler(
            database_manager=self.node.db_manager)
        get_revoc_reg_def_handler = GetRevocRegDefHandler(
            database_manager=self.node.db_manager)
        get_revoc_reg_handler = GetRevocRegHandler(
            database_manager=self.node.db_manager)
        get_revoc_reg_delta_handler = GetRevocRegDeltaHandler(
            database_manager=self.node.db_manager,
            get_revocation_strategy=RevocRegDefHandler.get_revocation_strategy)
        # Write handlers
        nym_handler = NymHandler(
            config=self.node.config,
            database_manager=self.node.db_manager,
            write_req_validator=self.node.write_req_validator)
        attrib_handler = AttributeHandler(
            database_manager=self.node.db_manager,
            write_req_validator=self.node.write_req_validator)
        schema_handler = SchemaHandler(
            database_manager=self.node.db_manager,
            write_req_validator=self.node.write_req_validator)
        claim_def_handler = ClaimDefHandler(
            database_manager=self.node.db_manager,
            write_req_validator=self.node.write_req_validator)
        revoc_reg_def_handler = RevocRegDefHandler(
            database_manager=self.node.db_manager,
            write_req_validator=self.node.write_req_validator)
        revoc_reg_entry_handler = RevocRegEntryHandler(
            database_manager=self.node.db_manager,
            write_req_validator=self.node.write_req_validator,
            get_revocation_strategy=RevocRegDefHandler.get_revocation_strategy)
        json_ld_context_handler = JsonLdContextHandler(
            database_manager=self.node.db_manager,
            write_req_validator=self.node.write_req_validator)
        rich_schema_handler = RichSchemaHandler(
            database_manager=self.node.db_manager,
            write_req_validator=self.node.write_req_validator)
        rich_schema_encoding_handler = RichSchemaEncodingHandler(
            database_manager=self.node.db_manager,
            write_req_validator=self.node.write_req_validator)
        rich_schema_mapping_handler = RichSchemaMappingHandler(
            database_manager=self.node.db_manager,
            write_req_validator=self.node.write_req_validator)
        rich_schema_cred_def_handler = RichSchemaCredDefHandler(
            database_manager=self.node.db_manager,
            write_req_validator=self.node.write_req_validator)
        rich_schema_pres_def_handler = RichSchemaPresDefHandler(
            database_manager=self.node.db_manager,
            write_req_validator=self.node.write_req_validator)
        get_rich_schema_obj_by_id_handler = GetRichSchemaObjectByIdHandler(
            database_manager=self.node.db_manager)
        get_rich_schema_obj_by_metadata_handler = GetRichSchemaObjectByMetadataHandler(
            database_manager=self.node.db_manager)

        # Register write handlers
        self.node.write_manager.register_req_handler(nym_handler)
        self.node.write_manager.register_req_handler(attrib_handler)
        self.node.write_manager.register_req_handler(schema_handler)
        self.node.write_manager.register_req_handler(claim_def_handler)
        self.node.write_manager.register_req_handler(revoc_reg_def_handler)
        self.node.write_manager.register_req_handler(revoc_reg_entry_handler)
        self.node.write_manager.register_req_handler(json_ld_context_handler)
        self.node.write_manager.register_req_handler(rich_schema_handler)
        self.node.write_manager.register_req_handler(
            rich_schema_encoding_handler)
        self.node.write_manager.register_req_handler(
            rich_schema_mapping_handler)
        self.node.write_manager.register_req_handler(
            rich_schema_cred_def_handler)
        self.node.write_manager.register_req_handler(
            rich_schema_pres_def_handler)
        # Additional handler for idCache
        self.register_idr_cache_nym_handler()
        # Register read handlers
        self.node.read_manager.register_req_handler(get_nym_handler)
        self.node.read_manager.register_req_handler(get_attribute_handler)
        self.node.read_manager.register_req_handler(get_schema_handler)
        self.node.read_manager.register_req_handler(get_claim_def_handler)
        self.node.read_manager.register_req_handler(get_revoc_reg_def_handler)
        self.node.read_manager.register_req_handler(get_revoc_reg_handler)
        self.node.read_manager.register_req_handler(
            get_revoc_reg_delta_handler)
        self.node.read_manager.register_req_handler(
            get_rich_schema_obj_by_id_handler)
        self.node.read_manager.register_req_handler(
            get_rich_schema_obj_by_metadata_handler)
コード例 #15
0
def test_claim_def_dynamic_validation_for_new_claim_def(claim_def_request, schema_request,
                                                        claim_def_handler: ClaimDefHandler):
    schema = reqToTxn(schema_request)
    claim_def_request.operation[REF] = get_seq_no(schema)
    claim_def_handler.ledger.appendTxns([schema])
    claim_def_handler.dynamic_validation(claim_def_request)
コード例 #16
0
def claim_def_handler(db_manager):
    f = FakeSomething()
    f.validate = lambda request, action_list: True
    return ClaimDefHandler(db_manager, f)