Skip to content

ESD-1638: Validate VXC update JSON with checked helpers and a field gate#526

Open
Phil-Browne wants to merge 10 commits into
mainfrom
esd-1638-vxc-update-json-checked
Open

ESD-1638: Validate VXC update JSON with checked helpers and a field gate#526
Phil-Browne wants to merge 10 commits into
mainfrom
esd-1638-vxc-update-json-checked

Conversation

@Phil-Browne

Copy link
Copy Markdown
Contributor

The VXC update JSON builder used raw type assertions, so a misspelled key or a wrong-typed value (e.g. --json '{"rateLimt": 500}' or {"rateLimit": "500"}') was silently dropped and the CLI happily reported success on an empty update.

  • Swap every raw rawData[...].(type) assertion in buildUpdateVXCRequestFromJSON for the checked utils.JSON* helpers already used by the buy path, so a typo or wrong type now returns a clear error.
  • Add an at-least-one-field gate: a payload that resolves to no recognized field (e.g. {} or only unknown keys) is rejected before any API call.
  • Add tests covering a typo key, a wrong-typed flat and nested value, a wrong-typed partner config, an empty object, the flat aEndVlan/bEndVlan fallback, and a valid multi-field payload.

buildUpdateVXCRequestFromJSON used raw type assertions, so a
misspelled key or wrong-typed value was silently dropped and an
empty update was sent to the API. Switch to the checked
utils.JSON* helpers used by the buy path, and reject a payload
that sets no recognized field before any API call.
Copilot AI review requested due to automatic review settings July 10, 2026 16:24
@Phil-Browne Phil-Browne requested a review from a team as a code owner July 10, 2026 16:24
@codecov

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.76536% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.30%. Comparing base (5fc464a) to head (03955a6).

Files with missing lines Patch % Lines
internal/commands/vxc/vxc_inputs_update.go 97.76% 2 Missing and 2 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #526      +/-   ##
==========================================
+ Coverage   78.87%   79.30%   +0.42%     
==========================================
  Files         193      193              
  Lines       18574    18683     +109     
==========================================
+ Hits        14651    14817     +166     
+ Misses       2857     2818      -39     
+ Partials     1066     1048      -18     
Files with missing lines Coverage Δ
internal/commands/vxc/vxc_inputs_update.go 85.76% <97.76%> (+34.76%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR improves the safety of the VXC update JSON input path by making JSON parsing type-safe (using shared utils.JSON* helpers) and by rejecting “empty/no-op” updates before any API call, with new tests covering the new validation behavior.

Changes:

  • Replaced raw JSON type assertions in buildUpdateVXCRequestFromJSON with checked utils.JSONString/JSONNumber/JSONBool/JSONObject helpers to surface key typos and wrong JSON types as errors.
  • Added an “at least one field must be updated” gate to prevent silent no-op updates.
  • Added unit tests covering typo keys, wrong-typed values (flat/nested/partner config), empty object, VLAN fallback behavior, and a valid multi-field update.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
internal/commands/vxc/vxc_inputs_update.go Uses checked JSON helpers across update fields and adds an at-least-one-field gate.
internal/commands/vxc/vxc_inputs_test.go Adds test coverage for typo/wrong-type/empty JSON update payloads and valid multi-field updates.

Comment thread internal/commands/vxc/vxc_inputs_update.go
Comment thread internal/commands/vxc/vxc_inputs_update.go
Comment thread internal/commands/vxc/vxc_inputs_update.go
Comment thread internal/commands/vxc/vxc_inputs_update.go
Comment thread internal/commands/vxc/vxc_inputs_update.go
Comment thread internal/commands/vxc/vxc_inputs_update.go
…date JSON

Copilot flagged that VLAN, inner VLAN, and vNIC-related fields silently
truncated fractional JSON numbers (e.g. 100.9 -> 100) before validation.
Add the same whole-number check already used for rateLimit/term to all
six affected fields. Also add tests for the remaining untested error
branches and valid-value paths in buildUpdateVXCRequestFromJSON.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread internal/commands/vxc/vxc_inputs_update.go Outdated
Comment thread internal/commands/vxc/vxc_inputs_update.go Outdated
…missing

Copilot noted that an absent connectType fell through to the generic
"only VRouter" message instead of naming the missing field.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread internal/commands/vxc/vxc_inputs_update.go
Wrap buildUpdateVXCRequestFromJSON's returned errors with
exitcodes.NewUsageError to match the buy JSON builder's convention,
so malformed or wrongly typed update payloads exit with the usage
code instead of the general code.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread internal/commands/vxc/vxc_inputs_test.go
Guards against a regression where an error message stays the same
but silently stops being classified as a usage error.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

Comment thread internal/commands/vxc/vxc_inputs_update.go
Comment thread internal/commands/vxc/vxc_inputs_update.go
Comment thread internal/commands/vxc/vxc_inputs_test.go

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread internal/commands/vxc/vxc_inputs_update.go Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

Comment thread internal/commands/vxc/vxc_inputs_update.go Outdated
Comment thread internal/commands/vxc/vxc_inputs_test.go
Comment thread internal/commands/vxc/vxc_inputs_test.go
Comment thread internal/commands/vxc/vxc_inputs_test.go

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@penzeliz-megaport

Copy link
Copy Markdown
Collaborator

The checked-helper swap is right, but the unknown-key rejection is only partial. The unrecognised-key scan runs only in the if !fieldSet branch of buildUpdateVXCRequestFromJSON, so a typo alongside a valid field slips through: --json '{"rateLimit":500,"rateLimt":999}' sets fieldSet=true from rateLimit, skips the scan, drops rateLimt silently, and reports success. That's the same typo-silently-dropped case this PR targets, fixed only for lone-typo payloads. Compute the unrecognised set over rawData (and the nested config maps) unconditionally and reject if non-empty, or unmarshal into a typed struct with DisallowUnknownFields.

…d is set

The unrecognized-key scan only ran inside the fieldSet == false branch,
so a typo alongside a valid field (e.g. rateLimit + rateLimt) set
fieldSet and skipped the scan, silently dropping the typo. Compute the
unrecognized set unconditionally and reject whenever it's non-empty.
@Phil-Browne

Copy link
Copy Markdown
Contributor Author

Good catch, fixed in eccef2d: the unrecognized-key scan now runs unconditionally over rawData (and the nested aEndConfiguration/bEndConfiguration maps) instead of only when fieldSet is false, so {"rateLimit":500,"rateLimt":999} is now rejected with unrecognized keys: rateLimt instead of silently dropping the typo. Added regression tests for both the top-level and nested sibling-typo cases.

…son-checked

# Conflicts:
#	internal/commands/vxc/vxc_inputs_test.go
#	internal/commands/vxc/vxc_inputs_update.go
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.

3 participants