From feb91abf3276222af8742bc37e9d989ca03be3f0 Mon Sep 17 00:00:00 2001 From: foefl Date: Fri, 27 Jun 2025 15:45:40 +0200 Subject: [PATCH] add context tests for injecting system cert stores, related to delta-barth/delta-barth-py#34 --- dopt.DeltaBarth.Tests/PluginTest.cs | 51 +++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/dopt.DeltaBarth.Tests/PluginTest.cs b/dopt.DeltaBarth.Tests/PluginTest.cs index 7d0acaa..c9b23df 100644 --- a/dopt.DeltaBarth.Tests/PluginTest.cs +++ b/dopt.DeltaBarth.Tests/PluginTest.cs @@ -6,6 +6,8 @@ namespace dopt.DeltaBarth.Tests { using System.Text.Encodings.Web; using Microsoft.Extensions.Configuration; + using Python.Runtime; + internal class Config { public string apiUrl; @@ -56,6 +58,41 @@ namespace dopt.DeltaBarth.Tests { base.Setup(datenPfad, basisApiUrl); } + public void TruststoreInjected() + { + using (Py.GIL()) + { + string code = @" +import pip_system_certs.wrapt_requests +pip_system_certs.wrapt_requests.inject_truststore() +import ssl +var1 = str(ssl.create_default_context()) +var2 = str(ssl.get_default_verify_paths()) +"; + dynamic pyScope = Py.CreateScope(); + pyScope.Exec(code); + dynamic var1 = pyScope.Get("var1"); + dynamic var2 = pyScope.Get("var2"); + Console.WriteLine($"Retrieved from Python: {var1}, {var2}"); + } + } + public void TruststoreDefault() + { + using (Py.GIL()) + { + string code = @" +import ssl +var1 = str(ssl.create_default_context()) +var2 = str(ssl.get_default_verify_paths()) +"; + dynamic pyScope = Py.CreateScope(); + pyScope.Exec(code); + dynamic var1 = pyScope.Get("var1"); + dynamic var2 = pyScope.Get("var2"); + Console.WriteLine($"Retrieved from Python: {var1}, {var2}"); + } + } + } [TestClass] public sealed class PluginTest @@ -267,5 +304,19 @@ namespace dopt.DeltaBarth.Tests Assert.AreEqual((int)StatusCodes.VerbindungTimeout, res.status.code); test.Dispose(); } + [TestMethod] + public void Set_SSLCertPaths_Inject_Test() + { + var test = new TPlugin(); + test.TruststoreInjected(); + test.Dispose(); + } + [TestMethod] + public void Set_SSLCertPaths_Default_Test() + { + var test = new TPlugin(); + test.TruststoreDefault(); + test.Dispose(); + } } }