Try to set Docker endpoint correctly for TLS
This commit is contained in:
parent
0e086b3b6c
commit
679c2c9af3
5 changed files with 67 additions and 3 deletions
|
@ -18,6 +18,9 @@ test:
|
|||
PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/docker
|
||||
script:
|
||||
- curl https://download.docker.com/linux/static/stable/x86_64/docker-20.10.4.tgz | tar -xzv -C /usr/local/
|
||||
- mkdir /usr/local/share/ca-certificates/docker-ca
|
||||
- cp "${DOCKER_CERT_PATH}/ca.pem" /usr/local/share/ca-certificates/docker-ca/
|
||||
- update-ca-certificates --fresh
|
||||
- dotnet tool restore
|
||||
- dotnet nuke Test
|
||||
|
||||
|
|
36
tests/INetMock.Client.IntegrationTest/DockerEndpoint.cs
Normal file
36
tests/INetMock.Client.IntegrationTest/DockerEndpoint.cs
Normal file
|
@ -0,0 +1,36 @@
|
|||
using System;
|
||||
using System.Globalization;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace INetMock.Client.IntegrationTest
|
||||
{
|
||||
internal static class DockerEndpoint
|
||||
{
|
||||
private const string DockerHostEnvName = "DOCKER_HOST";
|
||||
private const string DockerTlsVerifyEnvName = "DOCKER_TLS_VERIFY";
|
||||
|
||||
internal static string DetermineFromEnv() => DetermineEndpoint(
|
||||
Environment.GetEnvironmentVariable(DockerHostEnvName),
|
||||
Environment.GetEnvironmentVariable(DockerTlsVerifyEnvName)
|
||||
);
|
||||
|
||||
internal static string DetermineEndpoint(string? dockerHost, string? tlsVerify)
|
||||
{
|
||||
dockerHost ??= "";
|
||||
var dockerTlsVerify = int.TryParse(tlsVerify, out var verify) && verify == 1;
|
||||
var isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
|
||||
return (dockerHost, dockerTlsVerify, isWindows) switch
|
||||
{
|
||||
("", _, true) => "npipe://./pipe/docker_engine",
|
||||
("", _, false) => "unix:/var/run/docker.sock",
|
||||
(_, false, _) => dockerHost,
|
||||
(var h, true, _) when h.StartsWith("tcp") => h.Replace(
|
||||
"tcp",
|
||||
"https",
|
||||
true,
|
||||
CultureInfo.InvariantCulture),
|
||||
_ => "",
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
22
tests/INetMock.Client.IntegrationTest/DockerEndpointTests.cs
Normal file
22
tests/INetMock.Client.IntegrationTest/DockerEndpointTests.cs
Normal file
|
@ -0,0 +1,22 @@
|
|||
using Xunit;
|
||||
|
||||
namespace INetMock.Client.IntegrationTest
|
||||
{
|
||||
public class DockerEndpointTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(null, null, "unix:/var/run/docker.sock")]
|
||||
[InlineData("tcp://docker:2375", null, "tcp://docker:2375")]
|
||||
[InlineData("tcp://docker:2375", "0", "tcp://docker:2375")]
|
||||
[InlineData("http://docker:2375", null, "http://docker:2375")]
|
||||
[InlineData("http://docker:2375", "0", "http://docker:2375")]
|
||||
[InlineData("tcp://docker:2376", "1", "https://docker:2376")]
|
||||
[InlineData("https://docker:2376", "0", "https://docker:2376")]
|
||||
public void DetermineDockerEndpoint_Input_ExpectedOutput(string? dockerHost, string? tlsVerify, string expected)
|
||||
{
|
||||
var actual = DockerEndpoint.DetermineEndpoint(dockerHost, tlsVerify);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,6 +4,8 @@
|
|||
<TargetFramework>net5.0</TargetFramework>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -10,6 +10,7 @@ namespace INetMock.Client.IntegrationTest
|
|||
{
|
||||
public class INetMockServerFixture : IAsyncLifetime
|
||||
{
|
||||
|
||||
private readonly TestcontainersContainer _inetmockContainer;
|
||||
|
||||
public INetMockServerFixture()
|
||||
|
@ -19,13 +20,13 @@ namespace INetMock.Client.IntegrationTest
|
|||
.WithCommand("serve")
|
||||
.WithPortBinding(80, true)
|
||||
.WithWaitStrategy(Wait.ForUnixContainer().UntilPortIsAvailable(80))
|
||||
.WithDockerEndpoint(Environment.GetEnvironmentVariable("DOCKER_HOST") ?? "unix:///var/run/docker.sock")
|
||||
.WithDockerEndpoint(DockerEndpoint.DetermineFromEnv())
|
||||
.WithMount(Path.GetTempPath(), "/var/run/inetmock")
|
||||
.WithCleanUp(true)
|
||||
.Build();
|
||||
}
|
||||
|
||||
public Uri SocketPath => new ($"unix://{Path.Join(Path.GetTempPath(), "inetmock.sock")}", UriKind.Absolute);
|
||||
public Uri SocketPath => new($"unix://{Path.Join(Path.GetTempPath(), "inetmock.sock")}", UriKind.Absolute);
|
||||
|
||||
public async Task InitializeAsync()
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue