From 92f456c6d8f8af9c184c99fa606f761ede8e6c86 Mon Sep 17 00:00:00 2001 From: Paul Volavsek Date: Thu, 12 Oct 2023 15:21:35 +0200 Subject: [PATCH 1/7] udpate deps --- .../fiskaltrust.Launcher.Common.csproj | 2 +- src/fiskaltrust.Launcher/fiskaltrust.Launcher.csproj | 5 +++-- .../fiskaltrust.Launcher.IntegrationTest.csproj | 10 +++++----- .../fiskaltrust.Launcher.UnitTest.csproj | 10 +++++----- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/fiskaltrust.Launcher.Common/fiskaltrust.Launcher.Common.csproj b/src/fiskaltrust.Launcher.Common/fiskaltrust.Launcher.Common.csproj index d25251fb..8c1d32d6 100644 --- a/src/fiskaltrust.Launcher.Common/fiskaltrust.Launcher.Common.csproj +++ b/src/fiskaltrust.Launcher.Common/fiskaltrust.Launcher.Common.csproj @@ -11,7 +11,7 @@ - + diff --git a/src/fiskaltrust.Launcher/fiskaltrust.Launcher.csproj b/src/fiskaltrust.Launcher/fiskaltrust.Launcher.csproj index f0c8e7cc..6fc2bb1d 100644 --- a/src/fiskaltrust.Launcher/fiskaltrust.Launcher.csproj +++ b/src/fiskaltrust.Launcher/fiskaltrust.Launcher.csproj @@ -15,8 +15,8 @@ - - + + @@ -33,6 +33,7 @@ + diff --git a/test/fiskaltrust.Launcher.IntegrationTest/fiskaltrust.Launcher.IntegrationTest.csproj b/test/fiskaltrust.Launcher.IntegrationTest/fiskaltrust.Launcher.IntegrationTest.csproj index 2f7a90c8..0ddf8ba4 100644 --- a/test/fiskaltrust.Launcher.IntegrationTest/fiskaltrust.Launcher.IntegrationTest.csproj +++ b/test/fiskaltrust.Launcher.IntegrationTest/fiskaltrust.Launcher.IntegrationTest.csproj @@ -9,11 +9,11 @@ - - - - - + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/test/fiskaltrust.Launcher.UnitTest/fiskaltrust.Launcher.UnitTest.csproj b/test/fiskaltrust.Launcher.UnitTest/fiskaltrust.Launcher.UnitTest.csproj index 2e2af6b0..550e8823 100644 --- a/test/fiskaltrust.Launcher.UnitTest/fiskaltrust.Launcher.UnitTest.csproj +++ b/test/fiskaltrust.Launcher.UnitTest/fiskaltrust.Launcher.UnitTest.csproj @@ -9,12 +9,12 @@ - + - - - - + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all From b3e270d14e4e6c1343167646f3b0215df20704c2 Mon Sep 17 00:00:00 2001 From: Paul Volavsek Date: Thu, 12 Oct 2023 15:23:50 +0200 Subject: [PATCH 2/7] register custom encoding provider --- .../Commands/HostCommand.cs | 2 ++ .../ProcessHost/ProcessHostMonarch.cs | 8 +++---- .../Services/EncodingProvider.cs | 22 +++++++++++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 src/fiskaltrust.Launcher/Services/EncodingProvider.cs diff --git a/src/fiskaltrust.Launcher/Commands/HostCommand.cs b/src/fiskaltrust.Launcher/Commands/HostCommand.cs index df24a6e3..90168609 100644 --- a/src/fiskaltrust.Launcher/Commands/HostCommand.cs +++ b/src/fiskaltrust.Launcher/Commands/HostCommand.cs @@ -90,6 +90,8 @@ public async Task InvokeAsync(InvocationContext context) .WriteTo.GrpcSink(packageConfiguration, processHostService) .CreateLogger(); + System.Text.Encoding.RegisterProvider(new LauncherEncodingProvider()); + var builder = Host.CreateDefaultBuilder() .UseSerilog() .ConfigureServices(services => diff --git a/src/fiskaltrust.Launcher/ProcessHost/ProcessHostMonarch.cs b/src/fiskaltrust.Launcher/ProcessHost/ProcessHostMonarch.cs index d8ad6bfb..881e57e0 100644 --- a/src/fiskaltrust.Launcher/ProcessHost/ProcessHostMonarch.cs +++ b/src/fiskaltrust.Launcher/ProcessHost/ProcessHostMonarch.cs @@ -40,10 +40,10 @@ public ProcessHostMonarch(ILogger logger, LauncherConfigurat "--launcher-configuration", $"\"{Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(launcherConfiguration.Serialize()))}\"", }); - if (Debugger.IsAttached) - { - _process.StartInfo.Arguments += " --debugging"; - } + // if (Debugger.IsAttached) + // { + // _process.StartInfo.Arguments += " --debugging"; + // } _process.StartInfo.RedirectStandardInput = true; _process.StartInfo.RedirectStandardError = true; _process.StartInfo.RedirectStandardOutput = true; diff --git a/src/fiskaltrust.Launcher/Services/EncodingProvider.cs b/src/fiskaltrust.Launcher/Services/EncodingProvider.cs new file mode 100644 index 00000000..ce30b40d --- /dev/null +++ b/src/fiskaltrust.Launcher/Services/EncodingProvider.cs @@ -0,0 +1,22 @@ +using System.Text; + +namespace fiskaltrust.Launcher.Services +{ + public class LauncherEncodingProvider : EncodingProvider + { + public override Encoding? GetEncoding(int codepage) => CodePagesEncodingProvider.Instance.GetEncoding(codepage); + + public override Encoding? GetEncoding(string name) + { + if ((name.StartsWith('"') && name.EndsWith('"')) || (name.StartsWith('\'') && name.EndsWith('\''))) + { + // This does not lead to an endless recursion, because every time the Encoding.GetEncoding(string) method calls this method either more quotes are trimmed and its recursed or null is returned. + return Encoding.GetEncoding(name.Substring(1, name.Length - 2)); + } + else + { + return null; + } + } + } +} \ No newline at end of file From 07af5d13a1363e5f6b17c9c705599141bb57558b Mon Sep 17 00:00:00 2001 From: Paul Volavsek Date: Thu, 12 Oct 2023 15:24:55 +0200 Subject: [PATCH 3/7] update version --- version.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.json b/version.json index c26f6ba5..773fde25 100644 --- a/version.json +++ b/version.json @@ -1,5 +1,5 @@ { - "version": "2.0.0-rc.8", + "version": "2.0.0-rc.9", "releaseBranches": [ "^refs/tags/v\\d+(?:\\.\\d+)*(?:-.*)?$" ] From 17048edf3a9b073a3410b19a39957b2bf254791c Mon Sep 17 00:00:00 2001 From: Paul Volavsek Date: Thu, 12 Oct 2023 15:34:04 +0200 Subject: [PATCH 4/7] fix tests --- azure-pipelines/templates/stages/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines/templates/stages/test.yml b/azure-pipelines/templates/stages/test.yml index f9791a67..704bdecc 100644 --- a/azure-pipelines/templates/stages/test.yml +++ b/azure-pipelines/templates/stages/test.yml @@ -49,7 +49,7 @@ stages: - job: TestMacOS pool: - vmImage: macos-latest + vmImage: macos-11 steps: - template: ../restore.yml From f2116f64c760598dd8413eafcd938697e93bc8e3 Mon Sep 17 00:00:00 2001 From: Paul Volavsek Date: Fri, 13 Oct 2023 10:12:06 +0200 Subject: [PATCH 5/7] review --- .../Services/EncodingProvider.cs | 18 ++++++++++-------- .../fiskaltrust.Launcher.csproj | 1 - 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/fiskaltrust.Launcher/Services/EncodingProvider.cs b/src/fiskaltrust.Launcher/Services/EncodingProvider.cs index ce30b40d..ba51c483 100644 --- a/src/fiskaltrust.Launcher/Services/EncodingProvider.cs +++ b/src/fiskaltrust.Launcher/Services/EncodingProvider.cs @@ -4,19 +4,21 @@ namespace fiskaltrust.Launcher.Services { public class LauncherEncodingProvider : EncodingProvider { - public override Encoding? GetEncoding(int codepage) => CodePagesEncodingProvider.Instance.GetEncoding(codepage); + public override Encoding? GetEncoding(int codepage) => null; public override Encoding? GetEncoding(string name) { - if ((name.StartsWith('"') && name.EndsWith('"')) || (name.StartsWith('\'') && name.EndsWith('\''))) + try { - // This does not lead to an endless recursion, because every time the Encoding.GetEncoding(string) method calls this method either more quotes are trimmed and its recursed or null is returned. - return Encoding.GetEncoding(name.Substring(1, name.Length - 2)); - } - else - { - return null; + if ((name.StartsWith('"') && name.EndsWith('"')) || (name.StartsWith('\'') && name.EndsWith('\''))) + { + // This does not lead to an endless recursion, because every time the Encoding.GetEncoding(string) method calls this method either more quotes are trimmed and its recursed or null is returned. + return Encoding.GetEncoding(name.Substring(1, name.Length - 2)); + } } + catch { } + + return null; } } } \ No newline at end of file diff --git a/src/fiskaltrust.Launcher/fiskaltrust.Launcher.csproj b/src/fiskaltrust.Launcher/fiskaltrust.Launcher.csproj index 6fc2bb1d..3b00a172 100644 --- a/src/fiskaltrust.Launcher/fiskaltrust.Launcher.csproj +++ b/src/fiskaltrust.Launcher/fiskaltrust.Launcher.csproj @@ -33,7 +33,6 @@ - From de46c3b32f8f3863504b01988b574eec850921a4 Mon Sep 17 00:00:00 2001 From: Paul Volavsek Date: Fri, 13 Oct 2023 10:24:35 +0200 Subject: [PATCH 6/7] add tests --- .../Helpers/EncodingProvider.cs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 test/fiskaltrust.Launcher.UnitTest/Helpers/EncodingProvider.cs diff --git a/test/fiskaltrust.Launcher.UnitTest/Helpers/EncodingProvider.cs b/test/fiskaltrust.Launcher.UnitTest/Helpers/EncodingProvider.cs new file mode 100644 index 00000000..e0d9b3e0 --- /dev/null +++ b/test/fiskaltrust.Launcher.UnitTest/Helpers/EncodingProvider.cs @@ -0,0 +1,25 @@ +using System.Text; +using fiskaltrust.Launcher.Common; +using fiskaltrust.Launcher.Services; +using FluentAssertions; +using Xunit; + +namespace fiskaltrust.Launcher.UnitTest.Helpers +{ + public class LauncherEncodingProviderTest + { + [Fact] + public void GetEncoding_ReturnsUtf8Encoding() + { + var provider = new LauncherEncodingProvider(); + + Encoding.RegisterProvider(provider); + + provider.GetEncoding("\"UTF-8\"").Should().Be(Encoding.UTF8); + provider.GetEncoding("UTF-8").Should().Be(null); + + Encoding.GetEncoding("\"UTF-8\"").Should().Be(Encoding.UTF8); + Encoding.GetEncoding("UTF-8").Should().Be(Encoding.UTF8); + } + } +} \ No newline at end of file From aa25c10d4cb92f998bac3e7c5f192b29916de4f1 Mon Sep 17 00:00:00 2001 From: Paul Volavsek Date: Fri, 13 Oct 2023 10:29:09 +0200 Subject: [PATCH 7/7] add doc comment --- src/fiskaltrust.Launcher/Services/EncodingProvider.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/fiskaltrust.Launcher/Services/EncodingProvider.cs b/src/fiskaltrust.Launcher/Services/EncodingProvider.cs index ba51c483..8f2d7e47 100644 --- a/src/fiskaltrust.Launcher/Services/EncodingProvider.cs +++ b/src/fiskaltrust.Launcher/Services/EncodingProvider.cs @@ -6,6 +6,10 @@ public class LauncherEncodingProvider : EncodingProvider { public override Encoding? GetEncoding(int codepage) => null; + // This EncodingProvider needs to be registered in the plebian processes + // because ASP.NET Core uses the Encoding.GetEncoding(string) method to parse the charset of the Content-Type header. + // According to the http standard (https://datatracker.ietf.org/doc/html/rfc7231#section-3.1.1.1) the charset may be wrapped in quotes. + // Until this is fixed in ASP.NET we'll need the workaround below. public override Encoding? GetEncoding(string name) { try