Beispiel #1
0
def test_nym_dynamic_validation_for_new_nym(nym_request,
                                            nym_handler: NymHandler, creator):
    nym_handler.write_req_validator.validate = get_exception(False)
    add_to_idr(nym_handler.database_manager.idr_cache, creator, STEWARD)
    nym_handler.dynamic_validation(nym_request)

    nym_handler.write_req_validator.validate = get_exception(True)
    with pytest.raises(UnauthorizedClientRequest):
        nym_handler.dynamic_validation(nym_request)
Beispiel #2
0
def test_update_state(nym_request: Request, nym_handler: NymHandler):
    seq_no = 1
    txn_time = 1560241033
    nym = nym_request.operation.get(TARGET_NYM)
    txn = reqToTxn(nym_request)
    append_txn_metadata(txn, seq_no, txn_time)
    path = nym_to_state_key(nym)

    result = nym_handler.update_state(txn, None, nym_request)
    state_value = nym_handler.get_from_state(path)
    assert state_value == result
    assert state_value[IDENTIFIER] == nym_request.identifier
    assert state_value[F.seqNo.name] == seq_no
    assert state_value[ROLE] == nym_request.operation.get(ROLE)
    assert state_value[VERKEY] == nym_request.operation.get(VERKEY)
Beispiel #3
0
def test_nym_dynamic_validation_for_existing_nym_fails_with_no_changes(
        nym_handler: NymHandler, creator):
    nym_request = Request(identifier=creator,
                          reqId=5,
                          operation={
                              'type': NYM,
                              'dest': randomString()
                          })
    add_to_idr(nym_handler.database_manager.idr_cache,
               nym_request.operation['dest'], None)
    add_to_idr(nym_handler.database_manager.idr_cache, creator, STEWARD)

    nym_handler.write_req_validator.validate = get_exception(True)
    with pytest.raises(InvalidClientRequest):
        nym_handler.dynamic_validation(nym_request, 0)
    def get_result(self, request: Request):
        self._validate_request_type(request)
        nym = request.operation[TARGET_NYM]
        path = NymHandler.make_state_path_for_nym(nym)
        nym_data, proof = self._get_value_from_state(path, with_proof=True)
        if nym_data:
            nym_data = domain_state_serializer.deserialize(nym_data)
            nym_data[TARGET_NYM] = nym
            data = domain_state_serializer.serialize(nym_data)
            seq_no = nym_data[f.SEQ_NO.nm]
            update_time = nym_data[TXN_TIME]
        else:
            data = None
            seq_no = None
            update_time = None

        # TODO: add update time here!
        result = self.make_result(request=request,
                                  data=data,
                                  last_seq_no=seq_no,
                                  update_time=update_time,
                                  proof=proof)

        result.update(request.operation)
        return result
Beispiel #5
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)
     # 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)
Beispiel #6
0
def test_nym_static_validation_not_authorized_random(nym_request,
                                                     nym_handler: NymHandler):
    nym_request.operation['role'] = randomString()
    with pytest.raises(InvalidClientRequest):
        nym_handler.static_validation(nym_request)
Beispiel #7
0
def test_nym_static_validation_authorized(nym_request,
                                          nym_handler: NymHandler):
    for role in Authoriser.ValidRoles:
        nym_request.operation['role'] = role
        nym_handler.static_validation(nym_request)
Beispiel #8
0
def test_nym_static_validation_failed_with_spaced_dest(
        nym_request, nym_handler: NymHandler):
    nym_request.operation['dest'] = ' ' * 5
    with pytest.raises(InvalidClientRequest):
        nym_handler.static_validation(nym_request)
Beispiel #9
0
def test_nym_static_validation_passes(nym_request, nym_handler: NymHandler):
    nym_handler.static_validation(nym_request)
Beispiel #10
0
def nym_handler(db_manager, tconf, write_auth_req_validator):
    return NymHandler(tconf, db_manager, write_auth_req_validator)
Beispiel #11
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)
Beispiel #12
0
def nym_handler(db_manager):
    f = FakeSomething()
    f.validate = lambda request, action_list: True
    return NymHandler(db_manager, f)