mirror of
https://github.com/bitwarden/server.git
synced 2025-04-07 05:58:13 -05:00

* PM-10600: Notification push notification * PM-10600: Sending to specific client types for relay push notifications * PM-10600: Sending to specific client types for other clients * PM-10600: Send push notification on notification creation * PM-10600: Explicit group names * PM-10600: Id typos * PM-10600: Revert global push notifications * PM-10600: Added DeviceType claim * PM-10600: Sent to organization typo * PM-10600: UT coverage * PM-10600: Small refactor, UTs coverage * PM-10600: UTs coverage * PM-10600: Startup fix * PM-10600: Test fix * PM-10600: Required attribute, organization group for push notification fix * PM-10600: UT coverage * PM-10600: Fix Mobile devices not registering to organization push notifications We only register devices for organization push notifications when the organization is being created. This does not work, since we have a use case (Notification Center) of delivering notifications to all users of organization. This fixes it, by adding the organization id tag when device registers for push notifications. * PM-10600: Unit Test coverage for NotificationHubPushRegistrationService Fixed IFeatureService substitute mocking for Android tests. Added user part of organization test with organizationId tags expectation. * PM-10600: Unit Tests fix to NotificationHubPushRegistrationService after merge conflict * PM-10600: Organization push notifications not sending to mobile device from self-hosted. Self-hosted instance uses relay to register the mobile device against Bitwarden Cloud Api. Only the self-hosted server knows client's organization membership, which means it needs to pass in the organization id's information to the relay. Similarly, for Bitwarden Cloud, the organizaton id will come directly from the server. * PM-10600: Fix self-hosted organization notification not being received by mobile device. When mobile device registers on self-hosted through the relay, every single id, like user id, device id and now organization id needs to be prefixed with the installation id. This have been missing in the PushController that handles this for organization id. * PM-10600: Broken NotificationsController integration test Device type is now part of JWT access token, so the notification center results in the integration test are now scoped to client type web and all. * PM-10600: Merge conflicts fix * merge conflict fix
95 lines
2.8 KiB
C#
95 lines
2.8 KiB
C#
#nullable enable
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Text.Json;
|
|
using Bit.Core.Enums;
|
|
using Bit.Core.Models.Api;
|
|
using Bit.Core.Utilities;
|
|
using Bit.Test.Common.AutoFixture.Attributes;
|
|
using Xunit;
|
|
|
|
namespace Bit.Core.Test.Models.Api.Request;
|
|
|
|
public class PushSendRequestModelTests
|
|
{
|
|
[Theory]
|
|
[InlineData(null, null)]
|
|
[InlineData(null, "")]
|
|
[InlineData(null, " ")]
|
|
[InlineData("", null)]
|
|
[InlineData(" ", null)]
|
|
[InlineData("", "")]
|
|
[InlineData(" ", " ")]
|
|
public void Validate_UserIdOrganizationIdNullOrEmpty_Invalid(string? userId, string? organizationId)
|
|
{
|
|
var model = new PushSendRequestModel
|
|
{
|
|
UserId = userId,
|
|
OrganizationId = organizationId,
|
|
Type = PushType.SyncCiphers,
|
|
Payload = "test"
|
|
};
|
|
|
|
var results = Validate(model);
|
|
|
|
Assert.Single(results);
|
|
Assert.Contains(results, result => result.ErrorMessage == "UserId or OrganizationId is required.");
|
|
}
|
|
|
|
[Theory]
|
|
[BitAutoData("Payload")]
|
|
[BitAutoData("Type")]
|
|
public void Validate_RequiredFieldNotProvided_Invalid(string requiredField)
|
|
{
|
|
var model = new PushSendRequestModel
|
|
{
|
|
UserId = Guid.NewGuid().ToString(),
|
|
OrganizationId = Guid.NewGuid().ToString(),
|
|
Type = PushType.SyncCiphers,
|
|
Payload = "test"
|
|
};
|
|
|
|
var dictionary = new Dictionary<string, object?>();
|
|
foreach (var property in model.GetType().GetProperties())
|
|
{
|
|
if (property.Name == requiredField)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
dictionary[property.Name] = property.GetValue(model);
|
|
}
|
|
|
|
var serialized = JsonSerializer.Serialize(dictionary, JsonHelpers.IgnoreWritingNull);
|
|
var jsonException =
|
|
Assert.Throws<JsonException>(() => JsonSerializer.Deserialize<PushSendRequestModel>(serialized));
|
|
Assert.Contains($"missing required properties, including the following: {requiredField}",
|
|
jsonException.Message);
|
|
}
|
|
|
|
[Fact]
|
|
public void Validate_AllFieldsPresent_Valid()
|
|
{
|
|
var model = new PushSendRequestModel
|
|
{
|
|
UserId = Guid.NewGuid().ToString(),
|
|
OrganizationId = Guid.NewGuid().ToString(),
|
|
Type = PushType.SyncCiphers,
|
|
Payload = "test payload",
|
|
Identifier = Guid.NewGuid().ToString(),
|
|
ClientType = ClientType.All,
|
|
DeviceId = Guid.NewGuid().ToString()
|
|
};
|
|
|
|
var results = Validate(model);
|
|
|
|
Assert.Empty(results);
|
|
}
|
|
|
|
private static List<ValidationResult> Validate(PushSendRequestModel model)
|
|
{
|
|
var results = new List<ValidationResult>();
|
|
Validator.TryValidateObject(model, new ValidationContext(model), results, true);
|
|
return results;
|
|
}
|
|
}
|