Skip to content

Commit 68d4d76

Browse files
committed
Use Invariant when toString userIds
1 parent 25aae38 commit 68d4d76

File tree

10 files changed

+22
-18
lines changed

10 files changed

+22
-18
lines changed

src/Umbraco.Infrastructure/Install/InstallSteps/NewInstallStep.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ public override async Task<InstallSetupResult> ExecuteAsync(UserModel user)
7373

7474
_userService.Save(admin);
7575

76-
var membershipUser = await _userManager.FindByIdAsync(Constants.Security.SuperUserId.ToString());
76+
var membershipUser = await _userManager.FindByIdAsync(Constants.Security.SuperUserIdAsString);
7777
if (membershipUser == null)
7878
{
7979
throw new InvalidOperationException(
80-
$"No user found in membership provider with id of {Constants.Security.SuperUserId}.");
80+
$"No user found in membership provider with id of {Constants.Security.SuperUserIdAsString}.");
8181
}
8282

8383
//To change the password here we actually need to reset it since we don't have an old one to use to change

src/Umbraco.Infrastructure/Persistence/Factories/ExternalLoginFactory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ internal static class ExternalLoginFactory
99
{
1010
public static IIdentityUserToken BuildEntity(ExternalLoginTokenDto dto)
1111
{
12-
var entity = new IdentityUserToken(dto.Id, dto.ExternalLoginDto.LoginProvider, dto.Name, dto.Value, dto.ExternalLoginDto.UserId.ToString(), dto.CreateDate);
12+
var entity = new IdentityUserToken(dto.Id, dto.ExternalLoginDto.LoginProvider, dto.Name, dto.Value, dto.ExternalLoginDto.UserId.ToString(CultureInfo.InvariantCulture), dto.CreateDate);
1313

1414
// reset dirty initial properties (U4-1946)
1515
entity.ResetDirtyProperties(false);
@@ -18,7 +18,7 @@ public static IIdentityUserToken BuildEntity(ExternalLoginTokenDto dto)
1818

1919
public static IIdentityUserLogin BuildEntity(ExternalLoginDto dto)
2020
{
21-
var entity = new IdentityUserLogin(dto.Id, dto.LoginProvider, dto.ProviderKey, dto.UserId.ToString(), dto.CreateDate)
21+
var entity = new IdentityUserLogin(dto.Id, dto.LoginProvider, dto.ProviderKey, dto.UserId.ToString(CultureInfo.InvariantCulture), dto.CreateDate)
2222
{
2323
UserData = dto.UserData
2424
};

src/Umbraco.Infrastructure/Security/MemberIdentityUser.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Globalization;
34
using System.Linq;
45
using Umbraco.Cms.Core.Models.Membership;
56
using Umbraco.Extensions;
@@ -11,7 +12,7 @@ namespace Umbraco.Cms.Core.Security
1112
/// </summary>
1213
public class MemberIdentityUser : UmbracoIdentityUser
1314
{
14-
private string _comments;
15+
private string _comments;
1516

1617
// Custom comparer for enumerables
1718
private static readonly DelegateEqualityComparer<IReadOnlyCollection<IReadOnlyUserGroup>> s_groupsComparer = new DelegateEqualityComparer<IReadOnlyCollection<IReadOnlyUserGroup>>(
@@ -77,7 +78,7 @@ public string Comments
7778
/// </summary>
7879
public string MemberTypeAlias { get; set; }
7980

80-
private static string UserIdToString(int userId) => string.Intern(userId.ToString());
81+
private static string UserIdToString(int userId) => string.Intern(userId.ToString(CultureInfo.InvariantCulture));
8182

8283
// TODO: Should we support custom member properties for persistence/retrieval?
8384
}

src/Umbraco.Infrastructure/Security/UmbracoUserStore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected static int UserIdToInt(string userId)
3737
throw new InvalidOperationException($"Unable to convert user ID ({userId})to int using InvariantCulture");
3838
}
3939

40-
protected static string UserIdToString(int userId) => string.Intern(userId.ToString());
40+
protected static string UserIdToString(int userId) => string.Intern(userId.ToString(CultureInfo.InvariantCulture));
4141

4242
/// <summary>
4343
/// Not supported in Umbraco

src/Umbraco.Infrastructure/Services/Implement/ExternalLoginService.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using System.Globalization;
23
using System.Linq;
34
using Microsoft.Extensions.Logging;
45
using Umbraco.Cms.Core.Events;
@@ -25,7 +26,7 @@ public IEnumerable<IIdentityUserLogin> GetExternalLogins(int userId)
2526
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
2627
{
2728
// TODO: This is temp until we update the external service to support guids for both users and members
28-
var asString = userId.ToString();
29+
var asString = userId.ToString(CultureInfo.InvariantCulture);
2930
return _externalLoginRepository.Get(Query<IIdentityUserLogin>().Where(x => x.UserId == asString))
3031
.ToList();
3132
}
@@ -36,7 +37,7 @@ public IEnumerable<IIdentityUserToken> GetExternalLoginTokens(int userId)
3637
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
3738
{
3839
// TODO: This is temp until we update the external service to support guids for both users and members
39-
var asString = userId.ToString();
40+
var asString = userId.ToString(CultureInfo.InvariantCulture);
4041
return _externalLoginRepository.Get(Query<IIdentityUserToken>().Where(x => x.UserId == asString))
4142
.ToList();
4243
}

src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Authorization/AdminUsersHandlerTests.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// See LICENSE for more details.
33

44
using System.Collections.Generic;
5+
using System.Globalization;
56
using System.Security.Claims;
67
using System.Threading.Tasks;
78
using Microsoft.AspNetCore.Authorization;
@@ -59,7 +60,7 @@ public async Task Non_Integer_QueryString_Value_Is_Authorized()
5960
public async Task Editing_Single_Admin_User_By_Admin_User_Is_Authorized()
6061
{
6162
AuthorizationHandlerContext authHandlerContext = CreateAuthorizationHandlerContext();
62-
AdminUsersHandler sut = CreateHandler(queryStringValue: Admin2UserId.ToString(), editingWithAdmin: true);
63+
AdminUsersHandler sut = CreateHandler(queryStringValue: Admin2UserId.ToString(CultureInfo.InvariantCulture), editingWithAdmin: true);
6364

6465
await sut.HandleAsync(authHandlerContext);
6566

@@ -70,7 +71,7 @@ public async Task Editing_Single_Admin_User_By_Admin_User_Is_Authorized()
7071
public async Task Editing_Single_Admin_User_By_Non_Admin_User_Is_Not_Authorized()
7172
{
7273
AuthorizationHandlerContext authHandlerContext = CreateAuthorizationHandlerContext();
73-
AdminUsersHandler sut = CreateHandler(queryStringValue: Admin2UserId.ToString());
74+
AdminUsersHandler sut = CreateHandler(queryStringValue: Admin2UserId.ToString(CultureInfo.InvariantCulture));
7475

7576
await sut.HandleAsync(authHandlerContext);
7677

@@ -81,7 +82,7 @@ public async Task Editing_Single_Admin_User_By_Non_Admin_User_Is_Not_Authorized(
8182
public async Task Editing_Single_Non_Admin_User_By_Non_Admin_User_Is_Authorized()
8283
{
8384
AuthorizationHandlerContext authHandlerContext = CreateAuthorizationHandlerContext();
84-
AdminUsersHandler sut = CreateHandler(queryStringValue: NonAdmin2UserId.ToString());
85+
AdminUsersHandler sut = CreateHandler(queryStringValue: NonAdmin2UserId.ToString(CultureInfo.InvariantCulture));
8586

8687
await sut.HandleAsync(authHandlerContext);
8788

src/Umbraco.Web.BackOffice/Controllers/AuthenticationController.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Globalization;
34
using System.Linq;
45
using System.Security.Claims;
56
using System.Threading.Tasks;
@@ -510,7 +511,7 @@ public async Task<ActionResult<UserDetail>> PostVerify2FACode(Verify2FACodeModel
510511
[AllowAnonymous]
511512
public async Task<IActionResult> PostSetPassword(SetPasswordModel model)
512513
{
513-
var identityUser = await _userManager.FindByIdAsync(model.UserId.ToString());
514+
var identityUser = await _userManager.FindByIdAsync(model.UserId.ToString(CultureInfo.InvariantCulture));
514515

515516
var result = await _userManager.ResetPasswordAsync(identityUser, model.ResetCode, model.Password);
516517
if (result.Succeeded)
@@ -560,7 +561,7 @@ public async Task<IActionResult> PostSetPassword(SetPasswordModel model)
560561
}
561562
}
562563

563-
_userManager.NotifyForgotPasswordChanged(User, model.UserId.ToString());
564+
_userManager.NotifyForgotPasswordChanged(User, model.UserId.ToString(CultureInfo.InvariantCulture));
564565
return Ok();
565566
}
566567

src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ public ActionResult LinkLogin(string provider)
348348
[AllowAnonymous]
349349
public async Task<IActionResult> ValidatePasswordResetCode([Bind(Prefix = "u")]int userId, [Bind(Prefix = "r")]string resetCode)
350350
{
351-
var user = await _userManager.FindByIdAsync(userId.ToString());
351+
var user = await _userManager.FindByIdAsync(userId.ToString(CultureInfo.InvariantCulture));
352352
if (user != null)
353353
{
354354
var result = await _userManager.VerifyUserTokenAsync(user, "Default", "ResetPassword", resetCode);

src/Umbraco.Web.BackOffice/Controllers/CurrentUserController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ public async Task<ActionResult<ModelWithNotifications<string>>> PostChangePasswo
250250
[ValidateAngularAntiForgeryToken]
251251
public async Task<Dictionary<string, string>> GetCurrentUserLinkedLogins()
252252
{
253-
var identityUser = await _backOfficeUserManager.FindByIdAsync(_backofficeSecurityAccessor.BackOfficeSecurity.GetUserId().ResultOr(0).ToString());
253+
var identityUser = await _backOfficeUserManager.FindByIdAsync(_backofficeSecurityAccessor.BackOfficeSecurity.GetUserId().ResultOr(0).ToString(CultureInfo.InvariantCulture));
254254

255255
// deduplicate in case there are duplicates (there shouldn't be now since we have a unique constraint on the external logins
256256
// but there didn't used to be)

src/Umbraco.Web.BackOffice/Install/CreateUnattendedUserNotificationHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ public async Task HandleAsync(UnattendedInstallNotification notification, Cancel
7676
// Uses same approach as NewInstall Step
7777
using IServiceScope scope = _serviceScopeFactory.CreateScope();
7878
IBackOfficeUserManager backOfficeUserManager = scope.ServiceProvider.GetRequiredService<IBackOfficeUserManager>();
79-
BackOfficeIdentityUser membershipUser = await backOfficeUserManager.FindByIdAsync(Core.Constants.Security.SuperUserId.ToString());
79+
BackOfficeIdentityUser membershipUser = await backOfficeUserManager.FindByIdAsync(Core.Constants.Security.SuperUserIdAsString);
8080
if (membershipUser == null)
8181
{
82-
throw new InvalidOperationException($"No user found in membership provider with id of {Core.Constants.Security.SuperUserId}.");
82+
throw new InvalidOperationException($"No user found in membership provider with id of {Core.Constants.Security.SuperUserIdAsString}.");
8383
}
8484

8585
//To change the password here we actually need to reset it since we don't have an old one to use to change

0 commit comments

Comments
 (0)