|
11 | 11 | using System.Net.Http.Json; |
12 | 12 | using System.Reflection; |
13 | 13 | using System.Text; |
| 14 | +using System.Text.Json; |
14 | 15 | using System.Threading; |
15 | 16 | using System.Threading.Tasks; |
16 | 17 | using System.Xml.Linq; |
17 | 18 | using Microsoft.Azure.Storage.Blob; |
18 | 19 | using Microsoft.Azure.WebJobs.Script.Config; |
| 20 | +using Microsoft.Azure.WebJobs.Script.Diagnostics.HealthChecks; |
19 | 21 | using Microsoft.Azure.WebJobs.Script.Management.Models; |
20 | 22 | using Microsoft.Azure.WebJobs.Script.Models; |
21 | 23 | using Microsoft.Azure.WebJobs.Script.WebHost; |
@@ -366,6 +368,43 @@ public async Task HealthCheck_AdminToken_Succeeds(string uri) |
366 | 368 | Assert.Equal("{\"status\":\"Healthy\"}", body); |
367 | 369 | } |
368 | 370 |
|
| 371 | + [Theory] |
| 372 | + [InlineData("/admin/health?expand=true", null)] |
| 373 | + [InlineData("/admin/health/live?expand=true", HealthCheckTags.Liveness)] |
| 374 | + [InlineData("/admin/health/ready?expand=true", HealthCheckTags.Readiness)] |
| 375 | + public async Task HealthCheck_AdminToken_ExpandSucceeds(string uri, string tag) |
| 376 | + { |
| 377 | + // token specified as bearer token |
| 378 | + HttpRequestMessage request = new(HttpMethod.Get, uri); |
| 379 | + string token = _fixture.Host.GenerateAdminJwtToken(); |
| 380 | + request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token); |
| 381 | + HttpResponseMessage response = await _fixture.Host.HttpClient.SendAsync(request); |
| 382 | + Assert.Equal(HttpStatusCode.OK, response.StatusCode); |
| 383 | + |
| 384 | + // Not doing a deep validation of the response, just ensuring we get the correct tags. |
| 385 | + // The full response body is validated in other tests. |
| 386 | + using Stream stream = await response.Content.ReadAsStreamAsync(); |
| 387 | + JsonDocument json = await JsonDocument.ParseAsync(stream); |
| 388 | + JsonElement entries = json.RootElement.GetProperty("entries"); |
| 389 | + |
| 390 | + if (string.IsNullOrEmpty(tag)) |
| 391 | + { |
| 392 | + Assert.NotEmpty(entries.EnumerateObject()); |
| 393 | + } |
| 394 | + else |
| 395 | + { |
| 396 | + bool atLeastOne = false; |
| 397 | + foreach (JsonProperty entry in entries.EnumerateObject()) |
| 398 | + { |
| 399 | + atLeastOne = true; |
| 400 | + HashSet<string> tags = entry.Value.GetProperty("tags").Deserialize<HashSet<string>>(); |
| 401 | + Assert.Contains(tag, tags); |
| 402 | + } |
| 403 | + |
| 404 | + Assert.True(atLeastOne, "Expected at least one entry to have the specified tag."); |
| 405 | + } |
| 406 | + } |
| 407 | + |
369 | 408 | [Theory] |
370 | 409 | [InlineData("/admin/health")] |
371 | 410 | [InlineData("/admin/health/live")] |
|
0 commit comments