1
0
mirror of https://github.com/bitwarden/server.git synced 2025-01-08 19:47:44 +01:00

[EC-1032] if name is Empty, set to null before saving (#2619)

This commit is contained in:
Jake Fink 2023-01-25 11:07:33 -05:00 committed by GitHub
parent cb1ba50ce2
commit 64c15ed8cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -178,6 +178,12 @@ public class UserService : UserManager<User>, IUserService, IDisposable
throw new ApplicationException("Use register method to create a new user.");
}
// if the name is empty, set it to null
if (String.Equals(user.Name, String.Empty))
{
user.Name = null;
}
user.RevisionDate = user.AccountRevisionDate = DateTime.UtcNow;
await _userRepository.ReplaceAsync(user);

View File

@ -19,6 +19,14 @@ namespace Bit.Core.Test.Services;
[SutProviderCustomize]
public class UserServiceTests
{
[Theory, BitAutoData]
public async Task SaveUserAsync_SetsNameToNull_WhenNameIsEmpty(SutProvider<UserService> sutProvider, User user)
{
user.Name = string.Empty;
await sutProvider.Sut.SaveUserAsync(user);
Assert.Null(user.Name);
}
[Theory, BitAutoData]
public async Task UpdateLicenseAsync_Success(SutProvider<UserService> sutProvider,
User user, UserLicense userLicense)