diff --git a/perf/MicroBenchmarks/Identity/IdentityServer/StaticClientStoreTests.cs b/perf/MicroBenchmarks/Identity/IdentityServer/StaticClientStoreTests.cs index 1fcd6a9f9..9d88f960e 100644 --- a/perf/MicroBenchmarks/Identity/IdentityServer/StaticClientStoreTests.cs +++ b/perf/MicroBenchmarks/Identity/IdentityServer/StaticClientStoreTests.cs @@ -15,7 +15,7 @@ public class StaticClientStoreTests } [Params("mobile", "connector", "invalid", "a_much_longer_invalid_value_that_i_am_making_up", "WEB", "")] - public string? ClientId { get; set; } + public string ClientId { get; set; } = null!; [Benchmark] public Client? TryGetValue() diff --git a/test/Api.IntegrationTest/AdminConsole/Public/Controllers/MembersControllerTests.cs b/test/Api.IntegrationTest/AdminConsole/Public/Controllers/MembersControllerTests.cs index a977899e2..cd46369a3 100644 --- a/test/Api.IntegrationTest/AdminConsole/Public/Controllers/MembersControllerTests.cs +++ b/test/Api.IntegrationTest/AdminConsole/Public/Controllers/MembersControllerTests.cs @@ -21,8 +21,10 @@ public class MembersControllerTests : IClassFixture, IAsy private readonly HttpClient _client; private readonly ApiApplicationFactory _factory; private readonly LoginHelper _loginHelper; - private Organization _organization; - private string _ownerEmail; + + // These will get set in `InitializeAsync` which is ran before all tests + private Organization _organization = null!; + private string _ownerEmail = null!; public MembersControllerTests(ApiApplicationFactory factory) { @@ -74,7 +76,7 @@ public class MembersControllerTests : IClassFixture, IAsy m.Email == _ownerEmail && m.Type == OrganizationUserType.Owner)); // The custom user - var user1Result = result.Data.SingleOrDefault(m => m.Email == userEmail1); + var user1Result = result.Data.Single(m => m.Email == userEmail1); Assert.Equal(OrganizationUserType.Custom, user1Result.Type); AssertHelper.AssertPropertyEqual( new PermissionsModel { AccessImportExport = true, ManagePolicies = true, AccessReports = true }, @@ -156,6 +158,7 @@ public class MembersControllerTests : IClassFixture, IAsy var organizationUserRepository = _factory.GetService(); var orgUser = await organizationUserRepository.GetByIdAsync(result.Id); + Assert.NotNull(orgUser); Assert.Equal(email, orgUser.Email); Assert.Equal(OrganizationUserType.Custom, orgUser.Type); Assert.Equal("myCustomUser", orgUser.ExternalId); @@ -201,6 +204,7 @@ public class MembersControllerTests : IClassFixture, IAsy var organizationUserRepository = _factory.GetService(); var updatedOrgUser = await organizationUserRepository.GetByIdAsync(result.Id); + Assert.NotNull(updatedOrgUser); Assert.Equal(OrganizationUserType.Custom, updatedOrgUser.Type); Assert.Equal("example", updatedOrgUser.ExternalId); Assert.Equal(OrganizationUserStatusType.Confirmed, updatedOrgUser.Status); @@ -240,6 +244,7 @@ public class MembersControllerTests : IClassFixture, IAsy var organizationUserRepository = _factory.GetService(); var updatedOrgUser = await organizationUserRepository.GetByIdAsync(result.Id); + Assert.NotNull(updatedOrgUser); Assert.Equal(OrganizationUserType.Custom, updatedOrgUser.Type); AssertHelper.AssertPropertyEqual( new Permissions { CreateNewCollections = true, ManageScim = true, ManageGroups = true, ManageUsers = true }, diff --git a/test/Api.IntegrationTest/Helpers/OrganizationTestHelpers.cs b/test/Api.IntegrationTest/Helpers/OrganizationTestHelpers.cs index 3167edcd1..68146c102 100644 --- a/test/Api.IntegrationTest/Helpers/OrganizationTestHelpers.cs +++ b/test/Api.IntegrationTest/Helpers/OrganizationTestHelpers.cs @@ -1,4 +1,5 @@ -using Bit.Api.IntegrationTest.Factories; +using System.Diagnostics; +using Bit.Api.IntegrationTest.Factories; using Bit.Core.AdminConsole.Entities; using Bit.Core.Billing.Enums; using Bit.Core.Entities; @@ -38,6 +39,8 @@ public static class OrganizationTestHelpers PaymentMethodType = paymentMethod }); + Debug.Assert(signUpResult.organizationUser is not null); + return new Tuple(signUpResult.organization, signUpResult.organizationUser); } @@ -57,6 +60,7 @@ public static class OrganizationTestHelpers var organizationUserRepository = factory.GetService(); var user = await userRepository.GetByEmailAsync(userEmail); + Debug.Assert(user is not null); var orgUser = new OrganizationUser { diff --git a/test/Api.IntegrationTest/SecretsManager/Helpers/SecretsManagerOrganizationHelper.cs b/test/Api.IntegrationTest/SecretsManager/Helpers/SecretsManagerOrganizationHelper.cs index d2d03d979..dd997fee3 100644 --- a/test/Api.IntegrationTest/SecretsManager/Helpers/SecretsManagerOrganizationHelper.cs +++ b/test/Api.IntegrationTest/SecretsManager/Helpers/SecretsManagerOrganizationHelper.cs @@ -1,4 +1,5 @@ -using Bit.Api.IntegrationTest.Factories; +using System.Diagnostics; +using Bit.Api.IntegrationTest.Factories; using Bit.Api.IntegrationTest.Helpers; using Bit.Core.AdminConsole.Entities; using Bit.Core.Entities; @@ -35,7 +36,8 @@ public class SecretsManagerOrganizationHelper public async Task<(Organization organization, OrganizationUser owner)> Initialize(bool useSecrets, bool ownerAccessSecrets, bool organizationEnabled) { - (_organization, _owner) = await OrganizationTestHelpers.SignUpAsync(_factory, ownerEmail: _ownerEmail, billingEmail: _ownerEmail); + (_organization, _owner!) = await OrganizationTestHelpers.SignUpAsync(_factory, ownerEmail: _ownerEmail, billingEmail: _ownerEmail); + Debug.Assert(_owner is not null); if (useSecrets || !organizationEnabled) { diff --git a/test/Api.Test/AdminConsole/Controllers/GroupsControllerPutTests.cs b/test/Api.Test/AdminConsole/Controllers/GroupsControllerPutTests.cs index bc5bbfd32..0e260e73e 100644 --- a/test/Api.Test/AdminConsole/Controllers/GroupsControllerPutTests.cs +++ b/test/Api.Test/AdminConsole/Controllers/GroupsControllerPutTests.cs @@ -20,6 +20,8 @@ using Microsoft.AspNetCore.Authorization; using NSubstitute; using Xunit; +#nullable enable + namespace Bit.Api.Test.AdminConsole.Controllers; [ControllerCustomize(typeof(GroupsController))] @@ -305,7 +307,7 @@ public class GroupsControllerPutTests .Returns(new Tuple>(group, currentCollectionAccess ?? [])); if (savingUser != null) { - sutProvider.GetDependency().GetByOrganizationAsync(orgId, savingUser.UserId.Value) + sutProvider.GetDependency().GetByOrganizationAsync(orgId, savingUser.UserId!.Value) .Returns(savingUser); } diff --git a/test/Api.Test/Vault/Controllers/SyncControllerTests.cs b/test/Api.Test/Vault/Controllers/SyncControllerTests.cs index 66a59ef23..03c05ef0f 100644 --- a/test/Api.Test/Vault/Controllers/SyncControllerTests.cs +++ b/test/Api.Test/Vault/Controllers/SyncControllerTests.cs @@ -129,7 +129,7 @@ public class SyncControllerTests // Asserts // Assert that methods are called var hasEnabledOrgs = organizationUserDetails.Any(o => o.Enabled); - this.AssertMethodsCalledAsync(userService, organizationUserRepository, providerUserRepository, folderRepository, + await this.AssertMethodsCalledAsync(userService, organizationUserRepository, providerUserRepository, folderRepository, cipherRepository, sendRepository, collectionRepository, collectionCipherRepository, hasEnabledOrgs); Assert.IsType(result); @@ -216,7 +216,7 @@ public class SyncControllerTests // Assert that methods are called var hasEnabledOrgs = organizationUserDetails.Any(o => o.Enabled); - this.AssertMethodsCalledAsync(userService, organizationUserRepository, providerUserRepository, folderRepository, + await this.AssertMethodsCalledAsync(userService, organizationUserRepository, providerUserRepository, folderRepository, cipherRepository, sendRepository, collectionRepository, collectionCipherRepository, hasEnabledOrgs); Assert.IsType(result); @@ -293,7 +293,7 @@ public class SyncControllerTests // Assert that methods are called var hasEnabledOrgs = organizationUserDetails.Any(o => o.Enabled); - this.AssertMethodsCalledAsync(userService, organizationUserRepository, providerUserRepository, folderRepository, + await this.AssertMethodsCalledAsync(userService, organizationUserRepository, providerUserRepository, folderRepository, cipherRepository, sendRepository, collectionRepository, collectionCipherRepository, hasEnabledOrgs); Assert.IsType(result); diff --git a/test/Core.Test/AdminConsole/Services/OrganizationServiceTests.cs b/test/Core.Test/AdminConsole/Services/OrganizationServiceTests.cs index a8078ed01..fccfb3995 100644 --- a/test/Core.Test/AdminConsole/Services/OrganizationServiceTests.cs +++ b/test/Core.Test/AdminConsole/Services/OrganizationServiceTests.cs @@ -1115,7 +1115,7 @@ OrganizationUserInvite invite, SutProvider sutProvider) await sutProvider.Sut.InviteUsersAsync(organization.Id, savingUser.Id, systemUser: null, invites); - sutProvider.GetDependency().Received(1) + await sutProvider.GetDependency().Received(1) .UpdateSubscriptionAsync(Arg.Is(update => update.SmSeats == organization.SmSeats + invitedSmUsers && !update.SmServiceAccountsChanged && @@ -1158,7 +1158,7 @@ OrganizationUserInvite invite, SutProvider sutProvider) // OrgUser is reverted // Note: we don't know what their guids are so comparing length is the best we can do var invitedEmails = invites.SelectMany(i => i.invite.Emails); - sutProvider.GetDependency().Received(1).DeleteManyAsync( + await sutProvider.GetDependency().Received(1).DeleteManyAsync( Arg.Is>(ids => ids.Count() == invitedEmails.Count())); Received.InOrder(() => diff --git a/test/Core.Test/OrganizationFeatures/OrganizationSubscriptionUpdate/AddSecretsManagerSubscriptionCommandTests.cs b/test/Core.Test/OrganizationFeatures/OrganizationSubscriptionUpdate/AddSecretsManagerSubscriptionCommandTests.cs index 22d25f275..8dcfb198b 100644 --- a/test/Core.Test/OrganizationFeatures/OrganizationSubscriptionUpdate/AddSecretsManagerSubscriptionCommandTests.cs +++ b/test/Core.Test/OrganizationFeatures/OrganizationSubscriptionUpdate/AddSecretsManagerSubscriptionCommandTests.cs @@ -57,7 +57,7 @@ public class AddSecretsManagerSubscriptionCommandTests // TODO: call ReferenceEventService - see AC-1481 - sutProvider.GetDependency().Received(1).ReplaceAndUpdateCacheAsync(Arg.Is(c => + await sutProvider.GetDependency().Received(1).ReplaceAndUpdateCacheAsync(Arg.Is(c => c.SmSeats == plan.SecretsManager.BaseSeats + additionalSmSeats && c.SmServiceAccounts == plan.SecretsManager.BaseServiceAccount + additionalServiceAccounts && c.UseSecretsManager == true)); diff --git a/test/Core.Test/OrganizationFeatures/OrganizationSubscriptionUpdate/UpdateSecretsManagerSubscriptionCommandTests.cs b/test/Core.Test/OrganizationFeatures/OrganizationSubscriptionUpdate/UpdateSecretsManagerSubscriptionCommandTests.cs index 8e7018e06..546ea7770 100644 --- a/test/Core.Test/OrganizationFeatures/OrganizationSubscriptionUpdate/UpdateSecretsManagerSubscriptionCommandTests.cs +++ b/test/Core.Test/OrganizationFeatures/OrganizationSubscriptionUpdate/UpdateSecretsManagerSubscriptionCommandTests.cs @@ -663,8 +663,8 @@ public class UpdateSecretsManagerSubscriptionCommandTests .SendOrganizationMaxSeatLimitReachedEmailAsync(Arg.Any(), Arg.Any(), Arg.Any>()); - sutProvider.GetDependency().DidNotReceiveWithAnyArgs().ReplaceAsync(default); - sutProvider.GetDependency().DidNotReceiveWithAnyArgs().UpsertOrganizationAbilityAsync(default); + await sutProvider.GetDependency().DidNotReceiveWithAnyArgs().ReplaceAsync(default); + await sutProvider.GetDependency().DidNotReceiveWithAnyArgs().UpsertOrganizationAbilityAsync(default); } private void AssertUpdatedOrganization(Func organizationMatcher, SutProvider sutProvider) diff --git a/test/Core.Test/OrganizationFeatures/OrganizationSubscriptionUpdate/UpgradeOrganizationPlanCommandTests.cs b/test/Core.Test/OrganizationFeatures/OrganizationSubscriptionUpdate/UpgradeOrganizationPlanCommandTests.cs index e5bbd057c..0f47b6c92 100644 --- a/test/Core.Test/OrganizationFeatures/OrganizationSubscriptionUpdate/UpgradeOrganizationPlanCommandTests.cs +++ b/test/Core.Test/OrganizationFeatures/OrganizationSubscriptionUpdate/UpgradeOrganizationPlanCommandTests.cs @@ -165,7 +165,7 @@ public class UpgradeOrganizationPlanCommandTests var exception = await Assert.ThrowsAsync(() => sutProvider.Sut.UpgradePlanAsync(organization.Id, upgrade)); Assert.Contains("Your organization currently has 2 Secrets Manager seats filled. Your new plan only has", exception.Message); - sutProvider.GetDependency().DidNotReceiveWithAnyArgs().ReplaceAndUpdateCacheAsync(default); + await sutProvider.GetDependency().DidNotReceiveWithAnyArgs().ReplaceAndUpdateCacheAsync(default); } [Theory, FreeOrganizationUpgradeCustomize] @@ -194,6 +194,6 @@ public class UpgradeOrganizationPlanCommandTests var exception = await Assert.ThrowsAsync(() => sutProvider.Sut.UpgradePlanAsync(organization.Id, upgrade)); Assert.Contains($"Your organization currently has {currentServiceAccounts} machine accounts. Your new plan only allows", exception.Message); - sutProvider.GetDependency().DidNotReceiveWithAnyArgs().ReplaceAndUpdateCacheAsync(default); + await sutProvider.GetDependency().DidNotReceiveWithAnyArgs().ReplaceAndUpdateCacheAsync(default); } } diff --git a/test/Core.Test/Utilities/BulkAuthorizationHandlerTests.cs b/test/Core.Test/Utilities/BulkAuthorizationHandlerTests.cs index 88efbd3d9..8deb7f82a 100644 --- a/test/Core.Test/Utilities/BulkAuthorizationHandlerTests.cs +++ b/test/Core.Test/Utilities/BulkAuthorizationHandlerTests.cs @@ -62,11 +62,12 @@ public class BulkAuthorizationHandlerTests private class TestBulkAuthorizationHandler : BulkAuthorizationHandler { - protected override async Task HandleRequirementAsync(AuthorizationHandlerContext context, + protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, TestOperationRequirement requirement, ICollection resources) { context.Succeed(requirement); + return Task.CompletedTask; } } } diff --git a/test/Identity.Test/Controllers/AccountsControllerTests.cs b/test/Identity.Test/Controllers/AccountsControllerTests.cs index 8de0282bb..3abaa8a0b 100644 --- a/test/Identity.Test/Controllers/AccountsControllerTests.cs +++ b/test/Identity.Test/Controllers/AccountsControllerTests.cs @@ -86,7 +86,7 @@ public class AccountsControllerTests : IDisposable Kdf = KdfType.PBKDF2_SHA256, KdfIterations = AuthConstants.PBKDF2_ITERATIONS.Default }; - _userRepository.GetKdfInformationByEmailAsync(Arg.Any()).Returns(Task.FromResult(userKdfInfo)); + _userRepository.GetKdfInformationByEmailAsync(Arg.Any()).Returns(userKdfInfo); var response = await _sut.PostPrelogin(new PreloginRequestModel { Email = "user@example.com" }); @@ -97,7 +97,7 @@ public class AccountsControllerTests : IDisposable [Fact] public async Task PostPrelogin_WhenUserDoesNotExist_ShouldDefaultToPBKDF() { - _userRepository.GetKdfInformationByEmailAsync(Arg.Any()).Returns(Task.FromResult(null!)); + _userRepository.GetKdfInformationByEmailAsync(Arg.Any()).Returns(Task.FromResult(null)); var response = await _sut.PostPrelogin(new PreloginRequestModel { Email = "user@example.com" }); diff --git a/test/Infrastructure.IntegrationTest/AdminConsole/Repositories/OrganizationUserRepositoryTests.cs b/test/Infrastructure.IntegrationTest/AdminConsole/Repositories/OrganizationUserRepositoryTests.cs index 4ef057286..46d3e60ee 100644 --- a/test/Infrastructure.IntegrationTest/AdminConsole/Repositories/OrganizationUserRepositoryTests.cs +++ b/test/Infrastructure.IntegrationTest/AdminConsole/Repositories/OrganizationUserRepositoryTests.cs @@ -38,6 +38,7 @@ public class OrganizationUserRepositoryTests await organizationUserRepository.DeleteAsync(orgUser); var newUser = await userRepository.GetByIdAsync(user.Id); + Assert.NotNull(newUser); Assert.NotEqual(newUser.AccountRevisionDate, user.AccountRevisionDate); } @@ -90,7 +91,9 @@ public class OrganizationUserRepositoryTests }); var updatedUser1 = await userRepository.GetByIdAsync(user1.Id); + Assert.NotNull(updatedUser1); var updatedUser2 = await userRepository.GetByIdAsync(user2.Id); + Assert.NotNull(updatedUser2); Assert.NotEqual(updatedUser1.AccountRevisionDate, user1.AccountRevisionDate); Assert.NotEqual(updatedUser2.AccountRevisionDate, user2.AccountRevisionDate); diff --git a/test/Infrastructure.IntegrationTest/Auth/Repositories/AuthRequestRepositoryTests.cs b/test/Infrastructure.IntegrationTest/Auth/Repositories/AuthRequestRepositoryTests.cs index 835d1da74..9fddb571b 100644 --- a/test/Infrastructure.IntegrationTest/Auth/Repositories/AuthRequestRepositoryTests.cs +++ b/test/Infrastructure.IntegrationTest/Auth/Repositories/AuthRequestRepositoryTests.cs @@ -165,12 +165,15 @@ public class AuthRequestRepositoryTests // Assert that the unchanged auth request is still unchanged var skippedAuthRequest = await authRequestRepository.GetByIdAsync(authRequestNotToBeUpdated.Id); + Assert.NotNull(skippedAuthRequest); Assert.True(AuthRequestEquals(skippedAuthRequest, authRequestNotToBeUpdated)); // Assert that the values updated on the changed auth requests were updated, and no others var updatedAuthRequest1 = await authRequestRepository.GetByIdAsync(authRequestToBeUpdated1.Id); + Assert.NotNull(updatedAuthRequest1); Assert.True(AuthRequestEquals(authRequestToBeUpdated1, updatedAuthRequest1)); var updatedAuthRequest2 = await authRequestRepository.GetByIdAsync(authRequestToBeUpdated2.Id); + Assert.NotNull(updatedAuthRequest2); Assert.True(AuthRequestEquals(authRequestToBeUpdated2, updatedAuthRequest2)); // Assert that the auth request we never created is not created by diff --git a/test/Infrastructure.IntegrationTest/Auth/Repositories/EmergencyAccessRepositoryTests.cs b/test/Infrastructure.IntegrationTest/Auth/Repositories/EmergencyAccessRepositoryTests.cs index def3dcb1e..0f6d12537 100644 --- a/test/Infrastructure.IntegrationTest/Auth/Repositories/EmergencyAccessRepositoryTests.cs +++ b/test/Infrastructure.IntegrationTest/Auth/Repositories/EmergencyAccessRepositoryTests.cs @@ -39,6 +39,7 @@ public class EmergencyAccessRepositoriesTests var updatedGrantee = await userRepository.GetByIdAsync(granteeUser.Id); + Assert.NotNull(updatedGrantee); Assert.NotEqual(updatedGrantee.AccountRevisionDate, granteeUser.AccountRevisionDate); } } diff --git a/test/Infrastructure.IntegrationTest/ConfigurationExtensions.cs b/test/Infrastructure.IntegrationTest/ConfigurationExtensions.cs index 13f3b156d..f8e65ed26 100644 --- a/test/Infrastructure.IntegrationTest/ConfigurationExtensions.cs +++ b/test/Infrastructure.IntegrationTest/ConfigurationExtensions.cs @@ -21,9 +21,9 @@ public static class ConfigurationExtensions public static Database[] GetDatabases(this IConfiguration config) { var typedConfig = config.Get(); - if (typedConfig.Databases == null) + if (typedConfig?.Databases == null) { - return Array.Empty(); + return []; } return typedConfig.Databases.Where(d => d.Enabled).ToArray(); diff --git a/test/Infrastructure.IntegrationTest/Tools/SendRepositoryTests.cs b/test/Infrastructure.IntegrationTest/Tools/SendRepositoryTests.cs index 0abd0e5ec..bcc525e0d 100644 --- a/test/Infrastructure.IntegrationTest/Tools/SendRepositoryTests.cs +++ b/test/Infrastructure.IntegrationTest/Tools/SendRepositoryTests.cs @@ -27,6 +27,7 @@ public class SendRepositoryTests Assert.Equal(expirationDate, createdSend.ExpirationDate!.Value, LaxDateTimeComparer.Default); var sendFromDatabase = await sendRepository.GetByIdAsync(createdSend.Id); + Assert.NotNull(sendFromDatabase); Assert.Equal(expirationDate, sendFromDatabase.ExpirationDate!.Value, LaxDateTimeComparer.Default); Assert.Equal(SendType.Text, sendFromDatabase.Type); Assert.Equal(0, sendFromDatabase.AccessCount); diff --git a/test/Infrastructure.IntegrationTest/Vault/Repositories/CipherRepositoryTests.cs b/test/Infrastructure.IntegrationTest/Vault/Repositories/CipherRepositoryTests.cs index aeb1583c6..ce9b5ef7a 100644 --- a/test/Infrastructure.IntegrationTest/Vault/Repositories/CipherRepositoryTests.cs +++ b/test/Infrastructure.IntegrationTest/Vault/Repositories/CipherRepositoryTests.cs @@ -40,6 +40,7 @@ public class CipherRepositoryTests Assert.Null(deletedCipher); var updatedUser = await userRepository.GetByIdAsync(user.Id); + Assert.NotNull(updatedUser); Assert.NotEqual(updatedUser.AccountRevisionDate, user.AccountRevisionDate); } @@ -61,6 +62,7 @@ public class CipherRepositoryTests }); user = await userRepository.GetByIdAsync(user.Id); + Assert.NotNull(user); var organization = await organizationRepository.CreateAsync(new Organization { @@ -110,6 +112,7 @@ public class CipherRepositoryTests var updatedUser = await userRepository.GetByIdAsync(user.Id); + Assert.NotNull(updatedUser); Assert.True(updatedUser.AccountRevisionDate - user.AccountRevisionDate > TimeSpan.Zero, "The AccountRevisionDate is expected to be changed"); @@ -135,6 +138,7 @@ public class CipherRepositoryTests user = await userRepository.GetByIdAsync(user.Id); + Assert.NotNull(user); // Create cipher in personal vault var createdCipher = await cipherRepository.CreateAsync(new Cipher @@ -176,6 +180,7 @@ public class CipherRepositoryTests var updatedCipher = await cipherRepository.GetByIdAsync(createdCipher.Id); + Assert.NotNull(updatedCipher); Assert.Null(updatedCipher.UserId); Assert.Equal(organization.Id, updatedCipher.OrganizationId); Assert.NotNull(updatedCipher.Folders);