Add OpenSslLegacyShim to ensure OpenSSL 1.1 libraries are accessible on Linux
Some checks failed
Docs CI / lint-and-preview (push) Has been cancelled

This commit introduces the OpenSslLegacyShim class, which sets the LD_LIBRARY_PATH environment variable to include the directory containing OpenSSL 1.1 native libraries. This is necessary for Mongo2Go to function correctly on Linux platforms that do not ship these libraries by default. The shim checks if the current operating system is Linux and whether the required directory exists before modifying the environment variable.
This commit is contained in:
master
2025-11-02 21:41:03 +02:00
parent f98cea3bcf
commit 1d962ee6fc
71 changed files with 3675 additions and 1255 deletions

View File

@@ -0,0 +1,43 @@
using System;
using System.IO;
using System.Linq;
namespace StellaOps.Testing;
/// <summary>
/// Ensures OpenSSL 1.1 native libraries are visible to Mongo2Go on platforms that no longer ship them.
/// </summary>
public static class OpenSslLegacyShim
{
private const string LinuxLibraryVariable = "LD_LIBRARY_PATH";
public static void EnsureOpenSsl11()
{
if (!OperatingSystem.IsLinux())
{
return;
}
var nativeDirectory = Path.Combine(AppContext.BaseDirectory, "native", "linux-x64");
if (!Directory.Exists(nativeDirectory))
{
return;
}
var current = Environment.GetEnvironmentVariable(LinuxLibraryVariable);
if (string.IsNullOrEmpty(current))
{
Environment.SetEnvironmentVariable(LinuxLibraryVariable, nativeDirectory);
return;
}
const char separator = ':';
var segments = current.Split(separator, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
if (segments.Contains(nativeDirectory, StringComparer.Ordinal))
{
return;
}
Environment.SetEnvironmentVariable(LinuxLibraryVariable, string.Concat(nativeDirectory, separator, current));
}
}