Skip to content

Commit

Permalink
add testing setup
Browse files Browse the repository at this point in the history
  • Loading branch information
BeryJu committed Jul 30, 2023
1 parent 90c5a1b commit 2acf0a9
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 1 deletion.
27 changes: 27 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.SHELLFLAGS += -x -e
.ONESHELL:
PY_SOURCES = custom_components scripts
HASS_VERSION = $(shell pip freeze | grep \^homeassistant | sed 's/==/\n/g' | tail -n 1)
COMPOSE_ARGS = -f scripts/docker-compose.yml -p hass-auth-header

all: lint-fix lint

lint-fix:
isort $(PY_SOURCES)
black $(PY_SOURCES)
ruff $(PY_SOURCES)

lint:
pylint $(PY_SOURCES)

test-env-start:
VERSION=${HASS_VERSION} docker-compose $(COMPOSE_ARGS) up -d

test-env-stop:
VERSION=${HASS_VERSION} docker compose $(COMPOSE_ARGS) down

test-env-remove:
VERSION=${HASS_VERSION} docker compose $(COMPOSE_ARGS) down -v

hass-restart:
docker-compose $(COMPOSE_ARGS) exec homeassistant killall -HUP python3
2 changes: 1 addition & 1 deletion custom_components/auth_header/headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,5 @@ async def async_step_init(
if user.name == self._remote_user:
return await self.async_finish({"user": user.id})

_LOGGER.debug("no user found")
_LOGGER.debug("no matching user found")
return self.async_abort(reason="not_allowed")
29 changes: 29 additions & 0 deletions scripts/authentik-blueprint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# yaml-language-server: $schema=https://goauthentik.io/blueprints/schema.json
version: 1
metadata:
name: hass-auth-header - Testing setup
context:
# Needs to be changed if the test setup is completely in docker
internal_host: http://localhost:8123
entries:
- model: authentik_providers_proxy.proxyprovider
id: provider
identifiers:
name: hass-auth-header
attrs:
authorization_flow: !Find [authentik_flows.flow, [slug, default-provider-authorization-implicit-consent]]
mode: proxy
internal_host: !Context internal_host
external_host: http://hass-auth-header.127.0.0.1.nip.io:9000
- model: authentik_core.application
identifiers:
slug: hass-auth-header
attrs:
name: Homeassistant
provider: !KeyOf provider
- model: authentik_outposts.outpost
identifiers:
managed: goauthentik.io/outposts/embedded
attrs:
providers:
- !KeyOf provider
15 changes: 15 additions & 0 deletions scripts/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '3'
services:
homeassistant:
image: "ghcr.io/home-assistant/home-assistant:${VERSION}"
volumes:
- temp_config:/config
- ../custom_components:/config/custom_components
- ./fixed_config/configuration.yaml:/config/configuration.yaml
- /etc/localtime:/etc/localtime:ro
restart: unless-stopped
ports:
- 8123:8123

volumes:
temp_config:
14 changes: 14 additions & 0 deletions scripts/fixed_config/configuration.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Loads default set of integrations. Do not remove.
default_config:

http:
use_x_forwarded_for: true
trusted_proxies:
- 0.0.0.0/0
auth_header:
username_header: X-authentik-username

logger:
default: info
logs:
custom_components.auth_header: debug

0 comments on commit 2acf0a9

Please sign in to comment.