From 64c15ed8cdad00e41f908fcc39cb9479562f346d Mon Sep 17 00:00:00 2001 From: Jake Fink Date: Wed, 25 Jan 2023 11:07:33 -0500 Subject: [PATCH] [EC-1032] if name is Empty, set to null before saving (#2619) --- src/Core/Services/Implementations/UserService.cs | 6 ++++++ test/Core.Test/Services/UserServiceTests.cs | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/src/Core/Services/Implementations/UserService.cs b/src/Core/Services/Implementations/UserService.cs index 9d325bfba5..fed83f0a0c 100644 --- a/src/Core/Services/Implementations/UserService.cs +++ b/src/Core/Services/Implementations/UserService.cs @@ -178,6 +178,12 @@ public class UserService : UserManager, 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); diff --git a/test/Core.Test/Services/UserServiceTests.cs b/test/Core.Test/Services/UserServiceTests.cs index 845cf49b48..52d40e5781 100644 --- a/test/Core.Test/Services/UserServiceTests.cs +++ b/test/Core.Test/Services/UserServiceTests.cs @@ -19,6 +19,14 @@ namespace Bit.Core.Test.Services; [SutProviderCustomize] public class UserServiceTests { + [Theory, BitAutoData] + public async Task SaveUserAsync_SetsNameToNull_WhenNameIsEmpty(SutProvider sutProvider, User user) + { + user.Name = string.Empty; + await sutProvider.Sut.SaveUserAsync(user); + Assert.Null(user.Name); + } + [Theory, BitAutoData] public async Task UpdateLicenseAsync_Success(SutProvider sutProvider, User user, UserLicense userLicense)