From b04878d5930caab9d37d98722d158b92c5bdcf93 Mon Sep 17 00:00:00 2001 From: Timo Notheisen <65653426+tnotheis@users.noreply.github.com> Date: Tue, 17 Sep 2024 12:24:36 +0200 Subject: [PATCH] CanCreate returns true even though peer is in status ToBeDeleted (#871) * test: add test for missing condition * fix: check for identity status in controller --- .../Features/Relationships/CanCreate/GET.feature | 7 +++++++ .../Controllers/RelationshipsController.cs | 9 +++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Applications/ConsumerApi/test/ConsumerApi.Tests.Integration/Features/Relationships/CanCreate/GET.feature b/Applications/ConsumerApi/test/ConsumerApi.Tests.Integration/Features/Relationships/CanCreate/GET.feature index 600ca3a22c..b32127305a 100644 --- a/Applications/ConsumerApi/test/ConsumerApi.Tests.Integration/Features/Relationships/CanCreate/GET.feature +++ b/Applications/ConsumerApi/test/ConsumerApi.Tests.Integration/Features/Relationships/CanCreate/GET.feature @@ -36,3 +36,10 @@ Feature: GET /Relationships/CanCreate When i1 sends a GET request to the /Relationships/CanCreate?peer={id} endpoint with id=i2.id Then the response status code is 200 (OK) And a Relationship can be established + + Scenario: Cannot create Relationship if peer is to be deleted + Given Identities i1 and i2 + And i2 is in status "ToBeDeleted" + When i1 sends a GET request to the /Relationships/CanCreate?peer={id} endpoint with id=i2.id + Then the response status code is 200 (OK) + And a Relationship can not be established diff --git a/Modules/Relationships/src/Relationships.ConsumerApi/Controllers/RelationshipsController.cs b/Modules/Relationships/src/Relationships.ConsumerApi/Controllers/RelationshipsController.cs index c66ad3e60c..dfce39a31a 100644 --- a/Modules/Relationships/src/Relationships.ConsumerApi/Controllers/RelationshipsController.cs +++ b/Modules/Relationships/src/Relationships.ConsumerApi/Controllers/RelationshipsController.cs @@ -198,9 +198,14 @@ public async Task DecomposeRelationship([FromRoute] string id, Ca [HttpGet("CanCreate")] [ProducesResponseType(typeof(HttpResponseEnvelopeResult), StatusCodes.Status200OK)] [ProducesError(StatusCodes.Status400BadRequest)] - public async Task CanEstablishRelationship([FromQuery] string peer, CancellationToken cancellationToken) + public async Task CanEstablishRelationship([FromQuery(Name = "peer")] string peerAddress, CancellationToken cancellationToken) { - var response = await _mediator.Send(new CanEstablishRelationshipQuery { PeerAddress = peer }, cancellationToken); + var peerIdentity = await _mediator.Send(new GetIdentityQuery(peerAddress), cancellationToken); + + var response = peerIdentity.Status is IdentityStatus.ToBeDeleted + ? new CanEstablishRelationshipResponse { CanCreate = false } + : await _mediator.Send(new CanEstablishRelationshipQuery { PeerAddress = peerAddress }, cancellationToken); + return Ok(response); }