Skip to content

Conversation

@jaycollett
Copy link

Summary

Fixes the UniFi app test() method which was incorrectly reporting "Invalid credentials" even when credentials were valid and the dashboard stats were working correctly.

Root Cause

The original test() method used appTest() which only checked HTTP status codes. This approach had several issues:

  1. Self-hosted controllers return HTTP 400 (not 401) on authentication failure, with error details in the response body
  2. UDM devices might return HTTP 200 but still have authentication issues that need body validation
  3. The test didn't verify the session actually worked (unlike livestats() which implicitly validates by successfully fetching data)

Changes

  • Use execute() directly with explicit POST method (matching livestats() behavior)
  • Handle HTTP 400 errors for self-hosted controller authentication failures
  • Handle HTTP 401/403 errors for UDM authentication failures
  • Validate self-hosted response body (meta.rc === "ok")
  • Verify login success by attempting to fetch stats (same validation as dashboard)
  • Provide descriptive error messages for different failure scenarios

Related Issues

Testing

Tested on:

  • Device: UniFi Dream Machine Pro (UDM-Pro)
  • UniFi OS Console: Latest version
  • Network Application: Latest version
  • Heimdall: 2.6.3 running in Docker

Test Results

Scenario Before After
Valid credentials "Invalid credentials" error ✅ "Successfully connected to UniFi"
Invalid credentials "Invalid credentials" ✅ "Failed: Invalid credentials"
Connection error Generic error ✅ "Failed: Connection error"

Test Configuration

  • "Self Hosted" toggle: unchecked (UDM-Pro uses built-in controller)
  • URL: https:// endpoint (HTTP redirects to HTTPS on UDM)
  • Skip TLS verification: Not required when using valid SSL certificate

Notes

The test() method was using appTest() which only checked HTTP status codes,
causing false "Invalid credentials" errors even when credentials were valid.
This fix aligns the test() method with the working livestats() approach.

Changes:
- Use execute() directly with explicit POST method (same as livestats)
- Handle HTTP 400 errors for self-hosted controller auth failures
- Handle HTTP 401/403 errors for UDM auth failures
- Validate self-hosted response body (meta.rc === "ok")
- Verify login by fetching stats to confirm session is valid
- Provide descriptive error messages for different failure scenarios

Fixes linuxserver#640, linuxserver#695, linuxserver#811
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

1 participant