Skip to content

Commit

Permalink
refactor: removed flags tlsEnabled and tlsVerifyEnabled
Browse files Browse the repository at this point in the history
  • Loading branch information
vlaskal committed Oct 13, 2022
1 parent 8da5ab3 commit 2e11eae
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -21,7 +22,7 @@ public abstract class ProtectDockerDaemonSocket : IAsyncLifetime

private readonly IDockerImage image = new DockerImage(string.Empty, "docker", DockerVersion + "-dind");

public ProtectDockerDaemonSocket(ITestcontainersBuilder<TestcontainersContainer> containerConfiguration)
protected ProtectDockerDaemonSocket(ITestcontainersBuilder<TestcontainersContainer> containerConfiguration)
{
this.container = containerConfiguration
.WithImage(this.image)
Expand All @@ -33,13 +34,24 @@ public ProtectDockerDaemonSocket(ITestcontainersBuilder<TestcontainersContainer>
.Build();
}

public string ContainerCertDirectoryPath { get; }
internal ICustomConfiguration CustomConfiguration
{
get
{
var properties = new List<string>();
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
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<string>();
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<DockerMTlsFixture>
{
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]
Expand All @@ -57,13 +40,8 @@ public sealed class Tls : IClassFixture<DockerTlsFixture>
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]
Expand Down

0 comments on commit 2e11eae

Please sign in to comment.