fix(api): guard wireless state endpoints for devices with no WiFi port#1087
Open
shaoboon wants to merge 1 commit into
Open
fix(api): guard wireless state endpoints for devices with no WiFi port#1087shaoboon wants to merge 1 commit into
shaoboon wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1087 +/- ##
==========================================
+ Coverage 43.44% 43.46% +0.02%
==========================================
Files 143 143
Lines 13621 13626 +5
==========================================
+ Hits 5917 5922 +5
Misses 7143 7143
Partials 561 561 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR fixes inconsistent handling of wireless state endpoints for AMT devices that do not expose a WiFi interface, ensuring both GET/POST paths fail early and return a consistent 404 instead of surfacing a generic 500.
Changes:
- Add a WiFi-port presence guard (
GetWiFiPorts) before issuing a wireless state-change request. - Refactor
GetWirelessStateto reuseGetWiFiPortsinstead of inlining enumerate/pull logic. - Map
wsman.ErrNoWiFiPortto HTTP 404 in the v1 POST handler (matching existing GET behavior) and extend tests accordingly.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| internal/usecase/devices/wifistate.go | Adds WiFi-port guard to RequestWirelessStateChange and refactors GetWirelessState to use GetWiFiPorts. |
| internal/usecase/devices/wifistate_test.go | Updates mocks/tests for the new GetWiFiPorts guard and refactor. |
| internal/controller/httpapi/v1/wifistate.go | Maps ErrNoWiFiPort to 404 for the POST endpoint (consistent with GET). |
| internal/controller/httpapi/v1/wifistate_test.go | Adds a handler test for the new 404 behavior on POST when no WiFi port exists. |
RequestWirelessStateChange previously issued the state-change WSMAN call without checking that the device exposes a WiFi interface, and the POST handler routed any ErrNoWiFiPort through the default error path (500). Add the GetWiFiPorts guard to RequestWirelessStateChange and map ErrNoWiFiPort to 404 in requestWirelessStateChange, matching the existing GetWirelessState behavior. Refactor GetWirelessState to reuse the shared GetWiFiPorts helper instead of inlining enumerate/pull/empty-check. Both wireless state endpoints now return 404 consistently when the device has no WiFi port. OpenAPI already declares 404 via protectedRouteOptions, so the generated spec is unchanged. Resolves: #1057
11245ed to
5f2c3fd
Compare
Comment on lines
+33
to
+35
| if len(ports) > 0 && ports[0].EnabledState == wifi.EnabledState(requestedState) { | ||
| return requestedState, nil | ||
| } |
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.
RequestWirelessStateChange previously issued the state-change WSMAN call without checking that the device exposes a WiFi interface, and the POST handler routed any ErrNoWiFiPort through the default error path (500).
Add the GetWiFiPorts guard to RequestWirelessStateChange and map ErrNoWiFiPort to 404 in requestWirelessStateChange, matching the existing GetWirelessState behavior. Refactor GetWirelessState to reuse the shared GetWiFiPorts helper instead of inlining enumerate/pull/empty-check.
Both wireless state endpoints now return 404 consistently when the device has no WiFi port. OpenAPI already declares 404 via protectedRouteOptions, so the generated spec is unchanged.
Resolves: #1057