1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-30 07:36:14 -05:00

[PM-22190] Remove gathering and reporting of ReferenceEvents (#5897)

* Remove gathering and reporting of ReferenceEvents

* Fix test that relied on reference events throwing

---------

Co-authored-by: Daniel James Smith <djsmith85@users.noreply.github.com>
This commit is contained in:
Daniel James Smith
2025-06-02 16:49:49 +02:00
committed by GitHub
parent d7d90e7f3e
commit c7b1c7f6d5
47 changed files with 17 additions and 1147 deletions

View File

@ -9,10 +9,7 @@ using Bit.Core.Platform.Push;
using Bit.Core.Repositories;
using Bit.Core.Services;
using Bit.Core.Test.AutoFixture.CipherFixtures;
using Bit.Core.Tools.Enums;
using Bit.Core.Tools.ImportFeatures;
using Bit.Core.Tools.Models.Business;
using Bit.Core.Tools.Services;
using Bit.Core.Vault.Entities;
using Bit.Core.Vault.Models.Data;
using Bit.Core.Vault.Repositories;
@ -183,8 +180,6 @@ public class ImportCiphersAsyncCommandTests
!cus.Any(cu => cu.CollectionId == collections[0].Id) && // Check that access was not added for the collection that already existed in the organization
cus.All(cu => cu.OrganizationUserId == importingOrganizationUser.Id && cu.Manage == true)));
await sutProvider.GetDependency<IPushNotificationService>().Received(1).PushSyncVaultAsync(importingUserId);
await sutProvider.GetDependency<IReferenceEventService>().Received(1).RaiseEventAsync(
Arg.Is<ReferenceEvent>(e => e.Type == ReferenceEventType.VaultImported));
}
[Theory, BitAutoData]

View File

