Commit Graph

103 Commits

Author SHA1 Message Date
Franck Nijhof
9a4a7e2f4d Extend failed login message with the request URL (#75218) 2022-07-14 21:43:14 +02:00
J. Nick Koston
0c29b68cf8 Switch linear search to a dict lookup for ip bans (#74482) 2022-07-07 10:57:44 +02:00
J. Nick Koston
8b067e83f7 Initial orjson support take 3 (#73849)
* Initial orjson support take 2

Still need to work out problem building wheels

--

Redux of #72754 / #32153 Now possible since the following is solved:
ijl/orjson#220 (comment)

This implements orjson where we use our default encoder.  This does not implement orjson where `ExtendedJSONEncoder` is used as these areas tend to be called far less frequently.  If its desired, this could be done in a followup, but it seemed like a case of diminishing returns (except maybe for large diagnostics files, or traces, but those are not expected to be downloaded frequently).

Areas where this makes a perceptible difference:
- Anything that subscribes to entities (Initial subscribe_entities payload)
- Initial download of registries on first connection / restore
- History queries
- Saving states to the database
- Large logbook queries
- Anything that subscribes to events (appdaemon)

Cavets:
orjson supports serializing dataclasses natively (and much faster) which
eliminates the need to implement `as_dict` in many places
when the data is already in a dataclass. This works
well as long as all the data in the dataclass can also
be serialized. I audited all places where we have an `as_dict`
for a dataclass and found only backups needs to be adjusted (support for `Path` needed to be added for backups).  I was a little bit worried about `SensorExtraStoredData` with `Decimal` but it all seems to work out from since it converts it before it gets to the json encoding cc @dgomes

If it turns out to be a problem we can disable this
with option |= [orjson.OPT_PASSTHROUGH_DATACLASS](https://github.com/ijl/orjson#opt_passthrough_dataclass) and it
will fallback to `as_dict`

Its quite impressive for history queries
<img width="1271" alt="Screen_Shot_2022-05-30_at_23_46_30" src="https://user-images.githubusercontent.com/663432/171145699-661ad9db-d91d-4b2d-9c1a-9d7866c03a73.png">

* use for views as well

* handle UnicodeEncodeError

* tweak

* DRY

* DRY

* not needed

* fix tests

* Update tests/components/http/test_view.py

* Update tests/components/http/test_view.py

* black

* templates
2022-06-22 21:59:51 +02:00
Christopher Bailey
0461ec1566 Fix auth_sign_path with query params (take 2) (#73829) 2022-06-22 10:09:21 -05:00
J. Nick Koston
1e0a3246f4 Revert "Fix auth_sign_path with query params (#73240)" (#73808) 2022-06-21 22:45:16 -05:00
Christopher Bailey
67618311fa Fix auth_sign_path with query params (#73240)
Co-authored-by: J. Nick Koston <nick@koston.org>
2022-06-21 14:21:47 -05:00
Joakim Sørensen
3a0111e65d Use supervisor envs instead of hassio (#72601) 2022-05-30 12:00:13 +02:00
Franck Nijhof
3afadf8adb Revert "Block peer certs on supervisor" (#67104) 2022-02-23 12:32:07 +01:00
Paulus Schoutsen
938b64081b Block peer certs on supervisor (#66837)
Co-authored-by: Pascal Vizeli <pvizeli@syshack.ch>
Co-authored-by: Mike Degatano <michael.degatano@gmail.com>
2022-02-22 13:59:40 -08:00
J. Nick Koston
3bf2be1765 Startup with an emergency self signed cert if the ssl certificate cannot be loaded (#66707) 2022-02-18 16:08:26 -08:00
Paulus Schoutsen
63f8e437ed Add Home Assistant Content user (#64337) 2022-01-21 10:06:39 -08:00
Paulus Schoutsen
914f7f85ec Add local only users (#57598) 2021-11-29 14:01:03 -08:00
Bram Kragten
28c07f5c43 Fix CORS (#59360)
* Fix CORS

* rename

* Update view.py
2021-11-09 18:30:51 +01:00
Ville Skyttä
b52c5c82b1 Use http.HTTPStatus in components/[gh]* (#58246) 2021-10-23 20:34:53 +02:00
Paulus Schoutsen
a4d9019ffc Refactor persistent notification to no longer route all data via a service (#57157)
* Convert persistent notification tests to async

* Create/dismiss persistent notifications in exposed functions, not service calls

* Fix notify persistent_notification

* Remove setting up persistent_notification

* Drop more setups

* Empty methods

* Undeprecate sync methods because too big task

* Fix setup clearing notifications

* Fix a bunch of tests

* Fix more tests

* Uno mas

* Test persistent notification events

* Clean up stale comment

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-10-07 12:58:00 +02:00
Erik Montnemery
f6682ba99d Block tests from opening sockets (#55516) 2021-10-05 14:46:09 -10:00
Ville Skyttä
1aa7c87151 Remove redundant aiohttp response status=200 kwargs (#56417)
* Remove redundant aiohttp response status=200 kwargs

* Remove some more in h.c.auth

* Restore explicit status=HTTP_OK for auth and webhook per review request
2021-09-21 10:51:12 -07:00
Erik Montnemery
acdddabe1f Use hass_client_no_auth test fixture in integrations h-p (#55583) 2021-09-02 14:49:40 +02:00
Paulus Schoutsen
38a7bdbcf3 Do not process forwarded for headers for cloud requests (#54364) 2021-08-10 01:45:56 +02:00
Marc Mueller
10bfc78365 Fix missing encoding with open() (#53593)
* Fix missing encoding with open()

* Fix tests

* Improve open - frontend
2021-07-28 09:41:45 +02:00
Joakim Plate
d339e3bd8c Reject trusted network access from proxies (#52388) 2021-07-02 11:49:42 +02:00
Joakim Plate
eedf1c3ebe Reject requests from the proxy itself (#52073)
* Reject requests from the proxy itself

* Adjust tests
2021-06-27 19:02:51 +02:00
Franck Nijhof
33e08f38da Raise bad request when receiving HTTP request from untrusted proxy (#51839)
* Raise bad request when receiving HTTP request from untrusted proxy

* Fix code comment
2021-06-17 04:41:19 +02:00
Franck Nijhof
cdd1f6b2f0 Always load middle to handle forwarded proxy data (#51332) 2021-06-01 09:38:55 -07:00
J. Nick Koston
a4432557d3 Defer writing http config until after startup has calmed down (#50000) 2021-05-02 19:48:49 -10:00
Bram Kragten
e3105c7eb1 Revert CORS changes for my home assistant (#47064)
* Revert CORS changes for my home assistant

* Update test_init.py

* Update test_init.py
2021-02-25 15:28:22 -08:00
Franck Nijhof
22389043eb Remove base_url fallback (#46316) 2021-02-10 14:31:11 +01:00
Bram Kragten
6f446cf627 Add my component (#46058)
Co-authored-by: Franck Nijhof <git@frenck.dev>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-02-08 14:44:46 +01:00
gregod
cf9ea6f82d Sanitize user-agent in wrong_login message (#45251) 2021-01-18 09:21:30 +01:00
Pascal Vizeli
e1427c45f2 Bump aioHTTP 3.7.3 - YARL 1.6.3 (#45180) 2021-01-15 13:19:22 +01:00
Franck Nijhof
dee0f887de Extend filter and filter tests (#45179) 2021-01-15 10:30:29 +01:00
Franck Nijhof
f047d04882 Add filtering 2021-01-14 20:02:01 +01:00
Franck Nijhof
65cf2fcb6f Drop asynctest (#44746) 2021-01-01 22:31:56 +01:00
Franck Nijhof
1c2ebdf307 Upgrade black to 20.8b1 (#39287) 2020-08-27 13:56:20 +02:00
Franck Nijhof
475e70986b Extend IP ban / failed login notification information (#39020) 2020-08-18 23:32:19 +02:00
Franck Nijhof
cc4ebc925c Improve X-Forwarded-* request headers handling (#38696)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: Franck Nijhof <git@frenck.dev>
Co-authored-by: Pascal Vizeli <pvizeli@syshack.ch>
2020-08-11 22:57:50 +02:00
Franck Nijhof
20710d8605 Add current request context to get_url helper (#38602) 2020-08-09 14:07:31 +02:00
J. Nick Koston
578d4a9b6a Make the frontend available sooner (Part 1 of 2) (#36263)
* Part 1 of 2 (no breaking changes in part 1).

When integrations configured via the UI block startup or fail to start,
the webserver can remain offline which make it is impossible
to recover without manually changing files in
.storage since the UI is not available.

This change is the foundation that part 2 will build on
and enable a listener to start the webserver when the frontend
is finished loading.

Frontend Changes (home-assistant/frontend#6068)

* Address review comments

* bump timeout to 1800s, adjust comment

* bump timeout to 4h

* remove timeout failsafe

* and the test
2020-06-02 13:54:11 -05:00
Paulus Schoutsen
acbffb511d Fix base_url extract stack (#36331)
* Fix base_url extract stack

* Fix tests
2020-06-01 11:44:45 -07:00
Pascal Vizeli
ed014e3c96 Revert "Ensure frontend is available if integrations fail to start - Part 1 of 2 (#36093)" (#36251)
This reverts commit fbe7b4ddfa.
2020-05-29 10:18:39 +02:00
J. Nick Koston
fbe7b4ddfa Ensure frontend is available if integrations fail to start - Part 1 of 2 (#36093)
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
2020-05-28 21:09:07 -07:00
Franck Nijhof
e3e3a113e9 async_get_url -> get_url (#35382) 2020-05-08 21:53:28 +02:00
Franck Nijhof
e56dd8ed50 Detect use of deprecated base_url (#35353)
* Detect use of deprecated base_url

* Update get_url helper

* Update core migration

* Migrate all tests
2020-05-08 17:52:32 +02:00
Franck Nijhof
2223592486 Add get_url helper, deprecate base_url (#35224) 2020-05-08 02:29:47 +02:00
Paulus Schoutsen
2af984917e Use asynctest-mock in most places (#35109)
* Use asynctest-mock in most places

* Fix broken patch in pilight
2020-05-03 11:27:19 -07:00
Paulus Schoutsen
76f392476b Use a future for mock coro (#34989) 2020-04-30 16:31:00 -07:00
Paulus Schoutsen
ec47216388 Use built-in test helpers on 3.8 (#34901) 2020-04-30 13:29:50 -07:00
springstan
bc26be3c11 Add and use HTTP_FORBIDDEN constant (#33839) 2020-04-09 17:41:17 +02:00
Martin Hjelmare
c3decc6531 Do not ban supervisor ip if set (#33781)
* Use asynctest patch instead of mock_coro

* Add test for supervisor ip ban

* Do not ban supervisor ip if set

* Extract supervisor ip helper

* Check supervisor ip before banning

* Remove added blank line

* Clean up get supervisor ip

Co-Authored-By: Pascal Vizeli <pvizeli@syshack.ch>

Co-authored-by: Pascal Vizeli <pvizeli@syshack.ch>
2020-04-08 10:31:44 -07:00
Franck Nijhof
d7e9959442 String formatting improvements for tests (2) (#33666) 2020-04-05 00:33:07 +02:00