Skip to content

feat(remediation): input validation#1203

Open
kanstantsinbuklis-sap wants to merge 2 commits into
mainfrom
kanstantsinbuklis-sap/issue-1196/input-validation
Open

feat(remediation): input validation#1203
kanstantsinbuklis-sap wants to merge 2 commits into
mainfrom
kanstantsinbuklis-sap/issue-1196/input-validation

Conversation

@kanstantsinbuklis-sap
Copy link
Copy Markdown
Collaborator

Description

In this PR I've added validation for RemediationInput but also this solution can be applied not only for the Remediation

What type of PR is this? (check all applicable)

  • 🍕 Feature
  • 🐛 Bug Fix
  • 📝 Documentation Update
  • 🎨 Style
  • 🧑‍💻 Code Refactor
  • 🔥 Performance Improvements
  • ✅ Test
  • 🤖 Build
  • 🔁 CI
  • 📦 Chore (Release)
  • ⏩ Revert

Related Tickets & Documents

Added tests?

  • 👍 yes
  • 🙅 no, because they aren't needed
  • 🙋 no, because I need help
  • Separate ticket for tests # (issue/pr)

Added test to verify validation constraints

Added to documentation?

  • 📜 README.md
  • 🤝 Documentation pages updated
  • 🙅 no documentation needed
  • (if applicable) generated OpenAPI docs for CRD changes

@kanstantsinbuklis-sap kanstantsinbuklis-sap force-pushed the kanstantsinbuklis-sap/issue-1196/input-validation branch from 1fa251a to eb78990 Compare May 22, 2026 10:57
@kanstantsinbuklis-sap kanstantsinbuklis-sap linked an issue May 22, 2026 that may be closed by this pull request
@kanstantsinbuklis-sap kanstantsinbuklis-sap marked this pull request as ready for review May 22, 2026 10:58
Copilot AI review requested due to automatic review settings May 22, 2026 10:58
michalkrzyz
michalkrzyz previously approved these changes May 22, 2026
Copy link
Copy Markdown
Collaborator

@michalkrzyz michalkrzyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one!

Signed-off-by: Kanstantsin Buklis <kanstantsin.buklis@sap.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 @constraint directive implementation and register it in the GraphQL server.
  • Annotate RemediationInput fields 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 thread internal/api/graphql/graph/directive/constraint.go
Comment thread internal/app/remediation/remediation_handler.go
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>
@kanstantsinbuklis-sap kanstantsinbuklis-sap force-pushed the kanstantsinbuklis-sap/issue-1196/input-validation branch from d559b82 to 0b604d9 Compare May 22, 2026 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(remediation): input validation

3 participants