Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dotnet 8 #293

Merged
merged 7 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/lexbox-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ jobs:

steps:
- uses: actions/checkout@v3

- uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.x'
- name: Dotnet build
run: dotnet build
- name: Unit tests
Expand Down
13 changes: 9 additions & 4 deletions backend/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
<Project>
<PropertyGroup Condition="$(DockerDev) == 'true'">
<IntermediateOutputPath>/app/obj/</IntermediateOutputPath>
<OutputPath>/app/bin/</OutputPath>
<PropertyGroup>
<DefaultItemExcludes>$(DefaultItemExcludes);$(MSBuildProjectDirectory)/obj/**/*</DefaultItemExcludes>
<DefaultItemExcludes>$(DefaultItemExcludes);$(MSBuildProjectDirectory)/bin/**/*</DefaultItemExcludes>
</PropertyGroup>

<PropertyGroup Condition="'$(DOTNET_RUNNING_IN_CONTAINER)' == 'true'">
<BaseIntermediateOutputPath>$(MSBuildProjectDirectory)/obj/container/</BaseIntermediateOutputPath>
<BaseOutputPath>$(MSBuildProjectDirectory)/bin/container/</BaseOutputPath>
</PropertyGroup>
<PropertyGroup>
<EnforceCodeStyleInBuild>false</EnforceCodeStyleInBuild>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.6.40" PrivateAssets="all"/>
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.8.14" PrivateAssets="all"/>
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# syntax=docker/dockerfile:1
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build

