Disambiguate Supervisor HTTPUnauthorized on user/password validation (#44940)

* Disambiguate HTTPUnauthorized on user/password validation

The HA core API usually returns 401 when the request does not
have proper authentication tokens or they have expired.

However the user/password validation endpoint may also return
401 when the given user/password is invalid.

The supervisor is currently unable to distinguish both scenarios,
and it needs to.

See https://github.com/home-assistant/supervisor/issues/2408

* Return 404 if user& password are not found/valid

* Fix test for invalid user/password
pull/44957/head
Sergio Oller 2021-01-08 17:28:22 +01:00 committed by GitHub
parent 793adb7f40
commit 905100a189
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 2 deletions

View File

@ -82,7 +82,7 @@ class HassIOAuth(HassIOBaseAuth):
data[ATTR_USERNAME], data[ATTR_PASSWORD] data[ATTR_USERNAME], data[ATTR_PASSWORD]
) )
except auth_ha.InvalidAuth: except auth_ha.InvalidAuth:
raise HTTPUnauthorized() from None raise HTTPNotFound() from None
return web.Response(status=HTTP_OK) return web.Response(status=HTTP_OK)

View File

@ -66,7 +66,7 @@ async def test_login_error(hass, hassio_client_supervisor):
) )
# Check we got right response # Check we got right response
assert resp.status == 401 assert resp.status == 404
mock_login.assert_called_with("test", "123456") mock_login.assert_called_with("test", "123456")