-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consumer API: Prevent messages to identities to be deleted (#685)
* feat: add find all method with possible identity address collection filter * test: unit test find all identities handler * feat: ensure message is only sent if none of the recipients has an identity to be deleted * refactor: add status filter to list identities query to prevent pulling too many instances into memory * test: exclude consumer api projects from arch unit tests * test: add integration tests for messages controller (send messages) * refactor: use expression for identitiy filtering * fix: arch unit tests * test: try to make deserialization of data reusable * test: make PeersToBeDeleted property required and rename class * chore: formatting * fix: update npm packages with vulnerabilties --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Timo Notheisen <[email protected]>
- Loading branch information
1 parent
8f29142
commit de940a3
Showing
22 changed files
with
280 additions
and
78 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
ConsumerApi.Tests.Integration/Features/Messages/POST.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
@Integration | ||
Feature: POST Message | ||
|
||
User sends a Message | ||
|
||
Scenario: Sending a Message | ||
Given Identities i1 and i2 with an established Relationship | ||
When i1 sends a POST request to the /Messages endpoint with i2 as recipient | ||
Then the response status code is 201 (Created) | ||
And the response contains a SendMessageResponse | ||
|
||
Scenario: Sending a Message to Identity to be deleted | ||
Given Identities i1 and i2 with an established Relationship | ||
And i2 is in status "ToBeDeleted" | ||
When i1 sends a POST request to the /Messages endpoint with i2 as recipient | ||
Then the response status code is 400 (Bad Request) | ||
And the response content contains an error with the error code "error.platform.validation.message.recipientToBeDeleted" | ||
And the error contains a list of Identities to be deleted that includes i2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using Backbone.ConsumerApi.Sdk; | ||
using Backbone.ConsumerApi.Sdk.Endpoints.Relationships.Types.Requests; | ||
using Backbone.ConsumerApi.Sdk.Endpoints.RelationshipTemplates.Types.Requests; | ||
using Backbone.ConsumerApi.Tests.Integration.Extensions; | ||
using Backbone.Crypto; | ||
|
||
namespace Backbone.ConsumerApi.Tests.Integration.Helpers; | ||
|
||
public static class Utils | ||
{ | ||
public static async Task EstablishRelationshipBetween(Client client1, Client client2) | ||
{ | ||
var createRelationshipTemplateRequest = new CreateRelationshipTemplateRequest | ||
{ | ||
Content = ConvertibleString.FromUtf8("AAA").BytesRepresentation | ||
}; | ||
|
||
var relationshipTemplateResponse = await client1.RelationshipTemplates.CreateTemplate(createRelationshipTemplateRequest); | ||
relationshipTemplateResponse.Should().BeASuccess(); | ||
|
||
var createRelationshipRequest = new CreateRelationshipRequest | ||
{ | ||
RelationshipTemplateId = relationshipTemplateResponse.Result!.Id, | ||
Content = ConvertibleString.FromUtf8("AAA").BytesRepresentation | ||
}; | ||
|
||
var createRelationshipResponse = await client2.Relationships.CreateRelationship(createRelationshipRequest); | ||
createRelationshipResponse.Should().BeASuccess(); | ||
|
||
var completeRelationshipChangeRequest = new CompleteRelationshipChangeRequest | ||
{ | ||
Content = ConvertibleString.FromUtf8("AAA").BytesRepresentation | ||
}; | ||
var acceptRelationChangeResponse = | ||
await client1.Relationships.AcceptChange(createRelationshipResponse.Result!.Id, createRelationshipResponse.Result.Changes.First().Id, completeRelationshipChangeRequest); | ||
acceptRelationChangeResponse.Should().BeASuccess(); | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
ConsumerApi.Tests.Integration/StepDefinitions/MessagesStepDefinitions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
using Backbone.BuildingBlocks.SDK.Endpoints.Common.Types; | ||
using Backbone.ConsumerApi.Sdk; | ||
using Backbone.ConsumerApi.Sdk.Authentication; | ||
using Backbone.ConsumerApi.Sdk.Endpoints.Messages.Types.Requests; | ||
using Backbone.ConsumerApi.Sdk.Endpoints.Messages.Types.Responses; | ||
using Backbone.ConsumerApi.Tests.Integration.Configuration; | ||
using Backbone.ConsumerApi.Tests.Integration.Extensions; | ||
using Backbone.ConsumerApi.Tests.Integration.Helpers; | ||
using Backbone.ConsumerApi.Tests.Integration.Support; | ||
using Backbone.Crypto; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace Backbone.ConsumerApi.Tests.Integration.StepDefinitions; | ||
|
||
[Binding] | ||
[Scope(Feature = "POST Message")] | ||
internal class MessagesStepDefinitions | ||
{ | ||
private Client _client1 = null!; | ||
private Client _client2 = null!; | ||
private ApiResponse<SendMessageResponse>? _sendMessageResponse; | ||
private readonly ClientCredentials _clientCredentials; | ||
private readonly HttpClient _httpClient; | ||
|
||
public MessagesStepDefinitions(HttpClientFactory factory, IOptions<HttpConfiguration> httpConfiguration) | ||
{ | ||
_httpClient = factory.CreateClient(); | ||
_clientCredentials = new ClientCredentials(httpConfiguration.Value.ClientCredentials.ClientId, httpConfiguration.Value.ClientCredentials.ClientSecret); | ||
} | ||
|
||
[Given("Identities i1 and i2 with an established Relationship")] | ||
public async Task GivenIdentitiesI1AndI2WithAnEstablishedRelationship() | ||
{ | ||
_client1 = await Client.CreateForNewIdentity(_httpClient, _clientCredentials, Constants.DEVICE_PASSWORD); | ||
_client2 = await Client.CreateForNewIdentity(_httpClient, _clientCredentials, Constants.DEVICE_PASSWORD); | ||
|
||
await Utils.EstablishRelationshipBetween(_client1, _client2); | ||
} | ||
|
||
[Given("i2 is in status \"ToBeDeleted\"")] | ||
public async Task GivenIdentityI2IsToBeDeleted() | ||
{ | ||
var startDeletionProcessResponse = await _client2.Identities.StartDeletionProcess(); | ||
startDeletionProcessResponse.Should().BeASuccess(); | ||
} | ||
|
||
[When("i1 sends a POST request to the /Messages endpoint with i2 as recipient")] | ||
public async Task WhenAPostRequestIsSentToTheMessagesEndpoint() | ||
{ | ||
var sendMessageRequest = new SendMessageRequest | ||
{ | ||
Attachments = [], | ||
Body = ConvertibleString.FromUtf8("Some Message").BytesRepresentation, | ||
Recipients = | ||
[ | ||
new SendMessageRequestRecipientInformation | ||
{ | ||
Address = _client2.IdentityData!.Address, | ||
EncryptedKey = ConvertibleString.FromUtf8("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA").BytesRepresentation | ||
} | ||
] | ||
}; | ||
_sendMessageResponse = await _client1.Messages.SendMessage(sendMessageRequest); | ||
} | ||
|
||
[Then(@"the response status code is (\d\d\d) \(.+\)")] | ||
public void ThenTheResponseStatusCodeIs(int expectedStatusCode) | ||
{ | ||
((int)_sendMessageResponse!.Status).Should().Be(expectedStatusCode); | ||
} | ||
|
||
[Then("the response contains a SendMessageResponse")] | ||
public void ThenTheResponseContainsASendMessageResponse() | ||
{ | ||
_sendMessageResponse!.Result.Should().NotBeNull(); | ||
_sendMessageResponse.Should().BeASuccess(); | ||
_sendMessageResponse.Should().ComplyWithSchema(); | ||
} | ||
|
||
[Then(@"the response content contains an error with the error code ""([^""]*)""")] | ||
public void ThenTheResponseContentIncludesAnErrorWithTheErrorCode(string errorCode) | ||
{ | ||
_sendMessageResponse!.Error.Should().NotBeNull(); | ||
_sendMessageResponse.Error!.Code.Should().Be(errorCode); | ||
} | ||
|
||
[Then(@"the error contains a list of Identities to be deleted that includes i2")] | ||
public void ThenTheErrorContainsAListOfIdentitiesToBeDeletedThatIncludesIdentityI2() | ||
{ | ||
var data = _sendMessageResponse!.Error!.Data?.As<PeersToBeDeletedErrorData>(); | ||
data.Should().NotBeNull(); | ||
data!.PeersToBeDeleted.Contains(_client2.IdentityData!.Address).Should().BeTrue(); | ||
} | ||
} | ||
|
||
public class PeersToBeDeletedErrorData | ||
{ | ||
public required List<string> PeersToBeDeleted { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.