From 53327b19935fe1616aca42e89d4cdb37a8b20612 Mon Sep 17 00:00:00 2001 From: Matt Bishop Date: Fri, 16 Jun 2023 10:02:05 -0400 Subject: [PATCH] [PM-2633] Warnings cleanup (#3010) * Warnings cleanup * One-line response with null Co-authored-by: Thomas Avery <43214426+Thomas-Avery@users.noreply.github.com> * Remove condition * Fix lint from suggestion --------- Co-authored-by: Thomas Avery <43214426+Thomas-Avery@users.noreply.github.com> --- .../Repositories/SecretRepository.cs | 6 +-- .../AccessTokenCreationResponseModel.cs | 4 +- .../Response/PotentialGranteeResponseModel.cs | 2 +- src/Billing/Controllers/StripeController.cs | 12 +++--- .../Tools/Models/Business/ReferenceEvent.cs | 2 +- .../OrganizationDomainRepository.cs | 6 +-- .../SecretsManagerPortingControllerTests.cs | 3 -- .../OrganizationsControllerTests.cs | 1 - .../SelfHostedOrganizationDetailsTests.cs | 38 +++++++++---------- .../Repositories/CipherRepositoryTests.cs | 8 +--- .../Factories/WebApplicationFactoryBase.cs | 4 +- util/EfShared/MigrationBuilderExtensions.cs | 4 +- 12 files changed, 41 insertions(+), 49 deletions(-) diff --git a/bitwarden_license/src/Commercial.Infrastructure.EntityFramework/SecretsManager/Repositories/SecretRepository.cs b/bitwarden_license/src/Commercial.Infrastructure.EntityFramework/SecretsManager/Repositories/SecretRepository.cs index d25af115ce..6720c7116d 100644 --- a/bitwarden_license/src/Commercial.Infrastructure.EntityFramework/SecretsManager/Repositories/SecretRepository.cs +++ b/bitwarden_license/src/Commercial.Infrastructure.EntityFramework/SecretsManager/Repositories/SecretRepository.cs @@ -139,13 +139,13 @@ public class SecretRepository : Repository s.Id == secret.Id); - foreach (var p in entity.Projects?.Where(p => mappedEntity.Projects.All(mp => mp.Id != p.Id))) + foreach (var p in entity.Projects.Where(p => mappedEntity.Projects.All(mp => mp.Id != p.Id))) { entity.Projects.Remove(p); } // Add new relationships - foreach (var project in mappedEntity.Projects?.Where(p => entity.Projects.All(ep => ep.Id != p.Id))) + foreach (var project in mappedEntity.Projects.Where(p => entity.Projects.All(ep => ep.Id != p.Id))) { var p = dbContext.AttachToOrGet(_ => _.Id == project.Id, () => project); entity.Projects.Add(p); @@ -290,7 +290,7 @@ public class SecretRepository : Repository SecretToPermissionDetails(IQueryable query, Guid userId, AccessClientType accessType) diff --git a/src/Api/SecretsManager/Models/Response/AccessTokenCreationResponseModel.cs b/src/Api/SecretsManager/Models/Response/AccessTokenCreationResponseModel.cs index 874251504c..609ab4ebd9 100644 --- a/src/Api/SecretsManager/Models/Response/AccessTokenCreationResponseModel.cs +++ b/src/Api/SecretsManager/Models/Response/AccessTokenCreationResponseModel.cs @@ -23,8 +23,8 @@ public class AccessTokenCreationResponseModel : ResponseModel } public Guid Id { get; set; } - public string Name { get; set; } - public string ClientSecret { get; set; } + public string? Name { get; set; } + public string? ClientSecret { get; set; } public DateTime? ExpireAt { get; set; } public DateTime CreationDate { get; set; } public DateTime RevisionDate { get; set; } diff --git a/src/Api/SecretsManager/Models/Response/PotentialGranteeResponseModel.cs b/src/Api/SecretsManager/Models/Response/PotentialGranteeResponseModel.cs index b76af966fe..8d3a8236e0 100644 --- a/src/Api/SecretsManager/Models/Response/PotentialGranteeResponseModel.cs +++ b/src/Api/SecretsManager/Models/Response/PotentialGranteeResponseModel.cs @@ -71,5 +71,5 @@ public class PotentialGranteeResponseModel : ResponseModel public string Name { get; set; } public string Type { get; set; } - public string? Email { get; set; } + public string Email { get; set; } } diff --git a/src/Billing/Controllers/StripeController.cs b/src/Billing/Controllers/StripeController.cs index 8562bd0a24..445be1f521 100644 --- a/src/Billing/Controllers/StripeController.cs +++ b/src/Billing/Controllers/StripeController.cs @@ -131,12 +131,12 @@ public class StripeController : Controller if (subCanceled || subUnpaid || subIncompleteExpired) { // org - if (organizationId != null && organizationId != Guid.Empty) + if (organizationId != Guid.Empty) { await _organizationService.DisableAsync(organizationId, subscription.CurrentPeriodEnd); } // user - else if (userId != null && userId != Guid.Empty) + else if (userId != Guid.Empty) { await _userService.DisablePremiumAsync(userId, subscription.CurrentPeriodEnd); } @@ -145,11 +145,11 @@ public class StripeController : Controller if (subActive) { - if (organizationId != null && organizationId != Guid.Empty) + if (organizationId != Guid.Empty) { await _organizationService.EnableAsync(organizationId); } - else if (userId != null && userId != Guid.Empty) + else if (userId != Guid.Empty) { await _userService.EnablePremiumAsync(userId, subscription.CurrentPeriodEnd); @@ -159,7 +159,7 @@ public class StripeController : Controller if (subUpdated) { // org - if (organizationId != null && organizationId != Guid.Empty) + if (organizationId != Guid.Empty) { await _organizationService.UpdateExpirationDateAsync(organizationId, subscription.CurrentPeriodEnd); @@ -169,7 +169,7 @@ public class StripeController : Controller } } // user - else if (userId != null && userId != Guid.Empty) + else if (userId != Guid.Empty) { await _userService.UpdatePremiumExpirationAsync(userId, subscription.CurrentPeriodEnd); diff --git a/src/Core/Tools/Models/Business/ReferenceEvent.cs b/src/Core/Tools/Models/Business/ReferenceEvent.cs index 62dfa20533..393708668a 100644 --- a/src/Core/Tools/Models/Business/ReferenceEvent.cs +++ b/src/Core/Tools/Models/Business/ReferenceEvent.cs @@ -69,5 +69,5 @@ public class ReferenceEvent public bool? SalesAssistedTrialStarted { get; set; } public string ClientId { get; set; } - public Version? ClientVersion { get; set; } + public Version ClientVersion { get; set; } } diff --git a/src/Infrastructure.EntityFramework/Repositories/OrganizationDomainRepository.cs b/src/Infrastructure.EntityFramework/Repositories/OrganizationDomainRepository.cs index 64438bf704..ea507d5531 100644 --- a/src/Infrastructure.EntityFramework/Repositories/OrganizationDomainRepository.cs +++ b/src/Infrastructure.EntityFramework/Repositories/OrganizationDomainRepository.cs @@ -111,11 +111,11 @@ public class OrganizationDomainRepository : Repository (DateTime.UtcNow - x.CreationDate).Days == 4 && x.VerifiedDate == null) - .ToList(); + .AsNoTracking() + .ToListAsync(); return Mapper.Map>(domains); } diff --git a/test/Api.IntegrationTest/SecretsManager/Controllers/SecretsManagerPortingControllerTests.cs b/test/Api.IntegrationTest/SecretsManager/Controllers/SecretsManagerPortingControllerTests.cs index d4697711aa..62d5554099 100644 --- a/test/Api.IntegrationTest/SecretsManager/Controllers/SecretsManagerPortingControllerTests.cs +++ b/test/Api.IntegrationTest/SecretsManager/Controllers/SecretsManagerPortingControllerTests.cs @@ -9,9 +9,6 @@ namespace Bit.Api.IntegrationTest.SecretsManager.Controllers; public class SecretsManagerPortingControllerTests : IClassFixture, IAsyncLifetime { - private readonly string _mockEncryptedString = - "2.3Uk+WNBIoU5xzmVFNcoWzz==|1MsPIYuRfdOHfu/0uY6H2Q==|/98sp4wb6pHP1VTZ9JcNCYgQjEUMFPlqJgCwRk1YXKg="; - private readonly HttpClient _client; private readonly ApiApplicationFactory _factory; private readonly IProjectRepository _projectRepository; diff --git a/test/Api.Test/Controllers/OrganizationsControllerTests.cs b/test/Api.Test/Controllers/OrganizationsControllerTests.cs index 069b4bb27c..1d21e9b735 100644 --- a/test/Api.Test/Controllers/OrganizationsControllerTests.cs +++ b/test/Api.Test/Controllers/OrganizationsControllerTests.cs @@ -38,7 +38,6 @@ public class OrganizationsControllerTests : IDisposable private readonly ICloudGetOrganizationLicenseQuery _cloudGetOrganizationLicenseQuery; private readonly ICreateOrganizationApiKeyCommand _createOrganizationApiKeyCommand; private readonly IUpdateOrganizationLicenseCommand _updateOrganizationLicenseCommand; - private readonly IOrganizationDomainRepository _organizationDomainRepository; private readonly IFeatureService _featureService; private readonly ILicensingService _licensingService; diff --git a/test/Core.Test/Models/Data/SelfHostedOrganizationDetailsTests.cs b/test/Core.Test/Models/Data/SelfHostedOrganizationDetailsTests.cs index c0ab7b9c40..a46981ee9b 100644 --- a/test/Core.Test/Models/Data/SelfHostedOrganizationDetailsTests.cs +++ b/test/Core.Test/Models/Data/SelfHostedOrganizationDetailsTests.cs @@ -17,7 +17,7 @@ public class SelfHostedOrganizationDetailsTests [Theory] [BitAutoData] [OrganizationLicenseCustomize] - public async Task ValidateForOrganization_Success(List orgUsers, + public void ValidateForOrganization_Success(List orgUsers, List policies, SsoConfig ssoConfig, List> scimConnections, OrganizationLicense license) { var (orgDetails, orgLicense) = GetOrganizationAndLicense(orgUsers, policies, ssoConfig, scimConnections, license); @@ -31,7 +31,7 @@ public class SelfHostedOrganizationDetailsTests [Theory] [BitAutoData] [OrganizationLicenseCustomize] - public async Task ValidateForOrganization_OccupiedSeatCount_ExceedsLicense_Fail(List orgUsers, + public void ValidateForOrganization_OccupiedSeatCount_ExceedsLicense_Fail(List orgUsers, List policies, SsoConfig ssoConfig, List> scimConnections, OrganizationLicense license) { var (orgDetails, orgLicense) = GetOrganizationAndLicense(orgUsers, policies, ssoConfig, scimConnections, license); @@ -46,7 +46,7 @@ public class SelfHostedOrganizationDetailsTests [Theory] [BitAutoData] [OrganizationLicenseCustomize] - public async Task ValidateForOrganization_MaxCollections_ExceedsLicense_Fail(List orgUsers, + public void ValidateForOrganization_MaxCollections_ExceedsLicense_Fail(List orgUsers, List policies, SsoConfig ssoConfig, List> scimConnections, OrganizationLicense license) { var (orgDetails, orgLicense) = GetOrganizationAndLicense(orgUsers, policies, ssoConfig, scimConnections, license); @@ -61,7 +61,7 @@ public class SelfHostedOrganizationDetailsTests [Theory] [BitAutoData] [OrganizationLicenseCustomize] - public async Task ValidateForOrganization_Groups_NotAllowedByLicense_Fail(List orgUsers, + public void ValidateForOrganization_Groups_NotAllowedByLicense_Fail(List orgUsers, List policies, SsoConfig ssoConfig, List> scimConnections, OrganizationLicense license) { var (orgDetails, orgLicense) = GetOrganizationAndLicense(orgUsers, policies, ssoConfig, scimConnections, license); @@ -76,7 +76,7 @@ public class SelfHostedOrganizationDetailsTests [Theory] [BitAutoData] [OrganizationLicenseCustomize] - public async Task ValidateForOrganization_Policies_NotAllowedByLicense_Fail(List orgUsers, + public void ValidateForOrganization_Policies_NotAllowedByLicense_Fail(List orgUsers, List policies, SsoConfig ssoConfig, List> scimConnections, OrganizationLicense license) { var (orgDetails, orgLicense) = GetOrganizationAndLicense(orgUsers, policies, ssoConfig, scimConnections, license); @@ -91,7 +91,7 @@ public class SelfHostedOrganizationDetailsTests [Theory] [BitAutoData] [OrganizationLicenseCustomize] - public async Task ValidateForOrganization_DisabledPolicies_NotAllowedByLicense_Success(List orgUsers, + public void ValidateForOrganization_DisabledPolicies_NotAllowedByLicense_Success(List orgUsers, List policies, SsoConfig ssoConfig, List> scimConnections, OrganizationLicense license) { var (orgDetails, orgLicense) = GetOrganizationAndLicense(orgUsers, policies, ssoConfig, scimConnections, license); @@ -107,7 +107,7 @@ public class SelfHostedOrganizationDetailsTests [Theory] [BitAutoData] [OrganizationLicenseCustomize] - public async Task ValidateForOrganization_Sso_NotAllowedByLicense_Fail(List orgUsers, + public void ValidateForOrganization_Sso_NotAllowedByLicense_Fail(List orgUsers, List policies, SsoConfig ssoConfig, List> scimConnections, OrganizationLicense license) { var (orgDetails, orgLicense) = GetOrganizationAndLicense(orgUsers, policies, ssoConfig, scimConnections, license); @@ -122,7 +122,7 @@ public class SelfHostedOrganizationDetailsTests [Theory] [BitAutoData] [OrganizationLicenseCustomize] - public async Task ValidateForOrganization_DisabledSso_NotAllowedByLicense_Success(List orgUsers, + public void ValidateForOrganization_DisabledSso_NotAllowedByLicense_Success(List orgUsers, List policies, SsoConfig ssoConfig, List> scimConnections, OrganizationLicense license) { var (orgDetails, orgLicense) = GetOrganizationAndLicense(orgUsers, policies, ssoConfig, scimConnections, license); @@ -138,7 +138,7 @@ public class SelfHostedOrganizationDetailsTests [Theory] [BitAutoData] [OrganizationLicenseCustomize] - public async Task ValidateForOrganization_NoSso_NotAllowedByLicense_Success(List orgUsers, + public void ValidateForOrganization_NoSso_NotAllowedByLicense_Success(List orgUsers, List policies, SsoConfig ssoConfig, List> scimConnections, OrganizationLicense license) { var (orgDetails, orgLicense) = GetOrganizationAndLicense(orgUsers, policies, ssoConfig, scimConnections, license); @@ -154,7 +154,7 @@ public class SelfHostedOrganizationDetailsTests [Theory] [BitAutoData] [OrganizationLicenseCustomize] - public async Task ValidateForOrganization_KeyConnector_NotAllowedByLicense_Fail(List orgUsers, + public void ValidateForOrganization_KeyConnector_NotAllowedByLicense_Fail(List orgUsers, List policies, SsoConfig ssoConfig, List> scimConnections, OrganizationLicense license) { var (orgDetails, orgLicense) = GetOrganizationAndLicense(orgUsers, policies, ssoConfig, scimConnections, license); @@ -169,7 +169,7 @@ public class SelfHostedOrganizationDetailsTests [Theory] [BitAutoData] [OrganizationLicenseCustomize] - public async Task ValidateForOrganization_DisabledKeyConnector_NotAllowedByLicense_Success(List orgUsers, + public void ValidateForOrganization_DisabledKeyConnector_NotAllowedByLicense_Success(List orgUsers, List policies, SsoConfig ssoConfig, List> scimConnections, OrganizationLicense license) { var (orgDetails, orgLicense) = GetOrganizationAndLicense(orgUsers, policies, ssoConfig, scimConnections, license); @@ -185,7 +185,7 @@ public class SelfHostedOrganizationDetailsTests [Theory] [BitAutoData] [OrganizationLicenseCustomize] - public async Task ValidateForOrganization_NoSsoKeyConnector_NotAllowedByLicense_Success(List orgUsers, + public void ValidateForOrganization_NoSsoKeyConnector_NotAllowedByLicense_Success(List orgUsers, List policies, SsoConfig ssoConfig, List> scimConnections, OrganizationLicense license) { var (orgDetails, orgLicense) = GetOrganizationAndLicense(orgUsers, policies, ssoConfig, scimConnections, license); @@ -201,7 +201,7 @@ public class SelfHostedOrganizationDetailsTests [Theory] [BitAutoData] [OrganizationLicenseCustomize] - public async Task ValidateForOrganization_Scim_NotAllowedByLicense_Fail(List orgUsers, + public void ValidateForOrganization_Scim_NotAllowedByLicense_Fail(List orgUsers, List policies, SsoConfig ssoConfig, List> scimConnections, OrganizationLicense license) { var (orgDetails, orgLicense) = GetOrganizationAndLicense(orgUsers, policies, ssoConfig, scimConnections, license); @@ -216,7 +216,7 @@ public class SelfHostedOrganizationDetailsTests [Theory] [BitAutoData] [OrganizationLicenseCustomize] - public async Task ValidateForOrganization_DisabledScim_NotAllowedByLicense_Success(List orgUsers, + public void ValidateForOrganization_DisabledScim_NotAllowedByLicense_Success(List orgUsers, List policies, SsoConfig ssoConfig, List> scimConnections, OrganizationLicense license) { var (orgDetails, orgLicense) = GetOrganizationAndLicense(orgUsers, policies, ssoConfig, scimConnections, license); @@ -233,7 +233,7 @@ public class SelfHostedOrganizationDetailsTests [Theory] [BitAutoData] [OrganizationLicenseCustomize] - public async Task ValidateForOrganization_NoScimConfig_NotAllowedByLicense_Success(List orgUsers, + public void ValidateForOrganization_NoScimConfig_NotAllowedByLicense_Success(List orgUsers, List policies, SsoConfig ssoConfig, List> scimConnections, OrganizationLicense license) { var (orgDetails, orgLicense) = GetOrganizationAndLicense(orgUsers, policies, ssoConfig, scimConnections, license); @@ -249,7 +249,7 @@ public class SelfHostedOrganizationDetailsTests [Theory] [BitAutoData] [OrganizationLicenseCustomize] - public async Task ValidateForOrganization_CustomPermissions_NotAllowedByLicense_Fail(List orgUsers, + public void ValidateForOrganization_CustomPermissions_NotAllowedByLicense_Fail(List orgUsers, List policies, SsoConfig ssoConfig, List> scimConnections, OrganizationLicense license) { var (orgDetails, orgLicense) = GetOrganizationAndLicense(orgUsers, policies, ssoConfig, scimConnections, license); @@ -264,7 +264,7 @@ public class SelfHostedOrganizationDetailsTests [Theory] [BitAutoData] [OrganizationLicenseCustomize] - public async Task ValidateForOrganization_NoCustomPermissions_NotAllowedByLicense_Success(List orgUsers, + public void ValidateForOrganization_NoCustomPermissions_NotAllowedByLicense_Success(List orgUsers, List policies, SsoConfig ssoConfig, List> scimConnections, OrganizationLicense license) { var (orgDetails, orgLicense) = GetOrganizationAndLicense(orgUsers, policies, ssoConfig, scimConnections, license); @@ -280,7 +280,7 @@ public class SelfHostedOrganizationDetailsTests [Theory] [BitAutoData] [OrganizationLicenseCustomize] - public async Task ValidateForOrganization_ResetPassword_NotAllowedByLicense_Fail(List orgUsers, + public void ValidateForOrganization_ResetPassword_NotAllowedByLicense_Fail(List orgUsers, List policies, SsoConfig ssoConfig, List> scimConnections, OrganizationLicense license) { var (orgDetails, orgLicense) = GetOrganizationAndLicense(orgUsers, policies, ssoConfig, scimConnections, license); @@ -295,7 +295,7 @@ public class SelfHostedOrganizationDetailsTests [Theory] [BitAutoData] [OrganizationLicenseCustomize] - public async Task ValidateForOrganization_DisabledResetPassword_NotAllowedByLicense_Success(List orgUsers, + public void ValidateForOrganization_DisabledResetPassword_NotAllowedByLicense_Success(List orgUsers, List policies, SsoConfig ssoConfig, List> scimConnections, OrganizationLicense license) { var (orgDetails, orgLicense) = GetOrganizationAndLicense(orgUsers, policies, ssoConfig, scimConnections, license); diff --git a/test/Infrastructure.EFIntegration.Test/Vault/Repositories/CipherRepositoryTests.cs b/test/Infrastructure.EFIntegration.Test/Vault/Repositories/CipherRepositoryTests.cs index 36f92f9068..8af82bdd81 100644 --- a/test/Infrastructure.EFIntegration.Test/Vault/Repositories/CipherRepositoryTests.cs +++ b/test/Infrastructure.EFIntegration.Test/Vault/Repositories/CipherRepositoryTests.cs @@ -180,18 +180,14 @@ public class CipherRepositoryTests List efOrgRepos ) => await DeleteAsync_CipherIsDeleted(cipher, user, org, suts, efUserRepos, efOrgRepos); [CiSkippedTheory, EfOrganizationCipherCustomize, BitAutoData] - public Task OrganizationCipher_DeleteAsync_CipherIsDeleted( + public async Task OrganizationCipher_DeleteAsync_CipherIsDeleted( Cipher cipher, User user, Organization org, List suts, List efUserRepos, List efOrgRepos - ) - { - DeleteAsync_CipherIsDeleted(cipher, user, org, suts, efUserRepos, efOrgRepos); - return Task.CompletedTask; - } + ) => await DeleteAsync_CipherIsDeleted(cipher, user, org, suts, efUserRepos, efOrgRepos); private async Task DeleteAsync_CipherIsDeleted( Cipher cipher, diff --git a/test/IntegrationTestCommon/Factories/WebApplicationFactoryBase.cs b/test/IntegrationTestCommon/Factories/WebApplicationFactoryBase.cs index 96c9d2b043..5c949d4d9e 100644 --- a/test/IntegrationTestCommon/Factories/WebApplicationFactoryBase.cs +++ b/test/IntegrationTestCommon/Factories/WebApplicationFactoryBase.cs @@ -154,9 +154,9 @@ public abstract class WebApplicationFactoryBase : WebApplicationFactory return scope.ServiceProvider.GetRequiredService(); } - public T GetService() + public TS GetService() { var scope = Services.CreateScope(); - return scope.ServiceProvider.GetRequiredService(); + return scope.ServiceProvider.GetRequiredService(); } } diff --git a/util/EfShared/MigrationBuilderExtensions.cs b/util/EfShared/MigrationBuilderExtensions.cs index b59ad207fb..49fa102e9e 100644 --- a/util/EfShared/MigrationBuilderExtensions.cs +++ b/util/EfShared/MigrationBuilderExtensions.cs @@ -14,12 +14,12 @@ namespace Bit.EfShared; public static class MigrationBuilderExtensions { /// - /// Reads an embedded resource for it's SQL contents and formats it with the specified direction for easier custom migration steps + /// Reads an embedded resource for its SQL contents and formats it with the specified direction for easier custom migration steps /// /// The MigrationBuilder instance the sql should be applied to /// The file name portion of the resource name, it is assumed to be in a Scripts folder /// The direction of the migration taking place - public static void SqlResource(this MigrationBuilder migrationBuilder, string resourceName, [CallerMemberName] string dir = null) + public static void SqlResource(this MigrationBuilder migrationBuilder, string resourceName, [CallerMemberName] string dir = "") { var formattedResourceName = string.IsNullOrEmpty(dir) ? resourceName : string.Format(resourceName, dir);