1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-30 07:36:14 -05:00

[PM-5052] Upgrade to .NET 8 (#3461)

* Upgrade to .NET 8

* Linting

* Clean up old JSON deserialization code

* More .NET 8-oriented linting

* Light feedback

* Get rid of old test we don't know the root issue for

* Fix a new test

* Remove now-unnecessary Renovate constraint

* Use Any()

* Somehow a 6.0 tooling config we don't need snuck back in

* Space out properties that always change per release

* Bump a few core packages since the last update
This commit is contained in:
Matt Bishop
2024-02-05 13:03:42 -05:00
committed by GitHub
parent 3c5e9ac1aa
commit ae1fdb0992
38 changed files with 82 additions and 132 deletions

View File

@ -96,7 +96,7 @@ public class OrganizationServiceTests
await sutProvider.GetDependency<IOrganizationUserRepository>().DidNotReceiveWithAnyArgs()
.UpsertAsync(default);
await sutProvider.GetDependency<IOrganizationUserRepository>().Received(1)
.UpsertManyAsync(Arg.Is<IEnumerable<OrganizationUser>>(users => users.Count() == 0));
.UpsertManyAsync(Arg.Is<IEnumerable<OrganizationUser>>(users => !users.Any()));
await sutProvider.GetDependency<IOrganizationUserRepository>().DidNotReceiveWithAnyArgs()
.CreateAsync(default);

View File

@ -41,7 +41,7 @@ public class DeviceServiceTests
}
/// <summary>
/// Story: A user choosed to keep trust in one of their current trusted devices, but not in another one of their
/// Story: A user chose to keep trust in one of their current trusted devices, but not in another one of their
/// devices. We will rotate the trust of the currently signed in device as well as the device they chose but will
/// remove the trust of the device they didn't give new keys for.
/// </summary>
@ -117,8 +117,7 @@ public class DeviceServiceTests
.Received(3)
.UpsertAsync(Arg.Any<Device>());
// TODO: .NET 8: Use nameof for parameter name.
static void SetupOldTrust(Device device, [CallerArgumentExpression("device")] string expression = null)
static void SetupOldTrust(Device device, [CallerArgumentExpression(nameof(device))] string expression = null)
{
device.EncryptedPublicKey = $"old_public_{expression}";
device.EncryptedPrivateKey = $"old_private_{expression}";

View File

@ -31,22 +31,4 @@ public class SpanExtensionsTests
Assert.True(splitChunk.IsEmpty);
Assert.Equal(fullString, rest.ToString());
}
[Theory]
[InlineData("11111", '1', 5)]
[InlineData("Text", 'z', 0)]
[InlineData("1", '1', 1)]
public void Count_ReturnsCount(string text, char countChar, int expectedInstances)
{
Assert.Equal(expectedInstances, text.AsSpan().Count(countChar));
}
[Theory]
[InlineData(new[] { 5, 4 }, 5, 1)]
[InlineData(new[] { 1 }, 5, 0)]
[InlineData(new[] { 5, 5, 5 }, 5, 3)]
public void CountIntegers_ReturnsCount(int[] array, int countNumber, int expectedInstances)
{
Assert.Equal(expectedInstances, ((ReadOnlySpan<int>)array.AsSpan()).Count(countNumber));
}
}

View File

@ -15,7 +15,6 @@ using Bit.Core.Vault.Repositories;
using Bit.Core.Vault.Services;
using Bit.Test.Common.AutoFixture;
using Bit.Test.Common.AutoFixture.Attributes;
using Castle.Core.Internal;
using NSubstitute;
using Xunit;
@ -75,7 +74,7 @@ public class CipherServiceTests
!cols.Any(c => c.Id == collections[0].Id) && // Check that the collection that already existed in the organization was not added
cols.All(c => collections.Any(x => c.Name == x.Name))),
Arg.Is<IEnumerable<CollectionCipher>>(c => c.Count() == ciphers.Count),
Arg.Is<IEnumerable<CollectionUser>>(i => i.IsNullOrEmpty()));
Arg.Is<IEnumerable<CollectionUser>>(i => !i.Any()));
await sutProvider.GetDependency<IPushNotificationService>().Received(1).PushSyncVaultAsync(importingUserId);
await sutProvider.GetDependency<IReferenceEventService>().Received(1).RaiseEventAsync(
Arg.Is<ReferenceEvent>(e => e.Type == ReferenceEventType.VaultImported));
@ -683,7 +682,7 @@ public class CipherServiceTests
await sutProvider.Sut.ShareManyAsync(cipherInfos, organization.Id, collectionIds, sharingUserId);
await sutProvider.GetDependency<ICipherRepository>().Received(1).UpdateCiphersAsync(sharingUserId,
Arg.Is<IEnumerable<Cipher>>(arg => arg.Except(ciphers).IsNullOrEmpty()));
Arg.Is<IEnumerable<Cipher>>(arg => !arg.Except(ciphers).Any()));
}
[Theory]
@ -839,7 +838,7 @@ public class CipherServiceTests
await sutProvider.Sut.ShareManyAsync(cipherInfos, organizationId, collectionIds, sharingUserId);
await sutProvider.GetDependency<ICipherRepository>().Received(1).UpdateCiphersAsync(sharingUserId,
Arg.Is<IEnumerable<Cipher>>(arg => arg.Except(ciphers).IsNullOrEmpty()));
Arg.Is<IEnumerable<Cipher>>(arg => !arg.Except(ciphers).Any()));
}
private async Task AssertNoActionsAsync(SutProvider<CipherService> sutProvider)