@ -8,7 +8,6 @@ using Bit.Core.Test.AutoFixture.CurrentContextFixtures;
using Bit.Core.Test.Tools.AutoFixture.SendFixtures;
using Bit.Core.Tools.Entities;
using Bit.Core.Tools.Enums;
using Bit.Core.Tools.Models.Business;
using Bit.Core.Tools.Models.Data;
using Bit.Core.Tools.Repositories;
using Bit.Core.Tools.SendFeatures;
@ -32,7 +31,6 @@ public class NonAnonymousSendCommandTests
private readonly ISendAuthorizationService _sendAuthorizationService;
private readonly ISendValidationService _sendValidationService;
private readonly IFeatureService _featureService;
private readonly IReferenceEventService _referenceEventService;
private readonly ICurrentContext _currentContext;
private readonly ISendCoreHelperService _sendCoreHelperService;
private readonly NonAnonymousSendCommand _nonAnonymousSendCommand;
@ -45,7 +43,6 @@ public class NonAnonymousSendCommandTests
_sendAuthorizationService = Substitute.For<ISendAuthorizationService>();
_featureService = Substitute.For<IFeatureService>();
_sendValidationService = Substitute.For<ISendValidationService>();
_referenceEventService = Substitute.For<IReferenceEventService>();
_currentContext = Substitute.For<ICurrentContext>();
_sendCoreHelperService = Substitute.For<ISendCoreHelperService>();
@ -55,8 +52,6 @@ public class NonAnonymousSendCommandTests
_pushNotificationService,
_sendAuthorizationService,
_sendValidationService,
_referenceEventService,
_currentContext,
_sendCoreHelperService
);
}
@ -135,14 +130,6 @@ public class NonAnonymousSendCommandTests
// For new Sends
await _sendRepository.Received(1).CreateAsync(send);
await _pushNotificationService.Received(1).PushSyncSendCreateAsync(send);
await _referenceEventService.Received(1).RaiseEventAsync(Arg.Is<ReferenceEvent>(e =>
e.Id == userId &&
e.Type == ReferenceEventType.SendCreated &&
e.Source == ReferenceEventSource.User &&
e.SendType == send.Type &&
e.SendHasNotes == true &&
e.ClientId == "test-client" &&
e.ClientVersion == Version.Parse("1.0.0")));
}
else
{
@ -150,7 +137,6 @@ public class NonAnonymousSendCommandTests
await _sendRepository.Received(1).UpsertAsync(send);
Assert.NotEqual(initialDate, send.RevisionDate);
await _pushNotificationService.Received(1).PushSyncSendUpdateAsync(send);
await _referenceEventService.DidNotReceive().RaiseEventAsync(Arg.Any<ReferenceEvent>());
}
}
@ -234,14 +220,6 @@ public class NonAnonymousSendCommandTests
// For new Sends
await _sendRepository.Received(1).CreateAsync(send);
await _pushNotificationService.Received(1).PushSyncSendCreateAsync(send);
await _referenceEventService.Received(1).RaiseEventAsync(Arg.Is<ReferenceEvent>(e =>
e.Id == userId &&
e.Type == ReferenceEventType.SendCreated &&
e.Source == ReferenceEventSource.User &&
e.SendType == send.Type &&
e.HasPassword == false &&
e.ClientId == "test-client" &&
e.ClientVersion == Version.Parse("1.0.0")));
}
else
{
@ -249,7 +227,6 @@ public class NonAnonymousSendCommandTests
await _sendRepository.Received(1).UpsertAsync(send);
Assert.NotEqual(initialDate, send.RevisionDate);
await _pushNotificationService.Received(1).PushSyncSendUpdateAsync(send);
await _referenceEventService.DidNotReceive().RaiseEventAsync(Arg.Any<ReferenceEvent>());
}
}
@ -285,7 +262,6 @@ public class NonAnonymousSendCommandTests
await _sendRepository.DidNotReceive().UpsertAsync(Arg.Any<Send>());
await _pushNotificationService.DidNotReceive().PushSyncSendCreateAsync(Arg.Any<Send>());
await _pushNotificationService.DidNotReceive().PushSyncSendUpdateAsync(Arg.Any<Send>());
await _referenceEventService.DidNotReceive().RaiseEventAsync(Arg.Any<ReferenceEvent>());
}
[Theory]
@ -328,14 +304,6 @@ public class NonAnonymousSendCommandTests
// For new Sends
await _sendRepository.Received(1).CreateAsync(send);
await _pushNotificationService.Received(1).PushSyncSendCreateAsync(send);
await _referenceEventService.Received(1).RaiseEventAsync(Arg.Is<ReferenceEvent>(e =>
e.Id == userId &&
e.Type == ReferenceEventType.SendCreated &&
e.Source == ReferenceEventSource.User &&
e.SendType == send.Type &&
e.SendHasNotes == true &&
e.ClientId == "test-client" &&
e.ClientVersion == Version.Parse("1.0.0")));
}
else
{
@ -343,7 +311,6 @@ public class NonAnonymousSendCommandTests
await _sendRepository.Received(1).UpsertAsync(send);
Assert.NotEqual(initialDate, send.RevisionDate);
await _pushNotificationService.Received(1).PushSyncSendUpdateAsync(send);
await _referenceEventService.DidNotReceive().RaiseEventAsync(Arg.Any<ReferenceEvent>());
}
}
@ -386,9 +353,6 @@ public class NonAnonymousSendCommandTests
// Verify push notification wasn't sent
await _pushNotificationService.DidNotReceive().PushSyncSendCreateAsync(Arg.Any<Send>());
await _pushNotificationService.DidNotReceive().PushSyncSendUpdateAsync(Arg.Any<Send>());
// Verify reference event service wasn't called
await _referenceEventService.DidNotReceive().RaiseEventAsync(Arg.Any<ReferenceEvent>());
}
[Theory]
@ -431,13 +395,6 @@ public class NonAnonymousSendCommandTests
// For new Sends
await _sendRepository.Received(1).CreateAsync(send);
await _pushNotificationService.Received(1).PushSyncSendCreateAsync(send);
await _referenceEventService.Received(1).RaiseEventAsync(Arg.Is<ReferenceEvent>(e =>
e.Id == userId &&
e.Type == ReferenceEventType.SendCreated &&
e.Source == ReferenceEventSource.User &&
e.SendType == send.Type &&
e.ClientId == "test-client" &&
e.ClientVersion == Version.Parse("1.0.0")));
}
else
{
@ -445,7 +402,6 @@ public class NonAnonymousSendCommandTests
await _sendRepository.Received(1).UpsertAsync(send);
Assert.NotEqual(initialDate, send.RevisionDate);
await _pushNotificationService.Received(1).PushSyncSendUpdateAsync(send);
await _referenceEventService.DidNotReceive().RaiseEventAsync(Arg.Any<ReferenceEvent>());
}
}
@ -481,9 +437,6 @@ public class NonAnonymousSendCommandTests
// Verify push notification was sent for the update
await _pushNotificationService.Received(1).PushSyncSendUpdateAsync(send);
// Verify no reference event was raised (only happens for new sends)
await _referenceEventService.DidNotReceive().RaiseEventAsync(Arg.Any<ReferenceEvent>());
}
[Fact]

View File

@ -1,5 +1,4 @@
using Bit.Core.Context;
using Bit.Core.Platform.Push;
using Bit.Core.Platform.Push;
using Bit.Core.Tools.Entities;
using Bit.Core.Tools.Models.Data;
using Bit.Core.Tools.Repositories;
@ -15,8 +14,6 @@ public class SendAuthorizationServiceTests
private readonly ISendRepository _sendRepository;
private readonly IPasswordHasher<Bit.Core.Entities.User> _passwordHasher;
private readonly IPushNotificationService _pushNotificationService;
private readonly IReferenceEventService _referenceEventService;
private readonly ICurrentContext _currentContext;
private readonly SendAuthorizationService _sendAuthorizationService;
public SendAuthorizationServiceTests()
@ -24,15 +21,11 @@ public class SendAuthorizationServiceTests
_sendRepository = Substitute.For<ISendRepository>();
_passwordHasher = Substitute.For<IPasswordHasher<Bit.Core.Entities.User>>();
_pushNotificationService = Substitute.For<IPushNotificationService>();
_referenceEventService = Substitute.For<IReferenceEventService>();
_currentContext = Substitute.For<ICurrentContext>();
_sendAuthorizationService = new SendAuthorizationService(
_sendRepository,
_passwordHasher,
_pushNotificationService,
_referenceEventService,
_currentContext);
_pushNotificationService);
}