Skip to content

Commit

Permalink
Merge pull request #353 from POPWorldMedia/net8.0
Browse files Browse the repository at this point in the history
Update to .NET v8 (#348)
  • Loading branch information
jeffputz committed Nov 15, 2023
2 parents 90e4ff8 + 0d3bd00 commit a05dd49
Show file tree
Hide file tree
Showing 14 changed files with 101 additions and 75 deletions.
2 changes: 1 addition & 1 deletion docs/azurekitlibrary.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ You'll also need to setup the right configuration values:
```
* `Url`: The URL for Azure Search, typically `https://{nameOfSearchService}.search.windows.net` with the name set in the Azure portal
* `Key`: A key provisioned by the portal to connect to Azure Search
* `Provider`: This is only used in `PopForums.AzureKit.Functions`, where it's used to switch between `elasticsearch`, `azuresearch` and the default bits in the `PopForums.Sql` library
* `Provider`: This is only used in `PopForums.AzureKit.Functions`, where it's used to switch between `elasticsearch`, `azuresearch` and the default bits in the `PopForums.Sql` library. _Important: If the value is left blank, the Azure Functions will use the SQL-based search provider._

## Using Azure storage for hosting uploaded images in posts
The default implementation for uploading images into forum posts is to upload them into the database. While this is convenient and super portable, it may not be the least expensive option, since database storage is typically more expensive than other means. To that end, you can use `AzureKit` to upload and host the images in an Azure storage container.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Description>PopForums AzureKit Functions</Description>
<VersionPrefix>20.0.0-alpha1</VersionPrefix>
<Authors>Jeff Putz</Authors>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<AssemblyName>PopForums.AzureKit.Functions</AssemblyName>
<PackageId>PopForums.AzureKit.Functions</PackageId>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
Expand All @@ -14,12 +14,12 @@
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage" Version="6.2.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Timer" Version="4.2.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Timer" Version="4.3.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.14.1" OutputItemType="Analyzer" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.19.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.16.2" OutputItemType="Analyzer" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.20.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PopForums.AzureKit\PopForums.AzureKit.csproj" />
Expand Down
5 changes: 5 additions & 0 deletions src/PopForums.AzureKit.Functions/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,14 @@
case "elasticsearch":
case "elasticcloud":
s.AddPopForumsElasticSearch();
Console.WriteLine("ElasticSearch provider configured.");
break;
case "azuresearch":
s.AddPopForumsAzureSearch();
Console.WriteLine("Azure Search provider configured.");
break;
default:
Console.WriteLine("Default SQL based search provider configured.");
break;
}
})
Expand Down
2 changes: 1 addition & 1 deletion src/PopForums.AzureKit.Functions/local.settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"Search": {
"Url": "https://localhost:9200",
"Key": "elastic|1+GhSZd-+ActqOHZLkAL",
"Provider": "elasticsearch"
"Provider": ""
},
"Queue": {
"ConnectionString": "UseDevelopmentStorage=true"
Expand Down
12 changes: 6 additions & 6 deletions src/PopForums.AzureKit/PopForums.AzureKit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Description>PopForums AzureKit Class Library</Description>
<VersionPrefix>20.0.0-alpha1</VersionPrefix>
<Authors>Jeff Putz</Authors>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<AssemblyName>PopForums.AzureKit</AssemblyName>
<PackageId>PopForums.AzureKit</PackageId>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
Expand All @@ -25,11 +25,11 @@
<PackageReference Include="Azure.Search.Documents" Version="11.4.0" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.17.0" />
<PackageReference Include="Azure.Storage.Queues" Version="12.15.0" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.StackExchangeRedis" Version="7.0.10" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="StackExchange.Redis" Version="2.6.122" />
<PackageReference Include="System.Text.Json" Version="7.0.3" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.StackExchangeRedis" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="StackExchange.Redis" Version="2.7.4" />
<PackageReference Include="System.Text.Json" Version="8.0.0" />
</ItemGroup>

</Project>
6 changes: 3 additions & 3 deletions src/PopForums.ElasticKit/PopForums.ElasticKit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Description>PopForums ElasticKit Class Library</Description>
<VersionPrefix>20.0.0-alpha1</VersionPrefix>
<Authors>Jeff Putz</Authors>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<AssemblyName>PopForums.ElasticKit</AssemblyName>
<PackageId>PopForums.ElasticKit</PackageId>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
Expand All @@ -15,8 +15,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Elastic.Clients.Elasticsearch" Version="8.9.2" />
<PackageReference Include="Polly" Version="7.2.4" />
<PackageReference Include="Elastic.Clients.Elasticsearch" Version="8.11.0" />
<PackageReference Include="Polly" Version="8.2.0" />
</ItemGroup>

<ItemGroup>
Expand Down
36 changes: 25 additions & 11 deletions src/PopForums.ElasticKit/Search/SearchIndexSubsystem.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Elastic.Clients.Elasticsearch;
using Polly;
using Polly.Retry;
using PopForums.Configuration;
using PopForums.Services;

Expand Down Expand Up @@ -71,18 +73,30 @@ public void DoIndex(int topicID, string tenantID, bool isForRemoval)

try
{
var policy = Polly.Policy.HandleResult<IndexResponse>(x => !x.IsValidResponse)
.WaitAndRetry(new[]
var pipeline = new ResiliencePipelineBuilder<IndexResponse>()
.AddRetry(new RetryStrategyOptions<IndexResponse>
{
TimeSpan.FromSeconds(1),
TimeSpan.FromSeconds(5),
TimeSpan.FromSeconds(30)
}, (result, timeSpan) =>
{
result.Result.TryGetOriginalException(out var exc);
_errorLog.Log(exc, ErrorSeverity.Error, $"Retry after {timeSpan.Seconds}: {result.Result.DebugInformation}");
});
policy.Execute(() =>
ShouldHandle = new PredicateBuilder<IndexResponse>()
.HandleResult(static result => !result.IsValidResponse),
DelayGenerator = static args =>
{
var delay = args.AttemptNumber switch
{
0 => TimeSpan.FromSeconds(1),
1 => TimeSpan.FromSeconds(5),
_ => TimeSpan.FromSeconds(30)
};
return new ValueTask<TimeSpan?>(delay);
},
OnRetry = responseArgs =>
{
_errorLog.Log(responseArgs.Outcome.Exception, ErrorSeverity.Error,
$"Retry after {responseArgs.Duration.Seconds}: {responseArgs.Outcome.Result?.DebugInformation}");
return default;
}
}).Build();

pipeline.Execute(() =>
{
var indexResult = _elasticSearchClientWrapper.IndexTopic(searchTopic);
return indexResult;
Expand Down
2 changes: 1 addition & 1 deletion src/PopForums.Mvc/PopForums.Mvc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Description>PopForums Mvc Class Library</Description>
<VersionPrefix>20.0.0-alpha1</VersionPrefix>
<Authors>Jeff Putz</Authors>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<AssemblyName>PopForums.Mvc</AssemblyName>
<PackageId>PopForums.Mvc</PackageId>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
Expand Down
16 changes: 8 additions & 8 deletions src/PopForums.Mvc/package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"scripts": {},
"dependencies": {
"@microsoft/signalr": "7.0.2",
"axios": "1.6.0",
"bootstrap": "5.3.0",
"tinymce": "6.7.1",
"vue": "3.2.47",
"vue-router": "4.1.6"
"@microsoft/signalr": "8.0.0",
"axios": "1.6.2",
"bootstrap": "5.3.2",
"tinymce": "6.7.3",
"vue": "3.3.8",
"vue-router": "4.2.5"
},
"devDependencies": {
"typescript": "5.2.2",
"gulp-typescript": "5.0.1",
"@babel/core": "7.19.3",
"@babel/preset-env": "7.19.3",
"@babel/core": "7.23.3",
"@babel/preset-env": "7.23.3",
"gulp": "4.0.2",
"gulp-babel": "8.0.0",
"gulp-clean-css": "4.3.0",
Expand Down
8 changes: 4 additions & 4 deletions src/PopForums.Sql/PopForums.Sql.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Description>PopForums.Data.Sql Class Library</Description>
<VersionPrefix>20.0.0-alpha1</VersionPrefix>
<Authors>Jeff Putz</Authors>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<AssemblyName>PopForums.Sql</AssemblyName>
<PackageId>PopForums.Sql</PackageId>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
Expand All @@ -23,9 +23,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Dapper" Version="2.0.151" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.1" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="7.0.0" />
<PackageReference Include="Dapper" Version="2.1.21" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.0-preview3.23201.1" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.0" />
<PackageReference Include="System.Data.Common" Version="4.3.0" />
</ItemGroup>

Expand Down
10 changes: 5 additions & 5 deletions src/PopForums.Test/PopForums.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<VersionPrefix>20.0.0-alpha1</VersionPrefix>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<AssemblyName>PopForums.Test</AssemblyName>
<PackageId>PopForums.Test</PackageId>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
Expand All @@ -14,17 +14,17 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="NSubstitute" Version="5.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0-preview-23503-02" />
<PackageReference Include="NSubstitute" Version="5.1.0" />
<PackageReference Include="NSubstitute.Analyzers.CSharp" Version="1.0.16">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit" Version="2.6.1" />
</ItemGroup>

<ItemGroup>
Expand Down
51 changes: 29 additions & 22 deletions src/PopForums.Test/Services/UserServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,84 +48,89 @@ public async Task SetPassword()
}

[Fact]
public void CheckPassword()
public async Task CheckPassword()
{
var userService = GetMockedUserService();
_mockUserRepo.GetHashedPasswordByEmail(string.Empty).Returns(Task.FromResult(Tuple.Create("0M/C5TGbgs3HGjOHPoJsk9fuETY/iskcT6Oiz80ihuU=", (Guid?)null)));

var result = userService.CheckPassword(String.Empty, "fred").Result.Item1;
var result = await userService.CheckPassword(String.Empty, "fred");

Assert.True(result);
Assert.True(result.Item1);
}

[Fact]
public void CheckPasswordFail()
public async Task CheckPasswordFail()
{
var userService = GetMockedUserService();
_mockUserRepo.GetHashedPasswordByEmail(string.Empty).Returns(Task.FromResult(Tuple.Create("VwqQv7+MfqtdxdTiaDLVsQ==", (Guid?)null)));

var result = userService.CheckPassword(String.Empty, "fsdfsdfsdfsdf").Result.Item1;
var result = await userService.CheckPassword(String.Empty, "fsdfsdfsdfsdf");

Assert.False(result);
Assert.False(result.Item1);
}

[Fact]
public void CheckPasswordHasSalt()
public async Task CheckPasswordHasSalt()
{
var userService = GetMockedUserService();
Guid? salt = Guid.NewGuid();
var hashedPassword = "fred".GetSHA256Hash(salt.Value);
_mockUserRepo.GetHashedPasswordByEmail(string.Empty).Returns(Task.FromResult(Tuple.Create(hashedPassword, salt)));

Assert.True(userService.CheckPassword(String.Empty, "fred").Result.Item1);
var result = await userService.CheckPassword(String.Empty, "fred");
Assert.True(result.Item1);
}

[Fact]
public void CheckPasswordHasSaltFail()
public async Task CheckPasswordHasSaltFail()
{
var userService = GetMockedUserService();
Guid? salt = Guid.NewGuid();
var hashedPassword = "fred".GetSHA256Hash(salt.Value);
_mockUserRepo.GetHashedPasswordByEmail(string.Empty).Returns(Task.FromResult(Tuple.Create(hashedPassword, salt)));

Assert.False(userService.CheckPassword(String.Empty, "dsfsdfsdfsdf").Result.Item1);
var result = await userService.CheckPassword(String.Empty, "dsfsdfsdfsdf");
Assert.False(result.Item1);
}

[Fact]
public void CheckPasswordPassesWithoutSaltOnMD5Fallback()
public async Task CheckPasswordPassesWithoutSaltOnMD5Fallback()
{
var userService = GetMockedUserService();
Guid? salt = null;
var hashedPassword = "fred".GetMD5Hash();
_mockUserRepo.GetHashedPasswordByEmail(string.Empty).Returns(Task.FromResult(Tuple.Create(hashedPassword, salt)));

Assert.True(userService.CheckPassword(String.Empty, "fred").Result.Item1);
var result = await userService.CheckPassword(String.Empty, "fred");
Assert.True(result.Item1);
}

[Fact]
public void CheckPasswordPassesWithSaltOnMD5Fallback()
public async Task CheckPasswordPassesWithSaltOnMD5Fallback()
{
var userService = GetMockedUserService();
Guid? salt = Guid.NewGuid();
var hashedPassword = "fred".GetMD5Hash(salt.Value);
_mockUserRepo.GetHashedPasswordByEmail(string.Empty).Returns(Task.FromResult(Tuple.Create(hashedPassword, salt)));

Assert.True(userService.CheckPassword(String.Empty, "fred").Result.Item1);
var result = await userService.CheckPassword(String.Empty, "fred");
Assert.True(result.Item1);
}

[Fact]
public void CheckPasswordFailsOnMD5FallbackNoMatch()
public async Task CheckPasswordFailsOnMD5FallbackNoMatch()
{
var userService = GetMockedUserService();
Guid? salt = Guid.NewGuid();
var hashedPassword = "fred".GetMD5Hash(salt.Value);
_mockUserRepo.GetHashedPasswordByEmail(string.Empty).Returns(Task.FromResult(Tuple.Create(hashedPassword, salt)));

Assert.False(userService.CheckPassword(String.Empty, "blah").Result.Item1);
var result = await userService.CheckPassword(String.Empty, "blah");
Assert.False(result.Item1);
}

[Fact]
public void CheckPasswordFailsMD5FallbackDoesNotCallUpdate()
public async Task CheckPasswordFailsMD5FallbackDoesNotCallUpdate()
{
var userService = GetMockedUserService();
Guid? salt = Guid.NewGuid();
Expand All @@ -135,12 +140,13 @@ public void CheckPasswordFailsMD5FallbackDoesNotCallUpdate()
_mockUserRepo.GetHashedPasswordByEmail(email).Returns(Task.FromResult(Tuple.Create(hashedPassword, salt)));
_mockUserRepo.GetUserByEmail(email).Returns(Task.FromResult(user));

Assert.False(userService.CheckPassword(email, "abc").Result.Item1);
_mockUserRepo.DidNotReceive().SetHashedPassword(Arg.Any<User>(), Arg.Any<string>(), Arg.Any<Guid>());
var result = await userService.CheckPassword(email, "blah");
Assert.False(result.Item1);
await _mockUserRepo.DidNotReceive().SetHashedPassword(Arg.Any<User>(), Arg.Any<string>(), Arg.Any<Guid>());
}

[Fact]
public void CheckPasswordPassesWithSaltOnMD5FallbackCallsUpdate()
public async Task CheckPasswordPassesWithSaltOnMD5FallbackCallsUpdate()
{
var userService = GetMockedUserService();
Guid? salt = Guid.NewGuid();
Expand All @@ -150,8 +156,9 @@ public void CheckPasswordPassesWithSaltOnMD5FallbackCallsUpdate()
_mockUserRepo.GetHashedPasswordByEmail(email).Returns(Task.FromResult(Tuple.Create(hashedPassword, salt)));
_mockUserRepo.GetUserByEmail(email).Returns(Task.FromResult(user));

Assert.True(userService.CheckPassword(email, "fred").Result.Item1);
_mockUserRepo.Received().SetHashedPassword(user, Arg.Any<string>(), Arg.Any<Guid>());
var result = await userService.CheckPassword(email, "fred");
Assert.True(result.Item1);
await _mockUserRepo.Received().SetHashedPassword(user, Arg.Any<string>(), Arg.Any<Guid>());
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion src/PopForums.Web/PopForums.Web.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<VersionPrefix>20.0.0-alpha1</VersionPrefix>
<AssemblyName>PopForums.Web</AssemblyName>
<PackageId>PopForums.Web</PackageId>
Expand Down
Loading

0 comments on commit a05dd49

Please sign in to comment.