From 2e11eaec65d6e0d12395cd1cb5e8cf0aab24728e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vlastimil=20Kalu=C5=BEa?= Date: Thu, 13 Oct 2022 22:46:17 +0200 Subject: [PATCH] refactor: removed flags tlsEnabled and tlsVerifyEnabled --- .../Unix/ProtectDockerDaemonSocket.cs | 22 ++++++++++++---- .../Unix/ProtectDockerDaemonSocketTest.cs | 26 ++----------------- 2 files changed, 19 insertions(+), 29 deletions(-) diff --git a/tests/Testcontainers.Tests/Fixtures/Containers/Unix/ProtectDockerDaemonSocket.cs b/tests/Testcontainers.Tests/Fixtures/Containers/Unix/ProtectDockerDaemonSocket.cs index bfba65720..36b18de11 100644 --- a/tests/Testcontainers.Tests/Fixtures/Containers/Unix/ProtectDockerDaemonSocket.cs +++ b/tests/Testcontainers.Tests/Fixtures/Containers/Unix/ProtectDockerDaemonSocket.cs @@ -1,6 +1,7 @@ -namespace DotNet.Testcontainers.Tests.Fixtures +namespace DotNet.Testcontainers.Tests.Fixtures { using System; + using System.Collections.Generic; using System.IO; using System.Threading.Tasks; using DotNet.Testcontainers.Builders; @@ -21,7 +22,7 @@ public abstract class ProtectDockerDaemonSocket : IAsyncLifetime private readonly IDockerImage image = new DockerImage(string.Empty, "docker", DockerVersion + "-dind"); - public ProtectDockerDaemonSocket(ITestcontainersBuilder containerConfiguration) + protected ProtectDockerDaemonSocket(ITestcontainersBuilder containerConfiguration) { this.container = containerConfiguration .WithImage(this.image) @@ -33,13 +34,24 @@ public ProtectDockerDaemonSocket(ITestcontainersBuilder .Build(); } - public string ContainerCertDirectoryPath { get; } + internal ICustomConfiguration CustomConfiguration + { + get + { + var properties = new List(); + properties.Add($"docker.host={this.TcpEndpoint}"); + properties.Add($"docker.cert.path={Path.Combine(this.HostCertDirectoryPath, "client")}"); + return new PropertiesFileConfiguration(properties.ToArray()); + } + } + + private string ContainerCertDirectoryPath { get; } = Path.Combine("/", CertsDirectoryName); - public string HostCertDirectoryPath { get; } + private string HostCertDirectoryPath { get; } = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("D"), CertsDirectoryName); - public Uri TcpEndpoint + private Uri TcpEndpoint { get { diff --git a/tests/Testcontainers.Tests/Unit/Containers/Unix/ProtectDockerDaemonSocketTest.cs b/tests/Testcontainers.Tests/Unit/Containers/Unix/ProtectDockerDaemonSocketTest.cs index 162a4a0c3..23099a1fc 100644 --- a/tests/Testcontainers.Tests/Unit/Containers/Unix/ProtectDockerDaemonSocketTest.cs +++ b/tests/Testcontainers.Tests/Unit/Containers/Unix/ProtectDockerDaemonSocketTest.cs @@ -1,8 +1,6 @@ namespace DotNet.Testcontainers.Tests.Unit.Containers.Unix { using System; - using System.Collections.Generic; - using System.IO; using System.Threading.Tasks; using DotNet.Testcontainers.Builders; using DotNet.Testcontainers.Clients; @@ -13,28 +11,13 @@ namespace DotNet.Testcontainers.Tests.Unit.Containers.Unix public static class ProtectDockerDaemonSocketTest { - private static ICustomConfiguration GetCustomConfiguration(ProtectDockerDaemonSocket protectDockerDaemonSocket, bool tlsEnabled, bool tlsVerifyEnabled) - { - var properties = new List(); - properties.Add($"docker.host={protectDockerDaemonSocket.TcpEndpoint}"); - properties.Add($"docker.cert.path={Path.Combine(protectDockerDaemonSocket.HostCertDirectoryPath, "client")}"); - properties.Add($"docker.tls={tlsEnabled}"); - properties.Add($"docker.tls.verify={tlsVerifyEnabled}"); - return new PropertiesFileConfiguration(properties.ToArray()); - } - public sealed class MTls : IClassFixture { private readonly IDockerEndpointAuthenticationConfiguration authConfig; public MTls(DockerMTlsFixture dockerMTlsFixture) - : this(GetCustomConfiguration(dockerMTlsFixture, false, false)) { - } - - private MTls(ICustomConfiguration customConfiguration) - { - this.authConfig = new MTlsEndpointAuthenticationProvider(customConfiguration).GetAuthConfig(); + this.authConfig = new MTlsEndpointAuthenticationProvider(dockerMTlsFixture.CustomConfiguration).GetAuthConfig(); } [Fact] @@ -57,13 +40,8 @@ public sealed class Tls : IClassFixture private readonly IDockerEndpointAuthenticationConfiguration authConfig; public Tls(DockerTlsFixture dockerTlsFixture) - : this(GetCustomConfiguration(dockerTlsFixture, false, false)) - { - } - - private Tls(ICustomConfiguration customConfiguration) { - this.authConfig = new TlsEndpointAuthenticationProvider(customConfiguration).GetAuthConfig(); + this.authConfig = new TlsEndpointAuthenticationProvider(dockerTlsFixture.CustomConfiguration).GetAuthConfig(); } [Fact]