-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update packages (minor + major) #31
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3df0a42
(packages): apply minor version updates for all packages
fb-smit c47601f
(bogus): major update
fb-smit 29f8ae5
(yamlDotNet): major update
fb-smit 303750c
(aspNetCoreHealthChecks): major update
fb-smit ca43df0
(opentelemetry): major update
fb-smit 5d6dfc6
(nunit): major update
fb-smit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
26 changes: 26 additions & 0 deletions
26
...Abstractions/src/PiBox.Hosting.Abstractions/Middlewares/EnrichRequestMetricsMiddleware.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,26 @@ | ||
using Chronos.Abstractions; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Http.Features; | ||
using PiBox.Hosting.Abstractions.Attributes; | ||
|
||
namespace PiBox.Hosting.Abstractions.Middlewares | ||
{ | ||
[Middleware] | ||
public sealed class EnrichRequestMetricsMiddleware : ApiMiddleware | ||
{ | ||
public EnrichRequestMetricsMiddleware(RequestDelegate next, IDateTimeProvider dateTimeProvider) : base(next, | ||
dateTimeProvider) | ||
{ | ||
} | ||
|
||
public override Task Invoke(HttpContext context) | ||
{ | ||
var tagsFeature = context.Features.Get<IHttpMetricsTagsFeature>(); | ||
if (tagsFeature == null) return Next.Invoke(context); | ||
var authorizedParty = context.User.Claims.SingleOrDefault(x => x.Type == "azp")?.Value; | ||
tagsFeature.Tags.Add(new KeyValuePair<string, object>("azp", authorizedParty ?? "")); | ||
|
||
return Next.Invoke(context); | ||
} | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
.../test/PiBox.Hosting.Abstractions.Tests/Middlewares/EnrichRequestMetricsMiddlewareTests.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,86 @@ | ||
using System.Security.Claims; | ||
using Chronos.Abstractions; | ||
using FluentAssertions; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Http.Features; | ||
using NSubstitute; | ||
using NUnit.Framework; | ||
using PiBox.Hosting.Abstractions.Middlewares; | ||
|
||
namespace PiBox.Hosting.Abstractions.Tests.Middlewares | ||
{ | ||
public class EnrichRequestMetricsMiddlewareTests | ||
{ | ||
private readonly IDateTimeProvider _dateTimeProvider = Substitute.For<IDateTimeProvider>(); | ||
|
||
private static HttpContext GetContext() | ||
{ | ||
return new DefaultHttpContext { Response = { Body = new MemoryStream() } }; | ||
} | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
_dateTimeProvider.UtcNow.Returns(new DateTime(2020, 1, 1)); | ||
} | ||
|
||
[Test] | ||
public async Task ExistingAzpClaimShouldAddTagWithUserIdToMetrics() | ||
{ | ||
var httpMetricsTagsFeature = Substitute.For<IHttpMetricsTagsFeature>(); | ||
httpMetricsTagsFeature.Tags.Returns(new List<KeyValuePair<string, object>>()); | ||
var middleware = new EnrichRequestMetricsMiddleware(x => | ||
{ | ||
x.Response.StatusCode = 200; | ||
return Task.CompletedTask; | ||
}, _dateTimeProvider); | ||
var context = GetContext(); | ||
|
||
context.User = new ClaimsPrincipal(new ClaimsIdentity(new List<Claim>() { new Claim("azp", "userid1") })); | ||
context.Features.Set(httpMetricsTagsFeature); | ||
|
||
await middleware.Invoke(context); | ||
var metrics = context.Features.Get<IHttpMetricsTagsFeature>(); | ||
metrics.Tags.Should().Contain(x => x.Key == "azp" && x.Value.ToString() == "userid1"); | ||
} | ||
|
||
[Test] | ||
public async Task NonExistingAzpClaimShouldAddTagWithEmptyValueToMetrics() | ||
{ | ||
var httpMetricsTagsFeature = Substitute.For<IHttpMetricsTagsFeature>(); | ||
httpMetricsTagsFeature.Tags.Returns(new List<KeyValuePair<string, object>>()); | ||
var middleware = new EnrichRequestMetricsMiddleware(x => | ||
{ | ||
x.Response.StatusCode = 200; | ||
return Task.CompletedTask; | ||
}, _dateTimeProvider); | ||
var context = GetContext(); | ||
|
||
context.User = new ClaimsPrincipal(new ClaimsIdentity(new List<Claim>() { new Claim("azp1", "userid1") })); | ||
context.Features.Set(httpMetricsTagsFeature); | ||
|
||
await middleware.Invoke(context); | ||
var metrics = context.Features.Get<IHttpMetricsTagsFeature>(); | ||
metrics.Tags.Should().Contain(x => x.Key == "azp" && x.Value.ToString() == ""); | ||
} | ||
|
||
[Test] | ||
public async Task NoHttpMetricsTagsFeatureShouldNotAddMetricTagsToResponse() | ||
{ | ||
var httpMetricsTagsFeature = Substitute.For<IHttpMetricsTagsFeature>(); | ||
httpMetricsTagsFeature.Tags.Returns(new List<KeyValuePair<string, object>>()); | ||
var middleware = new EnrichRequestMetricsMiddleware(x => | ||
{ | ||
x.Response.StatusCode = 200; | ||
return Task.CompletedTask; | ||
}, _dateTimeProvider); | ||
var context = GetContext(); | ||
|
||
context.User = new ClaimsPrincipal(new ClaimsIdentity(new List<Claim>() { new Claim("azp1", "userid1") })); | ||
|
||
await middleware.Invoke(context); | ||
var metrics = context.Features.Get<IHttpMetricsTagsFeature>(); | ||
metrics.Should().BeNull(); | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<3