Browse Source
Add a path base matching test and document opt-in path matching
pull/26017/head
maliming
19 hours ago
No known key found for this signature in database
GPG Key ID: A646B9CB645ECEA4
3 changed files with
18 additions and
3 deletions
-
framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Uow/AbpAspNetCoreUnitOfWorkOptions.cs
-
framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs
-
framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Uow/UnitOfWorkMiddleware_Tests.cs
|
|
|
@ -31,9 +31,11 @@ public class AbpAspNetCoreUnitOfWorkOptions |
|
|
|
/// <summary>
|
|
|
|
/// Absolute request path prefixes (matched by segment) that opt-in to
|
|
|
|
/// <see cref="CompleteUnitOfWorkOnResponseStarting"/> even when it is globally disabled (for example
|
|
|
|
/// "/connect" matches "/connect/token" but not "/connections"). A trailing slash is normalized; blank,
|
|
|
|
/// non-absolute, and root ("/") entries are ignored - use <see cref="CompleteUnitOfWorkOnResponseStarting"/>
|
|
|
|
/// to enable it for every request handled by the middleware.
|
|
|
|
/// "/connect" matches "/connect/token" but not "/connections"). Each prefix is matched against both
|
|
|
|
/// the request path and the path base + request path, so an endpoint configured with the path base
|
|
|
|
/// still matches. A trailing slash is normalized; blank, non-absolute, and root ("/") entries are
|
|
|
|
/// ignored - use <see cref="CompleteUnitOfWorkOnResponseStarting"/> to enable it for every request
|
|
|
|
/// handled by the middleware.
|
|
|
|
/// </summary>
|
|
|
|
public List<string> CompleteUnitOfWorkOnResponseStartingUrls { get; } = new List<string>(); |
|
|
|
} |
|
|
|
|
|
|
|
@ -164,6 +164,9 @@ public class AbpAspNetCoreMvcTestModule : AbpModule |
|
|
|
app.UseStaticFiles(); |
|
|
|
app.UseAbpRequestLocalization(); |
|
|
|
app.UseAbpSecurityHeaders(); |
|
|
|
// Moves the "/pathbase-test" prefix into Request.PathBase so a unit of work opt-in test can
|
|
|
|
// exercise path base matching; a no-op for every other request.
|
|
|
|
app.UsePathBase("/pathbase-test"); |
|
|
|
app.UseRouting(); |
|
|
|
app.UseAuthentication(); |
|
|
|
app.UseAuthorization(); |
|
|
|
|
|
|
|
@ -139,4 +139,14 @@ public class UnitOfWorkMiddleware_Tests : AspNetCoreMvcTestBase |
|
|
|
var result = await GetResponseAsStringAsync("/api/unitofwork-test/CommitBeforeResponseFlush"); |
|
|
|
result.ShouldBe("first:not-completed"); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task Opt_In_Url_Including_The_Path_Base_Matches() |
|
|
|
{ |
|
|
|
// The request path is "/api/..." (the path base is stripped), so this only matches via path base + path.
|
|
|
|
Options.CompleteUnitOfWorkOnResponseStartingUrls.Add("/pathbase-test/api/unitofwork-test/CommitBeforeResponseFlush"); |
|
|
|
|
|
|
|
var result = await GetResponseAsStringAsync("/pathbase-test/api/unitofwork-test/CommitBeforeResponseFlush"); |
|
|
|
result.ShouldBe("first:completed"); |
|
|
|
} |
|
|
|
} |
|
|
|
|