-
Notifications
You must be signed in to change notification settings - Fork 0
Disable some ConfirmDownload validation for compatibility with A2 #824
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
base: main
Are you sure you want to change the base?
Conversation
📝 WalkthroughWalkthroughAdds a non-legacy guard to download confirmation, a new test exercising legacy vs A3 confirmation behavior, removes a string URN-prefix helper, and changes CloudEvent subject handling by introducing an AlternativeSubject and path-prefixed Subject construction. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
RagnarFatland
left a comment
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.
Looks good, nice and simple.
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
tests/Altinn.Broker.Tests/LegacyFileControllerTests.cs (1)
638-661: LGTM! Test effectively validates legacy vs. A3 behavior.The test correctly verifies that the A3 endpoint rejects confirmation without a prior download (BadRequest), while the legacy endpoint allows it for backward compatibility. The assertions confirm the expected status transitions.
Minor cleanup: The
uploadedFileLengthvariable on line 647 is assigned but never used in the test.Apply this diff if you'd like to remove it:
- var uploadedFileLength = await UploadZipFile(fileTransferId); + await UploadZipFile(fileTransferId);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/Altinn.Broker.Application/ConfirmDownload/ConfirmDownloadHandler.cs(1 hunks)tests/Altinn.Broker.Tests/LegacyFileControllerTests.cs(1 hunks)
🧰 Additional context used
🧠 Learnings (11)
📓 Common learnings
Learnt from: Ceredron
Repo: Altinn/altinn-broker PR: 560
File: src/Altinn.Broker.Core/Helpers/ManifestDownloadStream.cs:239-249
Timestamp: 2024-10-29T12:15:40.824Z
Learning: In the `ManifestDownloadStream` class (`src/Altinn.Broker.Core/Helpers/ManifestDownloadStream.cs`), ZIP file validation is performed later in the code within the `AddManifestFile` method, so enhancing the `IsZipFile` method is unnecessary.
📚 Learning: 2024-10-29T12:51:11.540Z
Learnt from: Ceredron
Repo: Altinn/altinn-broker PR: 560
File: tests/Altinn.Broker.Tests/ManifestDownloadStreamTests.cs:24-39
Timestamp: 2024-10-29T12:51:11.540Z
Learning: In `tests/Altinn.Broker.Tests/ManifestDownloadStreamTests.cs`, refactoring suggestions aimed at enhancing test organization and coverage may be considered less readable and of dubious value.
Applied to files:
tests/Altinn.Broker.Tests/LegacyFileControllerTests.cssrc/Altinn.Broker.Application/ConfirmDownload/ConfirmDownloadHandler.cs
📚 Learning: 2024-10-29T12:50:05.699Z
Learnt from: Ceredron
Repo: Altinn/altinn-broker PR: 560
File: tests/Altinn.Broker.Tests/Helpers/ManifestDownloadStreamHelpers.cs:18-28
Timestamp: 2024-10-29T12:50:05.699Z
Learning: In `tests/Altinn.Broker.Tests/Helpers/ManifestDownloadStreamHelpers.cs`, the test code is static and will not change, so refactoring suggestions on this file are unnecessary.
Applied to files:
tests/Altinn.Broker.Tests/LegacyFileControllerTests.cssrc/Altinn.Broker.Application/ConfirmDownload/ConfirmDownloadHandler.cs
📚 Learning: 2024-10-29T12:12:50.346Z
Learnt from: Ceredron
Repo: Altinn/altinn-broker PR: 560
File: tests/Altinn.Broker.Tests/Factories/FileTransferEntityFactory.cs:8-45
Timestamp: 2024-10-29T12:12:50.346Z
Learning: When suggesting code improvements in `tests/Altinn.Broker.Tests/Factories/FileTransferEntityFactory.cs`, avoid adding excessive comments and unnecessary code changes.
Applied to files:
tests/Altinn.Broker.Tests/LegacyFileControllerTests.cssrc/Altinn.Broker.Application/ConfirmDownload/ConfirmDownloadHandler.cs
📚 Learning: 2024-10-29T12:15:40.824Z
Learnt from: Ceredron
Repo: Altinn/altinn-broker PR: 560
File: src/Altinn.Broker.Core/Helpers/ManifestDownloadStream.cs:239-249
Timestamp: 2024-10-29T12:15:40.824Z
Learning: In the `ManifestDownloadStream` class (`src/Altinn.Broker.Core/Helpers/ManifestDownloadStream.cs`), ZIP file validation is performed later in the code within the `AddManifestFile` method, so enhancing the `IsZipFile` method is unnecessary.
Applied to files:
tests/Altinn.Broker.Tests/LegacyFileControllerTests.cssrc/Altinn.Broker.Application/ConfirmDownload/ConfirmDownloadHandler.cs
📚 Learning: 2024-11-14T07:00:48.796Z
Learnt from: Ceredron
Repo: Altinn/altinn-broker PR: 582
File: tests/Altinn.Broker.Tests.LargeFile/Program.cs:80-82
Timestamp: 2024-11-14T07:00:48.796Z
Learning: In test programs like `tests/Altinn.Broker.Tests.LargeFile/Program.cs` in the `Altinn.Broker` project, it's acceptable to proceed without checking the success of HTTP responses or adding additional error handling.
Applied to files:
tests/Altinn.Broker.Tests/LegacyFileControllerTests.cs
📚 Learning: 2024-10-29T10:43:16.160Z
Learnt from: Andreass2
Repo: Altinn/altinn-broker PR: 561
File: src/Altinn.Broker.API/Controllers/LegacyFileController.cs:80-81
Timestamp: 2024-10-29T10:43:16.160Z
Learning: In the Altinn Broker API, specifically in `src/Altinn.Broker.API/Controllers/LegacyFileController.cs`, when handling file uploads in the `UploadFileStreamed` method, we can assume that all uploaded files are small and that the `Content-Length` header is always provided. Therefore, additional error handling for missing `Content-Length` is not required.
Applied to files:
tests/Altinn.Broker.Tests/LegacyFileControllerTests.cssrc/Altinn.Broker.Application/ConfirmDownload/ConfirmDownloadHandler.cs
📚 Learning: 2024-10-29T12:45:23.330Z
Learnt from: Ceredron
Repo: Altinn/altinn-broker PR: 560
File: src/Altinn.Broker.Core/Helpers/ManifestDownloadStream.cs:199-237
Timestamp: 2024-10-29T12:45:23.330Z
Learning: In the `ManifestDownloadStream` class (`src/Altinn.Broker.Core/Helpers/ManifestDownloadStream.cs`), optimizing memory usage in `AddManifestFile` by modifying the ZIP archive without loading the entire content into memory is currently not feasible because the base stream is a `ReadOnlyMemoryStream` based on a download stream. This optimization will be evaluated when the download stream is re-written in the "Support bigger files"-PR.
Applied to files:
tests/Altinn.Broker.Tests/LegacyFileControllerTests.cssrc/Altinn.Broker.Application/ConfirmDownload/ConfirmDownloadHandler.cs
📚 Learning: 2024-11-14T07:01:04.663Z
Learnt from: Ceredron
Repo: Altinn/altinn-broker PR: 582
File: tests/Altinn.Broker.Tests.LargeFile/Program.cs:147-147
Timestamp: 2024-11-14T07:01:04.663Z
Learning: In the project `Altinn.Broker.Tests.LargeFile`, the codebase uses C# 12 features like collection expressions, such as initializing collections with `PropertyList = []`. Do not flag this syntax as invalid in future reviews.
Applied to files:
tests/Altinn.Broker.Tests/LegacyFileControllerTests.cs
📚 Learning: 2024-10-29T12:49:46.020Z
Learnt from: Ceredron
Repo: Altinn/altinn-broker PR: 560
File: tests/Altinn.Broker.Tests/Helpers/ManifestDownloadStreamHelpers.cs:34-43
Timestamp: 2024-10-29T12:49:46.020Z
Learning: In test code (e.g., 'tests/Altinn.Broker.Tests/Helpers/ManifestDownloadStreamHelpers.cs'), prefer simplicity ('KISS') over optimizations like caching instances.
Applied to files:
tests/Altinn.Broker.Tests/LegacyFileControllerTests.cs
📚 Learning: 2024-10-29T11:25:42.867Z
Learnt from: Andreass2
Repo: Altinn/altinn-broker PR: 560
File: src/Altinn.Broker.Application/DownloadFile/DownloadFileHandler.cs:49-55
Timestamp: 2024-10-29T11:25:42.867Z
Learning: In `DownloadFileHandler` in `src/Altinn.Broker.Application/DownloadFile/DownloadFileHandler.cs`, due to the 1 GB file size limit, loading the entire file into memory is acceptable in this context.
Applied to files:
src/Altinn.Broker.Application/ConfirmDownload/ConfirmDownloadHandler.cs
🧬 Code graph analysis (2)
tests/Altinn.Broker.Tests/LegacyFileControllerTests.cs (4)
tests/Altinn.Broker.Tests/FileTransferControllerTests.cs (15)
Fact(53-64)Fact(66-80)Fact(82-94)Fact(95-110)Fact(112-127)Fact(129-171)Fact(173-231)Fact(233-256)Fact(258-271)Fact(273-286)Fact(288-316)Fact(318-335)Task(894-903)Task(905-914)Task(915-922)tests/Altinn.Broker.Tests/Factories/FileTransferInitializeExtTestFactory.cs (1)
FileTransferInitializeExtTestFactory(5-43)src/Altinn.Broker.API/Models/FileTransferInitializeResponseExt.cs (1)
FileTransferInitializeResponseExt(6-12)src/Altinn.Broker.API/Mappers/LegacyFileStatusOverviewExtMapper.cs (3)
LegacyFileOverviewExt(17-36)LegacyRecipientFileStatusExt(124-133)LegacyFileStatusExt(38-52)
src/Altinn.Broker.Application/ConfirmDownload/ConfirmDownloadHandler.cs (1)
src/Altinn.Broker.API/Mappers/LegacyFileStatusOverviewExtMapper.cs (1)
ActorFileTransferStatus(75-89)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Analyze (csharp)
🔇 Additional comments (1)
src/Altinn.Broker.Application/ConfirmDownload/ConfirmDownloadHandler.cs (1)
69-73: LGTM! Legacy/A3 behavioral split implemented correctly.The conditional guard correctly implements the requirement: non-legacy (A3) requests now enforce that
DownloadStartedmust occur beforeDownloadConfirmed, while legacy requests bypass this validation for Altinn 2 compatibility.
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/Altinn.Broker.Integrations/Altinn/Events/CloudEvent.cs (1)
12-12: Consider adding XML documentation for the new AlternativeSubject property.The new
AlternativeSubjectproperty would benefit from XML documentation explaining its purpose, when it's populated, and how it differs from theSubjectproperty. This would help event consumers understand the dual-subject approach introduced for A2 compatibility.Example documentation:
+ /// <summary> + /// Gets or sets an alternative subject for the event, typically containing the party ID path when available. + /// Used alongside Subject to support both organization number and party ID based event routing. + /// </summary> public string? AlternativeSubject { get; set; }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/Altinn.Broker.Common/StringExtensions.cs(1 hunks)src/Altinn.Broker.Integrations/Altinn/Events/AltinnEventBus.cs(1 hunks)src/Altinn.Broker.Integrations/Altinn/Events/CloudEvent.cs(1 hunks)
🧰 Additional context used
🧠 Learnings (11)
📓 Common learnings
Learnt from: Ceredron
Repo: Altinn/altinn-broker PR: 560
File: src/Altinn.Broker.Core/Helpers/ManifestDownloadStream.cs:239-249
Timestamp: 2024-10-29T12:15:40.824Z
Learning: In the `ManifestDownloadStream` class (`src/Altinn.Broker.Core/Helpers/ManifestDownloadStream.cs`), ZIP file validation is performed later in the code within the `AddManifestFile` method, so enhancing the `IsZipFile` method is unnecessary.
Learnt from: Ceredron
Repo: Altinn/altinn-broker PR: 560
File: src/Altinn.Broker.Core/Helpers/ManifestDownloadStream.cs:199-237
Timestamp: 2024-10-29T12:45:23.330Z
Learning: In the `ManifestDownloadStream` class (`src/Altinn.Broker.Core/Helpers/ManifestDownloadStream.cs`), optimizing memory usage in `AddManifestFile` by modifying the ZIP archive without loading the entire content into memory is currently not feasible because the base stream is a `ReadOnlyMemoryStream` based on a download stream. This optimization will be evaluated when the download stream is re-written in the "Support bigger files"-PR.
Learnt from: Ceredron
Repo: Altinn/altinn-broker PR: 560
File: tests/Altinn.Broker.Tests/ManifestDownloadStreamTests.cs:24-39
Timestamp: 2024-10-29T12:51:11.540Z
Learning: In `tests/Altinn.Broker.Tests/ManifestDownloadStreamTests.cs`, refactoring suggestions aimed at enhancing test organization and coverage may be considered less readable and of dubious value.
Learnt from: Andreass2
Repo: Altinn/altinn-broker PR: 561
File: src/Altinn.Broker.API/Controllers/LegacyFileController.cs:80-81
Timestamp: 2024-10-29T10:43:16.160Z
Learning: In the Altinn Broker API, specifically in `src/Altinn.Broker.API/Controllers/LegacyFileController.cs`, when handling file uploads in the `UploadFileStreamed` method, we can assume that all uploaded files are small and that the `Content-Length` header is always provided. Therefore, additional error handling for missing `Content-Length` is not required.
Learnt from: Ceredron
Repo: Altinn/altinn-broker PR: 560
File: tests/Altinn.Broker.Tests/Helpers/ManifestDownloadStreamHelpers.cs:18-28
Timestamp: 2024-10-29T12:50:05.699Z
Learning: In `tests/Altinn.Broker.Tests/Helpers/ManifestDownloadStreamHelpers.cs`, the test code is static and will not change, so refactoring suggestions on this file are unnecessary.
📚 Learning: 2024-10-23T12:43:47.413Z
Learnt from: Ceredron
Repo: Altinn/altinn-broker PR: 552
File: src/Altinn.Broker.API/Helpers/AltinnTokenEventsHelper.cs:11-22
Timestamp: 2024-10-23T12:43:47.413Z
Learning: In the Altinn Broker API, when handling authentication failures in `AltinnTokenEventsHelper.OnAuthenticationFailed`, issuer values are case-sensitive, so issuer comparisons should be case-sensitive.
Applied to files:
src/Altinn.Broker.Integrations/Altinn/Events/AltinnEventBus.cssrc/Altinn.Broker.Common/StringExtensions.cs
📚 Learning: 2024-12-08T23:15:58.682Z
Learnt from: Ceredron
Repo: Altinn/altinn-broker PR: 610
File: src/Altinn.Broker.Core/StringExtensions.cs:0-0
Timestamp: 2024-12-08T23:15:58.682Z
Learning: In `src/Altinn.Broker.Core/StringExtensions.cs`, prefer keeping the `WithoutPrefix` method simple and readable, avoiding complex modifications that reduce readability.
Applied to files:
src/Altinn.Broker.Common/StringExtensions.cs
📚 Learning: 2024-12-08T22:55:30.559Z
Learnt from: Ceredron
Repo: Altinn/altinn-broker PR: 610
File: src/Altinn.Broker.Common/StringExtensions.cs:23-30
Timestamp: 2024-12-08T22:55:30.559Z
Learning: In `src/Altinn.Broker.Common/StringExtensions.cs`, the `WithoutPrefix` method in the C# project checks if `orgNumber` is null or whitespace and returns an empty string if it is. Therefore, calling `orgNumber.Split(':').Last()` is safe, as the method ensures `orgNumber` is non-empty before splitting.
Applied to files:
src/Altinn.Broker.Common/StringExtensions.cs
📚 Learning: 2024-10-29T12:12:50.346Z
Learnt from: Ceredron
Repo: Altinn/altinn-broker PR: 560
File: tests/Altinn.Broker.Tests/Factories/FileTransferEntityFactory.cs:8-45
Timestamp: 2024-10-29T12:12:50.346Z
Learning: When suggesting code improvements in `tests/Altinn.Broker.Tests/Factories/FileTransferEntityFactory.cs`, avoid adding excessive comments and unnecessary code changes.
Applied to files:
src/Altinn.Broker.Common/StringExtensions.cs
📚 Learning: 2024-10-29T12:50:05.699Z
Learnt from: Ceredron
Repo: Altinn/altinn-broker PR: 560
File: tests/Altinn.Broker.Tests/Helpers/ManifestDownloadStreamHelpers.cs:18-28
Timestamp: 2024-10-29T12:50:05.699Z
Learning: In `tests/Altinn.Broker.Tests/Helpers/ManifestDownloadStreamHelpers.cs`, the test code is static and will not change, so refactoring suggestions on this file are unnecessary.
Applied to files:
src/Altinn.Broker.Common/StringExtensions.cs
📚 Learning: 2024-11-27T14:04:55.778Z
Learnt from: RagnarFatland-Avanade
Repo: Altinn/altinn-broker PR: 593
File: src/Altinn.Broker.Application/ExpireFileTransfer/ExpireFileTransferHandler.cs:96-96
Timestamp: 2024-11-27T14:04:55.778Z
Learning: In the Altinn Broker codebase, when throwing exceptions in C# code, prefer to use generic exceptions rather than creating custom exception classes, aiming to keep the code simple.
Applied to files:
src/Altinn.Broker.Common/StringExtensions.cs
📚 Learning: 2024-11-14T07:12:14.214Z
Learnt from: Ceredron
Repo: Altinn/altinn-broker PR: 582
File: src/Altinn.Broker.Persistence/Repositories/FileTransferRepository.cs:176-177
Timestamp: 2024-11-14T07:12:14.214Z
Learning: In `src/Altinn.Broker.Persistence/Repositories/FileTransferRepository.cs`, avoid suggesting to extract inline SQL queries into constants.
Applied to files:
src/Altinn.Broker.Common/StringExtensions.cs
📚 Learning: 2024-10-29T12:51:11.540Z
Learnt from: Ceredron
Repo: Altinn/altinn-broker PR: 560
File: tests/Altinn.Broker.Tests/ManifestDownloadStreamTests.cs:24-39
Timestamp: 2024-10-29T12:51:11.540Z
Learning: In `tests/Altinn.Broker.Tests/ManifestDownloadStreamTests.cs`, refactoring suggestions aimed at enhancing test organization and coverage may be considered less readable and of dubious value.
Applied to files:
src/Altinn.Broker.Common/StringExtensions.cs
📚 Learning: 2024-11-14T07:00:59.444Z
Learnt from: Ceredron
Repo: Altinn/altinn-broker PR: 582
File: src/Altinn.Broker.Core/Domain/ServiceOwnerEntity.cs:11-21
Timestamp: 2024-11-14T07:00:59.444Z
Learning: In the Altinn.Broker project, exceptions should not be used for control flow or logic; prefer returning null or appropriate results instead.
Applied to files:
src/Altinn.Broker.Common/StringExtensions.cs
📚 Learning: 2024-11-14T07:00:48.796Z
Learnt from: Ceredron
Repo: Altinn/altinn-broker PR: 582
File: tests/Altinn.Broker.Tests.LargeFile/Program.cs:80-82
Timestamp: 2024-11-14T07:00:48.796Z
Learning: In test programs like `tests/Altinn.Broker.Tests.LargeFile/Program.cs` in the `Altinn.Broker` project, it's acceptable to proceed without checking the success of HTTP responses or adding additional error handling.
Applied to files:
src/Altinn.Broker.Common/StringExtensions.cs
🔇 Additional comments (2)
src/Altinn.Broker.Common/StringExtensions.cs (1)
1-114: LGTM! Dead code removal verified as safe and complete.Verification confirms that
WithUrnPrefixhas no remaining references in the codebase, and the removal of theAltinn.Broker.Common.Constantsusing directive fromStringExtensions.csis appropriate. TheConstantsnamespace remains correctly imported in other files that require it. TheWithoutPrefix()method is properly retained and continues to be used throughout the codebase.src/Altinn.Broker.Integrations/Altinn/Events/AltinnEventBus.cs (1)
96-97: Review comment is incorrect and should be disregarded.Based on git history, the current code (lines 96-97) is reverting a one-day-old experimental change. Commit 733f76d attempted to switch Subject to URN format and remove AlternativeSubject, but commit 536ac94 (merged today) reverted that change, restoring the original path format (
/organisation/and/party/) with both Subject and AlternativeSubject fields. This is not a breaking change being introduced—it's a revert to the established format. Event consumers are not impacted by a format migration; the code is restoring the previous working format.Likely an incorrect or invalid review comment.
Description
It was permitted in A2 to confirm download before they were attempted to be downloaded. Therefore loosen up this validation for Legacy calls.
Related Issue(s)
Verification
Documentation
Summary by CodeRabbit
Bug Fixes
New Features
Tests
✏️ Tip: You can customize this high-level summary in your review settings.