From 56d6c91b255861b8ca5dfb03d2bae103168ad16a Mon Sep 17 00:00:00 2001 From: Justin Baur <19896123+justindbaur@users.noreply.github.com> Date: Fri, 9 Aug 2024 09:31:06 -0400 Subject: [PATCH] Enable Nullable In Auth Repositories (#4600) --- .../Repositories/Cosmos/Base64IdStringConverter.cs | 12 +++++++----- src/Core/Auth/Repositories/Cosmos/GrantRepository.cs | 4 +++- src/Core/Auth/Repositories/IAuthRequestRepository.cs | 2 ++ .../Auth/Repositories/IEmergencyAccessRepository.cs | 4 +++- src/Core/Auth/Repositories/IGrantRepository.cs | 4 +++- src/Core/Auth/Repositories/ISsoConfigRepository.cs | 6 ++++-- src/Core/Auth/Repositories/ISsoUserRepository.cs | 4 +++- .../Repositories/IWebAuthnCredentialRepository.cs | 4 +++- src/Core/Utilities/CoreHelpers.cs | 2 ++ .../Auth/Repositories/AuthRequestRepository.cs | 2 ++ .../Auth/Repositories/EmergencyAccessRepository.cs | 4 +++- .../Auth/Repositories/GrantRepository.cs | 4 +++- .../Auth/Repositories/SsoConfigRepository.cs | 6 ++++-- .../Auth/Repositories/SsoUserRepository.cs | 4 +++- .../Repositories/WebAuthnCredentialRepository.cs | 4 +++- .../Auth/Repositories/AuthRequestRepository.cs | 4 +++- .../Auth/Repositories/EmergencyAccessRepository.cs | 4 +++- .../Auth/Repositories/GrantRepository.cs | 5 +++-- .../Queries/EmergencyAccessDetailsViewQuery.cs | 2 ++ .../EmergencyAccessReadCountByGrantorIdEmailQuery.cs | 2 ++ .../Auth/Repositories/SsoConfigRepository.cs | 6 ++++-- .../Auth/Repositories/SsoUserRepository.cs | 10 ++++++---- .../Repositories/WebAuthnCredentialRepository.cs | 4 +++- .../Controllers/AccountsControllerTest.cs | 1 + test/Api.IntegrationTest/Helpers/LoginHelper.cs | 2 +- 25 files changed, 76 insertions(+), 30 deletions(-) diff --git a/src/Core/Auth/Repositories/Cosmos/Base64IdStringConverter.cs b/src/Core/Auth/Repositories/Cosmos/Base64IdStringConverter.cs index 5ec53100f..68ccf698f 100644 --- a/src/Core/Auth/Repositories/Cosmos/Base64IdStringConverter.cs +++ b/src/Core/Auth/Repositories/Cosmos/Base64IdStringConverter.cs @@ -2,17 +2,19 @@ using System.Text.Json.Serialization; using Bit.Core.Utilities; +#nullable enable + namespace Bit.Core.Auth.Repositories.Cosmos; -public class Base64IdStringConverter : JsonConverter +public class Base64IdStringConverter : JsonConverter { - public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) => + public override string? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) => ToKey(reader.GetString()); - public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options) => + public override void Write(Utf8JsonWriter writer, string? value, JsonSerializerOptions options) => writer.WriteStringValue(ToId(value)); - public static string ToId(string key) + public static string? ToId(string? key) { if (key == null) { @@ -21,7 +23,7 @@ public class Base64IdStringConverter : JsonConverter return CoreHelpers.TransformToBase64Url(key); } - public static string ToKey(string id) + public static string? ToKey(string? id) { if (id == null) { diff --git a/src/Core/Auth/Repositories/Cosmos/GrantRepository.cs b/src/Core/Auth/Repositories/Cosmos/GrantRepository.cs index 66fc3fb79..36356f8d3 100644 --- a/src/Core/Auth/Repositories/Cosmos/GrantRepository.cs +++ b/src/Core/Auth/Repositories/Cosmos/GrantRepository.cs @@ -6,6 +6,8 @@ using Bit.Core.Settings; using Bit.Core.Utilities; using Microsoft.Azure.Cosmos; +#nullable enable + namespace Bit.Core.Auth.Repositories.Cosmos; public class GrantRepository : IGrantRepository @@ -34,7 +36,7 @@ public class GrantRepository : IGrantRepository _container = _database.GetContainer("grant"); } - public async Task GetByKeyAsync(string key) + public async Task GetByKeyAsync(string key) { var id = Base64IdStringConverter.ToId(key); try diff --git a/src/Core/Auth/Repositories/IAuthRequestRepository.cs b/src/Core/Auth/Repositories/IAuthRequestRepository.cs index 6662dd15f..3b01a452f 100644 --- a/src/Core/Auth/Repositories/IAuthRequestRepository.cs +++ b/src/Core/Auth/Repositories/IAuthRequestRepository.cs @@ -1,6 +1,8 @@ using Bit.Core.Auth.Entities; using Bit.Core.Auth.Models.Data; +#nullable enable + namespace Bit.Core.Repositories; public interface IAuthRequestRepository : IRepository diff --git a/src/Core/Auth/Repositories/IEmergencyAccessRepository.cs b/src/Core/Auth/Repositories/IEmergencyAccessRepository.cs index e22e93488..6edb941d3 100644 --- a/src/Core/Auth/Repositories/IEmergencyAccessRepository.cs +++ b/src/Core/Auth/Repositories/IEmergencyAccessRepository.cs @@ -2,6 +2,8 @@ using Bit.Core.Auth.Models.Data; using Bit.Core.Auth.UserFeatures.UserKey; +#nullable enable + namespace Bit.Core.Repositories; public interface IEmergencyAccessRepository : IRepository @@ -9,7 +11,7 @@ public interface IEmergencyAccessRepository : IRepository Task GetCountByGrantorIdEmailAsync(Guid grantorId, string email, bool onlyRegisteredUsers); Task> GetManyDetailsByGrantorIdAsync(Guid grantorId); Task> GetManyDetailsByGranteeIdAsync(Guid granteeId); - Task GetDetailsByIdGrantorIdAsync(Guid id, Guid grantorId); + Task GetDetailsByIdGrantorIdAsync(Guid id, Guid grantorId); Task> GetManyToNotifyAsync(); Task> GetExpiredRecoveriesAsync(); diff --git a/src/Core/Auth/Repositories/IGrantRepository.cs b/src/Core/Auth/Repositories/IGrantRepository.cs index 2304385be..7ed01fadd 100644 --- a/src/Core/Auth/Repositories/IGrantRepository.cs +++ b/src/Core/Auth/Repositories/IGrantRepository.cs @@ -1,10 +1,12 @@ using Bit.Core.Auth.Models.Data; +#nullable enable + namespace Bit.Core.Auth.Repositories; public interface IGrantRepository { - Task GetByKeyAsync(string key); + Task GetByKeyAsync(string key); Task> GetManyAsync(string subjectId, string sessionId, string clientId, string type); Task SaveAsync(IGrant obj); Task DeleteByKeyAsync(string key); diff --git a/src/Core/Auth/Repositories/ISsoConfigRepository.cs b/src/Core/Auth/Repositories/ISsoConfigRepository.cs index 2ed1a15ea..f5d6c5201 100644 --- a/src/Core/Auth/Repositories/ISsoConfigRepository.cs +++ b/src/Core/Auth/Repositories/ISsoConfigRepository.cs @@ -1,11 +1,13 @@ using Bit.Core.Auth.Entities; using Bit.Core.Repositories; +#nullable enable + namespace Bit.Core.Auth.Repositories; public interface ISsoConfigRepository : IRepository { - Task GetByOrganizationIdAsync(Guid organizationId); - Task GetByIdentifierAsync(string identifier); + Task GetByOrganizationIdAsync(Guid organizationId); + Task GetByIdentifierAsync(string identifier); Task> GetManyByRevisionNotBeforeDate(DateTime? notBefore); } diff --git a/src/Core/Auth/Repositories/ISsoUserRepository.cs b/src/Core/Auth/Repositories/ISsoUserRepository.cs index 9c97cfc94..6691b033a 100644 --- a/src/Core/Auth/Repositories/ISsoUserRepository.cs +++ b/src/Core/Auth/Repositories/ISsoUserRepository.cs @@ -1,10 +1,12 @@ using Bit.Core.Auth.Entities; using Bit.Core.Repositories; +#nullable enable + namespace Bit.Core.Auth.Repositories; public interface ISsoUserRepository : IRepository { Task DeleteAsync(Guid userId, Guid? organizationId); - Task GetByUserIdOrganizationIdAsync(Guid organizationId, Guid userId); + Task GetByUserIdOrganizationIdAsync(Guid organizationId, Guid userId); } diff --git a/src/Core/Auth/Repositories/IWebAuthnCredentialRepository.cs b/src/Core/Auth/Repositories/IWebAuthnCredentialRepository.cs index 1fab56d07..9a7fc8820 100644 --- a/src/Core/Auth/Repositories/IWebAuthnCredentialRepository.cs +++ b/src/Core/Auth/Repositories/IWebAuthnCredentialRepository.cs @@ -3,11 +3,13 @@ using Bit.Core.Auth.Models.Data; using Bit.Core.Auth.UserFeatures.UserKey; using Bit.Core.Repositories; +#nullable enable + namespace Bit.Core.Auth.Repositories; public interface IWebAuthnCredentialRepository : IRepository { - Task GetByIdAsync(Guid id, Guid userId); + Task GetByIdAsync(Guid id, Guid userId); Task> GetManyByUserIdAsync(Guid userId); Task UpdateAsync(WebAuthnCredential credential); UpdateEncryptedDataForKeyRotation UpdateKeysForRotationAsync(Guid userId, IEnumerable credentials); diff --git a/src/Core/Utilities/CoreHelpers.cs b/src/Core/Utilities/CoreHelpers.cs index 043a36c15..d900c82e2 100644 --- a/src/Core/Utilities/CoreHelpers.cs +++ b/src/Core/Utilities/CoreHelpers.cs @@ -388,6 +388,8 @@ public static class CoreHelpers /// Base64 standard formatted string public static string TransformFromBase64Url(string input) { + // TODO: .NET 9 Ships Base64Url in box, investigate replacing this usage with that + // Ref: https://github.com/dotnet/runtime/pull/102364 var output = input; // 62nd char of encoding output = output.Replace('-', '+'); diff --git a/src/Infrastructure.Dapper/Auth/Repositories/AuthRequestRepository.cs b/src/Infrastructure.Dapper/Auth/Repositories/AuthRequestRepository.cs index df68c06d0..db6419d38 100644 --- a/src/Infrastructure.Dapper/Auth/Repositories/AuthRequestRepository.cs +++ b/src/Infrastructure.Dapper/Auth/Repositories/AuthRequestRepository.cs @@ -8,6 +8,8 @@ using Bit.Infrastructure.Dapper.Repositories; using Dapper; using Microsoft.Data.SqlClient; +#nullable enable + namespace Bit.Infrastructure.Dapper.Auth.Repositories; public class AuthRequestRepository : Repository, IAuthRequestRepository diff --git a/src/Infrastructure.Dapper/Auth/Repositories/EmergencyAccessRepository.cs b/src/Infrastructure.Dapper/Auth/Repositories/EmergencyAccessRepository.cs index 195ebfada..e6bf92bde 100644 --- a/src/Infrastructure.Dapper/Auth/Repositories/EmergencyAccessRepository.cs +++ b/src/Infrastructure.Dapper/Auth/Repositories/EmergencyAccessRepository.cs @@ -9,6 +9,8 @@ using Bit.Infrastructure.Dapper.Repositories; using Dapper; using Microsoft.Data.SqlClient; +#nullable enable + namespace Bit.Infrastructure.Dapper.Auth.Repositories; public class EmergencyAccessRepository : Repository, IEmergencyAccessRepository @@ -60,7 +62,7 @@ public class EmergencyAccessRepository : Repository, IEme } } - public async Task GetDetailsByIdGrantorIdAsync(Guid id, Guid grantorId) + public async Task GetDetailsByIdGrantorIdAsync(Guid id, Guid grantorId) { using (var connection = new SqlConnection(ConnectionString)) { diff --git a/src/Infrastructure.Dapper/Auth/Repositories/GrantRepository.cs b/src/Infrastructure.Dapper/Auth/Repositories/GrantRepository.cs index a12969a8f..7389dd657 100644 --- a/src/Infrastructure.Dapper/Auth/Repositories/GrantRepository.cs +++ b/src/Infrastructure.Dapper/Auth/Repositories/GrantRepository.cs @@ -7,6 +7,8 @@ using Bit.Infrastructure.Dapper.Repositories; using Dapper; using Microsoft.Data.SqlClient; +#nullable enable + namespace Bit.Infrastructure.Dapper.Auth.Repositories; public class GrantRepository : BaseRepository, IGrantRepository @@ -19,7 +21,7 @@ public class GrantRepository : BaseRepository, IGrantRepository : base(connectionString, readOnlyConnectionString) { } - public async Task GetByKeyAsync(string key) + public async Task GetByKeyAsync(string key) { using (var connection = new SqlConnection(ConnectionString)) { diff --git a/src/Infrastructure.Dapper/Auth/Repositories/SsoConfigRepository.cs b/src/Infrastructure.Dapper/Auth/Repositories/SsoConfigRepository.cs index 0922b3a73..942ca1b3c 100644 --- a/src/Infrastructure.Dapper/Auth/Repositories/SsoConfigRepository.cs +++ b/src/Infrastructure.Dapper/Auth/Repositories/SsoConfigRepository.cs @@ -6,6 +6,8 @@ using Bit.Infrastructure.Dapper.Repositories; using Dapper; using Microsoft.Data.SqlClient; +#nullable enable + namespace Bit.Infrastructure.Dapper.Auth.Repositories; public class SsoConfigRepository : Repository, ISsoConfigRepository @@ -18,7 +20,7 @@ public class SsoConfigRepository : Repository, ISsoConfigReposi : base(connectionString, readOnlyConnectionString) { } - public async Task GetByOrganizationIdAsync(Guid organizationId) + public async Task GetByOrganizationIdAsync(Guid organizationId) { using (var connection = new SqlConnection(ConnectionString)) { @@ -31,7 +33,7 @@ public class SsoConfigRepository : Repository, ISsoConfigReposi } } - public async Task GetByIdentifierAsync(string identifier) + public async Task GetByIdentifierAsync(string identifier) { using (var connection = new SqlConnection(ConnectionString)) { diff --git a/src/Infrastructure.Dapper/Auth/Repositories/SsoUserRepository.cs b/src/Infrastructure.Dapper/Auth/Repositories/SsoUserRepository.cs index a25708f7e..99cbc25c5 100644 --- a/src/Infrastructure.Dapper/Auth/Repositories/SsoUserRepository.cs +++ b/src/Infrastructure.Dapper/Auth/Repositories/SsoUserRepository.cs @@ -6,6 +6,8 @@ using Bit.Infrastructure.Dapper.Repositories; using Dapper; using Microsoft.Data.SqlClient; +#nullable enable + namespace Bit.Infrastructure.Dapper.Auth.Repositories; public class SsoUserRepository : Repository, ISsoUserRepository @@ -29,7 +31,7 @@ public class SsoUserRepository : Repository, ISsoUserRepository } } - public async Task GetByUserIdOrganizationIdAsync(Guid organizationId, Guid userId) + public async Task GetByUserIdOrganizationIdAsync(Guid organizationId, Guid userId) { using (var connection = new SqlConnection(ConnectionString)) { diff --git a/src/Infrastructure.Dapper/Auth/Repositories/WebAuthnCredentialRepository.cs b/src/Infrastructure.Dapper/Auth/Repositories/WebAuthnCredentialRepository.cs index 85a7cc64e..0f7e1ea1b 100644 --- a/src/Infrastructure.Dapper/Auth/Repositories/WebAuthnCredentialRepository.cs +++ b/src/Infrastructure.Dapper/Auth/Repositories/WebAuthnCredentialRepository.cs @@ -9,6 +9,8 @@ using Bit.Infrastructure.Dapper.Repositories; using Dapper; using Microsoft.Data.SqlClient; +#nullable enable + namespace Bit.Infrastructure.Dapper.Auth.Repositories; @@ -22,7 +24,7 @@ public class WebAuthnCredentialRepository : Repository : base(connectionString, readOnlyConnectionString) { } - public async Task GetByIdAsync(Guid id, Guid userId) + public async Task GetByIdAsync(Guid id, Guid userId) { using (var connection = new SqlConnection(ConnectionString)) { diff --git a/src/Infrastructure.EntityFramework/Auth/Repositories/AuthRequestRepository.cs b/src/Infrastructure.EntityFramework/Auth/Repositories/AuthRequestRepository.cs index 11e5b3f65..7dee40a9e 100644 --- a/src/Infrastructure.EntityFramework/Auth/Repositories/AuthRequestRepository.cs +++ b/src/Infrastructure.EntityFramework/Auth/Repositories/AuthRequestRepository.cs @@ -8,6 +8,8 @@ using Bit.Infrastructure.EntityFramework.Repositories; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Bit.Infrastructure.EntityFramework.Auth.Repositories; public class AuthRequestRepository : Repository, IAuthRequestRepository @@ -25,7 +27,7 @@ public class AuthRequestRepository : Repository (a.Type != AuthRequestType.AdminApproval && a.CreationDate.AddSeconds(userRequestExpiration.TotalSeconds) < DateTime.UtcNow) || (a.Type == AuthRequestType.AdminApproval && a.Approved != true && a.CreationDate.AddSeconds(adminRequestExpiration.TotalSeconds) < DateTime.UtcNow) - || (a.Type == AuthRequestType.AdminApproval && a.Approved == true && a.ResponseDate.Value.AddSeconds(afterAdminApprovalExpiration.TotalSeconds) < DateTime.UtcNow)) + || (a.Type == AuthRequestType.AdminApproval && a.Approved == true && a.ResponseDate!.Value.AddSeconds(afterAdminApprovalExpiration.TotalSeconds) < DateTime.UtcNow)) .ToListAsync(); dbContext.AuthRequests.RemoveRange(expiredRequests); return await dbContext.SaveChangesAsync(); diff --git a/src/Infrastructure.EntityFramework/Auth/Repositories/EmergencyAccessRepository.cs b/src/Infrastructure.EntityFramework/Auth/Repositories/EmergencyAccessRepository.cs index e6a32542f..22ca89fa0 100644 --- a/src/Infrastructure.EntityFramework/Auth/Repositories/EmergencyAccessRepository.cs +++ b/src/Infrastructure.EntityFramework/Auth/Repositories/EmergencyAccessRepository.cs @@ -10,6 +10,8 @@ using Microsoft.Data.SqlClient; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Bit.Infrastructure.EntityFramework.Auth.Repositories; public class EmergencyAccessRepository : Repository, IEmergencyAccessRepository @@ -35,7 +37,7 @@ public class EmergencyAccessRepository : Repository GetDetailsByIdGrantorIdAsync(Guid id, Guid grantorId) + public async Task GetDetailsByIdGrantorIdAsync(Guid id, Guid grantorId) { using (var scope = ServiceScopeFactory.CreateScope()) { diff --git a/src/Infrastructure.EntityFramework/Auth/Repositories/GrantRepository.cs b/src/Infrastructure.EntityFramework/Auth/Repositories/GrantRepository.cs index 09fd46835..dd958e0c6 100644 --- a/src/Infrastructure.EntityFramework/Auth/Repositories/GrantRepository.cs +++ b/src/Infrastructure.EntityFramework/Auth/Repositories/GrantRepository.cs @@ -6,6 +6,8 @@ using Bit.Infrastructure.EntityFramework.Repositories; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Bit.Infrastructure.EntityFramework.Auth.Repositories; public class GrantRepository : BaseEntityFrameworkRepository, IGrantRepository @@ -36,7 +38,7 @@ public class GrantRepository : BaseEntityFrameworkRepository, IGrantRepository } } - public async Task GetByKeyAsync(string key) + public async Task GetByKeyAsync(string key) { using (var scope = ServiceScopeFactory.CreateScope()) { @@ -92,4 +94,3 @@ public class GrantRepository : BaseEntityFrameworkRepository, IGrantRepository } } } - diff --git a/src/Infrastructure.EntityFramework/Auth/Repositories/Queries/EmergencyAccessDetailsViewQuery.cs b/src/Infrastructure.EntityFramework/Auth/Repositories/Queries/EmergencyAccessDetailsViewQuery.cs index 7ddbcc346..d666df76c 100644 --- a/src/Infrastructure.EntityFramework/Auth/Repositories/Queries/EmergencyAccessDetailsViewQuery.cs +++ b/src/Infrastructure.EntityFramework/Auth/Repositories/Queries/EmergencyAccessDetailsViewQuery.cs @@ -2,6 +2,8 @@ using Bit.Infrastructure.EntityFramework.Repositories; using Bit.Infrastructure.EntityFramework.Repositories.Queries; +#nullable enable + namespace Bit.Infrastructure.EntityFramework.Auth.Repositories.Queries; public class EmergencyAccessDetailsViewQuery : IQuery diff --git a/src/Infrastructure.EntityFramework/Auth/Repositories/Queries/EmergencyAccessReadCountByGrantorIdEmailQuery.cs b/src/Infrastructure.EntityFramework/Auth/Repositories/Queries/EmergencyAccessReadCountByGrantorIdEmailQuery.cs index 0cdf19f2d..a0926db57 100644 --- a/src/Infrastructure.EntityFramework/Auth/Repositories/Queries/EmergencyAccessReadCountByGrantorIdEmailQuery.cs +++ b/src/Infrastructure.EntityFramework/Auth/Repositories/Queries/EmergencyAccessReadCountByGrantorIdEmailQuery.cs @@ -2,6 +2,8 @@ using Bit.Infrastructure.EntityFramework.Repositories; using Bit.Infrastructure.EntityFramework.Repositories.Queries; +#nullable enable + namespace Bit.Infrastructure.EntityFramework.Auth.Repositories.Queries; public class EmergencyAccessReadCountByGrantorIdEmailQuery : IQuery diff --git a/src/Infrastructure.EntityFramework/Auth/Repositories/SsoConfigRepository.cs b/src/Infrastructure.EntityFramework/Auth/Repositories/SsoConfigRepository.cs index 3113f31de..c34a024ae 100644 --- a/src/Infrastructure.EntityFramework/Auth/Repositories/SsoConfigRepository.cs +++ b/src/Infrastructure.EntityFramework/Auth/Repositories/SsoConfigRepository.cs @@ -4,6 +4,8 @@ using Bit.Infrastructure.EntityFramework.Auth.Models; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Bit.Infrastructure.EntityFramework.Repositories; public class SsoConfigRepository : Repository, ISsoConfigRepository @@ -12,7 +14,7 @@ public class SsoConfigRepository : Repository context.SsoConfigs) { } - public async Task GetByOrganizationIdAsync(Guid organizationId) + public async Task GetByOrganizationIdAsync(Guid organizationId) { using (var scope = ServiceScopeFactory.CreateScope()) { @@ -22,7 +24,7 @@ public class SsoConfigRepository : Repository GetByIdentifierAsync(string identifier) + public async Task GetByIdentifierAsync(string identifier) { using (var scope = ServiceScopeFactory.CreateScope()) diff --git a/src/Infrastructure.EntityFramework/Auth/Repositories/SsoUserRepository.cs b/src/Infrastructure.EntityFramework/Auth/Repositories/SsoUserRepository.cs index 278c5e870..7d0152912 100644 --- a/src/Infrastructure.EntityFramework/Auth/Repositories/SsoUserRepository.cs +++ b/src/Infrastructure.EntityFramework/Auth/Repositories/SsoUserRepository.cs @@ -4,6 +4,8 @@ using Bit.Infrastructure.EntityFramework.Auth.Models; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Bit.Infrastructure.EntityFramework.Repositories; public class SsoUserRepository : Repository, ISsoUserRepository @@ -17,13 +19,13 @@ public class SsoUserRepository : Repository su.UserId == userId && su.OrganizationId == organizationId); - dbContext.Entry(entity).State = EntityState.Deleted; - await dbContext.SaveChangesAsync(); + await dbContext.SsoUsers + .Where(su => su.UserId == userId && su.OrganizationId == organizationId) + .ExecuteDeleteAsync(); } } - public async Task GetByUserIdOrganizationIdAsync(Guid organizationId, Guid userId) + public async Task GetByUserIdOrganizationIdAsync(Guid organizationId, Guid userId) { using (var scope = ServiceScopeFactory.CreateScope()) { diff --git a/src/Infrastructure.EntityFramework/Auth/Repositories/WebAuthnCredentialRepository.cs b/src/Infrastructure.EntityFramework/Auth/Repositories/WebAuthnCredentialRepository.cs index 149981188..b670a3f1d 100644 --- a/src/Infrastructure.EntityFramework/Auth/Repositories/WebAuthnCredentialRepository.cs +++ b/src/Infrastructure.EntityFramework/Auth/Repositories/WebAuthnCredentialRepository.cs @@ -7,6 +7,8 @@ using Bit.Infrastructure.EntityFramework.Repositories; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Bit.Infrastructure.EntityFramework.Auth.Repositories; public class WebAuthnCredentialRepository : Repository, IWebAuthnCredentialRepository @@ -15,7 +17,7 @@ public class WebAuthnCredentialRepository : Repository context.WebAuthnCredentials) { } - public async Task GetByIdAsync(Guid id, Guid userId) + public async Task GetByIdAsync(Guid id, Guid userId) { using (var scope = ServiceScopeFactory.CreateScope()) { diff --git a/test/Api.IntegrationTest/Controllers/AccountsControllerTest.cs b/test/Api.IntegrationTest/Controllers/AccountsControllerTest.cs index a4500046e..1bce9398e 100644 --- a/test/Api.IntegrationTest/Controllers/AccountsControllerTest.cs +++ b/test/Api.IntegrationTest/Controllers/AccountsControllerTest.cs @@ -24,6 +24,7 @@ public class AccountsControllerTest : IClassFixture response.EnsureSuccessStatusCode(); var content = await response.Content.ReadFromJsonAsync(); + Assert.NotNull(content); Assert.Equal("integration-test@bitwarden.com", content.Email); Assert.Null(content.Name); Assert.False(content.EmailVerified); diff --git a/test/Api.IntegrationTest/Helpers/LoginHelper.cs b/test/Api.IntegrationTest/Helpers/LoginHelper.cs index f036970a0..d6ce911bd 100644 --- a/test/Api.IntegrationTest/Helpers/LoginHelper.cs +++ b/test/Api.IntegrationTest/Helpers/LoginHelper.cs @@ -32,6 +32,6 @@ public class LoginHelper var organizationApiKeyRepository = factory.GetService(); var apiKeys = await organizationApiKeyRepository.GetManyByOrganizationIdTypeAsync(organizationId); var clientId = $"organization.{organizationId}"; - return (clientId, apiKeys.SingleOrDefault().ApiKey); + return (clientId, apiKeys.Single().ApiKey); } }