Skip to content

fix(api): guard wireless state endpoints for devices with no WiFi port#1087

Open
shaoboon wants to merge 1 commit into
mainfrom
sb_wificheck
Open

fix(api): guard wireless state endpoints for devices with no WiFi port#1087
shaoboon wants to merge 1 commit into
mainfrom
sb_wificheck

Conversation

@shaoboon

Copy link
Copy Markdown
Contributor

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

@codecov

codecov Bot commented Jun 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 43.46%. Comparing base (82728e6) to head (5f2c3fd).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@shaoboon shaoboon marked this pull request as ready for review June 19, 2026 09:10
@shaoboon shaoboon requested a review from a team as a code owner June 19, 2026 09:10
@shaoboon shaoboon requested a review from Copilot June 19, 2026 09:10

Copilot AI left a comment

Copy link
Copy Markdown

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 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 GetWirelessState to reuse GetWiFiPorts instead of inlining enumerate/pull logic.
  • Map wsman.ErrNoWiFiPort to 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.

Comment thread internal/controller/httpapi/v1/wifistate.go
Comment thread internal/controller/httpapi/v1/wifistate_test.go
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

Copilot AI left a comment

Copy link
Copy Markdown

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 4 out of 4 changed files in this pull request and generated 1 comment.

Comment on lines +33 to +35
if len(ports) > 0 && ports[0].EnabledState == wifi.EnabledState(requestedState) {
return requestedState, nil
}
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.

error msg is not clear when posting wireless state on platform without wifi capability

2 participants