|
1 | 1 | using System.Net; |
| 2 | +using System.Security.Cryptography; |
| 3 | +using System.Security.Cryptography.X509Certificates; |
| 4 | +using HealthChecks.RavenDB; |
2 | 5 | using HealthChecks.UI.Client; |
3 | 6 |
|
4 | 7 | namespace HealthChecks.RavenDb.Tests.Functional; |
@@ -151,4 +154,31 @@ public async Task be_unhealthy_if_ravendb_is_available_but_database_doesnot_exis |
151 | 154 |
|
152 | 155 | response.StatusCode.ShouldBe(HttpStatusCode.ServiceUnavailable, await response.Content.ReadAsStringAsync()); |
153 | 156 | } |
| 157 | + |
| 158 | + [Fact] |
| 159 | + public async Task not_dispose_shared_certificate_when_store_initialization_fails() |
| 160 | + { |
| 161 | + using var rsa = RSA.Create(2048); |
| 162 | + var certificateRequest = new CertificateRequest("CN=ravendb-healthcheck-test", rsa, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1); |
| 163 | + using var certificate = certificateRequest.CreateSelfSigned(DateTimeOffset.UtcNow.AddDays(-1), DateTimeOffset.UtcNow.AddDays(1)); |
| 164 | + |
| 165 | + var options = new RavenDBOptions |
| 166 | + { |
| 167 | + Urls = ["http://localhost:0"], |
| 168 | + Certificate = certificate |
| 169 | + }; |
| 170 | + |
| 171 | + var healthCheck = new RavenDBHealthCheck(options); |
| 172 | + var context = new HealthCheckContext |
| 173 | + { |
| 174 | + Registration = new HealthCheckRegistration("ravendb", _ => healthCheck, HealthStatus.Unhealthy, tags: null) |
| 175 | + }; |
| 176 | + |
| 177 | + var result = await healthCheck.CheckHealthAsync(context); |
| 178 | + |
| 179 | + result.Status.ShouldBe(HealthStatus.Unhealthy); |
| 180 | + |
| 181 | + using var privateKey = certificate.GetRSAPrivateKey(); |
| 182 | + privateKey.ShouldNotBeNull(); |
| 183 | + } |
154 | 184 | } |
0 commit comments