1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Use http.HTTPStatus in components/[gh]* (#58246)

This commit is contained in:
Ville Skyttä
2021-10-23 21:34:53 +03:00
committed by GitHub
parent 583ae3c953
commit b52c5c82b1
38 changed files with 272 additions and 247 deletions

View File

@@ -1,4 +1,5 @@
"""Test cors for the HTTP component."""
from http import HTTPStatus
from pathlib import Path
from unittest.mock import patch
@@ -59,28 +60,28 @@ def client(loop, aiohttp_client):
async def test_cors_requests(client):
"""Test cross origin requests."""
req = await client.get("/", headers={ORIGIN: TRUSTED_ORIGIN})
assert req.status == 200
assert req.status == HTTPStatus.OK
assert req.headers[ACCESS_CONTROL_ALLOW_ORIGIN] == TRUSTED_ORIGIN
# With password in URL
req = await client.get(
"/", params={"api_password": "some-pass"}, headers={ORIGIN: TRUSTED_ORIGIN}
)
assert req.status == 200
assert req.status == HTTPStatus.OK
assert req.headers[ACCESS_CONTROL_ALLOW_ORIGIN] == TRUSTED_ORIGIN
# With password in headers
req = await client.get(
"/", headers={HTTP_HEADER_HA_AUTH: "some-pass", ORIGIN: TRUSTED_ORIGIN}
)
assert req.status == 200
assert req.status == HTTPStatus.OK
assert req.headers[ACCESS_CONTROL_ALLOW_ORIGIN] == TRUSTED_ORIGIN
# With auth token in headers
req = await client.get(
"/", headers={AUTHORIZATION: "Bearer some-token", ORIGIN: TRUSTED_ORIGIN}
)
assert req.status == 200
assert req.status == HTTPStatus.OK
assert req.headers[ACCESS_CONTROL_ALLOW_ORIGIN] == TRUSTED_ORIGIN
@@ -95,7 +96,7 @@ async def test_cors_preflight_allowed(client):
},
)
assert req.status == 200
assert req.status == HTTPStatus.OK
assert req.headers[ACCESS_CONTROL_ALLOW_ORIGIN] == TRUSTED_ORIGIN
assert req.headers[ACCESS_CONTROL_ALLOW_HEADERS] == "X-REQUESTED-WITH"
@@ -139,7 +140,7 @@ async def test_cors_works_with_frontend(hass, hass_client):
)
client = await hass_client()
resp = await client.get("/")
assert resp.status == 200
assert resp.status == HTTPStatus.OK
async def test_cors_on_static_files(hass, hass_client):
@@ -157,5 +158,5 @@ async def test_cors_on_static_files(hass, hass_client):
ACCESS_CONTROL_REQUEST_METHOD: "GET",
},
)
assert resp.status == 200
assert resp.status == HTTPStatus.OK
assert resp.headers[ACCESS_CONTROL_ALLOW_ORIGIN] == "http://www.example.com"