1
0
mirror of https://github.com/bitwarden/server.git synced 2025-05-11 14:42:19 -05:00

Resolve auth warnings (#5784)

This commit is contained in:
Justin Baur 2025-05-08 07:49:16 -04:00 committed by GitHub
parent 051f200d4b
commit 1228fe51c8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 18 additions and 24 deletions

View File

@ -16,10 +16,11 @@ public class DuoUniversalTokenProvider(
IDuoUniversalTokenService duoUniversalTokenService) : IUserTwoFactorTokenProvider<User> IDuoUniversalTokenService duoUniversalTokenService) : IUserTwoFactorTokenProvider<User>
{ {
/// <summary> /// <summary>
/// We need the IServiceProvider to resolve the IUserService. There is a complex dependency dance /// We need the IServiceProvider to resolve the <see cref="IUserService"/>. There is a complex dependency dance
/// occurring between IUserService, which extends the UserManager<User>, and the usage of the /// occurring between <see cref="IUserService"/>, which extends the <see cref="UserManager{User}"/>, and the usage
/// UserManager<User> within this class. Trying to resolve the IUserService using the DI pipeline /// of the <see cref="UserManager{User}"/> within this class. Trying to resolve the <see cref="IUserService"/> using
/// will not allow the server to start and it will hang and give no helpful indication as to the problem. /// the DI pipeline will not allow the server to start and it will hang and give no helpful indication as to the
/// problem.
/// </summary> /// </summary>
private readonly IServiceProvider _serviceProvider = serviceProvider; private readonly IServiceProvider _serviceProvider = serviceProvider;
private readonly IDataProtectorTokenFactory<DuoUserStateTokenable> _tokenDataFactory = tokenDataFactory; private readonly IDataProtectorTokenFactory<DuoUserStateTokenable> _tokenDataFactory = tokenDataFactory;

View File

@ -4,7 +4,7 @@
<GenerateUserSecretsAttribute>false</GenerateUserSecretsAttribute> <GenerateUserSecretsAttribute>false</GenerateUserSecretsAttribute>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile> <DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
<!-- Temp exclusions until warnings are fixed --> <!-- Temp exclusions until warnings are fixed -->
<WarningsNotAsErrors>$(WarningsNotAsErrors);CS1570;CS1574;CS9113;CS1998</WarningsNotAsErrors> <WarningsNotAsErrors>$(WarningsNotAsErrors);CS1574;CS9113;CS1998</WarningsNotAsErrors>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

View File

@ -3,8 +3,6 @@
<PropertyGroup> <PropertyGroup>
<UserSecretsId>bitwarden-Identity</UserSecretsId> <UserSecretsId>bitwarden-Identity</UserSecretsId>
<MvcRazorCompileOnPublish>false</MvcRazorCompileOnPublish> <MvcRazorCompileOnPublish>false</MvcRazorCompileOnPublish>
<!-- Temp exclusions until warnings are fixed -->
<WarningsNotAsErrors>$(WarningsNotAsErrors);CS0162</WarningsNotAsErrors>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(RunConfiguration)' == 'Identity' " /> <PropertyGroup Condition=" '$(RunConfiguration)' == 'Identity' " />

View File

@ -17,15 +17,11 @@ public class DeviceRepository : Repository<Device, Guid>, IDeviceRepository
private readonly IGlobalSettings _globalSettings; private readonly IGlobalSettings _globalSettings;
public DeviceRepository(GlobalSettings globalSettings) public DeviceRepository(GlobalSettings globalSettings)
: this(globalSettings.SqlServer.ConnectionString, globalSettings.SqlServer.ReadOnlyConnectionString) : base(globalSettings.SqlServer.ConnectionString, globalSettings.SqlServer.ReadOnlyConnectionString)
{ {
_globalSettings = globalSettings; _globalSettings = globalSettings;
} }
public DeviceRepository(string connectionString, string readOnlyConnectionString)
: base(connectionString, readOnlyConnectionString)
{ }
public async Task<Device?> GetByIdAsync(Guid id, Guid userId) public async Task<Device?> GetByIdAsync(Guid id, Guid userId)
{ {
var device = await GetByIdAsync(id); var device = await GetByIdAsync(id);

View File

@ -8,7 +8,6 @@ using Bit.Core.Entities;
using Bit.Core.Enums; using Bit.Core.Enums;
using Bit.Core.Repositories; using Bit.Core.Repositories;
using Bit.Core.Services; using Bit.Core.Services;
using Bit.Core.Settings;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using NSubstitute; using NSubstitute;
using Xunit; using Xunit;
@ -23,7 +22,6 @@ public class DevicesControllerTest
private readonly IUntrustDevicesCommand _untrustDevicesCommand; private readonly IUntrustDevicesCommand _untrustDevicesCommand;
private readonly IUserRepository _userRepositoryMock; private readonly IUserRepository _userRepositoryMock;
private readonly ICurrentContext _currentContextMock; private readonly ICurrentContext _currentContextMock;
private readonly IGlobalSettings _globalSettingsMock;
private readonly ILogger<DevicesController> _loggerMock; private readonly ILogger<DevicesController> _loggerMock;
private readonly DevicesController _sut; private readonly DevicesController _sut;

View File

@ -2,8 +2,6 @@
<PropertyGroup> <PropertyGroup>
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
<!-- Temp exclusions until warnings are fixed -->
<WarningsNotAsErrors>$(WarningsNotAsErrors);CS0672;CS1998</WarningsNotAsErrors>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -96,6 +96,7 @@ IBaseRequestValidatorTestWrapper
return context.ValidatedTokenRequest.Subject ?? new ClaimsPrincipal(); return context.ValidatedTokenRequest.Subject ?? new ClaimsPrincipal();
} }
[Obsolete]
protected override void SetErrorResult( protected override void SetErrorResult(
BaseRequestValidationContextFake context, BaseRequestValidationContextFake context,
Dictionary<string, object> customResponse) Dictionary<string, object> customResponse)
@ -103,6 +104,7 @@ IBaseRequestValidatorTestWrapper
context.GrantResult = new GrantValidationResult(TokenRequestErrors.InvalidGrant, customResponse: customResponse); context.GrantResult = new GrantValidationResult(TokenRequestErrors.InvalidGrant, customResponse: customResponse);
} }
[Obsolete]
protected override void SetSsoResult( protected override void SetSsoResult(
BaseRequestValidationContextFake context, BaseRequestValidationContextFake context,
Dictionary<string, object> customResponse) Dictionary<string, object> customResponse)
@ -121,6 +123,7 @@ IBaseRequestValidatorTestWrapper
return Task.CompletedTask; return Task.CompletedTask;
} }
[Obsolete]
protected override void SetTwoFactorResult( protected override void SetTwoFactorResult(
BaseRequestValidationContextFake context, BaseRequestValidationContextFake context,
Dictionary<string, object> customResponse) Dictionary<string, object> customResponse)

