diff --git a/src/Altinn.Broker.API/Controllers/ResourceController.cs b/src/Altinn.Broker.API/Controllers/ResourceController.cs index a754fc1d..b7a8fd74 100644 --- a/src/Altinn.Broker.API/Controllers/ResourceController.cs +++ b/src/Altinn.Broker.API/Controllers/ResourceController.cs @@ -49,6 +49,11 @@ public async Task UpdateMaxFileTransferSize([FromBody] ResourceExt { return BadRequest("Max upload size cannot be negative"); } + if (resourceExt.MaxFileTransferSize == 0) + { + return BadRequest("Max upload size cannot be zero"); + } + if (resourceExt.MaxFileTransferSize == resource.MaxFileTransferSize) { return BadRequest("Max upload size is already set to the requested value"); diff --git a/src/Altinn.Broker.Application/MalwareScanResults/MalwareScanResultHandler.cs b/src/Altinn.Broker.Application/MalwareScanResults/MalwareScanResultHandler.cs index 0c5cb70f..ff3121ad 100644 --- a/src/Altinn.Broker.Application/MalwareScanResults/MalwareScanResultHandler.cs +++ b/src/Altinn.Broker.Application/MalwareScanResults/MalwareScanResultHandler.cs @@ -1,12 +1,15 @@ using System.Text.Json; +using Altinn.Broker.Application.ExpireFileTransferCommand; using Altinn.Broker.Core.Application; using Altinn.Broker.Core.Domain; using Altinn.Broker.Core.Repositories; using Altinn.Broker.Core.Services; using Altinn.Broker.Core.Services.Enums; +using Hangfire; + using Microsoft.Extensions.Logging; using OneOf; @@ -18,17 +21,20 @@ public class MalwareScanningResultHandler : IHandler private readonly IFileTransferRepository _fileTransferRepository; private readonly IEventBus _eventBus; private readonly ILogger _logger; + private readonly IBackgroundJobClient _backgroundJobClient; public MalwareScanningResultHandler( IFileTransferStatusRepository fileTransferStatusRepository, IFileTransferRepository fileTransferRepository, IEventBus eventBus, - ILogger logger) + ILogger logger, + IBackgroundJobClient backgroundJobClient) { _fileTransferStatusRepository = fileTransferStatusRepository; _fileTransferRepository = fileTransferRepository; _eventBus = eventBus; _logger = logger; + _backgroundJobClient = backgroundJobClient; } public async Task> Process(ScanResultData data, CancellationToken cancellationToken) @@ -55,8 +61,13 @@ public async Task> Process(ScanResultData data, CancellationT } _logger.LogWarning("Suspicious scan result for file transfer {fileTransferId} with body {body}", fileTransferId, JsonSerializer.Serialize(data)); - await _fileTransferStatusRepository.InsertFileTransferStatus(fileTransferId, Core.Domain.Enums.FileTransferStatus.Failed, $"Malware scan failed: {data.ScanResultType}", cancellationToken); + await _fileTransferStatusRepository.InsertFileTransferStatus(fileTransferId, Core.Domain.Enums.FileTransferStatus.Failed, $"Malware scan failed: {data.ScanResultType}. Extra details: " + JsonSerializer.Serialize(data.ScanResultDetails), cancellationToken); await _eventBus.Publish(AltinnEventType.UploadFailed, fileTransfer.ResourceId, fileTransferIdFromUri, fileTransfer.Sender.ActorExternalId, cancellationToken); + _backgroundJobClient.Enqueue(handler => handler.RescheduleExpireEvent(new ExpireFileTransferCommandRequest + { + FileTransferId = fileTransfer.FileTransferId, + Force = true + }, CancellationToken.None)); return Task.CompletedTask; } } diff --git a/src/Altinn.Broker.Core/Domain/Webhooks/MalwareScan/ScanResultDetails.cs b/src/Altinn.Broker.Core/Domain/Webhooks/MalwareScan/ScanResultDetails.cs index 88c0150b..5688d810 100644 --- a/src/Altinn.Broker.Core/Domain/Webhooks/MalwareScan/ScanResultDetails.cs +++ b/src/Altinn.Broker.Core/Domain/Webhooks/MalwareScan/ScanResultDetails.cs @@ -4,5 +4,6 @@ public class ScanResultDetails { public List MalwareNamesFound { get; set; } = new List(); public string Sha256 { get; set; } = string.Empty; + public string NotScannedReason { get; set; } = string.Empty; } }