-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[PM-26429] Add validation to policy data and metadata #6460
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?
[PM-26429] Add validation to policy data and metadata #6460
Conversation
…policy data and metadata.
…lid data types in PolicyRequestModel and SavePolicyRequest.
…AndSerializePolicyData nullable
test/Api.IntegrationTest/AdminConsole/Controllers/PoliciesControllerTests.cs
Show resolved
Hide resolved
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6460 +/- ##
==========================================
+ Coverage 51.99% 52.02% +0.02%
==========================================
Files 1876 1877 +1
Lines 82633 82651 +18
Branches 7316 7316
==========================================
+ Hits 42969 42997 +28
+ Misses 38008 37995 -13
- Partials 1656 1659 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
New Issues (3)Checkmarx found the following issues in this Pull Request
|
…ing of invalid data types in policy updates.
…ata and metadata based on policy type.
…stModel to utilize PolicyDataValidator for data validation and serialization, removing redundant methods and improving code clarity.
…d Metadata properties with empty dictionaries.
| /// <param name="policyType">The type of policy</param> | ||
| /// <returns>Serialized JSON string if data is valid, null if data is null or empty</returns> | ||
| /// <exception cref="BadRequestException">Thrown when data validation fails</exception> | ||
| public static string? ValidateAndSerialize(Dictionary<string, object>? data, PolicyType policyType) |
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.
You can remove the nullable and null check now.
| /// <param name="metadata">The policy metadata to validate</param> | ||
| /// <param name="policyType">The type of policy</param> | ||
| /// <returns>Deserialized metadata model, or EmptyMetadataModel if metadata is null, empty, or validation fails</returns> | ||
| public static IPolicyMetadataModel ValidateAndDeserializeMetadata(Dictionary<string, object>? metadata, PolicyType policyType) |
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.
Save as above
…validation methods
…empty data and metadata, and remove null assignments in test cases for improved clarity.
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.
🚀
…ic details in BadRequestException messages.
…st responses by checking for specific field names in the response content.
|
@jrmccannon, I have updated the error message to explicitly say which field had the wrong type. |


🎟️ Tracking
https://bitwarden.atlassian.net/browse/PM-26429
📔 Objective
⏰ Reminders before review
🦮 Reviewer guidelines
:+1:) or similar for great changes:memo:) or ℹ️ (:information_source:) for notes or general info:question:) for questions:thinking:) or 💭 (:thought_balloon:) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion:art:) for suggestions / improvements:x:) or:warning:) for more significant problems or concerns needing attention:seedling:) or ♻️ (:recycle:) for future improvements or indications of technical debt:pick:) for minor or nitpick changes