-
-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(#370): Added working test for simple TLS endpoint
- Loading branch information
Showing
3 changed files
with
116 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 0 additions & 44 deletions
44
tests/Testcontainers.Tests/Unit/Containers/Unix/DockerTlsTest.cs
This file was deleted.
Oops, something went wrong.
80 changes: 80 additions & 0 deletions
80
tests/Testcontainers.Tests/Unit/Containers/Unix/DockerTlsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
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; | ||
using DotNet.Testcontainers.Configurations; | ||
using DotNet.Testcontainers.Tests.Fixtures; | ||
using Microsoft.Extensions.Logging.Abstractions; | ||
using Xunit; | ||
|
||
public static class DockerTlsTests | ||
{ | ||
private static ICustomConfiguration CreateConfiguration(DockerTlsFixtures fixture, bool tls = false, bool tlsVerify = false) | ||
{ | ||
var properties = new List<string>(); | ||
properties.Add($"docker.host={fixture.TcpEndpoint}"); | ||
properties.Add($"docker.cert.path={Path.Combine(fixture.HostCertDirectoryPath, "client")}"); | ||
properties.Add($"docker.tls={tls}"); | ||
properties.Add($"docker.tls.verify={tlsVerify}"); | ||
return new PropertiesFileConfiguration(properties.ToArray()); | ||
} | ||
|
||
public sealed class DockerTlsTest : IClassFixture<DockerTlsFixtures.DockerTlsFixture> | ||
{ | ||
private readonly ICustomConfiguration customConfiguration; | ||
private readonly string expectedVersion; | ||
|
||
public DockerTlsTest(DockerTlsFixtures.DockerTlsFixture dockerTlsFixture) | ||
{ | ||
this.customConfiguration = CreateConfiguration(dockerTlsFixture, true); | ||
this.expectedVersion = dockerTlsFixture.Version; | ||
} | ||
|
||
[Fact] | ||
public async Task GetVersionReturnsVersion() | ||
{ | ||
// Given | ||
var authConfig = new TlsEndpointAuthenticationProvider(this.customConfiguration).GetAuthConfig(); | ||
|
||
// When | ||
var systemOperations = new DockerSystemOperations(Guid.Empty, authConfig, NullLogger.Instance); | ||
var version = await systemOperations.GetVersion() | ||
.ConfigureAwait(false); | ||
|
||
// Then | ||
Assert.Equal(this.expectedVersion, version.Version); | ||
} | ||
} | ||
|
||
public sealed class DockerMTlsTest : IClassFixture<DockerTlsFixtures.DockerMTlsFixture> | ||
{ | ||
private readonly ICustomConfiguration customConfiguration; | ||
private readonly string expectedVersion; | ||
|
||
public DockerMTlsTest(DockerTlsFixtures.DockerMTlsFixture dockerMTlsFixture) | ||
{ | ||
this.customConfiguration = CreateConfiguration(dockerMTlsFixture, tlsVerify: true); | ||
this.expectedVersion = dockerMTlsFixture.Version; | ||
} | ||
|
||
[Fact] | ||
public async Task GetVersionReturnsVersion() | ||
{ | ||
// Given | ||
var authConfig = new MTlsEndpointAuthenticationProvider(this.customConfiguration).GetAuthConfig(); | ||
|
||
// When | ||
var systemOperations = new DockerSystemOperations(Guid.Empty, authConfig, NullLogger.Instance); | ||
var version = await systemOperations.GetVersion() | ||
.ConfigureAwait(false); | ||
|
||
// Then | ||
Assert.Equal(this.expectedVersion, version.Version); | ||
} | ||
} | ||
} | ||
} |