mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 15:42:48 -05:00
[PS-40] Upgrade to .NET 6 (#2056)
* Bump to .NET 6 * Update Docker images * Update docs * Update workflow for linter * Add all common versions to props file * Update tools manifest * Update csproj files * Update packages.lock.json files * Switch to setup-dotnet * Remove msbuild * Fix deps breaking changes * Manually install msbuild * Use msbuild for build * Fix verbosity switch * Remove unused exceptions * Address linter feedback * Make Obsolete warnings suggestions for now. * Force Evaluate * Format on tests * Run formatting again. * Use windows 2022 * force evaluate * Fix restore * Fix linter * Skip test * Update Directory.Build.props Co-authored-by: Matt Gibson <mgibson@bitwarden.com> * Address PR feedback * Add IntegationTest for Rate limiter * Fix test * Reenable test * Reorder test * Skip test again * Add tracking link * Update .github/workflows/build.yml Co-authored-by: Micaiah Martin <77340197+mimartin12@users.noreply.github.com> Co-authored-by: Matt Gibson <mgibson@bitwarden.com> Co-authored-by: Micaiah Martin <77340197+mimartin12@users.noreply.github.com>
This commit is contained in:
@ -5,18 +5,18 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="3.0.3">
|
||||
<PackageReference Include="coverlet.collector" Version="$(CoverletCollectorVersion)">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
|
||||
<PackageReference Include="NSubstitute" Version="4.2.2" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.2">
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNetTestSdkVersion)" />
|
||||
<PackageReference Include="NSubstitute" Version="$(NSubstitueVersion)" />
|
||||
<PackageReference Include="xunit" Version="$(XUnitVersion)" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="$(XUnitRunnerVisualStudioVersion)">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="AutoFixture.Xunit2" Version="4.14.0" />
|
||||
<PackageReference Include="AutoFixture.Xunit2" Version="$(AutoFixtureXUnit2Version)" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -5,18 +5,18 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNetTestSdkVersion)" />
|
||||
<PackageReference Include="xunit" Version="$(XUnitVersion)" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="$(XUnitRunnerVisualStudioVersion)">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="3.1.0">
|
||||
<PackageReference Include="coverlet.collector" Version="$(CoverletCollectorVersion)">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="AutoFixture.Xunit2" Version="4.14.0" />
|
||||
<PackageReference Include="NSubstitute" Version="4.2.2" />
|
||||
<PackageReference Include="AutoFixture.Xunit2" Version="$(AutoFixtureXUnit2Version)" />
|
||||
<PackageReference Include="NSubstitute" Version="$(NSubstitueVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -3,16 +3,17 @@
|
||||
<IsPackable>false</IsPackable>
|
||||
<RootNamespace>Bit.Test.Common</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NSubstitute" Version="4.2.2"/>
|
||||
<PackageReference Include="xunit" Version="2.4.1"/>
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.2">
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NSubstitute" Version="$(NSubstitueVersion)" />
|
||||
<PackageReference Include="xunit" Version="$(XUnitVersion)" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="$(XUnitRunnerVisualStudioVersion)">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="AutoFixture.Xunit2" Version="4.14.0"/>
|
||||
<PackageReference Include="AutoFixture.AutoNSubstitute" Version="4.14.0"/>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1"/>
|
||||
<PackageReference Include="AutoFixture.Xunit2" Version="$(AutoFixtureXUnit2Version)" />
|
||||
<PackageReference Include="AutoFixture.AutoNSubstitute" Version="$(AutoFixtureAutoNSubstituteVersion)" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNetTestSdkVersion)" />
|
||||
<PackageReference Include="Kralizek.AutoFixture.Extensions.MockHttp" Version="1.2.0"/>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -4,20 +4,20 @@
|
||||
<RootNamespace>Bit.Core.Test</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="3.0.3">
|
||||
<PackageReference Include="coverlet.collector" Version="$(CoverletCollectorVersion)">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1"/>
|
||||
<PackageReference Include="Moq" Version="4.16.1"/>
|
||||
<PackageReference Include="NSubstitute" Version="4.2.2"/>
|
||||
<PackageReference Include="xunit" Version="2.4.1"/>
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.2">
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNetTestSdkVersion)" />
|
||||
<PackageReference Include="Moq" Version="4.17.2" />
|
||||
<PackageReference Include="NSubstitute" Version="$(NSubstitueVersion)" />
|
||||
<PackageReference Include="xunit" Version="$(XUnitVersion)" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="$(XUnitRunnerVisualStudioVersion)">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="AutoFixture.Xunit2" Version="4.14.0"/>
|
||||
<PackageReference Include="AutoFixture.AutoNSubstitute" Version="4.14.0"/>
|
||||
<PackageReference Include="AutoFixture.Xunit2" Version="$(AutoFixtureXUnit2Version)" />
|
||||
<PackageReference Include="AutoFixture.AutoNSubstitute" Version="$(AutoFixtureAutoNSubstituteVersion)" />
|
||||
<PackageReference Include="Kralizek.AutoFixture.Extensions.MockHttp" Version="1.2.0"/>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -72,9 +72,7 @@ namespace Bit.Core.Test.Repositories.EntityFramework
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfUserCipherAutoData]
|
||||
public async void CreateAsync_BumpsUserAccountRevisionDate(Cipher cipher, User user,
|
||||
CipherCompare equalityComparer, List<EfRepo.CipherRepository> suts, List<EfRepo.UserRepository> efUserRepos,
|
||||
SqlRepo.CipherRepository sqlCipherRepo, SqlRepo.UserRepository sqlUserRepo)
|
||||
public async void CreateAsync_BumpsUserAccountRevisionDate(Cipher cipher, User user, List<EfRepo.CipherRepository> suts, List<EfRepo.UserRepository> efUserRepos)
|
||||
{
|
||||
var bumpedUsers = new List<User>();
|
||||
foreach (var sut in suts)
|
||||
@ -98,8 +96,7 @@ namespace Bit.Core.Test.Repositories.EntityFramework
|
||||
|
||||
[CiSkippedTheory, EfOrganizationCipherAutoData]
|
||||
public async void CreateAsync_BumpsOrgUserAccountRevisionDates(Cipher cipher, List<User> users,
|
||||
List<OrganizationUser> orgUsers, Collection collection, Organization org, CipherCompare equalityComparer,
|
||||
List<EfRepo.CipherRepository> suts, List<EfRepo.UserRepository> efUserRepos, List<EfRepo.OrganizationRepository> efOrgRepos,
|
||||
List<OrganizationUser> orgUsers, Collection collection, Organization org, List<EfRepo.CipherRepository> suts, List<EfRepo.UserRepository> efUserRepos, List<EfRepo.OrganizationRepository> efOrgRepos,
|
||||
List<EfRepo.OrganizationUserRepository> efOrgUserRepos, List<EfRepo.CollectionRepository> efCollectionRepos)
|
||||
{
|
||||
var savedCiphers = new List<Cipher>();
|
||||
|
@ -66,8 +66,7 @@ namespace Bit.Core.Test.Repositories.EntityFramework
|
||||
|
||||
[CiSkippedTheory, EfOrganizationAutoData]
|
||||
public async void DeleteAsync_Works_DataMatches(Organization organization,
|
||||
SqlRepo.OrganizationRepository sqlOrganizationRepo, OrganizationCompare equalityComparer,
|
||||
List<EfRepo.OrganizationRepository> suts)
|
||||
SqlRepo.OrganizationRepository sqlOrganizationRepo, List<EfRepo.OrganizationRepository> suts)
|
||||
{
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
@ -118,8 +117,7 @@ namespace Bit.Core.Test.Repositories.EntityFramework
|
||||
|
||||
[CiSkippedTheory, EfOrganizationAutoData]
|
||||
public async void GetManyByEnabledAsync_Works_DataMatches(Organization organization,
|
||||
SqlRepo.OrganizationRepository sqlOrganizationRepo, OrganizationCompare equalityCompare,
|
||||
List<EfRepo.OrganizationRepository> suts)
|
||||
SqlRepo.OrganizationRepository sqlOrganizationRepo, List<EfRepo.OrganizationRepository> suts)
|
||||
{
|
||||
var returnedOrgs = new List<Organization>();
|
||||
foreach (var sut in suts)
|
||||
@ -139,9 +137,7 @@ namespace Bit.Core.Test.Repositories.EntityFramework
|
||||
|
||||
// testing data matches here would require manipulating all organization abilities in the db
|
||||
[CiSkippedTheory, EfOrganizationAutoData]
|
||||
public async void GetManyAbilitiesAsync_Works(Organization organization,
|
||||
SqlRepo.OrganizationRepository sqlOrganizationRepo, OrganizationCompare equalityComparer,
|
||||
List<EfRepo.OrganizationRepository> suts)
|
||||
public async void GetManyAbilitiesAsync_Works(SqlRepo.OrganizationRepository sqlOrganizationRepo, List<EfRepo.OrganizationRepository> suts)
|
||||
{
|
||||
var list = new List<OrganizationAbility>();
|
||||
foreach (var sut in suts)
|
||||
|
@ -106,8 +106,7 @@ namespace Bit.Core.Test.Repositories.EntityFramework
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfOrganizationUserAutoData]
|
||||
public async void DeleteAsync_Works_DataMatches(OrganizationUser orgUser, User user, Organization org,
|
||||
OrganizationUserCompare equalityComparer, List<EfRepo.OrganizationUserRepository> suts,
|
||||
public async void DeleteAsync_Works_DataMatches(OrganizationUser orgUser, User user, Organization org, List<EfRepo.OrganizationUserRepository> suts,
|
||||
List<EfRepo.UserRepository> efUserRepos, List<EfRepo.OrganizationRepository> efOrgRepos,
|
||||
SqlRepo.OrganizationUserRepository sqlOrgUserRepo, SqlRepo.UserRepository sqlUserRepo,
|
||||
SqlRepo.OrganizationRepository sqlOrgRepo)
|
||||
|
@ -97,8 +97,7 @@ namespace Bit.Core.Test.Repositories.EntityFramework
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfSsoConfigAutoData]
|
||||
public async void DeleteAsync_Works_DataMatches(SsoConfig ssoConfig, Organization org,
|
||||
SsoConfigCompare equalityComparer, List<EfRepo.SsoConfigRepository> suts,
|
||||
public async void DeleteAsync_Works_DataMatches(SsoConfig ssoConfig, Organization org, List<EfRepo.SsoConfigRepository> suts,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos, SqlRepo.SsoConfigRepository sqlSsoConfigRepo,
|
||||
SqlRepo.OrganizationRepository sqlOrganizationRepo)
|
||||
{
|
||||
@ -211,7 +210,7 @@ namespace Bit.Core.Test.Repositories.EntityFramework
|
||||
// Testing that data matches here would involve manipulating all SsoConfig records in the db
|
||||
[CiSkippedTheory, EfSsoConfigAutoData]
|
||||
public async void GetManyByRevisionNotBeforeDate_Works(SsoConfig ssoConfig, DateTime notBeforeDate,
|
||||
Organization org, SsoConfigCompare equalityComparer, List<EfRepo.SsoConfigRepository> suts,
|
||||
Organization org, List<EfRepo.SsoConfigRepository> suts,
|
||||
List<EfRepo.OrganizationRepository> efOrgRepos)
|
||||
{
|
||||
foreach (var sut in suts)
|
||||
|
@ -102,8 +102,7 @@ namespace Bit.Core.Test.Repositories.EntityFramework
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfSsoUserAutoData]
|
||||
public async void DeleteAsync_Works_DataMatches(SsoUser ssoUser, Organization org, User user,
|
||||
SsoUserCompare equalityComparer, List<EfRepo.SsoUserRepository> suts,
|
||||
public async void DeleteAsync_Works_DataMatches(SsoUser ssoUser, Organization org, User user, List<EfRepo.SsoUserRepository> suts,
|
||||
List<EfRepo.UserRepository> efUserRepos, List<EfRepo.OrganizationRepository> efOrgRepos,
|
||||
SqlRepo.SsoUserRepository sqlSsoUserRepo, SqlRepo.UserRepository sqlUserRepo,
|
||||
SqlRepo.OrganizationRepository sqlOrganizationRepo)
|
||||
@ -146,7 +145,7 @@ namespace Bit.Core.Test.Repositories.EntityFramework
|
||||
|
||||
[CiSkippedTheory, EfSsoUserAutoData]
|
||||
public async void DeleteAsync_UserIdOrganizationId_Works_DataMatches(SsoUser ssoUser,
|
||||
User user, Organization org, SsoUserCompare equalityComparer, List<EfRepo.SsoUserRepository> suts,
|
||||
User user, Organization org, List<EfRepo.SsoUserRepository> suts,
|
||||
List<EfRepo.UserRepository> efUserRepos, List<EfRepo.OrganizationRepository> efOrgRepos,
|
||||
SqlRepo.SsoUserRepository sqlSsoUserRepo, SqlRepo.UserRepository sqlUserRepo, SqlRepo.OrganizationRepository sqlOrgRepo
|
||||
)
|
||||
|
@ -65,8 +65,7 @@ namespace Bit.Core.Test.Repositories.EntityFramework
|
||||
}
|
||||
|
||||
[CiSkippedTheory, EfUserAutoData]
|
||||
public async void DeleteAsync_Works_DataMatches(User user, UserCompare equalityComparer,
|
||||
List<EfRepo.UserRepository> suts, SqlRepo.UserRepository sqlUserRepo)
|
||||
public async void DeleteAsync_Works_DataMatches(User user, List<EfRepo.UserRepository> suts, SqlRepo.UserRepository sqlUserRepo)
|
||||
{
|
||||
foreach (var sut in suts)
|
||||
{
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using Bit.Core.Services;
|
||||
using Bit.Core.Settings;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NSubstitute;
|
||||
using Xunit;
|
||||
|
||||
@ -11,12 +12,14 @@ namespace Bit.Core.Test.Services
|
||||
private readonly AzureAttachmentStorageService _sut;
|
||||
|
||||
private readonly GlobalSettings _globalSettings;
|
||||
private readonly ILogger<AzureAttachmentStorageService> _logger;
|
||||
|
||||
public AzureAttachmentStorageServiceTests()
|
||||
{
|
||||
_globalSettings = new GlobalSettings();
|
||||
_logger = Substitute.For<ILogger<AzureAttachmentStorageService>>();
|
||||
|
||||
_sut = new AzureAttachmentStorageService(_globalSettings);
|
||||
_sut = new AzureAttachmentStorageService(_globalSettings, _logger);
|
||||
}
|
||||
|
||||
// Remove this test when we add actual tests. It only proves that
|
||||
|
@ -35,8 +35,7 @@ namespace Bit.Core.Test.Services
|
||||
|
||||
[Theory, CollectionAutoData]
|
||||
public async Task SaveAsync_DefaultIdWithGroups_CreateCollectionWithGroupsInRepository(Collection collection,
|
||||
IEnumerable<SelectionReadOnly> groups, Organization organization, OrganizationUser organizationUser,
|
||||
SutProvider<CollectionService> sutProvider)
|
||||
IEnumerable<SelectionReadOnly> groups, Organization organization, SutProvider<CollectionService> sutProvider)
|
||||
{
|
||||
collection.Id = default;
|
||||
organization.UseGroups = true;
|
||||
@ -70,7 +69,7 @@ namespace Bit.Core.Test.Services
|
||||
|
||||
[Theory, CollectionAutoData]
|
||||
public async Task SaveAsync_OrganizationNotUseGroup_CreateCollectionWithoutGroupsInRepository(Collection collection, IEnumerable<SelectionReadOnly> groups,
|
||||
Organization organization, OrganizationUser organizationUser, SutProvider<CollectionService> sutProvider)
|
||||
Organization organization, SutProvider<CollectionService> sutProvider)
|
||||
{
|
||||
collection.Id = default;
|
||||
sutProvider.GetDependency<IOrganizationRepository>().GetByIdAsync(organization.Id).Returns(organization);
|
||||
@ -120,7 +119,7 @@ namespace Bit.Core.Test.Services
|
||||
}
|
||||
|
||||
[Theory, CollectionAutoData]
|
||||
public async Task SaveAsync_ExceedsOrganizationMaxCollections_ThrowsBadRequest(Collection collection, Collection collection1, Collection collection2, Organization organization, SutProvider<CollectionService> sutProvider)
|
||||
public async Task SaveAsync_ExceedsOrganizationMaxCollections_ThrowsBadRequest(Collection collection, Organization organization, SutProvider<CollectionService> sutProvider)
|
||||
{
|
||||
collection.Id = default;
|
||||
sutProvider.GetDependency<IOrganizationRepository>().GetByIdAsync(organization.Id).Returns(organization);
|
||||
|
@ -68,7 +68,7 @@ namespace Bit.Core.Test.Services
|
||||
}
|
||||
|
||||
[Theory, CustomAutoData(typeof(SutProviderCustomization))]
|
||||
public async Task SaveAsync_NonExistingOrganizationId_ThrowsBadRequest(Group group, Organization organization, SutProvider<GroupService> sutProvider)
|
||||
public async Task SaveAsync_NonExistingOrganizationId_ThrowsBadRequest(Group group, SutProvider<GroupService> sutProvider)
|
||||
{
|
||||
var exception = await Assert.ThrowsAsync<BadRequestException>(
|
||||
() => sutProvider.Sut.SaveAsync(group));
|
||||
|
@ -869,7 +869,7 @@ namespace Bit.Core.Test.Services
|
||||
[InlinePaidOrganizationAutoData(0, null, 100, true, "")]
|
||||
[InlinePaidOrganizationAutoData(1, 100, null, true, "")]
|
||||
[InlinePaidOrganizationAutoData(1, 100, 100, false, "Cannot invite new users. Seat limit has been reached")]
|
||||
public async Task CanScale(int seatsToAdd, int? currentSeats, int? maxAutoscaleSeats,
|
||||
public void CanScale(int seatsToAdd, int? currentSeats, int? maxAutoscaleSeats,
|
||||
bool expectedResult, string expectedFailureMessage, Organization organization,
|
||||
SutProvider<OrganizationService> sutProvider)
|
||||
{
|
||||
@ -891,7 +891,7 @@ namespace Bit.Core.Test.Services
|
||||
}
|
||||
|
||||
[Theory, PaidOrganizationAutoData]
|
||||
public async Task CanScale_FailsOnSelfHosted(Organization organization,
|
||||
public void CanScale_FailsOnSelfHosted(Organization organization,
|
||||
SutProvider<OrganizationService> sutProvider)
|
||||
{
|
||||
sutProvider.GetDependency<IGlobalSettings>().SelfHosted.Returns(true);
|
||||
|
@ -495,8 +495,6 @@ namespace Bit.Core.Test.Services
|
||||
send.UserId = user.Id;
|
||||
send.Type = SendType.File;
|
||||
|
||||
var testUrl = "https://test.com/";
|
||||
|
||||
sutProvider.GetDependency<IUserRepository>()
|
||||
.GetByIdAsync(user.Id)
|
||||
.Returns(user);
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -5,14 +5,14 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="3.0.3">
|
||||
<PackageReference Include="coverlet.collector" Version="$(CoverletCollectorVersion)">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
|
||||
<PackageReference Include="NSubstitute" Version="4.2.2" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNetTestSdkVersion)" />
|
||||
<PackageReference Include="NSubstitute" Version="$(NSubstitueVersion)" />
|
||||
<PackageReference Include="xunit" Version="$(XUnitVersion)" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="$(XUnitRunnerVisualStudioVersion)">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
|
@ -14,7 +14,7 @@ namespace Bit.Icons.Test.Services
|
||||
[InlineData("neverssl.com")] // http site
|
||||
[InlineData("ameritrade.com")]
|
||||
[InlineData("icloud.com")]
|
||||
[InlineData("bofa.com")]
|
||||
[InlineData("bofa.com", Skip = "Broken in pipeline for .NET 6. Tracking link: https://bitwarden.atlassian.net/browse/PS-982")]
|
||||
public async Task GetIconAsync_Success(string domain)
|
||||
{
|
||||
var sut = new IconFetchingService(GetLogger());
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
@ -71,7 +72,7 @@ namespace Bit.Identity.IntegrationTest.Endpoints
|
||||
{ "grant_type", "password" },
|
||||
{ "username", username },
|
||||
{ "password", "master_password_hash" },
|
||||
}), context => context.Request.Headers.Add("Auth-Email", CoreHelpers.Base64UrlEncodeString(username)));
|
||||
}), context => context.SetAuthEmail(username));
|
||||
|
||||
using var body = await AssertDefaultTokenBodyAsync(context);
|
||||
var root = body.RootElement;
|
||||
@ -174,7 +175,7 @@ namespace Bit.Identity.IntegrationTest.Endpoints
|
||||
{ "grant_type", "password" },
|
||||
{ "username", username },
|
||||
{ "password", "master_password_hash" },
|
||||
}), context => context.Request.Headers.Add("Auth-Email", CoreHelpers.Base64UrlEncodeString("bad_value")));
|
||||
}), context => context.SetAuthEmail("bad_value"));
|
||||
|
||||
Assert.Equal(StatusCodes.Status400BadRequest, context.Response.StatusCode);
|
||||
|
||||
@ -399,6 +400,57 @@ namespace Bit.Identity.IntegrationTest.Endpoints
|
||||
Assert.Equal("invalid_client", error);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task TokenEndpoint_ToQuickInOneSecond_BlockRequest()
|
||||
{
|
||||
const int AmountInOneSecondAllowed = 5;
|
||||
|
||||
// The rule we are testing is 10 requests in 1 second
|
||||
var username = "test+ratelimiting@email.com";
|
||||
var deviceId = "8f14a393-edfe-40ba-8c67-a856cb89c509";
|
||||
|
||||
await _factory.RegisterAsync(new RegisterRequestModel
|
||||
{
|
||||
Email = username,
|
||||
MasterPasswordHash = "master_password_hash",
|
||||
});
|
||||
|
||||
var database = _factory.GetDatabaseContext();
|
||||
var user = await database.Users
|
||||
.FirstAsync(u => u.Email == username);
|
||||
|
||||
var tasks = new Task<HttpContext>[AmountInOneSecondAllowed + 1];
|
||||
|
||||
for (var i = 0; i < AmountInOneSecondAllowed + 1; i++)
|
||||
{
|
||||
// Queue all the amount of calls allowed plus 1
|
||||
tasks[i] = MakeRequest();
|
||||
}
|
||||
|
||||
var responses = await Task.WhenAll(tasks);
|
||||
|
||||
var allowedCalls = responses[..AmountInOneSecondAllowed];
|
||||
var notAllowedCall = responses[^1];
|
||||
|
||||
Assert.True(allowedCalls.All(c => c.Response.StatusCode == StatusCodes.Status200OK));
|
||||
Assert.True(notAllowedCall.Response.StatusCode == StatusCodes.Status429TooManyRequests);
|
||||
|
||||
Task<HttpContext> MakeRequest()
|
||||
{
|
||||
return _factory.Server.PostAsync("/connect/token", new FormUrlEncodedContent(new Dictionary<string, string>
|
||||
{
|
||||
{ "scope", "api offline_access" },
|
||||
{ "client_id", "web" },
|
||||
{ "deviceType", DeviceTypeAsString(DeviceType.FirefoxBrowser) },
|
||||
{ "deviceIdentifier", deviceId },
|
||||
{ "deviceName", "firefox" },
|
||||
{ "grant_type", "password" },
|
||||
{ "username", username },
|
||||
{ "password", "master_password_hash" },
|
||||
}), context => context.SetAuthEmail(username).SetIp("1.1.1.2"));
|
||||
}
|
||||
}
|
||||
|
||||
private static string DeviceTypeAsString(DeviceType deviceType)
|
||||
{
|
||||
return ((int)deviceType).ToString();
|
||||
|
@ -5,19 +5,19 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="3.0.3">
|
||||
<PackageReference Include="coverlet.collector" Version="$(CoverletCollectorVersion)">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="5.0.15" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
|
||||
<PackageReference Include="NSubstitute" Version="4.2.2" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.2">
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.5" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNetTestSdkVersion)" />
|
||||
<PackageReference Include="NSubstitute" Version="$(NSubstitueVersion)" />
|
||||
<PackageReference Include="xunit" Version="$(XUnitVersion)" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="$(XUnitRunnerVisualStudioVersion)">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="AutoFixture.Xunit2" Version="4.14.0" />
|
||||
<PackageReference Include="AutoFixture.Xunit2" Version="$(AutoFixtureXUnit2Version)" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -59,7 +59,7 @@ namespace Bit.Identity.Test.Controllers
|
||||
[Fact]
|
||||
public async Task PostPrelogin_WhenUserDoesNotExist_ShouldDefaultToSha256And100000Iterations()
|
||||
{
|
||||
_userRepository.GetKdfInformationByEmailAsync(Arg.Any<string>()).Returns(Task.FromResult((UserKdfInformation)null));
|
||||
_userRepository.GetKdfInformationByEmailAsync(Arg.Any<string>()).Returns(Task.FromResult<UserKdfInformation>(null!));
|
||||
|
||||
var response = await _sut.PostPrelogin(new PreloginRequestModel { Email = "user@example.com" });
|
||||
|
||||
@ -112,4 +112,3 @@ namespace Bit.Identity.Test.Controllers
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<Nullable>enable</Nullable>
|
||||
@ -6,18 +6,18 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="3.0.3">
|
||||
<PackageReference Include="coverlet.collector" Version="$(CoverletCollectorVersion)">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
|
||||
<PackageReference Include="NSubstitute" Version="4.2.2" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.2">
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNetTestSdkVersion)" />
|
||||
<PackageReference Include="NSubstitute" Version="$(NSubstitueVersion)" />
|
||||
<PackageReference Include="xunit" Version="$(XUnitVersion)" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="$(XUnitRunnerVisualStudioVersion)">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="AutoFixture.Xunit2" Version="4.14.0" />
|
||||
<PackageReference Include="AutoFixture.Xunit2" Version="$(AutoFixtureXUnit2Version)" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Bit.Core.Utilities;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.TestHost;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
@ -50,6 +51,19 @@ namespace Bit.IntegrationTestCommon.Factories
|
||||
string requestUri,
|
||||
Action<HttpContext> extraConfiguration = null)
|
||||
=> SendAsync(server, HttpMethod.Get, requestUri, content: null, extraConfiguration);
|
||||
|
||||
public static HttpContext SetAuthEmail(this HttpContext context, string username)
|
||||
{
|
||||
context.Request.Headers.Add("Auth-Email", CoreHelpers.Base64UrlEncodeString(username));
|
||||
return context;
|
||||
}
|
||||
|
||||
public static HttpContext SetIp(this HttpContext context, string ip)
|
||||
{
|
||||
context.Connection.RemoteIpAddress = IPAddress.Parse(ip);
|
||||
return context;
|
||||
}
|
||||
|
||||
public static async Task<string> ReadBodyAsStringAsync(this HttpContext context)
|
||||
{
|
||||
using var sr = new StreamReader(context.Response.Body);
|
||||
|
@ -5,9 +5,9 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="5.0.15" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="5.0.15" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.5" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.5" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user