Browse Source
Merge pull request #8515 from abpframework/auto-merge/rel-4-3/270
Merge branch dev with rel-4.3
pull/8550/head
maliming
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with
52 additions and
2 deletions
-
framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Auditing/AbpAuditingMiddleware.cs
-
framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Auditing/AuditTestController.cs
-
framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Auditing/AuditTestController_Tests.cs
-
framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Auditing/AuditTestPage.cshtml.cs
-
framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Auditing/AuditTestPage_Tests.cs
|
|
|
@ -45,19 +45,26 @@ namespace Volo.Abp.AspNetCore.Auditing |
|
|
|
var hasError = false; |
|
|
|
using (var saveHandle = _auditingManager.BeginScope()) |
|
|
|
{ |
|
|
|
Debug.Assert(_auditingManager.Current != null); |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
await next(context); |
|
|
|
|
|
|
|
Debug.Assert(_auditingManager.Current != null); |
|
|
|
if (_auditingManager.Current.Log.Exceptions.Any()) |
|
|
|
{ |
|
|
|
hasError = true; |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception) |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
hasError = true; |
|
|
|
|
|
|
|
if (!_auditingManager.Current.Log.Exceptions.Contains(ex)) |
|
|
|
{ |
|
|
|
_auditingManager.Current.Log.Exceptions.Add(ex); |
|
|
|
} |
|
|
|
|
|
|
|
throw; |
|
|
|
} |
|
|
|
finally |
|
|
|
|
|
|
|
@ -31,10 +31,18 @@ namespace Volo.Abp.AspNetCore.Mvc.Auditing |
|
|
|
{ |
|
|
|
throw new UserFriendlyException("Exception occurred!"); |
|
|
|
} |
|
|
|
|
|
|
|
[Route("audit-fail-object")] |
|
|
|
public object AuditFailForGetRequestsReturningObject() |
|
|
|
{ |
|
|
|
throw new UserFriendlyException("Exception occurred!"); |
|
|
|
} |
|
|
|
|
|
|
|
[HttpGet] |
|
|
|
[Route("audit-activate-failed")] |
|
|
|
public IActionResult AuditActivateFailed([FromServices] AbpAuditingOptions options) |
|
|
|
{ |
|
|
|
return Ok(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -74,5 +74,20 @@ namespace Volo.Abp.AspNetCore.Mvc.Auditing |
|
|
|
|
|
|
|
await _auditingStore.Received().SaveAsync(Arg.Any<AuditLogInfo>()); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task Should_Trigger_Middleware_And_AuditLog_Exception_When_Activate_Controller_Failed() |
|
|
|
{ |
|
|
|
_options.IsEnabledForGetRequests = true; |
|
|
|
_options.AlwaysLogOnException = true; |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
await GetResponseAsync("api/audit-test/audit-activate-failed", System.Net.HttpStatusCode.InternalServerError); |
|
|
|
} |
|
|
|
catch { } |
|
|
|
|
|
|
|
await _auditingStore.Received().SaveAsync(Arg.Is<AuditLogInfo>(x => x.Exceptions.Any())); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -34,5 +34,10 @@ namespace Volo.Abp.AspNetCore.Mvc.Auditing |
|
|
|
{ |
|
|
|
throw new UserFriendlyException("Exception occurred!"); |
|
|
|
} |
|
|
|
|
|
|
|
public IActionResult OnGetAuditActivateFailed([FromServices] AbpAuditingOptions options) |
|
|
|
{ |
|
|
|
return new OkResult(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -73,5 +73,20 @@ namespace Volo.Abp.AspNetCore.Mvc.Auditing |
|
|
|
|
|
|
|
await _auditingStore.Received().SaveAsync(Arg.Any<AuditLogInfo>()); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task Should_Trigger_Middleware_And_AuditLog_Exception_When_Activate_Page_Failed() |
|
|
|
{ |
|
|
|
_options.IsEnabledForGetRequests = true; |
|
|
|
_options.AlwaysLogOnException = true; |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
await GetResponseAsync("/Auditing/AuditTestPage?handler=AuditActivateFailed", System.Net.HttpStatusCode.InternalServerError); |
|
|
|
} |
|
|
|
catch { } |
|
|
|
|
|
|
|
await _auditingStore.Received().SaveAsync(Arg.Is<AuditLogInfo>(x => x.Exceptions.Any())); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|