mirror of
https://github.com/bitwarden/server
synced 2026-01-04 09:33:40 +00:00
[PM-16787] Web push enablement for server (#5395)
* Allow for binning of comb IDs by date and value * Introduce notification hub pool * Replace device type sharding with comb + range sharding * Fix proxy interface * Use enumerable services for multiServiceNotificationHub * Fix push interface usage * Fix push notification service dependencies * Fix push notification keys * Fixup documentation * Remove deprecated settings * Fix tests * PascalCase method names * Remove unused request model properties * Remove unused setting * Improve DateFromComb precision * Prefer readonly service enumerable * Pascal case template holes * Name TryParse methods TryParse * Apply suggestions from code review Co-authored-by: Justin Baur <19896123+justindbaur@users.noreply.github.com> * Include preferred push technology in config response SignalR will be the fallback, but clients should attempt web push first if offered and available to the client. * Register web push devices * Working signing and content encrypting * update to RFC-8291 and RFC-8188 * Notification hub is now working, no need to create our own * Fix body * Flip Success Check * use nifty json attribute * Remove vapid private key This is only needed to encrypt data for transmission along webpush -- it's handled by NotificationHub for us * Add web push feature flag to control config response * Update src/Core/NotificationHub/NotificationHubConnection.cs Co-authored-by: Justin Baur <19896123+justindbaur@users.noreply.github.com> * Update src/Core/NotificationHub/NotificationHubConnection.cs Co-authored-by: Justin Baur <19896123+justindbaur@users.noreply.github.com> * fixup! Update src/Core/NotificationHub/NotificationHubConnection.cs * Move to platform ownership * Remove debugging extension * Remove unused dependencies * Set json content directly * Name web push registration data * Fix FCM type typo * Determine specific feature flag from set of flags * Fixup merged tests * Fixup tests * Code quality suggestions * Fix merged tests * Fix test --------- Co-authored-by: Justin Baur <19896123+justindbaur@users.noreply.github.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Bit.Core.Settings;
|
||||
using Bit.Core.NotificationHub;
|
||||
using Bit.Core.Settings;
|
||||
using Bit.Core.Utilities;
|
||||
using Xunit;
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ public class NotificationHubPushRegistrationServiceTests
|
||||
SutProvider<NotificationHubPushRegistrationService> sutProvider, Guid deviceId, Guid userId, Guid identifier,
|
||||
Guid organizationId, Guid installationId)
|
||||
{
|
||||
await sutProvider.Sut.CreateOrUpdateRegistrationAsync(pushToken, deviceId.ToString(), userId.ToString(),
|
||||
await sutProvider.Sut.CreateOrUpdateRegistrationAsync(new PushRegistrationData(pushToken), deviceId.ToString(), userId.ToString(),
|
||||
identifier.ToString(), DeviceType.Android, [organizationId.ToString()], installationId);
|
||||
|
||||
sutProvider.GetDependency<INotificationHubPool>()
|
||||
@@ -39,7 +39,7 @@ public class NotificationHubPushRegistrationServiceTests
|
||||
|
||||
var pushToken = "test push token";
|
||||
|
||||
await sutProvider.Sut.CreateOrUpdateRegistrationAsync(pushToken, deviceId.ToString(), userId.ToString(),
|
||||
await sutProvider.Sut.CreateOrUpdateRegistrationAsync(new PushRegistrationData(pushToken), deviceId.ToString(), userId.ToString(),
|
||||
identifierNull ? null : identifier.ToString(), DeviceType.Android,
|
||||
partOfOrganizationId ? [organizationId.ToString()] : [],
|
||||
installationIdNull ? Guid.Empty : installationId);
|
||||
@@ -115,7 +115,7 @@ public class NotificationHubPushRegistrationServiceTests
|
||||
|
||||
var pushToken = "test push token";
|
||||
|
||||
await sutProvider.Sut.CreateOrUpdateRegistrationAsync(pushToken, deviceId.ToString(), userId.ToString(),
|
||||
await sutProvider.Sut.CreateOrUpdateRegistrationAsync(new PushRegistrationData(pushToken), deviceId.ToString(), userId.ToString(),
|
||||
identifierNull ? null : identifier.ToString(), DeviceType.iOS,
|
||||
partOfOrganizationId ? [organizationId.ToString()] : [],
|
||||
installationIdNull ? Guid.Empty : installationId);
|
||||
@@ -191,7 +191,7 @@ public class NotificationHubPushRegistrationServiceTests
|
||||
|
||||
var pushToken = "test push token";
|
||||
|
||||
await sutProvider.Sut.CreateOrUpdateRegistrationAsync(pushToken, deviceId.ToString(), userId.ToString(),
|
||||
await sutProvider.Sut.CreateOrUpdateRegistrationAsync(new PushRegistrationData(pushToken), deviceId.ToString(), userId.ToString(),
|
||||
identifierNull ? null : identifier.ToString(), DeviceType.AndroidAmazon,
|
||||
partOfOrganizationId ? [organizationId.ToString()] : [],
|
||||
installationIdNull ? Guid.Empty : installationId);
|
||||
@@ -268,7 +268,7 @@ public class NotificationHubPushRegistrationServiceTests
|
||||
|
||||
var pushToken = "test push token";
|
||||
|
||||
await sutProvider.Sut.CreateOrUpdateRegistrationAsync(pushToken, deviceId.ToString(), userId.ToString(),
|
||||
await sutProvider.Sut.CreateOrUpdateRegistrationAsync(new PushRegistrationData(pushToken), deviceId.ToString(), userId.ToString(),
|
||||
identifier.ToString(), deviceType, [organizationId.ToString()], installationId);
|
||||
|
||||
sutProvider.GetDependency<INotificationHubPool>()
|
||||
|
||||
@@ -4,6 +4,7 @@ using Bit.Core.Entities;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Exceptions;
|
||||
using Bit.Core.Models.Data.Organizations.OrganizationUsers;
|
||||
using Bit.Core.NotificationHub;
|
||||
using Bit.Core.Platform.Push;
|
||||
using Bit.Core.Repositories;
|
||||
using Bit.Core.Services;
|
||||
@@ -43,13 +44,13 @@ public class DeviceServiceTests
|
||||
Name = "test device",
|
||||
Type = DeviceType.Android,
|
||||
UserId = userId,
|
||||
PushToken = "testtoken",
|
||||
PushToken = "testToken",
|
||||
Identifier = "testid"
|
||||
};
|
||||
await deviceService.SaveAsync(device);
|
||||
|
||||
Assert.True(device.RevisionDate - DateTime.UtcNow < TimeSpan.FromSeconds(1));
|
||||
await pushRepo.Received(1).CreateOrUpdateRegistrationAsync("testtoken", id.ToString(),
|
||||
await pushRepo.Received(1).CreateOrUpdateRegistrationAsync(Arg.Is<PushRegistrationData>(v => v.Token == "testToken"), id.ToString(),
|
||||
userId.ToString(), "testid", DeviceType.Android,
|
||||
Arg.Do<IEnumerable<string>>(organizationIds =>
|
||||
{
|
||||
@@ -84,12 +85,12 @@ public class DeviceServiceTests
|
||||
Name = "test device",
|
||||
Type = DeviceType.Android,
|
||||
UserId = userId,
|
||||
PushToken = "testtoken",
|
||||
PushToken = "testToken",
|
||||
Identifier = "testid"
|
||||
};
|
||||
await deviceService.SaveAsync(device);
|
||||
|
||||
await pushRepo.Received(1).CreateOrUpdateRegistrationAsync("testtoken",
|
||||
await pushRepo.Received(1).CreateOrUpdateRegistrationAsync(Arg.Is<PushRegistrationData>(v => v.Token == "testToken"),
|
||||
Arg.Do<string>(id => Guid.TryParse(id, out var _)), userId.ToString(), "testid", DeviceType.Android,
|
||||
Arg.Do<IEnumerable<string>>(organizationIds =>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user