Skip to content

Commit

Permalink
code updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Xor-el committed Feb 1, 2025
1 parent 814de99 commit 1c55d3e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docs/modules/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ await moduleNameContainer.StartAsync();
| Keycloak | `quay.io/keycloak/keycloak:21.1` | [NuGet](https://www.nuget.org/packages/Testcontainers.Keycloak) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Keycloak) |
| Kusto emulator | `mcr.microsoft.com/azuredataexplorer/kustainer-linux:latest` | [NuGet](https://www.nuget.org/packages/Testcontainers.Kusto) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Kusto) |
| LocalStack | `localstack/localstack:2.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.LocalStack) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.LocalStack) |
| Lowkey Vault | `nagyesta/lowkey-vault:2.7.0-ubi9-minimal` | [NuGet](https://www.nuget.org/packages/Testcontainers.LowkeyVault) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.LowkeyVault) |
| Lowkey Vault | `nagyesta/lowkey-vault:2.7.1-ubi9-minimal` | [NuGet](https://www.nuget.org/packages/Testcontainers.LowkeyVault) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.LowkeyVault) |
| MariaDB | `mariadb:10.10` | [NuGet](https://www.nuget.org/packages/Testcontainers.MariaDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.MariaDb) |
| Milvus | `milvusdb/milvus:v2.3.10` | [NuGet](https://www.nuget.org/packages/Testcontainers.Milvus) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Milvus) |
| MinIO | `minio/minio:RELEASE.2023-01-31T02-24-19Z` | [NuGet](https://www.nuget.org/packages/Testcontainers.Minio) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Minio) |
Expand Down
2 changes: 1 addition & 1 deletion src/Testcontainers.LowkeyVault/LowkeyVaultBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Testcontainers.LowkeyVault;
[PublicAPI]
public sealed class LowkeyVaultBuilder : ContainerBuilder<LowkeyVaultBuilder, LowkeyVaultContainer, LowkeyVaultConfiguration>
{
public const string LowkeyVaultImage = "nagyesta/lowkey-vault:2.7.0-ubi9-minimal";
public const string LowkeyVaultImage = "nagyesta/lowkey-vault:2.7.1-ubi9-minimal";

public const ushort LowkeyVaultPort = 8443;

Expand Down
10 changes: 8 additions & 2 deletions src/Testcontainers.LowkeyVault/LowkeyVaultContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ namespace Testcontainers.LowkeyVault;
[PublicAPI]
public sealed class LowkeyVaultContainer : DockerContainer
{
private const string LocalHost = "localhost";

/// <summary>
/// Gets a configured HTTP client
/// </summary>
private HttpClient HttpClient => new();
private static HttpClient HttpClient => new();

/// <summary>
/// Initializes a new instance of the <see cref="LowkeyVaultContainer" /> class.
Expand Down Expand Up @@ -43,7 +45,11 @@ public string GetTokenEndpointUrl()
/// <returns>The vault base URL.</returns>
public string GetVaultBaseUrl(string vaultName)
{
return new UriBuilder(Uri.UriSchemeHttps, $"{vaultName}.{Hostname}", GetMappedPublicPort(LowkeyVaultBuilder.LowkeyVaultPort)).ToString();
// Using `LocalHost` here instead of `Hostname` (which resolves to `127.0.0.1` in this environment)
// to address a compatibility issue with the Java URI parser utilized by the Lowkey Vault client.
// The parser fails to properly handle URIs containing a mix of DNS names and IP addresses, leading to errors.
// For more details, refer to: https://github.com/nagyesta/lowkey-vault/issues/1319#issuecomment-2600214768
return new UriBuilder(Uri.UriSchemeHttps, $"{vaultName}.{LocalHost}", GetMappedPublicPort(LowkeyVaultBuilder.LowkeyVaultPort)).ToString();
}

/// <summary>
Expand Down
26 changes: 17 additions & 9 deletions tests/Testcontainers.LowkeyVault.Tests/LowkeyVaultContainerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,22 @@ public Task DisposeAsync()
[Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))]
public async Task TestContainerDefaults()
{
// Assert
var tokenEndpoint = _fakeLowkeyVaultContainer.GetTokenEndpointUrl();
// Given
const string Alias = "lowkey-vault.local";

await VerifyTokenEndpointIsWorking(tokenEndpoint, CreateHttpClientHandlerWithDisabledSslValidation());
// When
var tokenEndpoint = _fakeLowkeyVaultContainer.GetTokenEndpointUrl();

var keyStore = await _fakeLowkeyVaultContainer.GetDefaultKeyStore();

var password = await _fakeLowkeyVaultContainer.GetDefaultKeyStorePassword();

// Then
await VerifyTokenEndpointIsWorking(tokenEndpoint, CreateHttpClientHandlerWithDisabledSslValidation());

Assert.NotNull(keyStore);
Assert.NotNull(password);
Assert.Contains(keyStore, cert => cert.Subject.Split('=')?.LastOrDefault() == Alias);
}


Expand Down Expand Up @@ -130,7 +138,7 @@ private static DefaultAzureCredential CreateDefaultAzureCredential()
return new DefaultAzureCredential();
}

private SecretClientOptions CreateSecretClientOption()
private static SecretClientOptions CreateSecretClientOption()
{
return GetClientOptions(new SecretClientOptions(SecretClientOptions.ServiceVersion.V7_4)
{
Expand All @@ -139,7 +147,7 @@ private SecretClientOptions CreateSecretClientOption()
});
}

private CertificateClientOptions CreateCertificateClientOption()
private static CertificateClientOptions CreateCertificateClientOption()
{
return GetClientOptions(new CertificateClientOptions(CertificateClientOptions.ServiceVersion.V7_4)
{
Expand All @@ -148,7 +156,7 @@ private CertificateClientOptions CreateCertificateClientOption()
});
}

private T GetClientOptions<T>(T options) where T : ClientOptions
private static T GetClientOptions<T>(T options) where T : ClientOptions
{
DisableSslValidationOnClientOptions(options);
return options;
Expand All @@ -160,17 +168,17 @@ private T GetClientOptions<T>(T options) where T : ClientOptions
/// <b>WARNING: Do not use in production environments.</b>
/// </summary>
/// <param name="options"></param>
private void DisableSslValidationOnClientOptions(ClientOptions options)
private static void DisableSslValidationOnClientOptions(ClientOptions options)
{
options.Transport = new HttpClientTransport(CreateHttpClientHandlerWithDisabledSslValidation());
}

private HttpClientHandler CreateHttpClientHandlerWithDisabledSslValidation()
private static HttpClientHandler CreateHttpClientHandlerWithDisabledSslValidation()
{
return new HttpClientHandler { ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator };
}

private async Task VerifyTokenEndpointIsWorking(string endpointUrl, HttpClientHandler httpClientHandler)
private static async Task VerifyTokenEndpointIsWorking(string endpointUrl, HttpClientHandler httpClientHandler)
{
using var httpClient = new HttpClient(httpClientHandler);

Expand Down
1 change: 1 addition & 0 deletions tests/Testcontainers.LowkeyVault.Tests/Usings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
global using Azure.Security.KeyVault.Secrets;
global using DotNet.Testcontainers.Commons;
global using System;
global using System.Linq;
global using System.Net.Http;
global using System.Security.Cryptography.X509Certificates;
global using System.Threading;
Expand Down

0 comments on commit 1c55d3e

Please sign in to comment.