View File

@ -56,9 +56,9 @@ public class UserManagerTestWrapper<TUser> : UserManager<TUser> where TUser : cl
/// </summary> /// </summary>
/// <param name="user"></param> /// <param name="user"></param>
/// <returns></returns> /// <returns></returns>
public override async Task<bool> GetTwoFactorEnabledAsync(TUser user) public override Task<bool> GetTwoFactorEnabledAsync(TUser user)
{ {
return TWO_FACTOR_ENABLED; return Task.FromResult(TWO_FACTOR_ENABLED);
} }
/// <summary> /// <summary>
@ -66,9 +66,9 @@ public class UserManagerTestWrapper<TUser> : UserManager<TUser> where TUser : cl
/// </summary> /// </summary>
/// <param name="user"></param> /// <param name="user"></param>
/// <returns></returns> /// <returns></returns>
public override async Task<IList<string>> GetValidTwoFactorProvidersAsync(TUser user) public override Task<IList<string>> GetValidTwoFactorProvidersAsync(TUser user)
{ {
return TWO_FACTOR_PROVIDERS; return Task.FromResult(TWO_FACTOR_PROVIDERS);
} }
/// <summary> /// <summary>
@ -77,9 +77,9 @@ public class UserManagerTestWrapper<TUser> : UserManager<TUser> where TUser : cl
/// <param name="user"></param> /// <param name="user"></param>
/// <param name="tokenProvider"></param> /// <param name="tokenProvider"></param>
/// <returns></returns> /// <returns></returns>
public override async Task<string> GenerateTwoFactorTokenAsync(TUser user, string tokenProvider) public override Task<string> GenerateTwoFactorTokenAsync(TUser user, string tokenProvider)
{ {
return TWO_FACTOR_TOKEN; return Task.FromResult(TWO_FACTOR_TOKEN);
} }
/// <summary> /// <summary>
@ -89,8 +89,8 @@ public class UserManagerTestWrapper<TUser> : UserManager<TUser> where TUser : cl
/// <param name="tokenProvider"></param> /// <param name="tokenProvider"></param>
/// <param name="token"></param> /// <param name="token"></param>
/// <returns></returns> /// <returns></returns>
public override async Task<bool> VerifyTwoFactorTokenAsync(TUser user, string tokenProvider, string token) public override Task<bool> VerifyTwoFactorTokenAsync(TUser user, string tokenProvider, string token)
{ {
return TWO_FACTOR_TOKEN_VERIFIED; return Task.FromResult(TWO_FACTOR_TOKEN_VERIFIED);
} }
} }