COPY . .
# WORKDIR /src
Expand Down
2 changes: 1 addition & 1 deletion backend/FixFwData/FixFwData.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Authors>SIL International</Authors>
<Product>LexBoxApi Testing</Product>
<Copyright>Copyright © 2023 SIL International</Copyright>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion backend/LexBoxApi/Auth/JwtTicketDataFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static string ConvertAuthTicketToJwt(AuthenticationTicket data,
{
var jwtDate = DateTime.UtcNow;
_jwtSecurityTokenHandler.MapInboundClaims = jwtBearerOptions.MapInboundClaims;
var claimsIdentity = new ClaimsIdentity(data.Principal.Claims, data.Principal.Identity?.AuthenticationType);
var claimsIdentity = new ClaimsIdentity(data.Principal.Claims.Where(c => c.Type != JwtRegisteredClaimNames.Jti), data.Principal.Identity?.AuthenticationType);
var keyId = Guid.NewGuid().ToString().GetHashCode().ToString("x", CultureInfo.InvariantCulture);
claimsIdentity.AddClaim(new Claim(JwtRegisteredClaimNames.Jti, keyId));
//there may already be an audience claim, we want to reuse that if it exists, if not fallback to the default audience
Expand Down
1 change: 1 addition & 0 deletions backend/LexBoxApi/GraphQL/GraphQlSetupKernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public static void AddLexGraphQL(this IServiceCollection services, IHostEnvironm
{
options.IncludeExceptionDetails = true;
})
.AddType<DbErrorCode>()
.AddType(new DateTimeType("DateTime"))
.AddType(new UuidType("UUID"))
.AddType(new DateTimeType("timestamptz"))
Expand Down
43 changes: 22 additions & 21 deletions backend/LexBoxApi/LexBoxApi.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>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
Expand All @@ -10,35 +10,36 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="DataAnnotatedModelValidations" Version="4.1.0" />
<PackageReference Include="HotChocolate.Types.Analyzers" Version="13.5.1">
<PackageReference Include="DataAnnotatedModelValidations" Version="5.0.0" />
<PackageReference Include="HotChocolate.Analyzers" Version="13.7.0" />
<PackageReference Include="HotChocolate.Types.Analyzers" Version="13.7.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="HotChocolate.AspNetCore" Version="13.5.1" />
<PackageReference Include="HotChocolate.AspNetCore.Authorization" Version="13.5.1" />
<PackageReference Include="HotChocolate.Data.EntityFramework" Version="13.5.1" />
<PackageReference Include="HotChocolate.Diagnostics" Version="13.5.1" />
<PackageReference Include="HotChocolate.AspNetCore" Version="13.7.0" />
<PackageReference Include="HotChocolate.AspNetCore.Authorization" Version="13.7.0" />
<PackageReference Include="HotChocolate.Data.EntityFramework" Version="13.7.0" />
<PackageReference Include="HotChocolate.Diagnostics" Version="13.7.0" />
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
<PackageReference Include="MailKit" Version="4.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.3" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.2">
<PackageReference Include="MailKit" Version="4.3.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Nito.AsyncEx.Coordination" Version="5.1.2" />
<PackageReference Include="Npgsql.OpenTelemetry" Version="7.0.2" />
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.5.1" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.5.1" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.5.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.5.0-beta.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.EntityFrameworkCore" Version="1.0.0-beta.7" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.5.0-beta.1" />
<PackageReference Include="Npgsql.OpenTelemetry" Version="8.0.0" />
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.6.0" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.6.0" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.6.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.6.0-beta.3" />
<PackageReference Include="OpenTelemetry.Instrumentation.EntityFrameworkCore" Version="1.0.0-beta.8" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.6.0-beta.3" />
<PackageReference Include="OpenTelemetry.Instrumentation.Process" Version="0.5.0-beta.3" />
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
<PackageReference Include="tusdotnet" Version="2.7.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.5.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="tusdotnet" Version="2.7.2" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 1 addition & 2 deletions backend/LexBoxApi/dev.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# syntax=docker/dockerfile:1
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
EXPOSE 80
EXPOSE 443
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
Expand All @@ -14,5 +14,4 @@ RUN for file in $(ls *.csproj); do dir=${file%.*} mkdir -p ${file%.*}/ && mv $fi
COPY . .
WORKDIR /src/backend/LexBoxApi
RUN mkdir /src/frontend
ENV DockerDev=true
CMD dotnet watch run -lp docker --property:InformationalVersion=dockerDev
4 changes: 2 additions & 2 deletions backend/LexCore/LexCore.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<InformationalVersion>dev</InformationalVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EntityFrameworkCore.Projectables.Abstractions" Version="3.0.3" />
<PackageReference Include="EntityFrameworkCore.Projectables.Abstractions" Version="3.0.4" />
</ItemGroup>

</Project>
18 changes: 9 additions & 9 deletions backend/LexData/LexData.csproj
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<InformationalVersion>dev</InformationalVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EntityFrameworkCore.Projectables" Version="3.0.3" />
<PackageReference Include="EntityFrameworkCore.Projectables" Version="3.0.4" />
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.3">
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="7.0.5" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.1" />
<PackageReference Include="Microsoft.Extensions.Options.DataAnnotations" Version="7.0.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.3" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.DataAnnotations" Version="8.0.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.0" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="7.0.0" />
</ItemGroup>

Expand Down
3 changes: 1 addition & 2 deletions backend/SyncReverseProxy/Auth/BasicAuthHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ public class BasicAuthHandler : AuthenticationHandler<AuthenticationSchemeOption
public BasicAuthHandler(IOptionsMonitor<AuthenticationSchemeOptions> options,
ILoggerFactory logger,
UrlEncoder encoder,
ISystemClock clock,
ILexProxyService lexProxyService,
IMemoryCache memoryCache) : base(options, logger, encoder, clock)
IMemoryCache memoryCache) : base(options, logger, encoder)
{
_lexProxyService = lexProxyService;
_memoryCache = memoryCache;
Expand Down
24 changes: 12 additions & 12 deletions backend/SyncReverseProxy/SyncReverseProxy.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>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
Expand All @@ -10,17 +10,17 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.2" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.15.1" />
<PackageReference Include="Yarp.ReverseProxy" Version="2.0.1" />

<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.5.1" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.5.1" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.5.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.5.0-beta.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.5.0-beta.1" />
<PackageReference Include="Yarp.Telemetry.Consumption" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.0.3" />
<PackageReference Include="Yarp.ReverseProxy" Version="2.1.0" />

<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.6.0" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.6.0" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.6.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.6.0-beta.3" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.6.0-beta.3" />
<PackageReference Include="Yarp.Telemetry.Consumption" Version="2.1.0" />

</ItemGroup>

Expand Down
38 changes: 33 additions & 5 deletions backend/Testing/LexCore/LexAuthUserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.Extensions.Options;
using Microsoft.IdentityModel.Logging;
using Microsoft.IdentityModel.Tokens;
using Shouldly;

namespace Testing.LexCore;

public class LexAuthUserTests
{
static LexAuthUserTests()
{
IdentityModelEventSource.ShowPII = true;
}
private readonly LexAuthService _lexAuthService = new LexAuthService(
new OptionsWrapper<JwtOptions>(JwtOptions.TestingOptions),
null,
Expand All @@ -30,6 +35,12 @@ public class LexAuthUserTests
Projects = new[] { new AuthUserProject("test-flex", ProjectRole.Manager, Guid.NewGuid()) }
};

private static readonly JwtBearerOptions JwtBearerOptions = new()
{
TokenValidationParameters = LexAuthService.TokenValidationParameters(JwtOptions.TestingOptions),
MapInboundClaims = false
};

[Fact]
public void CanGetClaimsFromUser()
{
Expand Down Expand Up @@ -73,11 +84,7 @@ public void CanRoundTripClaimsWhenUsingSecurityTokenDescriptor()
var jwt = JwtTicketDataFormat.ConvertAuthTicketToJwt(
new AuthenticationTicket(_user.GetPrincipal("test"), "test"),
"testing",
new JwtBearerOptions
{
TokenValidationParameters = LexAuthService.TokenValidationParameters(jwtUserOptions),
MapInboundClaims = false
},
JwtBearerOptions,
jwtUserOptions
);
var tokenHandler = new JwtSecurityTokenHandler();
Expand All @@ -97,4 +104,25 @@ public void CanRoundTripJwtFromUserThroughLexAuthService()
var newUser = LexAuthUser.FromClaimsPrincipal(principal);
_user.ShouldBeEquivalentTo(newUser);
}

[Fact]
public void CanRoundTripThroughRefresh()
{
var (forgotJwt, _) = _lexAuthService.GenerateJwt(_user, audience:LexboxAudience.ForgotPassword);
//simulate parsing the token into a claims principal
var tokenHandler = new JwtSecurityTokenHandler();
var forgotPrincipal = new ClaimsPrincipal(new ClaimsIdentity(tokenHandler.ReadJwtToken(forgotJwt).Claims, "Testing"));

//simulate redirect refreshing the token
var redirectJwt = JwtTicketDataFormat.ConvertAuthTicketToJwt(
new AuthenticationTicket(forgotPrincipal, "test"),
"testing",
JwtBearerOptions,
JwtOptions.TestingOptions
);

var loggedInPrincipal = new ClaimsPrincipal(new ClaimsIdentity(tokenHandler.ReadJwtToken(redirectJwt).Claims, "Testing"));
var newUser = LexAuthUser.FromClaimsPrincipal(loggedInPrincipal);
(_user with { Audience = LexboxAudience.ForgotPassword }).ShouldBeEquivalentTo(newUser);
}
}
34 changes: 17 additions & 17 deletions backend/Testing/Testing.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

Expand All @@ -10,29 +10,29 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="Microsoft.Playwright" Version="1.35.0" />
<PackageReference Include="Microsoft.Playwright.TestAdapter" Version="1.35.0" />
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="Shouldly" Version="4.1.0" />
<PackageReference Include="SIL.Chorus.LibChorus" Version="5.2.0-beta0005" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Microsoft.Playwright" Version="1.39.0" />
<PackageReference Include="Microsoft.Playwright.TestAdapter" Version="1.39.0" />
<PackageReference Include="Moq" Version="4.20.69" />
<PackageReference Include="Shouldly" Version="4.2.1" />
<PackageReference Include="SIL.Chorus.LibChorus" Version="6.0.0-beta0041" />
<PackageReference Include="SIL.Chorus.Mercurial" Version="3.0.3.11" />
<PackageReference Include="SIL.ChorusPlugin.LfMergeBridge" Version="4.0.1" />
<PackageReference Include="SIL.Core" Version="12.1.0-beta0031" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.15.1" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="SIL.ChorusPlugin.LfMergeBridge" Version="4.1.0" />
<PackageReference Include="SIL.Core" Version="13.0.0-beta0074" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.0.3" />
<PackageReference Include="xunit" Version="2.6.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.4">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="XunitXml.TestLogger" Version="3.0.78" />
<PackageReference Include="XunitXml.TestLogger" Version="3.1.17" />
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions deployment/base/lexbox-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ spec:
selector:
matchLabels:
app: lexbox
progressDeadlineSeconds: 60
strategy:
rollingUpdate:
maxSurge: 2
Expand Down
Loading