Fix authenticated resource usage tracking
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
ebdf51f468
commit
7ee0c30500
4 changed files with 31 additions and 2 deletions
12
CHANGELOG.md
12
CHANGELOG.md
|
|
@ -1,6 +1,18 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## [1.0.8-rc25] - unstable
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
* [Yavsc.Api][Yavsc.Blogs] Les appels API et la bande passante sont
|
||||||
|
désormais enregistrés côté serveur pour les requêtes authentifiées :
|
||||||
|
le middleware de télémétrie est maintenant branché après
|
||||||
|
l'authentification, ce qui permet de comptabiliser `ApiCalls` et
|
||||||
|
`BandwidthMb` au lieu d'enregistrer des zéros.
|
||||||
|
|
||||||
## [1.0.8-rc24] - unstable
|
## [1.0.8-rc24] - unstable
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -134,11 +134,11 @@ internal class Program
|
||||||
if (app.Environment.IsDevelopment())
|
if (app.Environment.IsDevelopment())
|
||||||
app.UseDeveloperExceptionPage();
|
app.UseDeveloperExceptionPage();
|
||||||
|
|
||||||
app.UseMiddleware<ResourceUsageTelemetryMiddleware>();
|
|
||||||
app
|
app
|
||||||
.UseRouting()
|
.UseRouting()
|
||||||
.UseAuthentication()
|
.UseAuthentication()
|
||||||
.UseAuthorization()
|
.UseAuthorization()
|
||||||
|
.UseMiddleware<ResourceUsageTelemetryMiddleware>()
|
||||||
.UseCors("default");
|
.UseCors("default");
|
||||||
app.MapIdentityApi<ApplicationUser>().RequireAuthorization("ApiScope");
|
app.MapIdentityApi<ApplicationUser>().RequireAuthorization("ApiScope");
|
||||||
app.MapDefaultControllerRoute();
|
app.MapDefaultControllerRoute();
|
||||||
|
|
|
||||||
|
|
@ -98,11 +98,11 @@ internal class Program
|
||||||
{
|
{
|
||||||
if (app.Environment.IsDevelopment())
|
if (app.Environment.IsDevelopment())
|
||||||
app.UseDeveloperExceptionPage();
|
app.UseDeveloperExceptionPage();
|
||||||
app.UseMiddleware<ResourceUsageTelemetryMiddleware>();
|
|
||||||
app
|
app
|
||||||
.UseRouting()
|
.UseRouting()
|
||||||
.UseAuthentication()
|
.UseAuthentication()
|
||||||
.UseAuthorization()
|
.UseAuthorization()
|
||||||
|
.UseMiddleware<ResourceUsageTelemetryMiddleware>()
|
||||||
.UseCors("default")
|
.UseCors("default")
|
||||||
;
|
;
|
||||||
app.Services.GetRequiredService<ILoggerFactory>().CreateLogger("Program")
|
app.Services.GetRequiredService<ILoggerFactory>().CreateLogger("Program")
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,23 @@ public sealed class ResourceUsageApiControllerTests : IClassFixture<ApiWebServer
|
||||||
Assert.True(record.BandwidthMb >= 3.5m);
|
Assert.True(record.BandwidthMb >= 3.5m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task GetCurrentUserUsage_records_telemetry_values_from_authenticated_requests()
|
||||||
|
{
|
||||||
|
using var http = NewClient(_fixture, "telemetry-user");
|
||||||
|
|
||||||
|
var response = await http.GetAsync("/api/v1/resource-usage/me", TestContext.Current.CancellationToken);
|
||||||
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||||
|
|
||||||
|
using var scope = _fixture.Services.CreateScope();
|
||||||
|
var db = scope.ServiceProvider.GetRequiredService<Yavsc.Models.ApplicationDbContext>();
|
||||||
|
var record = await db.ResourceUsageRecords
|
||||||
|
.SingleAsync(r => r.UserId == "telemetry-user");
|
||||||
|
|
||||||
|
Assert.True(record.ApiCalls >= 1m);
|
||||||
|
Assert.True(record.BandwidthMb > 0m);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task GetAdminOverview_returns_latest_usage_snapshot_for_each_user()
|
public async Task GetAdminOverview_returns_latest_usage_snapshot_for_each_user()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue