Skip to content

Commit c0a568e

Browse files
committed
test: Add test to verify key created with openssl 3.1 is working. Verify key types in both tests
1 parent 60eb15e commit c0a568e

File tree

4 files changed

+59
-2
lines changed

4 files changed

+59
-2
lines changed

tests/Testcontainers.Tests/Fixtures/Containers/Unix/DockerMTls.cs

+11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
namespace DotNet.Testcontainers.Tests.Fixtures
22
{
33
using System.Collections.Generic;
4+
using System.IO;
45
using DotNet.Testcontainers.Builders;
6+
using Org.BouncyCastle.OpenSsl;
57

68
public abstract class DockerMTls : ProtectDockerDaemonSocket
79
{
@@ -10,6 +12,15 @@ public DockerMTls(string dockerImageVersion)
1012
{
1113
}
1214

15+
public object ClientCertificateKey()
16+
{
17+
var path = Path.Combine(_hostCertsDirectoryPath, "client", "key.pem");
18+
using (var keyFileStream = new StreamReader(path))
19+
{
20+
return new PemReader(keyFileStream).ReadObject();
21+
}
22+
}
23+
1324
public override IList<string> CustomProperties
1425
{
1526
get
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace DotNet.Testcontainers.Tests.Fixtures
2+
{
3+
using JetBrains.Annotations;
4+
5+
[UsedImplicitly]
6+
public sealed class OpenSsl3_1Fixture : DockerMTls
7+
{
8+
public const string DockerVersion = "24.0.5";
9+
public OpenSsl3_1Fixture() : base(DockerVersion)
10+
{
11+
}
12+
}
13+
}

tests/Testcontainers.Tests/Fixtures/Containers/Unix/ProtectDockerDaemonSocket.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ public abstract class ProtectDockerDaemonSocket : IAsyncLifetime
1616

1717
private const ushort TlsPort = 2376;
1818

19-
private readonly string _hostCertsDirectoryPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("D"), CertsDirectoryName);
20-
2119
private readonly string _containerCertsDirectoryPath = Path.Combine("/", CertsDirectoryName);
2220

2321
private readonly IContainer _container;
2422

23+
protected readonly string _hostCertsDirectoryPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("D"), CertsDirectoryName);
24+
2525
protected ProtectDockerDaemonSocket(ContainerBuilder containerConfiguration, string dockerImageVersion)
2626
{
2727
_container = containerConfiguration

tests/Testcontainers.Tests/Unit/Containers/Unix/ProtectDockerDaemonSocketTest.cs

+33
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ namespace DotNet.Testcontainers.Tests.Unit
88
using DotNet.Testcontainers.Configurations;
99
using DotNet.Testcontainers.Tests.Fixtures;
1010
using Microsoft.Extensions.Logging.Abstractions;
11+
using Org.BouncyCastle.Crypto;
12+
using Org.BouncyCastle.Crypto.Parameters;
1113
using Xunit;
1214

1315
public static class ProtectDockerDaemonSocketTest
@@ -20,10 +22,12 @@ private static IDockerEndpointAuthenticationConfiguration GetAuthConfig(ProtectD
2022

2123
public sealed class MTlsOpenSsl1_1_1 : IClassFixture<OpenSsl1_1_1Fixture>
2224
{
25+
private readonly OpenSsl1_1_1Fixture _fixture;
2326
private readonly IDockerEndpointAuthenticationConfiguration _authConfig;
2427

2528
public MTlsOpenSsl1_1_1(OpenSsl1_1_1Fixture dockerMTlsFixture)
2629
{
30+
_fixture = dockerMTlsFixture;
2731
_authConfig = GetAuthConfig(dockerMTlsFixture);
2832
}
2933

@@ -35,9 +39,38 @@ public async Task GetVersionReturnsVersion()
3539
// When
3640
var version = await client.System.GetVersionAsync()
3741
.ConfigureAwait(false);
42+
var key = _fixture.ClientCertificateKey();
3843

3944
// Then
4045
Assert.Equal(OpenSsl1_1_1Fixture.DockerVersion, version.Version);
46+
Assert.IsType<AsymmetricCipherKeyPair>(key);
47+
}
48+
}
49+
50+
public sealed class MTlsOpenSsl3_1 : IClassFixture<OpenSsl3_1Fixture>
51+
{
52+
private readonly OpenSsl3_1Fixture _fixture;
53+
private readonly IDockerEndpointAuthenticationConfiguration _authConfig;
54+
55+
public MTlsOpenSsl3_1(OpenSsl3_1Fixture dockerMTlsFixture)
56+
{
57+
_fixture = dockerMTlsFixture;
58+
_authConfig = GetAuthConfig(dockerMTlsFixture);
59+
}
60+
61+
[Fact]
62+
public async Task GetVersionReturnsVersion()
63+
{
64+
// Given
65+
var client = new TestcontainersClient(Guid.Empty, _authConfig, NullLogger.Instance);
66+
// When
67+
var version = await client.System.GetVersionAsync()
68+
.ConfigureAwait(false);
69+
var key = _fixture.ClientCertificateKey();
70+
71+
// Then
72+
Assert.Equal(OpenSsl3_1Fixture.DockerVersion, version.Version);
73+
Assert.IsType<RsaPrivateCrtKeyParameters>(key);
4174
}
4275
}
4376

0 commit comments

Comments
 (0)