From f96dec267bb366d89b2e05d91235f79849676ced Mon Sep 17 00:00:00 2001 From: "Dev (Paperclip)" Date: Thu, 26 Nov 2026 11:04:24 +0000 Subject: [PATCH] feat(git): Hinweis im Account-Panel, Startlog, Fehlersuche und Betriebs-Compose (#30) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Panel zeigt bei 503/G10 und 403/G07 einen Hinweis statt sich auszublenden; ohne Login unsichtbar - Startlog: Info-Zeile bei aktivem Backend (kid, Allowlist), ohne Secrets - docs/git: Abschnitt Fehlersuche / nachträglich aktivieren - docs/deploy: compose.yaml-Vorlage für das veröffentlichte Image, Verlinkung aus README/FORK/auth/storage - Dev-Compose reicht HB_ASSET_* durch Refs #30 Co-Authored-By: Claude Sonnet 5.5 --- .env.example | 5 + FORK.md | 2 + README.md | 352 +++++++++--------- client/fork/git/GitConnectionsPanel.jsx | 17 +- client/fork/git/git.less | 1 + client/fork/git/panelState.js | 18 + .../pages/accountPage/accountPage.jsx | 2 +- docker-compose.override.yml | 5 + docs/auth/README.md | 3 + docs/deploy/README.md | 44 +++ docs/deploy/compose.yaml | 70 ++++ docs/deploy/env.example | 15 + docs/git/README.md | 33 +- docs/storage/README.md | 2 + server/fork/git/index.js | 3 +- tests/fork/gitPanelState.test.js | 20 + tests/fork/gitStartupLog.test.js | 28 ++ 17 files changed, 439 insertions(+), 181 deletions(-) create mode 100644 client/fork/git/panelState.js create mode 100644 docs/deploy/README.md create mode 100644 docs/deploy/compose.yaml create mode 100644 docs/deploy/env.example create mode 100644 tests/fork/gitPanelState.test.js create mode 100644 tests/fork/gitStartupLog.test.js diff --git a/.env.example b/.env.example index b4452c47..437d5ceb 100644 --- a/.env.example +++ b/.env.example @@ -74,3 +74,8 @@ HB_OIDC_CLIENT_SECRET=dev-only-client-secret # HB_GIT_MAX_CONCURRENCY=2 # HB_GIT_COMMITTER_NAME=Homebrewery # HB_GIT_COMMITTER_EMAIL= +# Bild-Upload (ADR 0004): nur mit aktivem Git-Backend, Standard an +# HB_ASSETS_ENABLED=true +# HB_ASSET_MAX_BYTES=5242880 +# HB_ASSET_MAX_BYTES_PER_BREW=52428800 +# HB_ASSET_TYPES=png,jpeg,gif,webp diff --git a/FORK.md b/FORK.md index a9fe689e..98dee73e 100644 --- a/FORK.md +++ b/FORK.md @@ -105,6 +105,8 @@ version, run `dockerhub-sync.yml` with e.g. `v1.0.0`. `buildcache` is the BuildKit layer cache, not a runnable image. +Running the published image (Compose template with PostgreSQL 18, OIDC, Git backend and image upload, German): [docs/deploy/README.md](docs/deploy/README.md). + Runner and repository settings (repository → Settings → Actions): - **Runner:** jobs use `runs-on: ubuntu-latest` (public runner, as in the DnD Character Manager). diff --git a/README.md b/README.md index 0d524128..bc7204fc 100644 --- a/README.md +++ b/README.md @@ -1,174 +1,178 @@ -# The Homebrewery - -[![Homebrewery](https://circleci.com/gh/naturalcrit/homebrewery/tree/master.svg?style=svg)](https://app.circleci.com/pipelines/github/naturalcrit/homebrewery?branch=master) - -The Homebrewery is a tool for making authentic looking [D&D content][dnd-content-url] -using [Markdown][markdown-url]. It is distributed under the terms of the [MIT License](./license). - -[dnd-content-url]: https://dnd.wizards.com/products/tabletop-games/rpg-products/rpg_playershandbook -[markdown-url]: https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet - -## Quick Start -The easiest way to get started using The Homebrewery is to use it -[on our website][homebrewery-url]. The code is open source, so feel free to -clone it and tinker with it. If you want to make changes to the code, you can run -your own local version for testing by following the installation instructions -below. - -[homebrewery-url]: https://homebrewery.naturalcrit.com - -### Installation -First, install three programs that The Homebrewery requires to run and retrieve -updates: - -1. install [node](https://nodejs.org/en/), version v16 or higher. -1. install [mongodb](https://www.mongodb.com/try/download/community) (Community version) - - For the easiest installation, follow these steps: - 1. In the installer, uncheck the option to run as a service. - 1. You can install MongoDB Compass if you want a GUI to view your database documents. - 1. If you install any version over 6.0, you will have to install [MongoDB Shell](https://www.mongodb.com/try/download/shell). - 1. Go to the C:\ drive and create a folder called "data". - 1. Inside the "data" folder, create a new folder called "db". - 1. Open a command prompt or other terminal and navigate to your MongoDB install folder (C:\Program Files\Mongo\Server\6.0\bin). - 1. In the command prompt, run "mongod", which will start up your local database server. - 1. While MongoD is running, open a second command prompt and navigate to the MongoDB install folder. - 1. Search in Windows for "Advanced system settings" and open it. - 1. Click "Environment variables", find the "path" variable, and double-click to open it. - 1. Click "New" and paste in the path to the MongoDB "bin" folder. - 1. Click "OK" three times to close all the windows. - 1. In the second command prompt, run "mongo", which allows you to edit the database. - 1. Type `use homebrewery` to create The Homebrewery database. You should see `switched to db homebrewery`. - 1. Type `db.brews.insertOne({"title":"test"})` to create a blank document. You should see `{ -acknowledged: true, -insertedId: ObjectId("63c2fce9e5ac5a94fe2410cf") -}` - -1. install [git](https://git-scm.com/downloads) (select the option that allows Git to run from the command prompt). - -Checkout the repo ([documentation][github-clone-repo-docs-url]): -``` -git clone https://github.com/naturalcrit/homebrewery.git -``` - -[github-clone-repo-docs-url]: https://docs.github.com/en/free-pro-team@latest/github/creating-cloning-and-archiving-repositories/cloning-a-repository - -Second, you will need to add the environment variable `NODE_ENV=local` to allow -the project to run locally. - -You can set this **temporarily** (until you close the terminal) in your shell of choice with admin privileges: -* Windows Powershell: `$env:NODE_ENV="local"` -* Windows CMD: `set NODE_ENV=local` -* Linux / macOS: `export NODE_ENV=local` - -If you want to add this variable **permanently** the steps are as follows: - 1. Search in Windows for "Advanced system settings" and open it. - 1. Click "Environment variables". - 1. In System Variables, click "New" - 1. Click "New" and write `NODE_ENV` as a name and `local` as the value. - 1. Click "OK" three times to close all the windows. - This can be undone at any time if needed. - -Third, you will need to install the Node dependencies, compile the app, and run -it using the two commands: - -1. `npm install` -1. `npm start` - -When the Homebrewery server is started for the first time, it will modify the database to create the indexes required for better Homebrewery performance. This may take a few moments to complete for each index, dependent on how much content is in your local database - a brand new, empty database should be done in seconds. - -On completion, you should be able to go to [http://localhost:8000](http://localhost:8000) in your browser and use The Homebrewery offline. - -If you had any issue at all, here are some links that may be useful: -- [Course](https://learn.mongodb.com/courses/m103-basic-cluster-administration) on cluster administration, useful for beginners -- [Mongo community forums](https://www.mongodb.com/community/forums/) -- Useful Stack Overflow links for your most probable errors: [1](https://stackoverflow.com/questions/44962540/mongod-and-mongo-commands-not-working-on-windows-10), [2](https://stackoverflow.com/questions/15053893/mongo-command-not-recognized-when-trying-to-connect-to-a-mongodb-server/41507803#41507803), [3](https://stackoverflow.com/questions/51224959/mongo-is-not-recognized-as-an-internal-or-external-command-operable-program-o) - -If you still have problems, post in [Our Subreddit](https://www.reddit.com/r/homebrewery/) and we will help you. - -### Running the application via Docker - -Please see the docs here: [README.DOCKER.md](./README.DOCKER.md) - -### Lokal starten / Selbst hosten (Fork homebrewery-oidc) - -```bash -cp .env.example .env # optional, alle Werte haben Entwicklungs-Defaults -docker compose up --build # App + MongoDB -> http://localhost:8000 -``` - -`docker-compose.override.yml` (wird automatisch geladen) und `docker/` enthalten die Fork-Erweiterungen; `docker-compose.yml` bleibt Upstream-identisch. - -| Profil | Start | Ergebnis | -|---|---|---| -| `postgres` | `docker compose --profile postgres up -d postgres` | PostgreSQL 18 auf `127.0.0.1:5432` (ab M2) | -| `keycloak` | `docker compose --profile keycloak up -d` | Keycloak :8080, Realm `homebrewery`, Client `homebrewery`/`dev-only-client-secret`, Nutzer `testuser`/`testuser-dev`, Admin `admin`/`admin-dev`. Discovery: `http://keycloak.localhost:8080/realms/homebrewery/.well-known/openid-configuration` (Start dauert 1–2 Min.) | -| `authentik` | `docker compose --profile authentik up -d` | authentik :9000, Provider/App `homebrewery` per Blueprint, gleicher Client und Nutzer, Admin `akadmin`/`admin-dev`. Discovery: `http://authentik.localhost:9000/application/o/homebrewery/.well-known/openid-configuration` | - -Hinweise: Die IdPs laufen unter `keycloak.localhost:8080` bzw. `authentik.localhost:9000` (Issuer für Browser und App-Container identisch, Bindung nur an 127.0.0.1; `*.localhost` löst moderne Browser/OS automatisch auf, sonst `127.0.0.1 keycloak.localhost authentik.localhost` in `/etc/hosts`). Ports nur ändern, wenn Redirect-/Issuer-Einstellungen mitgezogen werden. Alle Zugangsdaten sind reine Dev-Werte, für den Betrieb in `.env` ersetzen. MongoDB 5+ benötigt eine CPU mit AVX; auf älteren CPUs/VMs `MONGO_TAG=4.4` setzen. Der authentik-Blueprint wird beim Erststart automatisch angewendet (dauert einige Minuten, bis die Discovery-URL 200 liefert). - -#### Login über OIDC (Keycloak, authentik, …) - -Der Fork bringt einen generischen OIDC-Login (Authorization Code + PKCE) mit. Konfiguration nur über Umgebungsvariablen (`HB_OIDC_ISSUER`, `HB_OIDC_CLIENT_ID`, `HB_OIDC_CLIENT_SECRET`, `HB_PUBLIC_URL`, `HB_SESSION_SECRET`, …, Vorlage in `.env.example`). Die bisherigen Logins (`naturalcrit`: Benutzername/Passwort, Google) bleiben Standard und lassen sich über `HB_AUTH_PROVIDERS` abschalten, abgeschaltete Methoden verschwinden aus der UI und ihre Endpunkte sind gesperrt. Einrichtung, Variablen und Kontozuordnung: [docs/auth/README.md](./docs/auth/README.md), [Keycloak](./docs/auth/keycloak.md), [authentik](./docs/auth/authentik.md). Entscheidung: [ADR 0001](./docs/adr/0001-auth-oidc.md). - -#### Brews in Git speichern - -Angemeldete OIDC-Nutzer können Brews in einem beliebigen Git-Repository speichern (HTTPS + Personal Access Token, providerneutral: Gitea, Forgejo, GitHub, GitLab, …). Speichern erzeugt einen Commit, beim Öffnen wird der Remote-Stand übernommen, Konflikte werden erkannt und angezeigt. Das Feature ist aus, solange `HB_GIT_TOKEN_KEY` fehlt. Einrichtung, Variablen, Sicherheit und Anbieter-Hinweise: [docs/git/README.md](./docs/git/README.md). Entscheidung: [ADR 0003](./docs/adr/0003-git-backend-und-teilen.md). - -### Running the application on FreeBSD or FreeNAS - -Please see the docs here: [README.FreeBSD.md](./README.FREEBSD.md) - -### Standalone PHB Stylesheet -If you just want the stylesheet that is generated to make pages look like they -are from the Player's Handbook, you will find it in the -[phb.standalone.css](./phb.standalone.css) file. - -If you are developing locally and would like to generate your own, follow the -above steps and then run `npm run phb`. - -## Issues, Suggestions, and Bugs -If you run into any issues using The Homebrewery or have suggestions for -improvement, please submit an issue [on GitHub][repo-issues-url]. -You can also get help for issues on the subreddit [r/homebrewery][subreddit-url] - -[repo-issues-url]: https://github.com/naturalcrit/homebrewery/issues -[subreddit-url]: https://www.reddit.com/r/homebrewery - -## Changelog - -You can check out the [changelog](./changelog.md). - -## License - -This project is licensed under the [MIT license](./license), which means you -are free to use The Homebrewery in any way that you want, except for claiming -that you made it yourself. - -If you wish to sell, or in some way gain profit for, what's created on this site, -it's your responsibility to ensure you have the proper licenses/rights for any -images or resources used. - -## Contributing - -You are welcome to contribute to the development and maintenance of the -project! There are several ways of doing that: -- At the moment, we have a huge backlog of [issues][repo-issues-url] and some - of them are outdated, duplicates, or don't contain any useful info. To help, you can [mark duplicates][github-mark-duplicate-url], try to - reproduce some complex or weird issues, try finding a workaround for a - reported bug, or just mention our issue managers team to let them know about - outdated issues via `@naturalcrit/issue-managers`. -- Our [subreddit][subreddit-url] is constantly growing and there are number of - bug reports. Any help with sorting them out is very welcome. -- And of course you can contribute by fixing a bug or implementing a new - feature by yourself, we are waiting for your - [pull requests][github-pr-docs-url]! - -Anyway, if you would like to get in touch with the team and discuss/coordinate -your contribution to the project, please join our [gitter chat][gitter-url]. - -[github-mark-duplicate-url]: https://docs.github.com/en/free-pro-team@latest/github/managing-your-work-on-github/about-duplicate-issues-and-pull-requests -[github-pr-docs-url]: https://docs.github.com/en/free-pro-team@latest/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request -[gitter-url]: https://gitter.im/naturalcrit/Lobby - - +# The Homebrewery + +[![Homebrewery](https://circleci.com/gh/naturalcrit/homebrewery/tree/master.svg?style=svg)](https://app.circleci.com/pipelines/github/naturalcrit/homebrewery?branch=master) + +The Homebrewery is a tool for making authentic looking [D&D content][dnd-content-url] +using [Markdown][markdown-url]. It is distributed under the terms of the [MIT License](./license). + +[dnd-content-url]: https://dnd.wizards.com/products/tabletop-games/rpg-products/rpg_playershandbook +[markdown-url]: https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet + +## Quick Start +The easiest way to get started using The Homebrewery is to use it +[on our website][homebrewery-url]. The code is open source, so feel free to +clone it and tinker with it. If you want to make changes to the code, you can run +your own local version for testing by following the installation instructions +below. + +[homebrewery-url]: https://homebrewery.naturalcrit.com + +### Installation +First, install three programs that The Homebrewery requires to run and retrieve +updates: + +1. install [node](https://nodejs.org/en/), version v16 or higher. +1. install [mongodb](https://www.mongodb.com/try/download/community) (Community version) + + For the easiest installation, follow these steps: + 1. In the installer, uncheck the option to run as a service. + 1. You can install MongoDB Compass if you want a GUI to view your database documents. + 1. If you install any version over 6.0, you will have to install [MongoDB Shell](https://www.mongodb.com/try/download/shell). + 1. Go to the C:\ drive and create a folder called "data". + 1. Inside the "data" folder, create a new folder called "db". + 1. Open a command prompt or other terminal and navigate to your MongoDB install folder (C:\Program Files\Mongo\Server\6.0\bin). + 1. In the command prompt, run "mongod", which will start up your local database server. + 1. While MongoD is running, open a second command prompt and navigate to the MongoDB install folder. + 1. Search in Windows for "Advanced system settings" and open it. + 1. Click "Environment variables", find the "path" variable, and double-click to open it. + 1. Click "New" and paste in the path to the MongoDB "bin" folder. + 1. Click "OK" three times to close all the windows. + 1. In the second command prompt, run "mongo", which allows you to edit the database. + 1. Type `use homebrewery` to create The Homebrewery database. You should see `switched to db homebrewery`. + 1. Type `db.brews.insertOne({"title":"test"})` to create a blank document. You should see `{ +acknowledged: true, +insertedId: ObjectId("63c2fce9e5ac5a94fe2410cf") +}` + +1. install [git](https://git-scm.com/downloads) (select the option that allows Git to run from the command prompt). + +Checkout the repo ([documentation][github-clone-repo-docs-url]): +``` +git clone https://github.com/naturalcrit/homebrewery.git +``` + +[github-clone-repo-docs-url]: https://docs.github.com/en/free-pro-team@latest/github/creating-cloning-and-archiving-repositories/cloning-a-repository + +Second, you will need to add the environment variable `NODE_ENV=local` to allow +the project to run locally. + +You can set this **temporarily** (until you close the terminal) in your shell of choice with admin privileges: +* Windows Powershell: `$env:NODE_ENV="local"` +* Windows CMD: `set NODE_ENV=local` +* Linux / macOS: `export NODE_ENV=local` + +If you want to add this variable **permanently** the steps are as follows: + 1. Search in Windows for "Advanced system settings" and open it. + 1. Click "Environment variables". + 1. In System Variables, click "New" + 1. Click "New" and write `NODE_ENV` as a name and `local` as the value. + 1. Click "OK" three times to close all the windows. + This can be undone at any time if needed. + +Third, you will need to install the Node dependencies, compile the app, and run +it using the two commands: + +1. `npm install` +1. `npm start` + +When the Homebrewery server is started for the first time, it will modify the database to create the indexes required for better Homebrewery performance. This may take a few moments to complete for each index, dependent on how much content is in your local database - a brand new, empty database should be done in seconds. + +On completion, you should be able to go to [http://localhost:8000](http://localhost:8000) in your browser and use The Homebrewery offline. + +If you had any issue at all, here are some links that may be useful: +- [Course](https://learn.mongodb.com/courses/m103-basic-cluster-administration) on cluster administration, useful for beginners +- [Mongo community forums](https://www.mongodb.com/community/forums/) +- Useful Stack Overflow links for your most probable errors: [1](https://stackoverflow.com/questions/44962540/mongod-and-mongo-commands-not-working-on-windows-10), [2](https://stackoverflow.com/questions/15053893/mongo-command-not-recognized-when-trying-to-connect-to-a-mongodb-server/41507803#41507803), [3](https://stackoverflow.com/questions/51224959/mongo-is-not-recognized-as-an-internal-or-external-command-operable-program-o) + +If you still have problems, post in [Our Subreddit](https://www.reddit.com/r/homebrewery/) and we will help you. + +### Running the application via Docker + +Please see the docs here: [README.DOCKER.md](./README.DOCKER.md) + +### Lokal starten / Selbst hosten (Fork homebrewery-oidc) + +```bash +cp .env.example .env # optional, alle Werte haben Entwicklungs-Defaults +docker compose up --build # App + MongoDB -> http://localhost:8000 +``` + +`docker-compose.override.yml` (wird automatisch geladen) und `docker/` enthalten die Fork-Erweiterungen; `docker-compose.yml` bleibt Upstream-identisch. + +| Profil | Start | Ergebnis | +|---|---|---| +| `postgres` | `docker compose --profile postgres up -d postgres` | PostgreSQL 18 auf `127.0.0.1:5432` (ab M2) | +| `keycloak` | `docker compose --profile keycloak up -d` | Keycloak :8080, Realm `homebrewery`, Client `homebrewery`/`dev-only-client-secret`, Nutzer `testuser`/`testuser-dev`, Admin `admin`/`admin-dev`. Discovery: `http://keycloak.localhost:8080/realms/homebrewery/.well-known/openid-configuration` (Start dauert 1–2 Min.) | +| `authentik` | `docker compose --profile authentik up -d` | authentik :9000, Provider/App `homebrewery` per Blueprint, gleicher Client und Nutzer, Admin `akadmin`/`admin-dev`. Discovery: `http://authentik.localhost:9000/application/o/homebrewery/.well-known/openid-configuration` | + +Hinweise: Die IdPs laufen unter `keycloak.localhost:8080` bzw. `authentik.localhost:9000` (Issuer für Browser und App-Container identisch, Bindung nur an 127.0.0.1; `*.localhost` löst moderne Browser/OS automatisch auf, sonst `127.0.0.1 keycloak.localhost authentik.localhost` in `/etc/hosts`). Ports nur ändern, wenn Redirect-/Issuer-Einstellungen mitgezogen werden. Alle Zugangsdaten sind reine Dev-Werte, für den Betrieb in `.env` ersetzen. MongoDB 5+ benötigt eine CPU mit AVX; auf älteren CPUs/VMs `MONGO_TAG=4.4` setzen. Der authentik-Blueprint wird beim Erststart automatisch angewendet (dauert einige Minuten, bis die Discovery-URL 200 liefert). + +#### Login über OIDC (Keycloak, authentik, …) + +Der Fork bringt einen generischen OIDC-Login (Authorization Code + PKCE) mit. Konfiguration nur über Umgebungsvariablen (`HB_OIDC_ISSUER`, `HB_OIDC_CLIENT_ID`, `HB_OIDC_CLIENT_SECRET`, `HB_PUBLIC_URL`, `HB_SESSION_SECRET`, …, Vorlage in `.env.example`). Die bisherigen Logins (`naturalcrit`: Benutzername/Passwort, Google) bleiben Standard und lassen sich über `HB_AUTH_PROVIDERS` abschalten, abgeschaltete Methoden verschwinden aus der UI und ihre Endpunkte sind gesperrt. Einrichtung, Variablen und Kontozuordnung: [docs/auth/README.md](./docs/auth/README.md), [Keycloak](./docs/auth/keycloak.md), [authentik](./docs/auth/authentik.md). Entscheidung: [ADR 0001](./docs/adr/0001-auth-oidc.md). + +#### Brews in Git speichern + +Angemeldete OIDC-Nutzer können Brews in einem beliebigen Git-Repository speichern (HTTPS + Personal Access Token, providerneutral: Gitea, Forgejo, GitHub, GitLab, …). Speichern erzeugt einen Commit, beim Öffnen wird der Remote-Stand übernommen, Konflikte werden erkannt und angezeigt. Das Feature ist aus, solange `HB_GIT_TOKEN_KEY` fehlt. Einrichtung, Variablen, Sicherheit und Anbieter-Hinweise: [docs/git/README.md](./docs/git/README.md). Entscheidung: [ADR 0003](./docs/adr/0003-git-backend-und-teilen.md). Fehlersuche und nachträgliches Aktivieren: [docs/git/README.md](./docs/git/README.md#fehlersuche--nachträglich-aktivieren). + +#### Betrieb mit dem veröffentlichten Image + +Compose-Vorlage (App + PostgreSQL 18, OIDC, Git, Bild-Upload) ohne Repo-Checkout: [docs/deploy/README.md](./docs/deploy/README.md). Wichtig: Jede `HB_*`-Variable muss im Container ankommen (`environment:`/`env_file:`), und nach Änderungen gilt `docker compose up -d`, nicht `restart`. + +### Running the application on FreeBSD or FreeNAS + +Please see the docs here: [README.FreeBSD.md](./README.FREEBSD.md) + +### Standalone PHB Stylesheet +If you just want the stylesheet that is generated to make pages look like they +are from the Player's Handbook, you will find it in the +[phb.standalone.css](./phb.standalone.css) file. + +If you are developing locally and would like to generate your own, follow the +above steps and then run `npm run phb`. + +## Issues, Suggestions, and Bugs +If you run into any issues using The Homebrewery or have suggestions for +improvement, please submit an issue [on GitHub][repo-issues-url]. +You can also get help for issues on the subreddit [r/homebrewery][subreddit-url] + +[repo-issues-url]: https://github.com/naturalcrit/homebrewery/issues +[subreddit-url]: https://www.reddit.com/r/homebrewery + +## Changelog + +You can check out the [changelog](./changelog.md). + +## License + +This project is licensed under the [MIT license](./license), which means you +are free to use The Homebrewery in any way that you want, except for claiming +that you made it yourself. + +If you wish to sell, or in some way gain profit for, what's created on this site, +it's your responsibility to ensure you have the proper licenses/rights for any +images or resources used. + +## Contributing + +You are welcome to contribute to the development and maintenance of the +project! There are several ways of doing that: +- At the moment, we have a huge backlog of [issues][repo-issues-url] and some + of them are outdated, duplicates, or don't contain any useful info. To help, you can [mark duplicates][github-mark-duplicate-url], try to + reproduce some complex or weird issues, try finding a workaround for a + reported bug, or just mention our issue managers team to let them know about + outdated issues via `@naturalcrit/issue-managers`. +- Our [subreddit][subreddit-url] is constantly growing and there are number of + bug reports. Any help with sorting them out is very welcome. +- And of course you can contribute by fixing a bug or implementing a new + feature by yourself, we are waiting for your + [pull requests][github-pr-docs-url]! + +Anyway, if you would like to get in touch with the team and discuss/coordinate +your contribution to the project, please join our [gitter chat][gitter-url]. + +[github-mark-duplicate-url]: https://docs.github.com/en/free-pro-team@latest/github/managing-your-work-on-github/about-duplicate-issues-and-pull-requests +[github-pr-docs-url]: https://docs.github.com/en/free-pro-team@latest/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request +[gitter-url]: https://gitter.im/naturalcrit/Lobby + + diff --git a/client/fork/git/GitConnectionsPanel.jsx b/client/fork/git/GitConnectionsPanel.jsx index 8896f4f7..9ae64417 100644 --- a/client/fork/git/GitConnectionsPanel.jsx +++ b/client/fork/git/GitConnectionsPanel.jsx @@ -1,13 +1,15 @@ import './git.less'; import React, { useEffect, useState } from 'react'; import { gitApi } from './gitApi.js'; +import { classifyListError } from './panelState.js'; // Verbindungen verwalten (ADR 0003 §7): anlegen, testen, löschen, Brews aus dem Repo importieren. // Das Token-Feld ist reines Eingabefeld und wird nie vorbefüllt; der Server gibt den Token nie zurück. const EMPTY = { label: '', repoUrl: '', authUsername: 'git', token: '' }; const GitConnectionsPanel = ()=>{ - const [state, setState] = useState('loading'); // loading | off | ready + const [state, setState] = useState('loading'); // loading | hidden | notice | ready + const [notice, setNotice] = useState(''); const [conns, setConns] = useState([]); const [form, setForm] = useState(EMPTY); const [msg, setMsg] = useState({}); // pro Verbindung: { ok, text } @@ -15,10 +17,19 @@ const GitConnectionsPanel = ()=>{ const [files, setFiles] = useState({}); // pro Verbindung: { branch, files } const reload = ()=>gitApi.listConnections().then((list)=>{ setConns(list); setState('ready'); }) - .catch((err)=>{ if([403, 503].includes(err.status)) setState('off'); else { setFormError(err.message); setState('ready'); } }); + .catch((err)=>{ + const { state: next, notice: text } = classifyListError(err); + if(next === 'error') { setFormError(err.message); setState('ready'); } else { setNotice(text ?? ''); setState(next); } + }); useEffect(()=>{ reload(); }, []); - if(state !== 'ready') return null; // Git-Backend deaktiviert oder kein OIDC-Konto + if(state === 'notice') return ( +
+

Git-Verbindungen

+

{notice}

+
+ ); + if(state !== 'ready') return null; // lädt oder nicht angemeldet const set = (id, ok, text)=>setMsg((m)=>({ ...m, [id]: { ok, text } })); diff --git a/client/fork/git/git.less b/client/fork/git/git.less index 8373a555..3c2bcd36 100644 --- a/client/fork/git/git.less +++ b/client/fork/git/git.less @@ -16,6 +16,7 @@ } .error { color : @red; font-weight : 800; } .ok { color : @teal; font-weight : 800; } + .notice { color : #555555; font-style : italic; } ul.files { list-style : none; padding : 0; li { margin : 2px 0; } } } diff --git a/client/fork/git/panelState.js b/client/fork/git/panelState.js new file mode 100644 index 00000000..02f9f6cc --- /dev/null +++ b/client/fork/git/panelState.js @@ -0,0 +1,18 @@ +// Zustand des Git-Panels auf der Account-Seite (FLW-258): aus dem Fehler von GET /api/git/connections +// wird entschieden, ob das Panel einen Hinweis zeigt, normal arbeitet oder unsichtbar bleibt. +export const NOTICES = { + disabled : 'Git-Backend auf diesem Server nicht aktiviert – siehe docs/git (Abschnitt „Fehlersuche / nachträglich aktivieren“).', + noOidc : 'Nur mit OIDC-Anmeldung verfügbar.' +}; + +/** + * @param {{ status?: number, HBErrorCode?: string }} err Fehler aus gitApi.listConnections() + * @returns {{ state: 'notice'|'hidden'|'error', notice?: string }} + * notice = Hinweis anzeigen, hidden = nichts anzeigen (nicht angemeldet), error = Panel mit Fehlermeldung + */ +export const classifyListError = (err)=>{ + if(err?.status === 503 && (!err.HBErrorCode || err.HBErrorCode === 'G10')) return { state: 'notice', notice: NOTICES.disabled }; + if(err?.status === 403 && (!err.HBErrorCode || err.HBErrorCode === 'G07')) return { state: 'notice', notice: NOTICES.noOidc }; + if(err?.status === 401) return { state: 'hidden' }; + return { state: 'error' }; +}; diff --git a/client/homebrew/pages/accountPage/accountPage.jsx b/client/homebrew/pages/accountPage/accountPage.jsx index f38d60b8..9b734ecb 100644 --- a/client/homebrew/pages/accountPage/accountPage.jsx +++ b/client/homebrew/pages/accountPage/accountPage.jsx @@ -69,7 +69,7 @@ const AccountPage = (props)=>{ {renderSaveLocationButton('Homebrewery', 'HOMEBREWERY')} {renderSaveLocationButton('Google Drive', 'GOOGLE-DRIVE', accountDetails.googleId)} - + {accountDetails.username && } ); }; diff --git a/docker-compose.override.yml b/docker-compose.override.yml index 9c0649c4..55c26595 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -45,6 +45,11 @@ services: HB_GIT_MAX_CONCURRENCY: ${HB_GIT_MAX_CONCURRENCY:-} HB_GIT_COMMITTER_NAME: ${HB_GIT_COMMITTER_NAME:-} HB_GIT_COMMITTER_EMAIL: ${HB_GIT_COMMITTER_EMAIL:-} + # Bild-Upload (ADR 0004, nur mit aktivem Git-Backend) + HB_ASSETS_ENABLED: ${HB_ASSETS_ENABLED:-} + HB_ASSET_MAX_BYTES: ${HB_ASSET_MAX_BYTES:-} + HB_ASSET_MAX_BYTES_PER_BREW: ${HB_ASSET_MAX_BYTES_PER_BREW:-} + HB_ASSET_TYPES: ${HB_ASSET_TYPES:-} ports: !override - "${APP_PORT:-8000}:8000" diff --git a/docs/auth/README.md b/docs/auth/README.md index 840c8c61..289674a2 100644 --- a/docs/auth/README.md +++ b/docs/auth/README.md @@ -36,6 +36,9 @@ Details: [keycloak.md](keycloak.md), [authentik.md](authentik.md). Die App startet nicht, wenn `oidc` aktiv ist und Pflichtwerte fehlen. +Betrieb mit dem veröffentlichten Image (eigene Compose-Datei): Alle Variablen müssen unter `environment:`/`env_file:` stehen, nach +Änderungen `docker compose up -d` statt `restart`. Vorlage: [docs/deploy/README.md](../deploy/README.md). + ## Login-Methoden ein-/ausschalten (`HB_AUTH_PROVIDERS`) Der Redirect-URI beim IdP ist `${HB_PUBLIC_URL}/auth/oidc/callback`, der Post-Logout-URI `${HB_PUBLIC_URL}/`. diff --git a/docs/deploy/README.md b/docs/deploy/README.md new file mode 100644 index 00000000..a8725994 --- /dev/null +++ b/docs/deploy/README.md @@ -0,0 +1,44 @@ +# Betrieb mit dem veröffentlichten Image + +Für den Betrieb ohne Repo-Checkout: [`compose.yaml`](compose.yaml) (App + PostgreSQL 18, OIDC, Git-Backend, +Bild-Upload) und [`env.example`](env.example). Das Dev-Compose im Repo-Root (`docker-compose.yml` + +`docker-compose.override.yml`) baut das Image selbst und ist nur für die Entwicklung gedacht. + +## Image + +| Registry | Image | Tags | +| --- | --- | --- | +| Gitea | `git.morlana.online/f.weber/homebrewery-oidc` | `main`, `vX.Y.Z`, `latest` (nur Release), `sha-<7>` | +| Docker Hub | `/homebrewery-oidc` | nur `vX.Y.Z` und `latest` | + +Details zu CI und Tags: [FORK.md](../../FORK.md#ci-and-container-image). Das Image enthält keine Konfiguration oder Secrets. + +## Einrichten + +```bash +mkdir homebrewery && cd homebrewery +# compose.yaml und env.example aus docs/deploy/ hierher kopieren +cp env.example .env # Werte eintragen +docker compose config -q # prüft Syntax und Pflichtvariablen +docker compose up -d +docker compose logs homebrewery | head +``` + +Der Redirect-URI beim IdP ist `/auth/oidc/callback` ([docs/auth](../auth/README.md)). TLS und Reverse +Proxy (nginx/Traefik vor Port 8000) sind nicht Teil der Vorlage; `HB_PUBLIC_URL` muss die extern erreichbare +`https://`-URL sein. Der App-Container verbindet sich beim Start mit dem IdP (Discovery) und mit PostgreSQL (Version ≥ 18). + +## Wichtig: Variablen müssen im Container ankommen + +Der Container sieht **nur** Variablen unter `environment:` (oder aus `env_file:`). Ein Eintrag in `.env` allein reicht +nicht, er füllt nur die `${…}`-Platzhalter in der Compose-Datei. Wer eine eigene Compose-Datei schreibt, muss jede +`HB_*`-Variable (insbesondere `HB_GIT_TOKEN_KEY`) dort ausdrücklich durchreichen. Die Vorlage tut das für alle +Variablen aus [docs/auth](../auth/README.md), [docs/git](../git/README.md) und [docs/storage](../storage/README.md). + +Nach jeder Änderung `docker compose up -d` ausführen: `docker compose restart` startet denselben Container mit der +alten Umgebung neu und übernimmt Änderungen **nicht**. + +## Git-Backend nachträglich einschalten + +Jederzeit möglich, kein Erststart nötig: `HB_GIT_TOKEN_KEY` in `.env` setzen, `docker compose up -d`. Prüfung und +Fehlersuche: [docs/git](../git/README.md#fehlersuche--nachträglich-aktivieren). diff --git a/docs/deploy/compose.yaml b/docs/deploy/compose.yaml new file mode 100644 index 00000000..50ae6cb6 --- /dev/null +++ b/docs/deploy/compose.yaml @@ -0,0 +1,70 @@ +# Betriebs-Vorlage: veröffentlichtes Image + PostgreSQL 18, OIDC-Login, Git-Backend, Bild-Upload. +# Siehe docs/deploy/README.md. Start: +# cp env.example .env # Werte eintragen (Secrets nie einchecken) +# docker compose up -d # nach jeder Änderung an .env erneut `up -d` (nicht `restart`) +# +# WICHTIG: Der Container sieht nur Variablen, die unter `environment:` stehen (oder per `env_file:` geladen werden). +# Eine Variable in .env allein reicht NICHT: .env füllt nur die ${…}-Platzhalter in dieser Datei. +services: + homebrewery: + # Gitea-Registry: git.morlana.online/f.weber/homebrewery-oidc: (main, vX.Y.Z, latest) + # Docker Hub (nur Release-Tags): /homebrewery-oidc:vX.Y.Z + image: ${HB_IMAGE:-git.morlana.online/f.weber/homebrewery-oidc:latest} + restart: unless-stopped + depends_on: + postgres: + condition: service_healthy + ports: + - "${APP_PORT:-8000}:8000" + environment: + # Storage (docs/storage/) + HB_DB_DRIVER: postgres + HB_POSTGRES_URL: postgres://${POSTGRES_USER:-homebrewery}:${POSTGRES_PASSWORD:?POSTGRES_PASSWORD setzen}@postgres:5432/${POSTGRES_DB:-homebrewery} + # Auth (docs/auth/) + HB_AUTH_PROVIDERS: oidc + HB_PUBLIC_URL: ${HB_PUBLIC_URL:?HB_PUBLIC_URL setzen} + HB_SESSION_SECRET: ${HB_SESSION_SECRET:?HB_SESSION_SECRET setzen (openssl rand -base64 48)} + HB_OIDC_ISSUER: ${HB_OIDC_ISSUER:?HB_OIDC_ISSUER setzen} + HB_OIDC_CLIENT_ID: ${HB_OIDC_CLIENT_ID:?HB_OIDC_CLIENT_ID setzen} + HB_OIDC_CLIENT_SECRET: ${HB_OIDC_CLIENT_SECRET:?HB_OIDC_CLIENT_SECRET setzen} + HB_OIDC_SCOPES: ${HB_OIDC_SCOPES:-} + HB_OIDC_USERNAME_CLAIM: ${HB_OIDC_USERNAME_CLAIM:-} + HB_OIDC_LINK_BY_EMAIL: ${HB_OIDC_LINK_BY_EMAIL:-} + HB_OIDC_END_SESSION: ${HB_OIDC_END_SESSION:-} + HB_OIDC_LABEL: ${HB_OIDC_LABEL:-} + HB_SESSION_TTL: ${HB_SESSION_TTL:-} + # Git-Backend (docs/git/). Leer = deaktiviert. Erzeugen: openssl rand -base64 32 + HB_GIT_TOKEN_KEY: ${HB_GIT_TOKEN_KEY:-} + HB_GIT_TOKEN_KEYS_OLD: ${HB_GIT_TOKEN_KEYS_OLD:-} + HB_GIT_ALLOWED_HOSTS: ${HB_GIT_ALLOWED_HOSTS:-} + HB_GIT_ALLOW_PRIVATE: ${HB_GIT_ALLOW_PRIVATE:-} + HB_GIT_ALLOW_HTTP: ${HB_GIT_ALLOW_HTTP:-} + HB_GIT_TIMEOUT_MS: ${HB_GIT_TIMEOUT_MS:-} + HB_GIT_OPEN_TIMEOUT_MS: ${HB_GIT_OPEN_TIMEOUT_MS:-} + HB_GIT_MAX_FILE_BYTES: ${HB_GIT_MAX_FILE_BYTES:-} + HB_GIT_MAX_CONCURRENCY: ${HB_GIT_MAX_CONCURRENCY:-} + HB_GIT_COMMITTER_NAME: ${HB_GIT_COMMITTER_NAME:-} + HB_GIT_COMMITTER_EMAIL: ${HB_GIT_COMMITTER_EMAIL:-} + # Bild-Upload (ADR 0004, nur mit aktivem Git-Backend) + HB_ASSETS_ENABLED: ${HB_ASSETS_ENABLED:-} + HB_ASSET_MAX_BYTES: ${HB_ASSET_MAX_BYTES:-} + HB_ASSET_MAX_BYTES_PER_BREW: ${HB_ASSET_MAX_BYTES_PER_BREW:-} + HB_ASSET_TYPES: ${HB_ASSET_TYPES:-} + + postgres: + image: postgres:18 + restart: unless-stopped + environment: + POSTGRES_DB: ${POSTGRES_DB:-homebrewery} + POSTGRES_USER: ${POSTGRES_USER:-homebrewery} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?POSTGRES_PASSWORD setzen} + volumes: + - pgdata:/var/lib/postgresql # PostgreSQL 18: Daten liegen unter /var/lib/postgresql/18/… + healthcheck: + test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"] + interval: 10s + timeout: 5s + retries: 10 + +volumes: + pgdata: diff --git a/docs/deploy/env.example b/docs/deploy/env.example new file mode 100644 index 00000000..dc4b2f9d --- /dev/null +++ b/docs/deploy/env.example @@ -0,0 +1,15 @@ +# Kopieren nach .env (neben compose.yaml). Keine Secrets einchecken. +# HB_IMAGE=git.morlana.online/f.weber/homebrewery-oidc:v1.0.0 +APP_PORT=8000 +POSTGRES_PASSWORD=bitte-aendern + +HB_PUBLIC_URL=https://brew.example.org +# openssl rand -base64 48 +HB_SESSION_SECRET=bitte-aendern-mindestens-32-byte-zufall-0123456789 +HB_OIDC_ISSUER=https://auth.example.org/application/o/homebrewery/ +HB_OIDC_CLIENT_ID=homebrewery +HB_OIDC_CLIENT_SECRET=bitte-aendern + +# Git-Backend: leer = aus. Erzeugen: openssl rand -base64 32 (genau 32 Byte, sonst Startabbruch; Schlüssel sichern!) +HB_GIT_TOKEN_KEY= +HB_GIT_ALLOWED_HOSTS=git.example.org diff --git a/docs/git/README.md b/docs/git/README.md index 02d5ddac..5e990053 100644 --- a/docs/git/README.md +++ b/docs/git/README.md @@ -11,7 +11,7 @@ Status/Pull ansehen, aber nichts selbst verknüpfen (`403 G07`). openssl rand -base64 32 # → HB_GIT_TOKEN_KEY ``` -Ohne `HB_GIT_TOKEN_KEY` ist das Backend deaktiviert (Warnung beim Start, `/api/git/*` antwortet `503 G10`, +Ohne `HB_GIT_TOKEN_KEY` ist das Backend deaktiviert (Warnung beim Start, Hinweis im Account-Panel, `/api/git/*` antwortet `503 G10`, gespeicherte Brews werden wie bisher nur in der DB gespeichert). Den Schlüssel **nicht verlieren**: Ohne ihn sind gespeicherte Tokens unbrauchbar (Nutzer müssen sie neu eintragen). @@ -29,7 +29,36 @@ sind gespeicherte Tokens unbrauchbar (Nutzer müssen sie neu eintragen). | `HB_GIT_MAX_CONCURRENCY` | `2` | gleichzeitige Git-Operationen pro Prozess (weitere warten, max. 20, sonst `503 G05`) | | `HB_GIT_COMMITTER_NAME` / `_EMAIL` | `Homebrewery` / `homebrewery@` | Committer; Autor ist der speichernde Nutzer | -Das Docker-Image enthält `git` bereits. Außerhalb von Docker muss `git` (≥ 2.30) im `PATH` liegen. +Für den Betrieb mit dem veröffentlichten Image siehe [docs/deploy](../deploy/README.md). Das Docker-Image enthält `git` bereits. Außerhalb von Docker muss `git` (≥ 2.30) im `PATH` liegen. + +## Fehlersuche / nachträglich aktivieren + +Das Backend lässt sich **jederzeit** einschalten, ein Erststart ist nicht nötig: `HB_GIT_TOKEN_KEY` setzen und den +Prozess neu starten. Die Variable wird bei jedem Start gelesen, die Postgres-Migration `0002_git_backend` läuft immer mit. + +Mit Docker Compose gilt: Nach einer Änderung der Umgebung `docker compose up -d` ausführen (erstellt den Container neu). +`docker compose restart` startet den alten Container mit der **alten** Umgebung neu. Die Variable muss außerdem unter +`environment:` (oder `env_file:`) des App-Service stehen, siehe [Betrieb mit dem veröffentlichten Image](../deploy/README.md). + +Prüfen, in dieser Reihenfolge: + +1. **Kommt der Schlüssel im Container an?** `docker compose exec printenv HB_GIT_TOKEN_KEY | wc -c`: `0` oder + Fehler = nicht gesetzt; ein gültiger Schlüssel (32 Byte, base64) hat 45 Zeichen (44 + Zeilenumbruch). +2. **Startlog** (`docker compose logs `): `Git-Backend aktiv (kid=…, Host-Allowlist: ja|nein)` = an; + `Git-Backend deaktiviert: HB_GIT_TOKEN_KEY ist nicht gesetzt` = aus. Der Log enthält nie den Schlüssel. +3. **API**: `curl -i /api/git/connections`: + `503` + `G10` = Backend aus (Schritt 1/2), `401` = nicht angemeldet, `403` + `G07` = Sitzung ohne OIDC-Konto, + `200` = alles in Ordnung (für `403`/`200` mit Sitzungs-Cookie des Browsers). +4. **Panel**: liegt ganz unten auf `/account` („Git-Verbindungen“) und erscheint nur für angemeldete **OIDC-Konten**. + Ist das Backend aus, steht dort der Hinweis „Git-Backend auf diesem Server nicht aktiviert“, bei einer + naturalcrit-Sitzung „Nur mit OIDC-Anmeldung verfügbar“. Ohne Anmeldung ist das Panel unsichtbar. + +Ein ungültiger Schlüssel (nicht base64 oder ≠ 32 Byte, auch in `HB_GIT_TOKEN_KEYS_OLD`) **bricht den Start ab** +(`HB_GIT_TOKEN_KEY muss 32 Byte (base64) lang sein`); der Container läuft dann in eine Neustart-Schleife, die Ursache steht im Log. + +Schlüsselwechsel: neuen Schlüssel als `HB_GIT_TOKEN_KEY` setzen, den bisherigen in `HB_GIT_TOKEN_KEYS_OLD` (kommagetrennt) +aufnehmen, `up -d`. Tokens werden bei der nächsten Nutzung mit dem neuen Schlüssel neu verschlüsselt; der alte Schlüssel +darf erst entfallen, wenn alle Verbindungen genutzt wurden (die `kid` im Format `v1..…` identifiziert den Schlüssel). ## Benutzung diff --git a/docs/storage/README.md b/docs/storage/README.md index 49142b09..d31a14d8 100644 --- a/docs/storage/README.md +++ b/docs/storage/README.md @@ -30,6 +30,8 @@ docker compose --profile postgres up --build homebrewery-pg Die Service-Namen gehören dazu: Mit `--profile postgres up` ohne Namen startet Compose zusätzlich die profillosen Services `homebrewery` und `mongodb` (beide auf `APP_PORT`). +Für den Betrieb mit dem veröffentlichten Image (PostgreSQL 18, ohne Repo-Checkout): [docs/deploy/README.md](../deploy/README.md). + ## Repository-Schicht `server/storage/` – `getStorage()` liefert `{ brews, notifications, users }` (`gitConnections`, `brewGitLinks`, diff --git a/server/fork/git/index.js b/server/fork/git/index.js index 3807b99b..27fafa78 100644 --- a/server/fork/git/index.js +++ b/server/fork/git/index.js @@ -1,4 +1,4 @@ -import { readGitConfig } from './config.js'; +import { readGitConfig, keyId } from './config.js'; import { createGitService } from './brewSync.js'; import { createGitRouter } from './routes.js'; import { configureGitHooks } from './hooks.js'; @@ -14,6 +14,7 @@ export { readGitConfig, createGitService, createGitRouter, configureGitHooks }; export const createGitBackend = ({ getStorage, api, splitTextStyleAndMetadata, env = process.env, logger = console })=>{ const cfg = readGitConfig(env); if(!cfg.enabled) logger.warn?.('Git-Backend deaktiviert: HB_GIT_TOKEN_KEY ist nicht gesetzt (openssl rand -base64 32).'); + else logger.info?.(`Git-Backend aktiv (kid=${keyId(cfg.key)}, alte Schlüssel: ${cfg.oldKeys.length}, Host-Allowlist: ${cfg.allowedHosts.length ? `ja (${cfg.allowedHosts.length})` : 'nein'}).`); const service = createGitService({ cfg, getStorage, api, splitTextStyleAndMetadata, logger }); configureGitHooks(cfg.enabled ? service : undefined); // Bild-Upload (ADR 0004) hängt vor dem Git-Router, damit POST …/assets die rohen Bilddaten selbst liest diff --git a/tests/fork/gitPanelState.test.js b/tests/fork/gitPanelState.test.js new file mode 100644 index 00000000..04f1bba8 --- /dev/null +++ b/tests/fork/gitPanelState.test.js @@ -0,0 +1,20 @@ +import { classifyListError, NOTICES } from '../../client/fork/git/panelState.js'; + +describe('Git-Panel: Zustand aus dem Listen-Fehler (FLW-258)', ()=>{ + test('503 G10: Hinweis „nicht aktiviert“ mit Verweis auf docs/git', ()=>{ + const r = classifyListError({ status: 503, HBErrorCode: 'G10' }); + expect(r).toEqual({ state: 'notice', notice: NOTICES.disabled }); + expect(r.notice).toMatch(/nicht aktiviert.*docs\/git/); + }); + test('403 G07: Hinweis „Nur mit OIDC-Anmeldung verfügbar“', ()=>{ + expect(classifyListError({ status: 403, HBErrorCode: 'G07' })).toEqual({ state: 'notice', notice: 'Nur mit OIDC-Anmeldung verfügbar.' }); + }); + test('401 (nicht angemeldet): Panel bleibt unsichtbar', ()=>{ + expect(classifyListError({ status: 401, HBErrorCode: '04' })).toEqual({ state: 'hidden' }); + }); + test('andere Fehler (G05-503, 500, Netzwerk): Panel mit Fehlermeldung, kein Hinweis', ()=>{ + expect(classifyListError({ status: 503, HBErrorCode: 'G05' }).state).toBe('error'); + expect(classifyListError({ status: 500 }).state).toBe('error'); + expect(classifyListError(new Error('offline')).state).toBe('error'); + }); +}); diff --git a/tests/fork/gitStartupLog.test.js b/tests/fork/gitStartupLog.test.js new file mode 100644 index 00000000..f2b0b38f --- /dev/null +++ b/tests/fork/gitStartupLog.test.js @@ -0,0 +1,28 @@ +import { createGitBackend } from '../../server/fork/git/index.js'; +import { configureGitHooks } from '../../server/fork/git/hooks.js'; + +const KEY = Buffer.alloc(32, 7).toString('base64'); +const boot = (env)=>{ + const logger = { warn: jest.fn(), info: jest.fn(), error: jest.fn() }; + createGitBackend({ getStorage: ()=>({}), api: {}, splitTextStyleAndMetadata: ()=>({}), env, logger }); + configureGitHooks(undefined); + return logger; +}; + +describe('Git-Backend: Startlog (FLW-258)', ()=>{ + test('ohne Schlüssel: Warnung, keine Info-Zeile', ()=>{ + const l = boot({}); + expect(l.warn).toHaveBeenCalledWith(expect.stringMatching(/deaktiviert.*HB_GIT_TOKEN_KEY/)); + expect(l.info).not.toHaveBeenCalled(); + }); + test('mit Schlüssel: Info mit kid und Allowlist, ohne Secrets', ()=>{ + const l = boot({ HB_GIT_TOKEN_KEY: KEY, HB_GIT_ALLOWED_HOSTS: 'git.example.org' }); + expect(l.warn).not.toHaveBeenCalled(); + const line = l.info.mock.calls[0][0]; + expect(line).toMatch(/aktiv \(kid=[0-9a-f]{8}.*Host-Allowlist: ja/); + expect(line).not.toContain(KEY); + }); + test('ohne Allowlist: „nein“', ()=>{ + expect(boot({ HB_GIT_TOKEN_KEY: KEY }).info.mock.calls[0][0]).toMatch(/Host-Allowlist: nein/); + }); +});