feat(remediation): input validation#1203
Open
kanstantsinbuklis-sap wants to merge 2 commits into
Open
Conversation
1fa251a to
eb78990
Compare
Signed-off-by: Kanstantsin Buklis <kanstantsin.buklis@sap.com>
e3f3ce5 to
3d2410b
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Adds GraphQL-level input validation for RemediationInput by introducing a reusable @constraint schema directive, wiring it into the gqlgen server, and extending E2E coverage for rejected overlong inputs.
Changes:
- Introduce a gqlgen
@constraintdirective implementation and register it in the GraphQL server. - Annotate
RemediationInputfields with length (and URL format) constraints. - Add E2E tests asserting that invalid/overlong remediation inputs are rejected.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/e2e/remediation_query_test.go | Adds E2E cases for constraint validation failures on create/update remediation mutations. |
| internal/app/remediation/remediation_handler.go | Removes create-path URL parsing/validation for risk-accepted remediations. |
| internal/api/graphql/server.go | Registers the new Constraint directive with gqlgen config. |
| internal/api/graphql/graph/schema/remediation.graphqls | Applies @constraint annotations to RemediationInput string fields. |
| internal/api/graphql/graph/schema/common.graphqls | Defines the @constraint directive in the shared schema. |
| internal/api/graphql/graph/directive/constraint.go | Implements directive logic for min/max length and URL validation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+34
to
+40
|
|
||
| if minLength != nil && len(str) < *minLength { | ||
| return nil, fmt.Errorf("value must be at least %d characters", *minLength) | ||
| } | ||
|
|
||
| if maxLength != nil && len(str) > *maxLength { | ||
| return nil, fmt.Errorf("value must not exceed %d characters", *maxLength) |
Comment on lines
+326
to
+336
| It("rejects url exceeding 2048 characters", func() { | ||
| _, err := e2e_common.ExecuteGqlQueryFromFile[struct { | ||
| Remediation model.Remediation `json:"createRemediation"` | ||
| }]( | ||
| cfg.Port, | ||
| "../api/graphql/graph/queryCollection/remediation/create.graphql", | ||
| map[string]any{ | ||
| "input": map[string]any{ | ||
| "url": strings.Repeat("a", 2049), | ||
| }, | ||
| }, |
…ation Signed-off-by: Kanstantsin Buklis <kanstantsin.buklis@sap.com>
d559b82 to
0b604d9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
In this PR I've added validation for
RemediationInputbut also this solution can be applied not only for the RemediationWhat type of PR is this? (check all applicable)
Related Tickets & Documents
Added tests?
Added test to verify validation constraints
Added to documentation?