mirror of
https://github.com/bitwarden/server.git
synced 2025-04-04 20:50:21 -05:00
ArgumentNullException: Value cannot be null in POST /push/register (#5472)
This commit is contained in:
parent
cb1c12794f
commit
8628206fa9
@ -43,8 +43,9 @@ public class PushController : Controller
|
|||||||
public async Task RegisterAsync([FromBody] PushRegistrationRequestModel model)
|
public async Task RegisterAsync([FromBody] PushRegistrationRequestModel model)
|
||||||
{
|
{
|
||||||
CheckUsage();
|
CheckUsage();
|
||||||
await _pushRegistrationService.CreateOrUpdateRegistrationAsync(new PushRegistrationData(model.PushToken), Prefix(model.DeviceId),
|
await _pushRegistrationService.CreateOrUpdateRegistrationAsync(new PushRegistrationData(model.PushToken),
|
||||||
Prefix(model.UserId), Prefix(model.Identifier), model.Type, model.OrganizationIds.Select(Prefix), model.InstallationId);
|
Prefix(model.DeviceId), Prefix(model.UserId), Prefix(model.Identifier), model.Type,
|
||||||
|
model.OrganizationIds?.Select(Prefix) ?? [], model.InstallationId);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("delete")]
|
[HttpPost("delete")]
|
||||||
|
@ -243,20 +243,22 @@ public class PushControllerTests
|
|||||||
PushToken = "test-push-token",
|
PushToken = "test-push-token",
|
||||||
UserId = userId.ToString(),
|
UserId = userId.ToString(),
|
||||||
Type = DeviceType.Android,
|
Type = DeviceType.Android,
|
||||||
Identifier = identifier.ToString()
|
Identifier = identifier.ToString(),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
Assert.Equal("Not correctly configured for push relays.", exception.Message);
|
Assert.Equal("Not correctly configured for push relays.", exception.Message);
|
||||||
|
|
||||||
await sutProvider.GetDependency<IPushRegistrationService>().Received(0)
|
await sutProvider.GetDependency<IPushRegistrationService>().Received(0)
|
||||||
.CreateOrUpdateRegistrationAsync(Arg.Any<PushRegistrationData>(), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>(),
|
.CreateOrUpdateRegistrationAsync(Arg.Any<PushRegistrationData>(), Arg.Any<string>(), Arg.Any<string>(),
|
||||||
Arg.Any<DeviceType>(), Arg.Any<IEnumerable<string>>(), Arg.Any<Guid>());
|
Arg.Any<string>(), Arg.Any<DeviceType>(), Arg.Any<IEnumerable<string>>(), Arg.Any<Guid>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[BitAutoData]
|
[BitAutoData(false)]
|
||||||
public async Task? RegisterAsync_ValidModel_CreatedOrUpdatedRegistration(SutProvider<PushController> sutProvider,
|
[BitAutoData(true)]
|
||||||
Guid installationId, Guid userId, Guid identifier, Guid deviceId, Guid organizationId)
|
public async Task RegisterAsync_ValidModel_CreatedOrUpdatedRegistration(bool haveOrganizationId,
|
||||||
|
SutProvider<PushController> sutProvider, Guid installationId, Guid userId, Guid identifier, Guid deviceId,
|
||||||
|
Guid organizationId)
|
||||||
{
|
{
|
||||||
sutProvider.GetDependency<IGlobalSettings>().SelfHosted = false;
|
sutProvider.GetDependency<IGlobalSettings>().SelfHosted = false;
|
||||||
sutProvider.GetDependency<ICurrentContext>().InstallationId.Returns(installationId);
|
sutProvider.GetDependency<ICurrentContext>().InstallationId.Returns(installationId);
|
||||||
@ -273,19 +275,29 @@ public class PushControllerTests
|
|||||||
UserId = userId.ToString(),
|
UserId = userId.ToString(),
|
||||||
Type = DeviceType.Android,
|
Type = DeviceType.Android,
|
||||||
Identifier = identifier.ToString(),
|
Identifier = identifier.ToString(),
|
||||||
OrganizationIds = [organizationId.ToString()],
|
OrganizationIds = haveOrganizationId ? [organizationId.ToString()] : null,
|
||||||
InstallationId = installationId
|
InstallationId = installationId
|
||||||
};
|
};
|
||||||
|
|
||||||
await sutProvider.Sut.RegisterAsync(model);
|
await sutProvider.Sut.RegisterAsync(model);
|
||||||
|
|
||||||
await sutProvider.GetDependency<IPushRegistrationService>().Received(1)
|
await sutProvider.GetDependency<IPushRegistrationService>().Received(1)
|
||||||
.CreateOrUpdateRegistrationAsync(Arg.Is<PushRegistrationData>(data => data == new PushRegistrationData(model.PushToken)), expectedDeviceId, expectedUserId,
|
.CreateOrUpdateRegistrationAsync(
|
||||||
|
Arg.Is<PushRegistrationData>(data => data == new PushRegistrationData(model.PushToken)),
|
||||||
|
expectedDeviceId, expectedUserId,
|
||||||
expectedIdentifier, DeviceType.Android, Arg.Do<IEnumerable<string>>(organizationIds =>
|
expectedIdentifier, DeviceType.Android, Arg.Do<IEnumerable<string>>(organizationIds =>
|
||||||
{
|
{
|
||||||
|
Assert.NotNull(organizationIds);
|
||||||
var organizationIdsList = organizationIds.ToList();
|
var organizationIdsList = organizationIds.ToList();
|
||||||
Assert.Contains(expectedOrganizationId, organizationIdsList);
|
if (haveOrganizationId)
|
||||||
Assert.Single(organizationIdsList);
|
{
|
||||||
|
Assert.Contains(expectedOrganizationId, organizationIdsList);
|
||||||
|
Assert.Single(organizationIdsList);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Assert.Empty(organizationIdsList);
|
||||||
|
}
|
||||||
}), installationId);
|
}), installationId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user