View File

@ -68,11 +68,11 @@ public class IconLinkTests
}
[Fact]
public void FetchAsync_Unvalidated_ReturnsNull()
public async Task FetchAsync_Unvalidated_ReturnsNull()
{
var result = new IconLink(_element, _uri, _baseUrlPath).FetchAsync(_logger, _httpClientFactory, _uriService);
var result = await new IconLink(_element, _uri, _baseUrlPath).FetchAsync(_logger, _httpClientFactory, _uriService);
Assert.Null(result.Result);
Assert.Null(result);
}
private void SetAttributeValue(string attribute, string value)

View File

@ -11,9 +11,8 @@ public class IconFetchingServiceTests : ServiceTestBase<IconFetchingService>
[InlineData("neverssl.com")] // http site
[InlineData("neopets.com")] // uses favicon.ico
[InlineData("hopin.com")] // uses svg+xml format
[InlineData("ameritrade.com")] // redirects to tdameritrace.com
[InlineData("ameritrade.com")] // redirects to tdameritrade.com
[InlineData("icloud.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 = BuildSut();

View File

@ -106,7 +106,7 @@ public class IdentityServerTests : IClassFixture<IdentityApplicationFactory>
MasterPasswordHash = "master_password_hash",
});
var context = await PostLoginAsync(_factory.Server, username, deviceId, context => context.Request.Headers.Add("Auth-Email", "bad_value"));
var context = await PostLoginAsync(_factory.Server, username, deviceId, context => context.Request.Headers.Append("Auth-Email", "bad_value"));
Assert.Equal(StatusCodes.Status400BadRequest, context.Response.StatusCode);

View File

@ -183,7 +183,7 @@ public class OrganizationRepositoryTests
Assert.Equal(efOrgRepos.Count, efList.Count);
Assert.True(efList.All(o => o.Name == org.Name));
Assert.Equal(1, sqlResult.Count);
Assert.Single(sqlResult);
Assert.True(sqlResult.All(o => o.Name == org.Name));
}
}

View File

@ -35,7 +35,7 @@ public class IdentityApplicationFactory : WebApplicationFactoryBase<Startup>
{ "grant_type", "password" },
{ "username", username },
{ "password", password },
}), context => context.Request.Headers.Add("Auth-Email", CoreHelpers.Base64UrlEncodeString(username)));
}), context => context.Request.Headers.Append("Auth-Email", CoreHelpers.Base64UrlEncodeString(username)));
using var body = await AssertHelper.AssertResponseTypeIs<JsonDocument>(context);
var root = body.RootElement;

View File

@ -28,7 +28,7 @@ public static class WebApplicationFactoryExtensions
{
foreach (var header in content.Headers)
{
httpContext.Request.Headers.Add(header.Key, new StringValues(header.Value.ToArray()));
httpContext.Request.Headers.Append(header.Key, new StringValues(header.Value.ToArray()));
}
httpContext.Request.Body = content.ReadAsStream();
@ -64,7 +64,7 @@ public static class WebApplicationFactoryExtensions
public static HttpContext SetAuthEmail(this HttpContext context, string username)
{
context.Request.Headers.Add("Auth-Email", CoreHelpers.Base64UrlEncodeString(username));
context.Request.Headers.Append("Auth-Email", CoreHelpers.Base64UrlEncodeString(username));
return context;
}