-
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.
Possibility for a device to find out whether its identity was deleted (…
…#949) * refactor: optimize SeedTestUsers * test: add integration test * refactor: use generic Find method for audit log entries * feat: add DeletionCompleted audit log entry and associate usernames after finished deletion * feat: add migrations * feat: add possibility to query whether an identity was deleted * chore: formatting * refactor: simplify Handler for SeedTestUsersCommand * refactor: use NameValueCollection instead of Dictionary<string, string> * refactor: rename BelongsTo method * chore: fix archunit test errors * chore: formatting * test: fix test by configuring fake * refactor: cleanup HandleCompletedDeletionProcessCommand Handler * feat: add validator for HandleCompletedDeletionProcessCommand * chore: formatting/cleanup * refactor: improve AssociateUsernames method * refactor: extract variable * test: change test names * chore: remove leftover comment * test: make AssociateUsernames test more concrete * refactor: use init property instead of constructor * feat: remove migration * refactor: use List<string> instead of string as type for UsernameHashesBase64 column * test: test for length of UsernameHashesBase64 * test: check what happens if we remove all calls to Hasher.SetHasher * test: check what happens if we remove all calls to Hasher.SetHasher * feat: IsDeleted returns true if grace period is over but identity is not deleted yet * Revert "test: check what happens if we remove all calls to Hasher.SetHasher" This reverts commit d3e03f9. * test: reset hasher after the tests have finished --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Mika Herrmann <[email protected]>
- Loading branch information
1 parent
dcec3ea
commit 1035c98
Showing
41 changed files
with
2,473 additions
and
74 deletions.
There are no files selected for viewing
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
12 changes: 12 additions & 0 deletions
12
.../ConsumerApi/test/ConsumerApi.Tests.Integration/Features/Identities/IsDeleted/GET.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,12 @@ | ||
@Integration | ||
Feature: GET /Identities/IsDeleted | ||
|
||
User wants to know whether its identity was deleted | ||
|
||
Scenario: Asking whether a not-yet-deleted identity was deleted | ||
Given an Identity i with a Device d | ||
And an active deletion process for i exists | ||
When an anonymous user sends a GET request to the /Identities/IsDeleted endpoint with d.Username | ||
Then the response status code is 200 (OK) | ||
And the response says that the identity was not deleted | ||
And the deletion date is not 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
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
15 changes: 15 additions & 0 deletions
15
...entities/Commands/HandleCompletedDeletionProcess/HandleCompletedDeletionProcessCommand.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,15 @@ | ||
using MediatR; | ||
|
||
namespace Backbone.Modules.Devices.Application.Identities.Commands.HandleCompletedDeletionProcess; | ||
|
||
public class HandleCompletedDeletionProcessCommand : IRequest | ||
{ | ||
public HandleCompletedDeletionProcessCommand(string identityAddress, IEnumerable<string> usernames) | ||
{ | ||
IdentityAddress = identityAddress; | ||
Usernames = usernames; | ||
} | ||
|
||
public string IdentityAddress { get; } | ||
public IEnumerable<string> Usernames { get; } | ||
} |
39 changes: 39 additions & 0 deletions
39
...ces/src/Devices.Application/Identities/Commands/HandleCompletedDeletionProcess/Handler.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,39 @@ | ||
using Backbone.DevelopmentKit.Identity.ValueObjects; | ||
using Backbone.Modules.Devices.Application.Infrastructure.Persistence.Repository; | ||
using Backbone.Modules.Devices.Domain.Entities.Identities; | ||
using MediatR; | ||
|
||
namespace Backbone.Modules.Devices.Application.Identities.Commands.HandleCompletedDeletionProcess; | ||
|
||
public class Handler : IRequestHandler<HandleCompletedDeletionProcessCommand> | ||
{ | ||
private readonly IIdentitiesRepository _identitiesRepository; | ||
|
||
public Handler(IIdentitiesRepository identitiesRepository) | ||
{ | ||
_identitiesRepository = identitiesRepository; | ||
} | ||
|
||
public async Task Handle(HandleCompletedDeletionProcessCommand request, CancellationToken cancellationToken) | ||
{ | ||
await _identitiesRepository.AddDeletionProcessAuditLogEntry(IdentityDeletionProcessAuditLogEntry.DeletionCompleted(request.IdentityAddress)); | ||
|
||
await AssociateUsernames(request, cancellationToken); | ||
} | ||
|
||
private async Task AssociateUsernames(HandleCompletedDeletionProcessCommand request, CancellationToken cancellationToken) | ||
{ | ||
var identityAddressHash = Hasher.HashUtf8(request.IdentityAddress); | ||
|
||
var auditLogEntries = await _identitiesRepository.GetIdentityDeletionProcessAuditLogs(l => l.IdentityAddressHash == identityAddressHash, CancellationToken.None, track: true); | ||
|
||
var auditLogEntriesArray = auditLogEntries.ToArray(); | ||
|
||
foreach (var auditLogEntry in auditLogEntriesArray) | ||
{ | ||
auditLogEntry.AssociateUsernames(request.Usernames.Select(Username.Parse)); | ||
} | ||
|
||
await _identitiesRepository.Update(auditLogEntriesArray, cancellationToken); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...s/src/Devices.Application/Identities/Commands/HandleCompletedDeletionProcess/Validator.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,15 @@ | ||
using Backbone.BuildingBlocks.Application.Extensions; | ||
using Backbone.BuildingBlocks.Application.FluentValidation; | ||
using Backbone.DevelopmentKit.Identity.ValueObjects; | ||
using FluentValidation; | ||
|
||
namespace Backbone.Modules.Devices.Application.Identities.Commands.HandleCompletedDeletionProcess; | ||
|
||
public class Validator : AbstractValidator<HandleCompletedDeletionProcessCommand> | ||
{ | ||
public Validator() | ||
{ | ||
RuleFor(c => c.IdentityAddress).ValidId<HandleCompletedDeletionProcessCommand, IdentityAddress>(); | ||
RuleFor(c => c.Usernames).DetailedNotEmpty(); | ||
} | ||
} |
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.