mirror of
https://github.com/gethomepage/homepage.git
synced 2026-03-31 15:22:16 -07:00
Compare commits
47 Commits
feature/au
...
v1.11.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a4e29bc7a7 | ||
|
|
a7982bda06 | ||
|
|
f7c12ad642 | ||
|
|
a6639b04b9 | ||
|
|
6b3bff1f1d | ||
|
|
597059045f | ||
|
|
b676424d98 | ||
|
|
e87b62f3ac | ||
|
|
776f190aed | ||
|
|
71a524da89 | ||
|
|
9dea3a4d4f | ||
|
|
adc042fa8a | ||
|
|
f16878bca9 | ||
|
|
01b951f3ba | ||
|
|
94122ba078 | ||
|
|
fb88da5a5a | ||
|
|
de7e730283 | ||
|
|
b5b502b433 | ||
|
|
db9b2d0245 | ||
|
|
51d718a21a | ||
|
|
29e2502d74 | ||
|
|
d529f81cb4 | ||
|
|
1645c1b8a1 | ||
|
|
e3ca0adf11 | ||
|
|
614a87d768 | ||
|
|
862c5d9f38 | ||
|
|
d3374dc461 | ||
|
|
795e2505ca | ||
|
|
cb8421df0b | ||
|
|
152888d611 | ||
|
|
ea527e4fb1 | ||
|
|
09bab7637e | ||
|
|
597f6ecf16 | ||
|
|
fe0b214334 | ||
|
|
cdc96438cd | ||
|
|
ca7dfb56c8 | ||
|
|
95852d23c2 | ||
|
|
84231a1754 | ||
|
|
f4f54cea60 | ||
|
|
06595ef107 | ||
|
|
91b9aa479a | ||
|
|
08cde2f597 | ||
|
|
d62404f164 | ||
|
|
0ce175cda5 | ||
|
|
7f1de58e71 | ||
|
|
f729290e96 | ||
|
|
4974cd96b6 |
@@ -9,11 +9,11 @@ coverage:
|
||||
project:
|
||||
default:
|
||||
target: 100%
|
||||
threshold: 25%
|
||||
threshold: 15%
|
||||
patch:
|
||||
default:
|
||||
target: 100%
|
||||
threshold: 25%
|
||||
threshold: 10%
|
||||
|
||||
comment:
|
||||
layout: "reach,diff,flags,files"
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
title: "[Feature Request] "
|
||||
labels: ["enhancement"]
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
#### ⚠️ Don't forget to search [existing issues](https://github.com/gethomepage/homepage/search?q=&type=issues) and [discussions](https://github.com/gethomepage/homepage/search?q=&type=discussions) (including closed ones!).
|
||||
- type: textarea
|
||||
id: description
|
||||
attributes:
|
||||
|
||||
2
.github/DISCUSSION_TEMPLATE/support.yml
vendored
2
.github/DISCUSSION_TEMPLATE/support.yml
vendored
@@ -51,7 +51,7 @@ body:
|
||||
id: troubleshooting
|
||||
attributes:
|
||||
label: Troubleshooting
|
||||
description: Please include output from your [troubleshooting steps](https://gethomepage.dev/more/troubleshooting/#service-widget-errors), if relevant.
|
||||
description: Please include output from your [troubleshooting steps](https://gethomepage.dev/troubleshooting/#service-widget-errors), if relevant.
|
||||
validations:
|
||||
required: true
|
||||
- type: markdown
|
||||
|
||||
6
.github/PULL_REQUEST_TEMPLATE.md
vendored
6
.github/PULL_REQUEST_TEMPLATE.md
vendored
@@ -35,8 +35,8 @@ What type of change does your PR introduce to Homepage?
|
||||
## Checklist:
|
||||
|
||||
- [ ] If applicable, I have added corresponding documentation changes.
|
||||
- [ ] If applicable, I have added or updated tests for new features and bug fixes.
|
||||
- [ ] If applicable, I have reviewed the [feature / enhancement](https://gethomepage.dev/more/development/#new-feature-guidelines) and / or [service widget guidelines](https://gethomepage.dev/more/development/#service-widget-guidelines).
|
||||
- [ ] I have checked that all code style checks pass using [pre-commit hooks](https://gethomepage.dev/more/development/#code-formatting-with-pre-commit-hooks) and [linting checks](https://gethomepage.dev/more/development/#code-linting).
|
||||
- [ ] If applicable, I have added or updated tests for new features and bug fixes (see [testing](https://gethomepage.dev/widgets/authoring/getting-started/#testing)).
|
||||
- [ ] If applicable, I have reviewed the [feature / enhancement](https://gethomepage.dev/widgets/authoring/getting-started/#new-feature-guidelines) and / or [service widget guidelines](https://gethomepage.dev/widgets/authoring/getting-started/#service-widget-guidelines).
|
||||
- [ ] I have checked that all code style checks pass using [pre-commit hooks](https://gethomepage.dev/widgets/authoring/getting-started/#code-formatting-with-pre-commit-hooks) and [linting checks](https://gethomepage.dev/widgets/authoring/getting-started/#code-linting).
|
||||
- [ ] If applicable, I have tested my code for new features & regressions on both mobile & desktop devices, using the latest version of major browsers.
|
||||
- [ ] In the description above I have disclosed the use of AI tools in the coding of this PR.
|
||||
|
||||
12
.github/workflows/docker-publish.yml
vendored
12
.github/workflows/docker-publish.yml
vendored
@@ -66,7 +66,7 @@ jobs:
|
||||
|
||||
- name: Extract Docker metadata
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
uses: docker/metadata-action@v6
|
||||
with:
|
||||
images: |
|
||||
${{ env.IMAGE_NAME }}
|
||||
@@ -115,7 +115,7 @@ jobs:
|
||||
|
||||
- name: Log into registry ${{ env.REGISTRY }}
|
||||
if: github.event_name != 'pull_request'
|
||||
uses: docker/login-action@v3
|
||||
uses: docker/login-action@v4
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
@@ -123,20 +123,20 @@ jobs:
|
||||
|
||||
- name: Login to Docker Hub
|
||||
if: github.event_name != 'pull_request'
|
||||
uses: docker/login-action@v3
|
||||
uses: docker/login-action@v4
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
- name: Setup QEMU
|
||||
uses: docker/setup-qemu-action@v3.7.0
|
||||
uses: docker/setup-qemu-action@v4.0.0
|
||||
|
||||
- name: Setup Docker buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
uses: docker/setup-buildx-action@v4
|
||||
|
||||
- name: Build and push Docker image
|
||||
id: build-and-push
|
||||
uses: docker/build-push-action@v6
|
||||
uses: docker/build-push-action@v7
|
||||
with:
|
||||
context: .
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
|
||||
50
.github/workflows/docs-publish.yml
vendored
50
.github/workflows/docs-publish.yml
vendored
@@ -9,7 +9,9 @@ on:
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
contents: read
|
||||
pages: write
|
||||
id-token: write
|
||||
|
||||
jobs:
|
||||
pre-commit:
|
||||
@@ -35,44 +37,34 @@ jobs:
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: 3.x
|
||||
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
|
||||
- uses: actions/cache@v5
|
||||
with:
|
||||
key: mkdocs-material-${{ env.cache_id }}
|
||||
path: .cache
|
||||
restore-keys: |
|
||||
mkdocs-material-
|
||||
python-version-file: ".python-version"
|
||||
- name: Install uv
|
||||
uses: astral-sh/setup-uv@v7
|
||||
- run: sudo apt-get install pngquant
|
||||
- run: pip install mkdocs-material mkdocs-redirects "mkdocs-material[imaging]"
|
||||
- name: Test Docs Build
|
||||
run: MKINSIDERS=false mkdocs build
|
||||
run: uv run --frozen zensical build --clean
|
||||
deploy:
|
||||
name: Build & Deploy Docs
|
||||
if: github.repository == 'gethomepage/homepage' && github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
|
||||
runs-on: ubuntu-latest
|
||||
environment:
|
||||
name: github-pages
|
||||
url: ${{ steps.deployment.outputs.page_url }}
|
||||
needs:
|
||||
- pre-commit
|
||||
steps:
|
||||
- uses: actions/configure-pages@v5
|
||||
- uses: actions/checkout@v6
|
||||
- name: Configure Git Credentials
|
||||
run: |
|
||||
git config user.name github-actions[bot]
|
||||
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
|
||||
- uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: 3.x
|
||||
- run: echo "cache_id=${{github.sha}}" >> $GITHUB_ENV
|
||||
- uses: actions/cache@v5
|
||||
with:
|
||||
key: mkdocs-material-${{ env.cache_id }}
|
||||
path: .cache
|
||||
restore-keys: |
|
||||
mkdocs-material-
|
||||
python-version-file: ".python-version"
|
||||
- name: Install uv
|
||||
uses: astral-sh/setup-uv@v7
|
||||
- run: sudo apt-get install pngquant
|
||||
- run: pip install git+https://${GH_TOKEN}@github.com/benphelps/mkdocs-material-insiders.git
|
||||
- run: pip install mkdocs-redirects "mkdocs-material[imaging]"
|
||||
- name: Docs Deploy
|
||||
run: MKINSIDERS=true mkdocs gh-deploy --force
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN }}
|
||||
- name: Build Docs
|
||||
run: uv run --frozen zensical build --clean
|
||||
- uses: actions/upload-pages-artifact@v4
|
||||
with:
|
||||
path: site
|
||||
- uses: actions/deploy-pages@v4
|
||||
id: deployment
|
||||
|
||||
18
.github/workflows/pr-quality.yml
vendored
Normal file
18
.github/workflows/pr-quality.yml
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
name: PR Quality
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
issues: read
|
||||
pull-requests: write
|
||||
|
||||
on:
|
||||
pull_request_target:
|
||||
types: [opened, reopened]
|
||||
|
||||
jobs:
|
||||
anti-slop:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: peakoss/anti-slop@v0
|
||||
with:
|
||||
max-failures: 4
|
||||
4
.github/workflows/test.yml
vendored
4
.github/workflows/test.yml
vendored
@@ -13,13 +13,13 @@ jobs:
|
||||
matrix:
|
||||
shard: [1, 2, 3, 4]
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- uses: pnpm/action-setup@v4
|
||||
with:
|
||||
version: 9
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
- uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version: 20
|
||||
cache: pnpm
|
||||
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -46,7 +46,7 @@ next-env.d.ts
|
||||
# IDEs
|
||||
/.idea/
|
||||
|
||||
# MkDocs documentation
|
||||
# Zensical documentation
|
||||
site*/
|
||||
.cache/
|
||||
|
||||
|
||||
1
.python-version
Normal file
1
.python-version
Normal file
@@ -0,0 +1 @@
|
||||
3.13
|
||||
@@ -38,11 +38,11 @@ People _love_ thorough bug reports. I'm not even kidding.
|
||||
|
||||
## Development Guidelines
|
||||
|
||||
Please see the [documentation regarding development](https://gethomepage.dev/more/development/) and specifically the [guidelines for new service widgets](https://gethomepage.dev/more/development/#service-widget-guidelines) if you are considering making one.
|
||||
Please see the [documentation regarding development](https://gethomepage.dev/widgets/authoring/getting-started/#development) and specifically the [guidelines for new service widgets](https://gethomepage.dev/widgets/authoring/getting-started/#service-widget-guidelines) if you are considering making one.
|
||||
|
||||
## Use a Consistent Coding Style
|
||||
|
||||
Please see information in the docs regarding [code formatting with pre-commit hooks](https://gethomepage.dev/more/development/#code-formatting-with-pre-commit-hooks).
|
||||
Please see information in the docs regarding [code formatting with pre-commit hooks](https://gethomepage.dev/widgets/authoring/getting-started/#code-formatting-with-pre-commit-hooks).
|
||||
|
||||
## License
|
||||
|
||||
|
||||
67
README.md
67
README.md
@@ -70,14 +70,65 @@ For configuration options, examples and more, [please check out the homepage doc
|
||||
|
||||
## Security Notice 🔒
|
||||
|
||||
Please note that when using features such as widgets, Homepage can access personal information (for example from your home automation system). To keep your information private, if Homepage is reachable from any untrusted network, it:
|
||||
Please note that when using features such as widgets, Homepage can access personal information (for example from your home automation system) and Homepage currently does not (and is not planned to) include any authentication layer itself. If Homepage is reachable from any untrusted network, it **must** sit behind a reverse proxy (and/or VPN) that enforces authentication, TLS, and strictly validates Host headers. The built-in host check in Homepage is a best-effort guard and should not be treated as security when exposed publicly.
|
||||
|
||||
1. **must** sit behind a reverse proxy (and/or VPN) that enforces authentication, TLS, and strictly validates Host headers.
|
||||
2. An optional built-in OIDC login flow is available (opt-in) offering a simple “authenticated or not” guard.
|
||||
## With Docker
|
||||
|
||||
## Installation
|
||||
Using docker compose:
|
||||
|
||||
See the [Installation](https://gethomepage.dev/installation/) section of the docs for instructions on installing Homepage via Docker, Kubernetes, Unraid, or from source.
|
||||
```yaml
|
||||
services:
|
||||
homepage:
|
||||
image: ghcr.io/gethomepage/homepage:latest
|
||||
container_name: homepage
|
||||
environment:
|
||||
HOMEPAGE_ALLOWED_HOSTS: gethomepage.dev # required, may need port. See gethomepage.dev/installation/#homepage_allowed_hosts
|
||||
PUID: 1000 # optional, your user id
|
||||
PGID: 1000 # optional, your group id
|
||||
ports:
|
||||
- 3000:3000
|
||||
volumes:
|
||||
- /path/to/config:/app/config # Make sure your local config directory exists
|
||||
- /var/run/docker.sock:/var/run/docker.sock:ro # optional, for docker integrations
|
||||
restart: unless-stopped
|
||||
```
|
||||
|
||||
or docker run:
|
||||
|
||||
```bash
|
||||
docker run --name homepage \
|
||||
-e HOMEPAGE_ALLOWED_HOSTS=gethomepage.dev \
|
||||
-e PUID=1000 \
|
||||
-e PGID=1000 \
|
||||
-p 3000:3000 \
|
||||
-v /path/to/config:/app/config \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock:ro \
|
||||
--restart unless-stopped \
|
||||
ghcr.io/gethomepage/homepage:latest
|
||||
```
|
||||
|
||||
## From Source
|
||||
|
||||
First, clone the repository:
|
||||
|
||||
```bash
|
||||
git clone https://github.com/gethomepage/homepage.git
|
||||
```
|
||||
|
||||
Then install dependencies and build the production bundle:
|
||||
|
||||
```bash
|
||||
pnpm install
|
||||
pnpm build
|
||||
```
|
||||
|
||||
If this is your first time starting, copy the `src/skeleton` directory to `config/` to populate initial example config files.
|
||||
|
||||
Finally, run the server in production mode:
|
||||
|
||||
```bash
|
||||
pnpm start
|
||||
```
|
||||
|
||||
# Configuration
|
||||
|
||||
@@ -105,16 +156,16 @@ This is a [Next.js](https://nextjs.org/) application, see their documentation fo
|
||||
|
||||
The homepage documentation is available at [https://gethomepage.dev/](https://gethomepage.dev/).
|
||||
|
||||
Homepage uses Material for MkDocs for documentation. To run the documentation locally, first install the dependencies:
|
||||
Homepage uses Zensical for documentation. To run the documentation locally, first install the dependencies:
|
||||
|
||||
```bash
|
||||
pip install -r requirements.txt
|
||||
uv sync
|
||||
```
|
||||
|
||||
Then run the development server:
|
||||
|
||||
```bash
|
||||
mkdocs serve # or build, to build the static site
|
||||
uv run zensical serve # or build, to build the static site
|
||||
```
|
||||
|
||||
# Support & Suggestions
|
||||
|
||||
@@ -177,6 +177,16 @@ labels:
|
||||
- homepage.widget.fields=["field1","field2"] # optional
|
||||
```
|
||||
|
||||
!!! note
|
||||
|
||||
If you use mapping syntax (`:`) for labels instead of list syntax (`-`), array values like `fields` must be wrapped in single quotes so they are passed as a string:
|
||||
|
||||
```yaml
|
||||
labels:
|
||||
...
|
||||
homepage.widget.fields: '["field1","field2"]'
|
||||
```
|
||||
|
||||
Multiple widgets can be specified by incrementing the index, e.g.
|
||||
|
||||
```yaml
|
||||
|
||||
@@ -129,7 +129,7 @@ A progressive web app is an app that can be installed on a device and provide us
|
||||
|
||||
More information on PWAs can be found in [MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps).
|
||||
|
||||
## App icons
|
||||
### App icons
|
||||
|
||||
You can set custom icons for installable apps. More information about how you can set them can be found in the [MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps/Manifest/Reference/icons).
|
||||
|
||||
@@ -150,7 +150,7 @@ For icon `src` you can pass either full URL or a local path relative to the `/ap
|
||||
|
||||
### Shortcuts
|
||||
|
||||
Shortcuts can e used to specify links to tabs, to be preselected when the homepage is opened as an app.
|
||||
Shortcuts can be used to specify links to tabs, to be preselected when the homepage is opened as an app.
|
||||
More information about how you can set them can be found in the [MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps/Manifest/Reference/shortcuts).
|
||||
|
||||
```yaml
|
||||
|
||||
@@ -15,6 +15,8 @@ services:
|
||||
volumes:
|
||||
- /path/to/config:/app/config # Make sure your local config directory exists
|
||||
- /var/run/docker.sock:/var/run/docker.sock:ro # (optional) For docker integrations
|
||||
environment:
|
||||
HOMEPAGE_ALLOWED_HOSTS: gethomepage.dev # required, may need port. See gethomepage.dev/installation/#homepage_allowed_hosts
|
||||
```
|
||||
|
||||
### Running as non-root
|
||||
@@ -36,6 +38,7 @@ services:
|
||||
- /path/to/config:/app/config # Make sure your local config directory exists
|
||||
- /var/run/docker.sock:/var/run/docker.sock:ro # (optional) For docker integrations, see alternative methods
|
||||
environment:
|
||||
HOMEPAGE_ALLOWED_HOSTS: gethomepage.dev # required, may need port. See gethomepage.dev/installation/#homepage_allowed_hosts
|
||||
PUID: $PUID
|
||||
PGID: $PGID
|
||||
```
|
||||
@@ -43,7 +46,7 @@ services:
|
||||
### With Docker Run
|
||||
|
||||
```bash
|
||||
docker run -p 3000:3000 -v /path/to/config:/app/config -v /var/run/docker.sock:/var/run/docker.sock ghcr.io/gethomepage/homepage:latest
|
||||
docker run -p 3000:3000 -e HOMEPAGE_ALLOWED_HOSTS=gethomepage.dev -v /path/to/config:/app/config -v /var/run/docker.sock:/var/run/docker.sock ghcr.io/gethomepage/homepage:latest
|
||||
```
|
||||
|
||||
### Using Environment Secrets
|
||||
|
||||
@@ -27,25 +27,14 @@ You have a few options for deploying homepage, depending on your needs. We offer
|
||||
|
||||
</div>
|
||||
|
||||
### Security & Authentication
|
||||
### `HOMEPAGE_ALLOWED_HOSTS`
|
||||
|
||||
Public deployments of Homepage should be secured via a reverse proxy, VPN, or similar. As of version 2.0, Homepage supports a simple authorization gate with a password or OIDC. When enabled, Homepage will use password login by default unless OIDC variables are provided.
|
||||
As of v1.0 there is one required environment variable to access homepage via a URL other than `localhost`, <code>HOMEPAGE_ALLOWED_HOSTS</code>. The setting helps prevent certain kinds of attacks when retrieving data from the homepage API proxy.
|
||||
|
||||
Required environment variables for authentication:
|
||||
The value is a comma-separated (no spaces) list of allowed hosts (sometimes with the port) that can host your homepage install. See the [docker](docker.md), [kubernetes](k8s.md) and [source](source.md) installation pages for more information about where / how to set the variable.
|
||||
|
||||
- `HOMEPAGE_AUTH_ENABLED=true`
|
||||
- `HOMEPAGE_AUTH_SECRET` (random string for signing/encrypting cookies)
|
||||
`localhost:3000` and `127.0.0.1:3000` are always included, but you can add a domain or IP address to this list to allow that host such as `HOMEPAGE_ALLOWED_HOSTS=gethomepage.dev,192.168.1.2:1234`, etc.
|
||||
|
||||
For password-only login:
|
||||
If you are seeing errors about host validation, check the homepage logs and ensure that the host exactly as output in the logs is in the `HOMEPAGE_ALLOWED_HOSTS` list.
|
||||
|
||||
- `HOMEPAGE_AUTH_PASSWORD` (password-only login; required unless OIDC settings are provided)
|
||||
|
||||
For OIDC login (overrides password login):
|
||||
|
||||
- `HOMEPAGE_OIDC_ISSUER` (OIDC issuer URL, e.g., `https://auth.example.com/realms/homepage`)
|
||||
- `HOMEPAGE_OIDC_CLIENT_ID`
|
||||
- `HOMEPAGE_OIDC_CLIENT_SECRET`
|
||||
- `HOMEPAGE_EXTERNAL_URL` (external URL to your Homepage instance; used for callbacks)
|
||||
- Optional: `HOMEPAGE_OIDC_NAME` (display name), `HOMEPAGE_OIDC_SCOPE` (defaults to `openid email profile`)
|
||||
|
||||
All app pages and `/api` routes will require a signed-in session. Static assets remain public. Homepage still does not implement per-user dashboards or roles; authentication is a simple gate only.
|
||||
This can be disabled by setting `HOMEPAGE_ALLOWED_HOSTS` to `*` but this is not recommended. Public deployments must rely on a reverse proxy (and/or VPN) that enforces authentication, TLS, and unexpected Host headers; the built-in host check is a best-effort guard for local setups and is not a substitute for edge protections.
|
||||
|
||||
@@ -223,10 +223,33 @@ spec:
|
||||
- name: homepage
|
||||
image: "ghcr.io/gethomepage/homepage:latest"
|
||||
imagePullPolicy: Always
|
||||
securityContext:
|
||||
allowPrivilegeEscalation: false
|
||||
capabilities:
|
||||
drop:
|
||||
- ALL
|
||||
runAsNonRoot: true
|
||||
runAsUser: 1000
|
||||
runAsGroup: 1000
|
||||
seccompProfile:
|
||||
type: RuntimeDefault
|
||||
env:
|
||||
- name: MY_POD_IP
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
fieldPath: status.podIP
|
||||
- name: HOMEPAGE_ALLOWED_HOSTS
|
||||
value: "$(MY_POD_IP):3000,gethomepage.dev" # See gethomepage.dev/installation/#homepage_allowed_hosts . Value before the comma is required for the k8s probe
|
||||
ports:
|
||||
- name: http
|
||||
containerPort: 3000
|
||||
protocol: TCP
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /api/healthcheck
|
||||
port: http
|
||||
initialDelaySeconds: 5
|
||||
periodSeconds: 15
|
||||
volumeMounts:
|
||||
- mountPath: /app/config/custom.js
|
||||
name: homepage-config
|
||||
|
||||
@@ -27,7 +27,9 @@ If this is your first time starting, copy the `src/skeleton` directory to `confi
|
||||
Finally, run the server:
|
||||
|
||||
```bash
|
||||
pnpm start
|
||||
HOMEPAGE_ALLOWED_HOSTS=gethomepage.dev:1234 pnpm start
|
||||
```
|
||||
|
||||
When updating homepage versions you will need to re-build the static files i.e. repeat the process above.
|
||||
|
||||
See [HOMEPAGE_ALLOWED_HOSTS](index.md#homepage_allowed_hosts) for more information on this environment variable.
|
||||
|
||||
@@ -16,6 +16,7 @@ The Glances widget allows you to monitor the resources (CPU, memory, storage, te
|
||||
cpu: true # optional, enabled by default, disable by setting to false
|
||||
mem: true # optional, enabled by default, disable by setting to false
|
||||
cputemp: true # disabled by default
|
||||
unit: imperial # optional for temp, default is metric
|
||||
uptime: true # disabled by default
|
||||
disk: / # disabled by default, use mount point of disk(s) in glances. Can also be a list (see below)
|
||||
diskUnits: bytes # optional, bytes (default) or bbytes. Only applies to disk
|
||||
@@ -31,5 +32,3 @@ disk:
|
||||
- /boot
|
||||
...
|
||||
```
|
||||
|
||||
_Added in v0.4.18, updated in v0.6.11, v0.6.21_
|
||||
|
||||
@@ -7,13 +7,17 @@ You can include all or some of the available resources. If you do not want to se
|
||||
|
||||
The disk path is the path reported by `df` (Mounted On), or the mount point of the disk.
|
||||
|
||||
!!! note
|
||||
|
||||
Any disk you wish to access must be mounted to your container as a volume.
|
||||
|
||||
The cpu and memory resource information are the container's usage while [glances](glances.md) displays statistics for the host machine on which it is installed.
|
||||
|
||||
The resources widget primarily relies on a popular tool called [systeminformation](https://systeminformation.io). Thus, any limitiations of that software apply, for example, BRTFS RAID is not supported for the disk usage. In this case users may want to use the [glances widget](glances.md) instead.
|
||||
|
||||
_Note: unfortunately, the package used for getting CPU temp ([systeminformation](https://systeminformation.io)) is not compatible with some setups and will not report any value(s) for CPU temp._
|
||||
!!! warning
|
||||
|
||||
**Any disk you wish to access must be mounted to your container as a volume.**
|
||||
The package used for getting CPU temp ([systeminformation](https://systeminformation.io)) is not compatible with some setups and will not report any value(s) for CPU temp.
|
||||
|
||||
```yaml
|
||||
- resources:
|
||||
@@ -75,3 +79,10 @@ You can additionally supply an optional `expanded` property set to true in order
|
||||
```
|
||||
|
||||

|
||||
|
||||
To monitor a named host network interface in Docker (for example `network: eno1`), mount host `/sys` (read-only):
|
||||
|
||||
```yaml
|
||||
volumes:
|
||||
- /sys:/sys:ro
|
||||
```
|
||||
|
||||
@@ -67,7 +67,7 @@ You can also find a list of all available service widgets in the sidebar navigat
|
||||
- [Jackett](jackett.md)
|
||||
- [JDownloader](jdownloader.md)
|
||||
- [Jellyfin](jellyfin.md)
|
||||
- [Jellyseerr](jellyseerr.md)
|
||||
- [Seerr](seerr.md)
|
||||
- [Jellystat](jellystat.md)
|
||||
- [Kavita](kavita.md)
|
||||
- [Komga](komga.md)
|
||||
@@ -101,7 +101,6 @@ You can also find a list of all available service widgets in the sidebar navigat
|
||||
- [OpenMediaVault](openmediavault.md)
|
||||
- [OpenWRT](openwrt.md)
|
||||
- [OPNsense](opnsense.md)
|
||||
- [Overseerr](overseerr.md)
|
||||
- [PaperlessNGX](paperlessngx.md)
|
||||
- [Peanut](peanut.md)
|
||||
- [pfSense](pfsense.md)
|
||||
|
||||
@@ -5,7 +5,7 @@ description: Jellyfin Widget Configuration
|
||||
|
||||
Learn more about [Jellyfin](https://github.com/jellyfin/jellyfin).
|
||||
|
||||
You can create an API key from inside Jellyfin at `Settings > Advanced > Api Keys`.
|
||||
You can create an API key from inside the Jellyfin Administration Dashboard under `Advanced > API Keys`.
|
||||
|
||||
As of v0.6.11 the widget supports fields `["movies", "series", "episodes", "songs"]`. These blocks are disabled by default but can be enabled with the `enableBlocks` option, and the "Now Playing" feature (enabled by default) can be disabled with the `enableNowPlaying` option.
|
||||
|
||||
@@ -17,7 +17,7 @@ As of v0.6.11 the widget supports fields `["movies", "series", "episodes", "song
|
||||
```yaml
|
||||
widget:
|
||||
type: jellyfin
|
||||
url: http://jellyfin.host.or.ip
|
||||
url: http://jellyfin.host.or.ip:port
|
||||
key: apikeyapikeyapikeyapikeyapikey
|
||||
version: 2 # optional, default is 1
|
||||
enableBlocks: true # optional, defaults to false
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
---
|
||||
title: Jellyseerr
|
||||
description: Jellyseerr Widget Configuration
|
||||
---
|
||||
|
||||
Learn more about [Jellyseerr](https://github.com/Fallenbagel/jellyseerr).
|
||||
|
||||
Find your API key under `Settings > General > API Key`.
|
||||
|
||||
Allowed fields: `["pending", "approved", "available", "issues"]`.
|
||||
Default fields: `["pending", "approved", "available"]`.
|
||||
|
||||
```yaml
|
||||
widget:
|
||||
type: jellyseerr
|
||||
url: http://jellyseerr.host.or.ip
|
||||
key: apikeyapikeyapikeyapikeyapikey
|
||||
```
|
||||
@@ -1,17 +0,0 @@
|
||||
---
|
||||
title: Overseerr
|
||||
description: Overseerr Widget Configuration
|
||||
---
|
||||
|
||||
Learn more about [Overseerr](https://github.com/sct/overseerr).
|
||||
|
||||
Find your API key under `Settings > General`.
|
||||
|
||||
Allowed fields: `["pending", "approved", "available", "processing"]`.
|
||||
|
||||
```yaml
|
||||
widget:
|
||||
type: overseerr
|
||||
url: http://overseerr.host.or.ip
|
||||
key: apikeyapikeyapikeyapikeyapikey
|
||||
```
|
||||
@@ -12,7 +12,7 @@ Allowed fields: no configurable fields for this widget.
|
||||
```yaml
|
||||
widget:
|
||||
type: tautulli
|
||||
url: http://tautulli.host.or.ip
|
||||
url: http://tautulli.host.or.ip:port
|
||||
key: apikeyapikeyapikeyapikeyapikey
|
||||
enableUser: true # optional, defaults to false
|
||||
showEpisodeNumber: true # optional, defaults to false
|
||||
|
||||
20
docs/widgets/services/seerr.md
Normal file
20
docs/widgets/services/seerr.md
Normal file
@@ -0,0 +1,20 @@
|
||||
---
|
||||
title: Seerr Widget
|
||||
description: Seerr Widget Configuration
|
||||
---
|
||||
|
||||
Learn more about [Seerr](https://github.com/seerr-team/seerr).
|
||||
|
||||
Find your API key under `Settings > General > API Key`.
|
||||
|
||||
_Jellyseerr and Overseerr merged into Seerr. Use `type: seerr` (legacy `type: jellyseerr` and `type: overseerr` are aliased)._
|
||||
|
||||
Allowed fields: `["pending", "approved", "available", "completed", "processing", "issues"]`.
|
||||
Default fields: `["pending", "approved", "completed"]`.
|
||||
|
||||
```yaml
|
||||
widget:
|
||||
type: seerr
|
||||
url: http://seerr.host.or.ip
|
||||
key: apikeyapikeyapikeyapikeyapikey
|
||||
```
|
||||
15
docs/widgets/services/sparkyfitness.md
Normal file
15
docs/widgets/services/sparkyfitness.md
Normal file
@@ -0,0 +1,15 @@
|
||||
---
|
||||
title: SparkyFitness
|
||||
description: SparkyFitness Widget Configuration
|
||||
---
|
||||
|
||||
Learn more about [SparkyFitness](https://github.com/CodeWithCJ/SparkyFitness).
|
||||
|
||||
Allowed fields: `["eaten", "burned", "remaining", "steps"]`.
|
||||
|
||||
```yaml
|
||||
widget:
|
||||
type: sparkyfitness
|
||||
url: http://sparkyfitness.host.or.ip
|
||||
key: apikeyapikeyapikeyapikeyapikey
|
||||
```
|
||||
21
docs/widgets/services/tracearr.md
Normal file
21
docs/widgets/services/tracearr.md
Normal file
@@ -0,0 +1,21 @@
|
||||
---
|
||||
title: Tracearr
|
||||
description: Tracearr Widget Configuration
|
||||
---
|
||||
|
||||
Learn more about [Tracearr](https://www.tracearr.com/).
|
||||
|
||||
Provides detailed information about currently active streams across multiple servers.
|
||||
|
||||
Allowed fields (for summary view): `["streams", "transcodes", "directplay", "bitrate"]`.
|
||||
|
||||
```yaml
|
||||
widget:
|
||||
type: tracearr
|
||||
url: http://tracearr.host.or.ip:3000
|
||||
key: apikeyapikeyapikeyapikeyapikey
|
||||
view: both # optional, "summary", "details", or "both", defaults to "details"
|
||||
enableUser: true # optional, defaults to false
|
||||
showEpisodeNumber: true # optional, defaults to false
|
||||
expandOneStreamToTwoRows: false # optional, defaults to true
|
||||
```
|
||||
@@ -91,7 +91,6 @@ nav:
|
||||
- widgets/services/jackett.md
|
||||
- widgets/services/jdownloader.md
|
||||
- widgets/services/jellyfin.md
|
||||
- widgets/services/jellyseerr.md
|
||||
- widgets/services/jellystat.md
|
||||
- widgets/services/kavita.md
|
||||
- widgets/services/komga.md
|
||||
@@ -125,7 +124,6 @@ nav:
|
||||
- widgets/services/openmediavault.md
|
||||
- widgets/services/opnsense.md
|
||||
- widgets/services/openwrt.md
|
||||
- widgets/services/overseerr.md
|
||||
- widgets/services/pangolin.md
|
||||
- widgets/services/paperlessngx.md
|
||||
- widgets/services/peanut.md
|
||||
@@ -151,8 +149,10 @@ nav:
|
||||
- widgets/services/rutorrent.md
|
||||
- widgets/services/sabnzbd.md
|
||||
- widgets/services/scrutiny.md
|
||||
- widgets/services/seerr.md
|
||||
- widgets/services/slskd.md
|
||||
- widgets/services/sonarr.md
|
||||
- widgets/services/sparkyfitness.md
|
||||
- widgets/services/speedtest-tracker.md
|
||||
- widgets/services/spoolman.md
|
||||
- widgets/services/stash.md
|
||||
@@ -165,6 +165,7 @@ nav:
|
||||
- widgets/services/technitium.md
|
||||
- widgets/services/tdarr.md
|
||||
- widgets/services/traefik.md
|
||||
- widgets/services/tracearr.md
|
||||
- widgets/services/transmission.md
|
||||
- widgets/services/trilium.md
|
||||
- widgets/services/truenas.md
|
||||
|
||||
15
package.json
15
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "homepage",
|
||||
"version": "1.10.0",
|
||||
"version": "1.11.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"preinstall": "npx only-allow pnpm",
|
||||
@@ -22,20 +22,19 @@
|
||||
"follow-redirects": "^1.15.11",
|
||||
"gamedig": "^5.3.2",
|
||||
"i18next": "^25.8.0",
|
||||
"ical.js": "^2.1.0",
|
||||
"ical.js": "^2.2.1",
|
||||
"js-yaml": "^4.1.1",
|
||||
"json-rpc-2.0": "^1.7.0",
|
||||
"luxon": "^3.6.1",
|
||||
"memory-cache": "^0.2.0",
|
||||
"minecraftstatuspinger": "^1.2.2",
|
||||
"next": "^15.5.11",
|
||||
"next-auth": "^4.24.10",
|
||||
"next-i18next": "^12.1.0",
|
||||
"next-i18next": "^15.4.3",
|
||||
"ping": "^0.4.4",
|
||||
"pretty-bytes": "^7.1.0",
|
||||
"raw-body": "^3.0.2",
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.3.1",
|
||||
"react": "^19.2.4",
|
||||
"react-dom": "^19.2.4",
|
||||
"react-i18next": "^15.5.3",
|
||||
"react-icons": "^5.5.0",
|
||||
"recharts": "^3.1.2",
|
||||
@@ -64,9 +63,9 @@
|
||||
"eslint-plugin-prettier": "^5.5.4",
|
||||
"eslint-plugin-react": "^7.37.4",
|
||||
"eslint-plugin-react-hooks": "^5.2.0",
|
||||
"jsdom": "^26.1.0",
|
||||
"jsdom": "^28.1.0",
|
||||
"postcss": "^8.5.6",
|
||||
"prettier": "^3.7.3",
|
||||
"prettier": "^3.8.1",
|
||||
"prettier-plugin-organize-imports": "^4.3.0",
|
||||
"tailwind-scrollbar": "^4.0.2",
|
||||
"tailwindcss": "^4.1.18",
|
||||
|
||||
834
pnpm-lock.yaml
generated
834
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -184,6 +184,13 @@
|
||||
"no_active": "No Active Streams",
|
||||
"plex_connection_error": "Check Plex Connection"
|
||||
},
|
||||
"tracearr": {
|
||||
"no_active": "No Active Streams",
|
||||
"streams": "Streams",
|
||||
"transcodes": "Transcodes",
|
||||
"directplay": "Direct Play",
|
||||
"bitrate": "Bitrate"
|
||||
},
|
||||
"omada": {
|
||||
"connectedAp": "Connected APs",
|
||||
"activeUser": "Active devices",
|
||||
@@ -282,17 +289,13 @@
|
||||
"approved": "Approved",
|
||||
"available": "Available"
|
||||
},
|
||||
"jellyseerr": {
|
||||
"seerr": {
|
||||
"pending": "Pending",
|
||||
"approved": "Approved",
|
||||
"available": "Available",
|
||||
"issues": "Open Issues"
|
||||
},
|
||||
"overseerr": {
|
||||
"pending": "Pending",
|
||||
"completed": "Completed",
|
||||
"processing": "Processing",
|
||||
"approved": "Approved",
|
||||
"available": "Available"
|
||||
"issues": "Open Issues"
|
||||
},
|
||||
"netalertx": {
|
||||
"total": "Total",
|
||||
@@ -1171,5 +1174,11 @@
|
||||
"paused": "Paused",
|
||||
"total": "Total",
|
||||
"environment_not_found": "Environment Not Found"
|
||||
},
|
||||
"sparkyfitness": {
|
||||
"eaten": "Eaten",
|
||||
"burned": "Burned",
|
||||
"remaining": "Remaining",
|
||||
"steps": "Steps"
|
||||
}
|
||||
}
|
||||
|
||||
8
pyproject.toml
Normal file
8
pyproject.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[project]
|
||||
name = "homepage-docs"
|
||||
version = "1.0.0"
|
||||
description = "Documentation for the Homepage project"
|
||||
requires-python = ">=3.13"
|
||||
dependencies = [
|
||||
"zensical>=0.0.21",
|
||||
]
|
||||
@@ -1,47 +0,0 @@
|
||||
Babel==2.12.1
|
||||
backrefs==5.9
|
||||
cairocffi==1.7.1
|
||||
CairoSVG==2.7.1
|
||||
certifi==2023.7.22
|
||||
cffi==1.17.1
|
||||
cfgv==3.4.0
|
||||
charset-normalizer==3.2.0
|
||||
click==8.1.7
|
||||
colorama==0.4.6
|
||||
cssselect2==0.7.0
|
||||
defusedxml==0.7.1
|
||||
distlib==0.3.9
|
||||
filelock==3.17.0
|
||||
ghp-import==2.1.0
|
||||
identify==2.6.7
|
||||
idna==3.4
|
||||
Jinja2==3.1.2
|
||||
Markdown==3.4.4
|
||||
MarkupSafe==2.1.3
|
||||
mergedeep==1.3.4
|
||||
mkdocs==1.6.0
|
||||
mkdocs-get-deps==0.2.0
|
||||
mkdocs-material==9.6.18
|
||||
mkdocs-material-extensions==1.3.1
|
||||
mkdocs-redirects==1.2.1
|
||||
nodeenv==1.9.1
|
||||
packaging==23.1
|
||||
paginate==0.5.6
|
||||
pathspec==0.11.2
|
||||
pillow==10.4.0
|
||||
platformdirs==3.10.0
|
||||
pre-commit==3.5.0
|
||||
pycparser==2.22
|
||||
Pygments==2.16.1
|
||||
pymdown-extensions==10.3
|
||||
python-dateutil==2.8.2
|
||||
PyYAML==6.0.1
|
||||
pyyaml_env_tag==0.1
|
||||
regex==2023.8.8
|
||||
requests==2.31.0
|
||||
six==1.16.0
|
||||
tinycss2==1.4.0
|
||||
urllib3==2.0.5
|
||||
virtualenv==20.29.2
|
||||
watchdog==3.0.0
|
||||
webencodings==0.5.1
|
||||
@@ -1,124 +0,0 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const { nextAuthMock } = vi.hoisted(() => ({
|
||||
nextAuthMock: vi.fn((options) => ({ options })),
|
||||
}));
|
||||
|
||||
vi.mock("next-auth", () => ({
|
||||
default: nextAuthMock,
|
||||
}));
|
||||
|
||||
describe("pages/api/auth/[...nextauth]", () => {
|
||||
const originalEnv = process.env;
|
||||
|
||||
beforeEach(() => {
|
||||
vi.resetModules();
|
||||
nextAuthMock.mockClear();
|
||||
process.env = { ...originalEnv };
|
||||
delete process.env.NEXTAUTH_SECRET;
|
||||
delete process.env.NEXTAUTH_URL;
|
||||
});
|
||||
|
||||
it("configures no providers when auth is disabled", async () => {
|
||||
const mod = await import("pages/api/auth/[...nextauth]");
|
||||
|
||||
expect(nextAuthMock).toHaveBeenCalledTimes(1);
|
||||
expect(mod.default.options.providers).toEqual([]);
|
||||
expect(mod.default.options.pages?.signIn).toBe("/auth/signin");
|
||||
});
|
||||
|
||||
it("maps HOMEPAGE_AUTH_SECRET and HOMEPAGE_EXTERNAL_URL to NextAuth envs", async () => {
|
||||
process.env.HOMEPAGE_AUTH_SECRET = "secret";
|
||||
process.env.HOMEPAGE_EXTERNAL_URL = "https://homepage.example";
|
||||
|
||||
const mod = await import("pages/api/auth/[...nextauth]");
|
||||
|
||||
expect(process.env.NEXTAUTH_SECRET).toBe("secret");
|
||||
expect(process.env.NEXTAUTH_URL).toBe("https://homepage.example");
|
||||
expect(mod.default.options.secret).toBe("secret");
|
||||
});
|
||||
|
||||
it("throws when auth is enabled but no provider settings are present", async () => {
|
||||
process.env.HOMEPAGE_AUTH_ENABLED = "true";
|
||||
|
||||
await expect(import("pages/api/auth/[...nextauth]")).rejects.toThrow(
|
||||
/Password auth is enabled but required settings are missing/i,
|
||||
);
|
||||
});
|
||||
|
||||
it("builds a password provider when auth is enabled without OIDC config", async () => {
|
||||
process.env.HOMEPAGE_AUTH_ENABLED = "true";
|
||||
process.env.HOMEPAGE_AUTH_PASSWORD = "secret";
|
||||
process.env.HOMEPAGE_AUTH_SECRET = "auth-secret";
|
||||
|
||||
const mod = await import("pages/api/auth/[...nextauth]");
|
||||
const [provider] = mod.default.options.providers;
|
||||
|
||||
expect(provider.id).toBe("credentials");
|
||||
expect(provider.name).toBe("Credentials");
|
||||
expect(provider.type).toBe("credentials");
|
||||
expect(typeof provider.authorize).toBe("function");
|
||||
});
|
||||
|
||||
it("builds an OIDC provider when enabled and maps profile fields", async () => {
|
||||
process.env.HOMEPAGE_AUTH_ENABLED = "true";
|
||||
process.env.HOMEPAGE_OIDC_ISSUER = "https://issuer.example/";
|
||||
process.env.HOMEPAGE_OIDC_CLIENT_ID = "client-id";
|
||||
process.env.HOMEPAGE_OIDC_CLIENT_SECRET = "client-secret";
|
||||
process.env.HOMEPAGE_AUTH_SECRET = "auth-secret";
|
||||
process.env.HOMEPAGE_EXTERNAL_URL = "https://homepage.example";
|
||||
process.env.HOMEPAGE_OIDC_NAME = "My OIDC";
|
||||
process.env.HOMEPAGE_OIDC_SCOPE = "openid email";
|
||||
|
||||
const mod = await import("pages/api/auth/[...nextauth]");
|
||||
const [provider] = mod.default.options.providers;
|
||||
|
||||
expect(provider).toMatchObject({
|
||||
id: "homepage-oidc",
|
||||
name: "My OIDC",
|
||||
type: "oauth",
|
||||
idToken: true,
|
||||
issuer: "https://issuer.example",
|
||||
wellKnown: "https://issuer.example/.well-known/openid-configuration",
|
||||
clientId: "client-id",
|
||||
clientSecret: "client-secret",
|
||||
});
|
||||
expect(provider.authorization.params.scope).toBe("openid email");
|
||||
|
||||
expect(
|
||||
provider.profile({
|
||||
sub: "sub",
|
||||
preferred_username: "user",
|
||||
email: "user@example.com",
|
||||
picture: "https://example.com/p.png",
|
||||
}),
|
||||
).toEqual({
|
||||
id: "sub",
|
||||
name: "user",
|
||||
email: "user@example.com",
|
||||
image: "https://example.com/p.png",
|
||||
});
|
||||
|
||||
expect(
|
||||
provider.profile({
|
||||
id: "id",
|
||||
name: "name",
|
||||
}),
|
||||
).toEqual({
|
||||
id: "id",
|
||||
name: "name",
|
||||
email: null,
|
||||
image: null,
|
||||
});
|
||||
});
|
||||
|
||||
it("throws when only partial OIDC settings are provided", async () => {
|
||||
process.env.HOMEPAGE_AUTH_ENABLED = "true";
|
||||
process.env.HOMEPAGE_OIDC_ISSUER = "https://issuer.example";
|
||||
process.env.HOMEPAGE_AUTH_SECRET = "auth-secret";
|
||||
|
||||
await expect(import("pages/api/auth/[...nextauth]")).rejects.toThrow(
|
||||
/OIDC auth is enabled but required settings are missing/i,
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -344,4 +344,17 @@ describe("pages/api/services/proxy", () => {
|
||||
expect(res.statusCode).toBe(500);
|
||||
expect(res.body).toEqual({ error: "Unexpected error" });
|
||||
});
|
||||
|
||||
it("returns 500 when an async proxy handler throws", async () => {
|
||||
getServiceWidget.mockResolvedValue({ type: "linkwarden" });
|
||||
handlerFn.handler.mockRejectedValueOnce(new Error("proxy boom"));
|
||||
|
||||
const req = { method: "GET", query: { group: "g", service: "s", index: "0" } };
|
||||
const res = createMockRes();
|
||||
|
||||
await servicesProxy(req, res);
|
||||
|
||||
expect(res.statusCode).toBe(500);
|
||||
expect(res.body).toEqual({ error: "Unexpected error" });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -90,17 +90,74 @@ describe("pages/api/widgets/resources", () => {
|
||||
});
|
||||
|
||||
it("returns 404 when requested network interface does not exist", async () => {
|
||||
si.networkStats.mockResolvedValueOnce([{ iface: "en0" }]);
|
||||
si.networkStats.mockResolvedValueOnce([{ iface: "en0" }]).mockResolvedValueOnce([
|
||||
{
|
||||
iface: "missing",
|
||||
operstate: "unknown",
|
||||
rx_bytes: 0,
|
||||
rx_dropped: 0,
|
||||
rx_errors: 0,
|
||||
tx_bytes: 0,
|
||||
tx_dropped: 0,
|
||||
tx_errors: 0,
|
||||
rx_sec: null,
|
||||
tx_sec: null,
|
||||
ms: 0,
|
||||
},
|
||||
]);
|
||||
|
||||
const req = { query: { type: "network", interfaceName: "missing" } };
|
||||
const res = createMockRes();
|
||||
|
||||
await handler(req, res);
|
||||
|
||||
expect(si.networkStats).toHaveBeenNthCalledWith(1, "*");
|
||||
expect(si.networkStats).toHaveBeenNthCalledWith(2, "missing");
|
||||
expect(res.statusCode).toBe(404);
|
||||
expect(res.body).toEqual({ error: "Interface not found" });
|
||||
});
|
||||
|
||||
it("falls back to direct named interface query when wildcard enumeration misses it", async () => {
|
||||
si.networkStats.mockResolvedValueOnce([{ iface: "eth0", rx_bytes: 1 }]).mockResolvedValueOnce([
|
||||
{
|
||||
iface: "eno1",
|
||||
operstate: "up",
|
||||
rx_bytes: 1000,
|
||||
rx_dropped: 0,
|
||||
rx_errors: 0,
|
||||
tx_bytes: 500,
|
||||
tx_dropped: 0,
|
||||
tx_errors: 0,
|
||||
rx_sec: null,
|
||||
tx_sec: null,
|
||||
ms: 0,
|
||||
},
|
||||
]);
|
||||
|
||||
const req = { query: { type: "network", interfaceName: "eno1" } };
|
||||
const res = createMockRes();
|
||||
|
||||
await handler(req, res);
|
||||
|
||||
expect(si.networkStats).toHaveBeenNthCalledWith(1, "*");
|
||||
expect(si.networkStats).toHaveBeenNthCalledWith(2, "eno1");
|
||||
expect(res.statusCode).toBe(200);
|
||||
expect(res.body.interface).toBe("eno1");
|
||||
expect(res.body.network).toEqual({
|
||||
iface: "eno1",
|
||||
operstate: "up",
|
||||
rx_bytes: 1000,
|
||||
rx_dropped: 0,
|
||||
rx_errors: 0,
|
||||
tx_bytes: 500,
|
||||
tx_dropped: 0,
|
||||
tx_errors: 0,
|
||||
rx_sec: null,
|
||||
tx_sec: null,
|
||||
ms: 0,
|
||||
});
|
||||
});
|
||||
|
||||
it("returns default interface network stats", async () => {
|
||||
si.networkStats.mockResolvedValueOnce([{ iface: "en0", rx_bytes: 1 }]);
|
||||
si.networkInterfaceDefault.mockResolvedValueOnce("en0");
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
// @vitest-environment jsdom
|
||||
|
||||
import { render, screen, waitFor } from "@testing-library/react";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
const { getSettingsMock } = vi.hoisted(() => ({
|
||||
getSettingsMock: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("utils/config/config", () => ({
|
||||
getSettings: getSettingsMock,
|
||||
}));
|
||||
|
||||
vi.mock("next/router", () => ({
|
||||
useRouter: () => ({
|
||||
query: {},
|
||||
}),
|
||||
}));
|
||||
|
||||
import { getProviders } from "next-auth/react";
|
||||
import SignInPage, { getServerSideProps } from "pages/auth/signin";
|
||||
|
||||
describe("pages/auth/signin", () => {
|
||||
it("renders an error state when no providers are configured", async () => {
|
||||
render(
|
||||
<SignInPage
|
||||
providers={{}}
|
||||
settings={{
|
||||
theme: "dark",
|
||||
color: "slate",
|
||||
title: "Homepage",
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(screen.getByText("Authentication not configured")).toBeInTheDocument();
|
||||
|
||||
await waitFor(() => {
|
||||
expect(document.documentElement.classList.contains("dark")).toBe(true);
|
||||
expect(document.documentElement.classList.contains("scheme-dark")).toBe(true);
|
||||
expect(document.documentElement.classList.contains("theme-slate")).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it("renders provider buttons when providers are available", () => {
|
||||
render(
|
||||
<SignInPage
|
||||
providers={{
|
||||
oidc: { id: "oidc", name: "OIDC" },
|
||||
}}
|
||||
settings={{
|
||||
theme: "light",
|
||||
color: "emerald",
|
||||
title: "My Dashboard",
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(screen.getByText("Sign in")).toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: /login via oidc/i })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("getServerSideProps returns providers and settings", async () => {
|
||||
getProviders.mockResolvedValueOnce({ foo: { id: "foo", name: "Foo" } });
|
||||
getSettingsMock.mockReturnValueOnce({ theme: "dark" });
|
||||
|
||||
const res = await getServerSideProps({});
|
||||
|
||||
expect(getProviders).toHaveBeenCalled();
|
||||
expect(getSettingsMock).toHaveBeenCalled();
|
||||
expect(res).toEqual({
|
||||
props: {
|
||||
providers: { foo: { id: "foo", name: "Foo" } },
|
||||
settings: { theme: "dark" },
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,6 +1,6 @@
|
||||
// @vitest-environment jsdom
|
||||
|
||||
import { fireEvent, screen } from "@testing-library/react";
|
||||
import { act, fireEvent, screen } from "@testing-library/react";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { renderWithProviders } from "test-utils/render-with-providers";
|
||||
@@ -188,7 +188,9 @@ describe("components/services/item", () => {
|
||||
// Still rendered while the close animation runs.
|
||||
expect(screen.getByTestId("docker-widget")).toBeInTheDocument();
|
||||
|
||||
await vi.advanceTimersByTimeAsync(300);
|
||||
act(() => {
|
||||
vi.advanceTimersByTime(300);
|
||||
});
|
||||
expect(screen.queryByTestId("docker-widget")).not.toBeInTheDocument();
|
||||
|
||||
vi.useRealTimers();
|
||||
|
||||
@@ -9,6 +9,8 @@ import { buildHighlightConfig } from "utils/highlights";
|
||||
const ALIASED_WIDGETS = {
|
||||
pialert: "netalertx",
|
||||
hoarder: "karakeep",
|
||||
jellyseerr: "seerr",
|
||||
overseerr: "seerr",
|
||||
};
|
||||
|
||||
export default function Container({ error = false, children, service }) {
|
||||
|
||||
@@ -58,6 +58,26 @@ describe("components/services/widget/container", () => {
|
||||
expect(screen.getByTestId("karakeep.count")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("supports seerr aliases when filtering (jellyseerr/overseerr -> seerr)", () => {
|
||||
renderWithProviders(
|
||||
<Container service={{ widget: { type: "jellyseerr", fields: ["pending"] } }}>
|
||||
<Dummy label="seerr.pending" />
|
||||
</Container>,
|
||||
{ settings: {} },
|
||||
);
|
||||
|
||||
expect(screen.getByTestId("seerr.pending")).toBeInTheDocument();
|
||||
|
||||
renderWithProviders(
|
||||
<Container service={{ widget: { type: "overseerr", fields: ["processing"] } }}>
|
||||
<Dummy label="seerr.processing" />
|
||||
</Container>,
|
||||
{ settings: {} },
|
||||
);
|
||||
|
||||
expect(screen.getByTestId("seerr.processing")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("returns null when errors are hidden via settings.hideErrors", () => {
|
||||
const { container } = renderWithProviders(
|
||||
<Container error="nope" service={{ widget: { type: "omada", hide_errors: false } }}>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// @vitest-environment jsdom
|
||||
|
||||
import { screen } from "@testing-library/react";
|
||||
import { act, screen } from "@testing-library/react";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { renderWithProviders } from "test-utils/render-with-providers";
|
||||
@@ -21,7 +21,9 @@ describe("components/widgets/datetime", () => {
|
||||
// `render` wraps in `act`, so effects should flush synchronously.
|
||||
expect(screen.getByText(expected0)).toBeInTheDocument();
|
||||
|
||||
await vi.advanceTimersByTimeAsync(1000);
|
||||
act(() => {
|
||||
vi.advanceTimersByTime(1000);
|
||||
});
|
||||
const expected1 = new Intl.DateTimeFormat("en-US", format).format(new Date());
|
||||
|
||||
expect(screen.getByText(expected1)).toBeInTheDocument();
|
||||
|
||||
@@ -11,7 +11,7 @@ import Resource from "../widget/resource";
|
||||
import Resources from "../widget/resources";
|
||||
import WidgetLabel from "../widget/widget_label";
|
||||
|
||||
const cpuSensorLabels = ["cpu_thermal", "Core", "Tctl"];
|
||||
const cpuSensorLabels = ["cpu_thermal", "Core", "Tctl", "Temperature"];
|
||||
|
||||
function convertToFahrenheit(t) {
|
||||
return (t * 9) / 5 + 32;
|
||||
|
||||
@@ -1,34 +1,23 @@
|
||||
import { getToken } from "next-auth/jwt";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
const authEnabled = Boolean(process.env.HOMEPAGE_AUTH_ENABLED);
|
||||
const authSecret = process.env.NEXTAUTH_SECRET || process.env.HOMEPAGE_AUTH_SECRET;
|
||||
let warnedAllowedHosts = false;
|
||||
|
||||
export async function middleware(req) {
|
||||
if (!warnedAllowedHosts && process.env.HOMEPAGE_ALLOWED_HOSTS) {
|
||||
warnedAllowedHosts = true;
|
||||
console.warn(
|
||||
"HOMEPAGE_ALLOWED_HOSTS is deprecated. To secure a publicly accessible homepage, configure authentication instead.",
|
||||
export function middleware(req) {
|
||||
// Check the Host header, if HOMEPAGE_ALLOWED_HOSTS is set
|
||||
const host = req.headers.get("host");
|
||||
const port = process.env.PORT || 3000;
|
||||
let allowedHosts = [`localhost:${port}`, `127.0.0.1:${port}`, `[::1]:${port}`];
|
||||
const allowAll = process.env.HOMEPAGE_ALLOWED_HOSTS === "*";
|
||||
if (process.env.HOMEPAGE_ALLOWED_HOSTS) {
|
||||
allowedHosts = allowedHosts.concat(process.env.HOMEPAGE_ALLOWED_HOSTS.split(","));
|
||||
}
|
||||
if (!allowAll && (!host || !allowedHosts.includes(host))) {
|
||||
console.error(
|
||||
`Host validation failed for: ${host}. Hint: Set the HOMEPAGE_ALLOWED_HOSTS environment variable to allow requests from this host / port.`,
|
||||
);
|
||||
return NextResponse.json({ error: "Host validation failed. See logs for more details." }, { status: 400 });
|
||||
}
|
||||
|
||||
if (authEnabled) {
|
||||
const token = await getToken({ req, secret: authSecret });
|
||||
if (!token) {
|
||||
const signInUrl = new URL("/auth/signin", req.url);
|
||||
signInUrl.searchParams.set("callbackUrl", "/");
|
||||
return NextResponse.redirect(signInUrl);
|
||||
}
|
||||
}
|
||||
|
||||
return NextResponse.next();
|
||||
}
|
||||
|
||||
export const config = {
|
||||
// Protect all app and API routes; allow Next.js internals, public assets, auth pages, and NextAuth endpoints.
|
||||
matcher: [
|
||||
"/",
|
||||
"/((?!_next/static|_next/image|favicon.ico|robots.txt|manifest.json|sitemap.xml|icons/|api/auth|auth/).*)",
|
||||
],
|
||||
matcher: "/api/:path*",
|
||||
};
|
||||
|
||||
@@ -1,89 +1,70 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const { NextResponse, getToken } = vi.hoisted(() => ({
|
||||
const { NextResponse } = vi.hoisted(() => ({
|
||||
NextResponse: {
|
||||
json: vi.fn((body, init) => ({ type: "json", body, init })),
|
||||
next: vi.fn(() => ({ type: "next" })),
|
||||
redirect: vi.fn((url) => ({ type: "redirect", url })),
|
||||
},
|
||||
getToken: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("next/server", () => ({ NextResponse }));
|
||||
vi.mock("next-auth/jwt", () => ({ getToken }));
|
||||
|
||||
async function loadMiddleware() {
|
||||
vi.resetModules();
|
||||
const mod = await import("./middleware");
|
||||
return mod.middleware;
|
||||
}
|
||||
import { middleware } from "./middleware";
|
||||
|
||||
function createReq(url = "http://localhost:3000/") {
|
||||
function createReq(host) {
|
||||
return {
|
||||
url,
|
||||
headers: {
|
||||
get: () => null,
|
||||
get: (key) => (key === "host" ? host : null),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
describe("middleware", () => {
|
||||
const originalEnv = process.env;
|
||||
const originalConsoleWarn = console.warn;
|
||||
const originalConsoleError = console.error;
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
process.env = { ...originalEnv };
|
||||
console.warn = originalConsoleWarn;
|
||||
console.error = originalConsoleError;
|
||||
});
|
||||
|
||||
it("allows requests when auth is disabled", async () => {
|
||||
const middleware = await loadMiddleware();
|
||||
const res = await middleware(createReq());
|
||||
it("allows requests for default localhost hosts", () => {
|
||||
process.env.PORT = "3000";
|
||||
const res = middleware(createReq("localhost:3000"));
|
||||
|
||||
expect(NextResponse.next).toHaveBeenCalled();
|
||||
expect(res).toEqual({ type: "next" });
|
||||
});
|
||||
|
||||
it("warns once when HOMEPAGE_ALLOWED_HOSTS is set, but does not block", async () => {
|
||||
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
||||
process.env.HOMEPAGE_ALLOWED_HOSTS = "example.com";
|
||||
it("blocks requests when host is not allowed", () => {
|
||||
process.env.PORT = "3000";
|
||||
const errSpy = vi.spyOn(console, "error").mockImplementation(() => {});
|
||||
|
||||
const middleware = await loadMiddleware();
|
||||
const res1 = await middleware(createReq());
|
||||
const res2 = await middleware(createReq());
|
||||
const res = middleware(createReq("evil.com"));
|
||||
|
||||
expect(errSpy).toHaveBeenCalled();
|
||||
expect(NextResponse.json).toHaveBeenCalledWith(
|
||||
{ error: "Host validation failed. See logs for more details." },
|
||||
{ status: 400 },
|
||||
);
|
||||
expect(res.type).toBe("json");
|
||||
expect(res.init.status).toBe(400);
|
||||
});
|
||||
|
||||
it("allows requests when HOMEPAGE_ALLOWED_HOSTS is '*'", () => {
|
||||
process.env.HOMEPAGE_ALLOWED_HOSTS = "*";
|
||||
const res = middleware(createReq("anything.example"));
|
||||
|
||||
expect(warnSpy).toHaveBeenCalledTimes(1);
|
||||
expect(NextResponse.next).toHaveBeenCalled();
|
||||
expect(res1).toEqual({ type: "next" });
|
||||
expect(res2).toEqual({ type: "next" });
|
||||
expect(res).toEqual({ type: "next" });
|
||||
});
|
||||
|
||||
it("redirects to signin when auth is enabled and no token is present", async () => {
|
||||
process.env.HOMEPAGE_AUTH_ENABLED = "true";
|
||||
process.env.HOMEPAGE_AUTH_SECRET = "secret";
|
||||
it("allows requests when host is included in HOMEPAGE_ALLOWED_HOSTS", () => {
|
||||
process.env.PORT = "3000";
|
||||
process.env.HOMEPAGE_ALLOWED_HOSTS = "example.com:3000,other:3000";
|
||||
|
||||
getToken.mockResolvedValueOnce(null);
|
||||
|
||||
const middleware = await loadMiddleware();
|
||||
const res = await middleware(createReq("http://localhost:3000/some"));
|
||||
|
||||
expect(getToken).toHaveBeenCalledWith({
|
||||
req: expect.objectContaining({ url: "http://localhost:3000/some" }),
|
||||
secret: "secret",
|
||||
});
|
||||
expect(NextResponse.redirect).toHaveBeenCalled();
|
||||
expect(res.type).toBe("redirect");
|
||||
expect(String(res.url)).toContain("/auth/signin");
|
||||
});
|
||||
|
||||
it("allows requests when auth is enabled and a token is present", async () => {
|
||||
process.env.HOMEPAGE_AUTH_ENABLED = "true";
|
||||
process.env.HOMEPAGE_AUTH_SECRET = "secret";
|
||||
|
||||
getToken.mockResolvedValueOnce({ sub: "user" });
|
||||
|
||||
const middleware = await loadMiddleware();
|
||||
const res = await middleware(createReq("http://localhost:3000/"));
|
||||
const res = middleware(createReq("example.com:3000"));
|
||||
|
||||
expect(NextResponse.next).toHaveBeenCalled();
|
||||
expect(res).toEqual({ type: "next" });
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
/* eslint-disable react/jsx-props-no-spreading */
|
||||
import { SessionProvider } from "next-auth/react";
|
||||
import { appWithTranslation } from "next-i18next";
|
||||
import Head from "next/head";
|
||||
import "styles/globals.css";
|
||||
@@ -70,30 +69,28 @@ const tailwindSafelist = [
|
||||
|
||||
function MyApp({ Component, pageProps }) {
|
||||
return (
|
||||
<SessionProvider session={pageProps.session}>
|
||||
<SWRConfig
|
||||
value={{
|
||||
fetcher: (resource, init) => fetch(resource, init).then((res) => res.json()),
|
||||
}}
|
||||
>
|
||||
<Head>
|
||||
{/* https://nextjs.org/docs/messages/no-document-viewport-meta */}
|
||||
<meta
|
||||
name="viewport"
|
||||
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"
|
||||
/>
|
||||
</Head>
|
||||
<ColorProvider>
|
||||
<ThemeProvider>
|
||||
<SettingsProvider>
|
||||
<TabProvider>
|
||||
<Component {...pageProps} />
|
||||
</TabProvider>
|
||||
</SettingsProvider>
|
||||
</ThemeProvider>
|
||||
</ColorProvider>
|
||||
</SWRConfig>
|
||||
</SessionProvider>
|
||||
<SWRConfig
|
||||
value={{
|
||||
fetcher: (resource, init) => fetch(resource, init).then((res) => res.json()),
|
||||
}}
|
||||
>
|
||||
<Head>
|
||||
{/* https://nextjs.org/docs/messages/no-document-viewport-meta */}
|
||||
<meta
|
||||
name="viewport"
|
||||
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"
|
||||
/>
|
||||
</Head>
|
||||
<ColorProvider>
|
||||
<ThemeProvider>
|
||||
<SettingsProvider>
|
||||
<TabProvider>
|
||||
<Component {...pageProps} />
|
||||
</TabProvider>
|
||||
</SettingsProvider>
|
||||
</ThemeProvider>
|
||||
</ColorProvider>
|
||||
</SWRConfig>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,114 +0,0 @@
|
||||
import { timingSafeEqual } from "node:crypto";
|
||||
|
||||
import NextAuth from "next-auth";
|
||||
import CredentialsProvider from "next-auth/providers/credentials";
|
||||
|
||||
const authEnabled = Boolean(process.env.HOMEPAGE_AUTH_ENABLED);
|
||||
const issuer = process.env.HOMEPAGE_OIDC_ISSUER;
|
||||
const clientId = process.env.HOMEPAGE_OIDC_CLIENT_ID;
|
||||
const clientSecret = process.env.HOMEPAGE_OIDC_CLIENT_SECRET;
|
||||
const homepageAuthSecret = process.env.HOMEPAGE_AUTH_SECRET;
|
||||
const homepageExternalUrl = process.env.HOMEPAGE_EXTERNAL_URL;
|
||||
const homepageAuthPassword = process.env.HOMEPAGE_AUTH_PASSWORD;
|
||||
|
||||
// Map HOMEPAGE_* envs to what NextAuth expects
|
||||
if (!process.env.NEXTAUTH_SECRET && homepageAuthSecret) {
|
||||
process.env.NEXTAUTH_SECRET = homepageAuthSecret;
|
||||
}
|
||||
if (!process.env.NEXTAUTH_URL && homepageExternalUrl) {
|
||||
process.env.NEXTAUTH_URL = homepageExternalUrl;
|
||||
}
|
||||
|
||||
const defaultScope = process.env.HOMEPAGE_OIDC_SCOPE || "openid email profile";
|
||||
const cleanedIssuer = issuer ? issuer.replace(/\/+$/, "") : issuer;
|
||||
const hasOidcConfig = Boolean(issuer && clientId && clientSecret);
|
||||
const hasAnyOidcConfig = Boolean(issuer || clientId || clientSecret);
|
||||
|
||||
if (authEnabled) {
|
||||
if (hasOidcConfig) {
|
||||
if (!process.env.NEXTAUTH_SECRET || !process.env.NEXTAUTH_URL) {
|
||||
throw new Error("OIDC auth is enabled but required settings are missing.");
|
||||
}
|
||||
} else if (hasAnyOidcConfig) {
|
||||
throw new Error("OIDC auth is enabled but required settings are missing.");
|
||||
} else if (!homepageAuthPassword || !process.env.NEXTAUTH_SECRET) {
|
||||
throw new Error("Password auth is enabled but required settings are missing.");
|
||||
}
|
||||
}
|
||||
|
||||
let providers = [];
|
||||
if (authEnabled) {
|
||||
if (hasOidcConfig) {
|
||||
providers = [
|
||||
{
|
||||
id: "homepage-oidc",
|
||||
name: process.env.HOMEPAGE_OIDC_NAME || "Homepage OIDC",
|
||||
type: "oauth",
|
||||
idToken: true,
|
||||
issuer: cleanedIssuer,
|
||||
wellKnown: `${cleanedIssuer}/.well-known/openid-configuration`,
|
||||
clientId,
|
||||
clientSecret,
|
||||
authorization: {
|
||||
params: {
|
||||
scope: defaultScope,
|
||||
},
|
||||
},
|
||||
profile(profile) {
|
||||
return {
|
||||
id: profile.sub ?? profile.id ?? profile.user_id ?? profile.uid ?? profile.email,
|
||||
name: profile.name ?? profile.preferred_username ?? profile.nickname ?? profile.email,
|
||||
email: profile.email ?? null,
|
||||
image: profile.picture ?? null,
|
||||
};
|
||||
},
|
||||
},
|
||||
];
|
||||
} else {
|
||||
providers = [
|
||||
CredentialsProvider({
|
||||
name: "Password",
|
||||
credentials: {
|
||||
password: { label: "Password", type: "password" },
|
||||
},
|
||||
async authorize(credentials) {
|
||||
const provided = credentials?.password ?? "";
|
||||
const expected = homepageAuthPassword ?? "";
|
||||
if (!expected || provided.length !== expected.length) {
|
||||
return null;
|
||||
}
|
||||
const isMatch = timingSafeEqual(Buffer.from(provided), Buffer.from(expected));
|
||||
if (!isMatch) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
id: "homepage",
|
||||
name: "Homepage",
|
||||
};
|
||||
},
|
||||
}),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
export default NextAuth({
|
||||
providers,
|
||||
session: {
|
||||
strategy: "jwt",
|
||||
},
|
||||
secret: process.env.NEXTAUTH_SECRET,
|
||||
pages: {
|
||||
signIn: "/auth/signin",
|
||||
},
|
||||
debug: true,
|
||||
logger: {
|
||||
error: (...args) => console.error("[nextauth][error]", ...args),
|
||||
warn: (...args) => console.warn("[nextauth][warn]", ...args),
|
||||
debug: (...args) => console.debug("[nextauth][debug]", ...args),
|
||||
},
|
||||
events: {
|
||||
signIn: async (message) => console.debug("[nextauth][event][signIn]", message),
|
||||
signOut: async (message) => console.debug("[nextauth][event][signOut]", message),
|
||||
error: async (message) => console.error("[nextauth][event][error]", message),
|
||||
},
|
||||
});
|
||||
@@ -29,7 +29,7 @@ export default async function handler(req, res) {
|
||||
if (serviceProxyHandler instanceof Function) {
|
||||
// quick return for no endpoint services, calendar is an exception
|
||||
if (!req.query.endpoint || serviceProxyHandler === calendarProxyHandler) {
|
||||
return serviceProxyHandler(req, res);
|
||||
return await serviceProxyHandler(req, res);
|
||||
}
|
||||
|
||||
// map opaque endpoints to their actual endpoint
|
||||
@@ -90,15 +90,15 @@ export default async function handler(req, res) {
|
||||
}
|
||||
|
||||
if (endpointProxy instanceof Function) {
|
||||
return endpointProxy(req, res, map);
|
||||
return await endpointProxy(req, res, map);
|
||||
}
|
||||
|
||||
return serviceProxyHandler(req, res, map);
|
||||
return await serviceProxyHandler(req, res, map);
|
||||
}
|
||||
|
||||
if (widget.allowedEndpoints instanceof RegExp) {
|
||||
if (widget.allowedEndpoints.test(req.query.endpoint)) {
|
||||
return serviceProxyHandler(req, res);
|
||||
return await serviceProxyHandler(req, res);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,21 @@ import createLogger from "utils/logger";
|
||||
|
||||
const logger = createLogger("resources");
|
||||
|
||||
function isMissingNetworkStat(networkData, interfaceName) {
|
||||
return (
|
||||
networkData.operstate === "unknown" &&
|
||||
networkData.rx_bytes === 0 &&
|
||||
networkData.rx_dropped === 0 &&
|
||||
networkData.rx_errors === 0 &&
|
||||
networkData.tx_bytes === 0 &&
|
||||
networkData.tx_dropped === 0 &&
|
||||
networkData.tx_errors === 0 &&
|
||||
networkData.rx_sec === null &&
|
||||
networkData.tx_sec === null &&
|
||||
networkData.ms === 0
|
||||
);
|
||||
}
|
||||
|
||||
export default async function handler(req, res) {
|
||||
const { type, target, interfaceName = "default" } = req.query;
|
||||
|
||||
@@ -64,6 +79,17 @@ export default async function handler(req, res) {
|
||||
logger.debug("networkData:", JSON.stringify(networkData));
|
||||
if (interfaceName && interfaceName !== "default") {
|
||||
networkData = networkData.filter((network) => network.iface === interfaceName).at(0);
|
||||
if (!networkData) {
|
||||
// Fallback for e.g. docker where networkStats("*") may not return stats for host interfaces
|
||||
const directNetworkData = await si.networkStats(interfaceName);
|
||||
logger.debug("directNetworkData:", JSON.stringify(directNetworkData));
|
||||
networkData = Array.isArray(directNetworkData) ? directNetworkData.at(0) : null;
|
||||
|
||||
// si returns unknown + zeroes when interface truly does not exist
|
||||
if (!networkData || isMissingNetworkStat(networkData, interfaceName)) {
|
||||
networkData = null;
|
||||
}
|
||||
}
|
||||
if (!networkData) {
|
||||
return res.status(404).json({
|
||||
error: "Interface not found",
|
||||
|
||||
@@ -1,210 +0,0 @@
|
||||
import classNames from "classnames";
|
||||
import { getProviders, signIn } from "next-auth/react";
|
||||
import { useRouter } from "next/router";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { BiShieldQuarter } from "react-icons/bi";
|
||||
|
||||
import { getSettings } from "utils/config/config";
|
||||
|
||||
export default function SignIn({ providers, settings }) {
|
||||
const router = useRouter();
|
||||
const [password, setPassword] = useState("");
|
||||
const theme = settings?.theme || "dark";
|
||||
const color = settings?.color || "slate";
|
||||
const title = settings?.title || "Homepage";
|
||||
const callbackUrl = useMemo(() => {
|
||||
const value = router.query?.callbackUrl;
|
||||
return typeof value === "string" ? value : "/";
|
||||
}, [router.query?.callbackUrl]);
|
||||
const error = router.query?.error;
|
||||
|
||||
let backgroundImage = "";
|
||||
let opacity = settings?.backgroundOpacity ?? 0;
|
||||
let backgroundBlur = false;
|
||||
let backgroundSaturate = false;
|
||||
let backgroundBrightness = false;
|
||||
|
||||
if (settings?.background) {
|
||||
const bg = settings.background;
|
||||
if (typeof bg === "object") {
|
||||
backgroundImage = bg.image || "";
|
||||
if (bg.opacity !== undefined) {
|
||||
opacity = 1 - bg.opacity / 100;
|
||||
}
|
||||
backgroundBlur = bg.blur !== undefined;
|
||||
backgroundSaturate = bg.saturate !== undefined;
|
||||
backgroundBrightness = bg.brightness !== undefined;
|
||||
} else {
|
||||
backgroundImage = bg;
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const html = document.documentElement;
|
||||
const body = document.body;
|
||||
|
||||
html.classList.remove("dark", "scheme-dark", "scheme-light");
|
||||
html.classList.toggle("dark", theme === "dark");
|
||||
html.classList.add(theme === "dark" ? "scheme-dark" : "scheme-light");
|
||||
|
||||
const desiredThemeClass = `theme-${color}`;
|
||||
const themeClassesToRemove = Array.from(html.classList).filter(
|
||||
(cls) => cls.startsWith("theme-") && cls !== desiredThemeClass,
|
||||
);
|
||||
if (themeClassesToRemove.length) {
|
||||
html.classList.remove(...themeClassesToRemove);
|
||||
}
|
||||
if (!html.classList.contains(desiredThemeClass)) {
|
||||
html.classList.add(desiredThemeClass);
|
||||
}
|
||||
|
||||
body.style.backgroundImage = "";
|
||||
body.style.backgroundColor = "";
|
||||
body.style.backgroundAttachment = "";
|
||||
}, [color, theme]);
|
||||
|
||||
if (!providers || Object.keys(providers).length === 0) {
|
||||
return (
|
||||
<>
|
||||
{backgroundImage && (
|
||||
<div
|
||||
id="background"
|
||||
aria-hidden="true"
|
||||
style={{
|
||||
backgroundImage: `linear-gradient(rgb(var(--bg-color) / ${opacity}), rgb(var(--bg-color) / ${opacity})), url('${backgroundImage}')`,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
<main
|
||||
className={classNames(
|
||||
"relative flex min-h-screen items-center justify-center px-6 py-12",
|
||||
backgroundBlur &&
|
||||
`backdrop-blur${settings?.background?.blur?.length ? `-${settings.background.blur}` : ""}`,
|
||||
backgroundSaturate && `backdrop-saturate-${settings.background.saturate}`,
|
||||
backgroundBrightness && `backdrop-brightness-${settings.background.brightness}`,
|
||||
)}
|
||||
>
|
||||
<div className="relative w-full max-w-xl overflow-hidden rounded-3xl border border-white/40 bg-white/80 p-10 text-center shadow-2xl shadow-black/10 dark:border-white/10 dark:bg-slate-900/70">
|
||||
<div
|
||||
aria-hidden="true"
|
||||
className="pointer-events-none absolute inset-x-0 top-0 h-24 bg-gradient-to-r from-theme-500/20 via-theme-500/5 to-transparent"
|
||||
/>
|
||||
<div className="mx-auto flex h-12 w-12 items-center justify-center rounded-2xl bg-theme-500/15 text-theme-600 dark:text-theme-300">
|
||||
<BiShieldQuarter className="h-6 w-6" />
|
||||
</div>
|
||||
<h1 className="mt-6 text-2xl font-semibold text-gray-900 dark:text-slate-100">
|
||||
Authentication not configured
|
||||
</h1>
|
||||
<p className="mt-3 text-sm text-gray-600 dark:text-slate-400">OIDC is disabled or misconfigured.</p>
|
||||
</div>
|
||||
</main>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
const passwordProvider = providers
|
||||
? Object.values(providers).find((provider) => provider.type === "credentials")
|
||||
: null;
|
||||
const hasPasswordProvider = Boolean(passwordProvider);
|
||||
|
||||
return (
|
||||
<>
|
||||
{backgroundImage && (
|
||||
<div
|
||||
id="background"
|
||||
aria-hidden="true"
|
||||
style={{
|
||||
backgroundImage: `linear-gradient(rgb(var(--bg-color) / ${opacity}), rgb(var(--bg-color) / ${opacity})), url('${backgroundImage}')`,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
<main className="relative flex min-h-screen items-center justify-center px-6 py-12">
|
||||
<div
|
||||
className={classNames(
|
||||
"relative w-full max-w-4xl overflow-hidden rounded-3xl border border-white/50 bg-white/80 shadow-2xl shadow-black/10 backdrop-blur-xl dark:border-white/10 dark:bg-slate-950/70",
|
||||
backgroundBlur &&
|
||||
`backdrop-blur${settings?.background?.blur?.length ? `-${settings.background.blur}` : ""}`,
|
||||
backgroundSaturate && `backdrop-saturate-${settings.background.saturate}`,
|
||||
backgroundBrightness && `backdrop-brightness-${settings.background.brightness}`,
|
||||
)}
|
||||
>
|
||||
<div className="pointer-events-none absolute -left-24 -top-20 h-64 w-64 rounded-full bg-theme-500/20 blur-3xl" />
|
||||
<div className="pointer-events-none absolute -bottom-24 right-0 h-72 w-72 rounded-full bg-theme-500/10 blur-3xl" />
|
||||
<div className="grid gap-10 px-8 py-12 md:grid-cols-[1.2fr_1fr] md:px-12">
|
||||
<section className="flex flex-col justify-between">
|
||||
<div>
|
||||
<div className="inline-flex items-center gap-2 rounded-full border border-theme-500/30 bg-theme-500/10 px-3 py-1 text-xs font-semibold uppercase tracking-[0.2em] text-theme-600 dark:text-theme-300">
|
||||
Login Required
|
||||
</div>
|
||||
<h1 className="mt-6 text-3xl font-semibold text-gray-900 dark:text-slate-100">{title}</h1>
|
||||
<p className="mt-3 text-sm text-gray-600 dark:text-slate-300">Login to view your dashboard.</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section className="flex flex-col justify-center gap-6">
|
||||
<div className="rounded-2xl border border-white/60 bg-white/70 p-6 shadow-lg shadow-black/5 dark:border-white/10 dark:bg-slate-900/70">
|
||||
<h2 className="text-lg font-semibold text-gray-900 dark:text-slate-100">Sign in</h2>
|
||||
<div className="mt-6 space-y-3">
|
||||
{hasPasswordProvider && (
|
||||
<form
|
||||
className="space-y-3"
|
||||
onSubmit={async (event) => {
|
||||
event.preventDefault();
|
||||
await signIn(passwordProvider?.id ?? "credentials", {
|
||||
redirect: true,
|
||||
callbackUrl,
|
||||
password,
|
||||
});
|
||||
}}
|
||||
>
|
||||
<label className="block text-sm font-medium text-gray-700 dark:text-slate-300">Password</label>
|
||||
<input
|
||||
type="password"
|
||||
name="password"
|
||||
value={password}
|
||||
onChange={(event) => setPassword(event.target.value)}
|
||||
autoComplete="current-password"
|
||||
className="w-full rounded-xl border border-slate-200 bg-white/90 px-4 py-3 text-sm text-gray-900 shadow-sm outline-none ring-0 transition focus:border-theme-500 focus:ring-2 focus:ring-theme-500/30 dark:border-slate-700 dark:bg-slate-900/60 dark:text-slate-100"
|
||||
required
|
||||
/>
|
||||
<button
|
||||
type="submit"
|
||||
className="group w-full rounded-xl bg-theme-600 px-4 py-3 text-sm font-semibold text-white shadow-lg shadow-theme-600/20 transition hover:-translate-y-0.5 hover:bg-theme-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-theme-500"
|
||||
>
|
||||
<span className="flex items-center justify-center gap-2">Sign in →</span>
|
||||
</button>
|
||||
</form>
|
||||
)}
|
||||
{!hasPasswordProvider &&
|
||||
Object.values(providers).map((provider) => (
|
||||
<button
|
||||
key={provider.id}
|
||||
type="button"
|
||||
onClick={() => signIn(provider.id, { callbackUrl })}
|
||||
className="group w-full rounded-xl bg-theme-600 px-4 py-3 text-sm font-semibold text-white shadow-lg shadow-theme-600/20 transition hover:-translate-y-0.5 hover:bg-theme-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-theme-500"
|
||||
>
|
||||
<span className="flex items-center justify-center gap-2">Login via {provider.name} →</span>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
{hasPasswordProvider && error && (
|
||||
<p className="mt-4 rounded-xl border border-red-200 bg-red-50 px-3 py-2 text-xs text-red-700 dark:border-red-800/60 dark:bg-red-950/40 dark:text-red-200">
|
||||
Invalid password. Please try again.
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export async function getServerSideProps(context) {
|
||||
const providers = await getProviders();
|
||||
const settings = getSettings();
|
||||
return {
|
||||
props: { providers, settings },
|
||||
};
|
||||
}
|
||||
@@ -1,4 +1,12 @@
|
||||
import { expect } from "vitest";
|
||||
|
||||
export function findServiceBlockByLabel(container, label) {
|
||||
const blocks = Array.from(container.querySelectorAll(".service-block"));
|
||||
return blocks.find((b) => b.textContent?.includes(label));
|
||||
}
|
||||
|
||||
export function expectBlockValue(container, label, value) {
|
||||
const block = findServiceBlockByLabel(container, label);
|
||||
expect(block, `missing block for ${label}`).toBeTruthy();
|
||||
expect(block.textContent).toContain(String(value));
|
||||
}
|
||||
|
||||
@@ -313,7 +313,7 @@ export function cleanServiceGroups(groups) {
|
||||
enableNowPlaying,
|
||||
enableMediaControl,
|
||||
|
||||
// emby, jellyfin, tautulli
|
||||
// emby, jellyfin, tautulli, tracearr
|
||||
enableUser,
|
||||
expandOneStreamToTwoRows,
|
||||
showEpisodeNumber,
|
||||
@@ -542,12 +542,15 @@ export function cleanServiceGroups(groups) {
|
||||
if (enableBlocks !== undefined) widget.enableBlocks = JSON.parse(enableBlocks);
|
||||
if (enableNowPlaying !== undefined) widget.enableNowPlaying = JSON.parse(enableNowPlaying);
|
||||
}
|
||||
if (["emby", "jellyfin", "tautulli"].includes(type)) {
|
||||
if (["emby", "jellyfin", "tautulli", "tracearr"].includes(type)) {
|
||||
if (expandOneStreamToTwoRows !== undefined)
|
||||
widget.expandOneStreamToTwoRows = !!JSON.parse(expandOneStreamToTwoRows);
|
||||
if (showEpisodeNumber !== undefined) widget.showEpisodeNumber = !!JSON.parse(showEpisodeNumber);
|
||||
if (enableUser !== undefined) widget.enableUser = !!JSON.parse(enableUser);
|
||||
}
|
||||
if (type === "tracearr") {
|
||||
if (view !== undefined) widget.view = view;
|
||||
}
|
||||
if (["sonarr", "radarr"].includes(type)) {
|
||||
if (enableQueue !== undefined) widget.enableQueue = JSON.parse(enableQueue);
|
||||
}
|
||||
|
||||
@@ -312,6 +312,13 @@ describe("utils/config/service-helpers", () => {
|
||||
{ type: "healthchecks", uuid: "u" },
|
||||
{ type: "speedtest", bitratePrecision: "3", version: "1" },
|
||||
{ type: "stocks", watchlist: "AAPL", showUSMarketStatus: true },
|
||||
{
|
||||
type: "tracearr",
|
||||
expandOneStreamToTwoRows: "true",
|
||||
showEpisodeNumber: "true",
|
||||
enableUser: "true",
|
||||
view: "both",
|
||||
},
|
||||
{ type: "wgeasy", threshold: "10", version: "1" },
|
||||
{ type: "technitium", range: "24h" },
|
||||
{ type: "lubelogger", vehicleID: "12" },
|
||||
@@ -350,6 +357,14 @@ describe("utils/config/service-helpers", () => {
|
||||
expect(widgets.find((w) => w.type === "speedtest")).toEqual(
|
||||
expect.objectContaining({ bitratePrecision: 3, version: 1 }),
|
||||
);
|
||||
expect(widgets.find((w) => w.type === "tracearr")).toEqual(
|
||||
expect.objectContaining({
|
||||
expandOneStreamToTwoRows: true,
|
||||
showEpisodeNumber: true,
|
||||
enableUser: true,
|
||||
view: "both",
|
||||
}),
|
||||
);
|
||||
expect(widgets.find((w) => w.type === "jellystat")).toEqual(expect.objectContaining({ days: 7 }));
|
||||
expect(widgets.find((w) => w.type === "lubelogger")).toEqual(expect.objectContaining({ vehicleID: 12 }));
|
||||
});
|
||||
|
||||
@@ -74,6 +74,21 @@ const toNumber = (value) => {
|
||||
return undefined;
|
||||
};
|
||||
|
||||
const extractNumericToken = (value) => {
|
||||
if (typeof value !== "string") return undefined;
|
||||
const match = value.match(/[-+]?\d[\d\s.,]*/);
|
||||
if (!match) return undefined;
|
||||
|
||||
const token = match[0].trim();
|
||||
if (!token) return undefined;
|
||||
|
||||
const prefix = value.slice(0, match.index).trim();
|
||||
const suffix = value.slice((match.index ?? 0) + match[0].length).trim();
|
||||
if (/\d/.test(prefix) || /\d/.test(suffix)) return undefined;
|
||||
|
||||
return token;
|
||||
};
|
||||
|
||||
const parseNumericValue = (value) => {
|
||||
if (value === null || value === undefined) return undefined;
|
||||
if (typeof value === "number" && Number.isFinite(value)) return value;
|
||||
@@ -85,7 +100,9 @@ const parseNumericValue = (value) => {
|
||||
const direct = Number(trimmed);
|
||||
if (!Number.isNaN(direct)) return direct;
|
||||
|
||||
const compact = trimmed.replace(/\s+/g, "");
|
||||
const candidate = extractNumericToken(trimmed);
|
||||
const numericString = candidate ?? trimmed;
|
||||
const compact = numericString.replace(/\s+/g, "");
|
||||
if (!compact || !/^[-+]?[0-9.,]+$/.test(compact)) return undefined;
|
||||
|
||||
const commaCount = (compact.match(/,/g) || []).length;
|
||||
|
||||
@@ -136,6 +136,9 @@ describe("utils/highlights", () => {
|
||||
const cfg = buildHighlightConfig(null, {
|
||||
// string numeric rule values go through toNumber()
|
||||
gt: { numeric: { when: "gt", value: "5", level: "warn" } },
|
||||
withUnitSuffix: { numeric: { when: "gt", value: 5, level: "warn" } },
|
||||
withUnitPrefix: { numeric: { when: "gt", value: 5, level: "warn" } },
|
||||
localizedUnitSuffix: { numeric: { when: "gt", value: 0.5, level: "warn" } },
|
||||
commaGrouped: { numeric: { when: "eq", value: 1234, level: "good" } },
|
||||
commaDecimal: { numeric: { when: "eq", value: 12.34, level: "good" } },
|
||||
dotDecimal: { numeric: { when: "eq", value: 12.34, level: "good" } },
|
||||
@@ -143,6 +146,12 @@ describe("utils/highlights", () => {
|
||||
});
|
||||
|
||||
expect(evaluateHighlight("gt", "6", cfg)).toMatchObject({ level: "warn", source: "numeric" });
|
||||
expect(evaluateHighlight("withUnitSuffix", "5.2 ms", cfg)).toMatchObject({ level: "warn", source: "numeric" });
|
||||
expect(evaluateHighlight("withUnitPrefix", "ms 5.2", cfg)).toMatchObject({ level: "warn", source: "numeric" });
|
||||
expect(evaluateHighlight("localizedUnitSuffix", "0,71\u202Fms", cfg)).toMatchObject({
|
||||
level: "warn",
|
||||
source: "numeric",
|
||||
});
|
||||
expect(evaluateHighlight("commaGrouped", "1,234", cfg)).toMatchObject({ level: "good", source: "numeric" });
|
||||
expect(evaluateHighlight("commaDecimal", "12,34", cfg)).toMatchObject({ level: "good", source: "numeric" });
|
||||
// Include a space so Number(trimmed) fails and we exercise the dot parsing branch.
|
||||
@@ -161,6 +170,9 @@ describe("utils/highlights", () => {
|
||||
// "1.2.3" is not a valid grouped or decimal number for our parser.
|
||||
expect(evaluateHighlight("num", "1.2.3", cfg)).toBeNull();
|
||||
|
||||
// Multiple numbers in one string should not be treated as a single numeric value.
|
||||
expect(evaluateHighlight("num", "5/10 ms", cfg)).toBeNull();
|
||||
|
||||
// JSX-ish values should not be treated as numeric.
|
||||
expect(evaluateHighlight("num", { props: { children: "x" } }, cfg)).toBeNull();
|
||||
});
|
||||
|
||||
@@ -6,7 +6,7 @@ export function formatApiCall(url, args) {
|
||||
if (key === "url") {
|
||||
value = value.replace(/\/+$/, ""); // remove trailing slashes
|
||||
}
|
||||
return value || "";
|
||||
return value?.toString() || "";
|
||||
};
|
||||
|
||||
return url.replace(find, replace).replace(find, replace);
|
||||
|
||||
@@ -64,6 +64,7 @@ export default async function credentialedProxyHandler(req, res, map) {
|
||||
"pangolin",
|
||||
"tailscale",
|
||||
"tandoor",
|
||||
"tracearr",
|
||||
"pterodactyl",
|
||||
"vikunja",
|
||||
"firefly",
|
||||
|
||||
@@ -24,7 +24,8 @@ export default function Component({ service }) {
|
||||
const { data: images, error: imagesError } = useWidgetAPI(widget, "images");
|
||||
const { data: updates, error: updatesError } = useWidgetAPI(widget, "updates");
|
||||
|
||||
const error = containersError ?? imagesError ?? updatesError;
|
||||
const error =
|
||||
containersError ?? imagesError ?? updatesError ?? containers?.detail ?? images?.detail ?? updates?.detail;
|
||||
if (error) {
|
||||
return <Container service={service} error={error} />;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import { screen } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { renderWithProviders } from "test-utils/render-with-providers";
|
||||
import { expectBlockValue } from "test-utils/widget-assertions";
|
||||
|
||||
const { useWidgetAPI } = vi.hoisted(() => ({ useWidgetAPI: vi.fn() }));
|
||||
|
||||
@@ -13,13 +14,6 @@ vi.mock("utils/proxy/use-widget-api", () => ({
|
||||
|
||||
import Component from "./component";
|
||||
|
||||
function expectBlockValue(container, label, value) {
|
||||
const blocks = Array.from(container.querySelectorAll(".service-block"));
|
||||
const block = blocks.find((b) => b.textContent?.includes(label));
|
||||
expect(block, `missing block for ${label}`).toBeTruthy();
|
||||
expect(block.textContent).toContain(String(value));
|
||||
}
|
||||
|
||||
describe("widgets/arcane/component", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
@@ -34,6 +28,16 @@ describe("widgets/arcane/component", () => {
|
||||
expect(screen.getByText("arcane.environment_required")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("shows an error when API calls return detail errors", () => {
|
||||
useWidgetAPI.mockImplementation(() => ({ data: { detail: "Specific API error" }, error: undefined }));
|
||||
|
||||
renderWithProviders(<Component service={{ widget: { type: "arcane", env: "prod" } }} />, {
|
||||
settings: { hideErrors: false },
|
||||
});
|
||||
|
||||
expect(screen.getByText("Specific API error")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders placeholders while loading data", () => {
|
||||
useWidgetAPI.mockImplementation(() => ({ data: undefined, error: undefined }));
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import { screen } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { renderWithProviders } from "test-utils/render-with-providers";
|
||||
import { expectBlockValue } from "test-utils/widget-assertions";
|
||||
|
||||
const { useWidgetAPI } = vi.hoisted(() => ({ useWidgetAPI: vi.fn() }));
|
||||
|
||||
@@ -13,13 +14,6 @@ vi.mock("utils/proxy/use-widget-api", () => ({
|
||||
|
||||
import Component from "./component";
|
||||
|
||||
function expectBlockValue(container, label, value) {
|
||||
const blocks = Array.from(container.querySelectorAll(".service-block"));
|
||||
const block = blocks.find((b) => b.textContent?.includes(label));
|
||||
expect(block, `missing block for ${label}`).toBeTruthy();
|
||||
expect(block.textContent).toContain(String(value));
|
||||
}
|
||||
|
||||
describe("widgets/argocd/component", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
@@ -4,6 +4,7 @@ import { screen } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { renderWithProviders } from "test-utils/render-with-providers";
|
||||
import { expectBlockValue } from "test-utils/widget-assertions";
|
||||
|
||||
const { useWidgetAPI } = vi.hoisted(() => ({ useWidgetAPI: vi.fn() }));
|
||||
|
||||
@@ -13,13 +14,6 @@ vi.mock("utils/proxy/use-widget-api", () => ({
|
||||
|
||||
import Component from "./component";
|
||||
|
||||
function expectBlockValue(container, label, value) {
|
||||
const blocks = Array.from(container.querySelectorAll(".service-block"));
|
||||
const block = blocks.find((b) => b.textContent?.includes(label));
|
||||
expect(block, `missing block for ${label}`).toBeTruthy();
|
||||
expect(block.textContent).toContain(String(value));
|
||||
}
|
||||
|
||||
describe("widgets/audiobookshelf/component", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
@@ -4,6 +4,7 @@ import { screen } from "@testing-library/react";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { renderWithProviders } from "test-utils/render-with-providers";
|
||||
import { expectBlockValue } from "test-utils/widget-assertions";
|
||||
|
||||
const { useWidgetAPI } = vi.hoisted(() => ({ useWidgetAPI: vi.fn() }));
|
||||
|
||||
@@ -13,13 +14,6 @@ vi.mock("utils/proxy/use-widget-api", () => ({
|
||||
|
||||
import Component from "./component";
|
||||
|
||||
function expectBlockValue(container, label, value) {
|
||||
const blocks = Array.from(container.querySelectorAll(".service-block"));
|
||||
const block = blocks.find((b) => b.textContent?.includes(label));
|
||||
expect(block, `missing block for ${label}`).toBeTruthy();
|
||||
expect(block.textContent).toContain(String(value));
|
||||
}
|
||||
|
||||
describe("widgets/authentik/component", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
@@ -4,6 +4,7 @@ import { screen } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { renderWithProviders } from "test-utils/render-with-providers";
|
||||
import { expectBlockValue } from "test-utils/widget-assertions";
|
||||
|
||||
const { useWidgetAPI } = vi.hoisted(() => ({ useWidgetAPI: vi.fn() }));
|
||||
|
||||
@@ -13,13 +14,6 @@ vi.mock("utils/proxy/use-widget-api", () => ({
|
||||
|
||||
import Component from "./component";
|
||||
|
||||
function expectBlockValue(container, label, value) {
|
||||
const blocks = Array.from(container.querySelectorAll(".service-block"));
|
||||
const block = blocks.find((b) => b.textContent?.includes(label));
|
||||
expect(block, `missing block for ${label}`).toBeTruthy();
|
||||
expect(block.textContent).toContain(String(value));
|
||||
}
|
||||
|
||||
describe("widgets/autobrr/component", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
@@ -4,6 +4,7 @@ import { screen } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { renderWithProviders } from "test-utils/render-with-providers";
|
||||
import { expectBlockValue } from "test-utils/widget-assertions";
|
||||
|
||||
const { useWidgetAPI } = vi.hoisted(() => ({ useWidgetAPI: vi.fn() }));
|
||||
|
||||
@@ -13,13 +14,6 @@ vi.mock("utils/proxy/use-widget-api", () => ({
|
||||
|
||||
import Component from "./component";
|
||||
|
||||
function expectBlockValue(container, label, value) {
|
||||
const blocks = Array.from(container.querySelectorAll(".service-block"));
|
||||
const block = blocks.find((b) => b.textContent?.includes(label));
|
||||
expect(block, `missing block for ${label}`).toBeTruthy();
|
||||
expect(block.textContent).toContain(String(value));
|
||||
}
|
||||
|
||||
describe("widgets/azuredevops/component", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
@@ -54,7 +54,10 @@ export default function Component({ service }) {
|
||||
<Block label="beszel.cpu" value={t("common.percent", { value: system.info.cpu, maximumFractionDigits: 2 })} />
|
||||
<Block label="beszel.memory" value={t("common.percent", { value: system.info.mp, maximumFractionDigits: 2 })} />
|
||||
<Block label="beszel.disk" value={t("common.percent", { value: system.info.dp, maximumFractionDigits: 2 })} />
|
||||
<Block label="beszel.network" value={t("common.percent", { value: system.info.b, maximumFractionDigits: 2 })} />
|
||||
<Block
|
||||
label="beszel.network"
|
||||
value={t("common.byterate", { value: system.info.bb, maximumFractionDigits: 2 })}
|
||||
/>
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { screen } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { renderWithProviders } from "test-utils/render-with-providers";
|
||||
import { findServiceBlockByLabel } from "test-utils/widget-assertions";
|
||||
import { expectBlockValue } from "test-utils/widget-assertions";
|
||||
|
||||
const { useWidgetAPI } = vi.hoisted(() => ({ useWidgetAPI: vi.fn() }));
|
||||
|
||||
@@ -12,12 +12,6 @@ vi.mock("utils/proxy/use-widget-api", () => ({ default: useWidgetAPI }));
|
||||
|
||||
import Component from "./component";
|
||||
|
||||
function expectBlockValue(container, label, value) {
|
||||
const block = findServiceBlockByLabel(container, label);
|
||||
expect(block, `missing block for ${label}`).toBeTruthy();
|
||||
expect(block.textContent).toContain(String(value));
|
||||
}
|
||||
|
||||
describe("widgets/beszel/component", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
@@ -82,6 +76,35 @@ describe("widgets/beszel/component", () => {
|
||||
expect(screen.queryByText("beszel.updated")).toBeNull();
|
||||
});
|
||||
|
||||
it("renders optional fields", () => {
|
||||
useWidgetAPI.mockReturnValue({
|
||||
data: {
|
||||
totalItems: 1,
|
||||
items: [
|
||||
{
|
||||
id: "sys1",
|
||||
name: "MySystem",
|
||||
status: "up",
|
||||
updated: 123,
|
||||
info: { cpu: 10, mp: 20, dp: 30, b: 40, bb: 14.5 },
|
||||
},
|
||||
],
|
||||
},
|
||||
error: undefined,
|
||||
});
|
||||
|
||||
const service = {
|
||||
widget: { type: "beszel", systemId: "sys1", fields: ["name", "disk", "network"] },
|
||||
};
|
||||
const { container } = renderWithProviders(<Component service={service} />, { settings: { hideErrors: false } });
|
||||
|
||||
expect(service.widget.fields).toEqual(["name", "disk", "network"]);
|
||||
expect(container.querySelectorAll(".service-block")).toHaveLength(3);
|
||||
expectBlockValue(container, "beszel.name", "MySystem");
|
||||
expectBlockValue(container, "beszel.disk", 30);
|
||||
expectBlockValue(container, "beszel.network", 14.5);
|
||||
});
|
||||
|
||||
it("renders error when systemId is not found", () => {
|
||||
useWidgetAPI.mockReturnValue({
|
||||
data: { totalItems: 1, items: [{ id: "sys1", name: "MySystem", status: "up", info: {} }] },
|
||||
|
||||
@@ -4,7 +4,7 @@ import { screen } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { renderWithProviders } from "test-utils/render-with-providers";
|
||||
import { findServiceBlockByLabel } from "test-utils/widget-assertions";
|
||||
import { expectBlockValue } from "test-utils/widget-assertions";
|
||||
|
||||
const { useWidgetAPI } = vi.hoisted(() => ({ useWidgetAPI: vi.fn() }));
|
||||
|
||||
@@ -12,12 +12,6 @@ vi.mock("utils/proxy/use-widget-api", () => ({ default: useWidgetAPI }));
|
||||
|
||||
import Component from "./component";
|
||||
|
||||
function expectBlockValue(container, label, value) {
|
||||
const block = findServiceBlockByLabel(container, label);
|
||||
expect(block, `missing block for ${label}`).toBeTruthy();
|
||||
expect(block.textContent).toContain(String(value));
|
||||
}
|
||||
|
||||
describe("widgets/caddy/component", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
@@ -4,7 +4,7 @@ import { screen } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { renderWithProviders } from "test-utils/render-with-providers";
|
||||
import { findServiceBlockByLabel } from "test-utils/widget-assertions";
|
||||
import { expectBlockValue } from "test-utils/widget-assertions";
|
||||
|
||||
const { useWidgetAPI } = vi.hoisted(() => ({ useWidgetAPI: vi.fn() }));
|
||||
|
||||
@@ -12,12 +12,6 @@ vi.mock("utils/proxy/use-widget-api", () => ({ default: useWidgetAPI }));
|
||||
|
||||
import Component from "./component";
|
||||
|
||||
function expectBlockValue(container, label, value) {
|
||||
const block = findServiceBlockByLabel(container, label);
|
||||
expect(block, `missing block for ${label}`).toBeTruthy();
|
||||
expect(block.textContent).toContain(String(value));
|
||||
}
|
||||
|
||||
describe("widgets/changedetectionio/component", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
@@ -4,7 +4,7 @@ import { screen } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { renderWithProviders } from "test-utils/render-with-providers";
|
||||
import { findServiceBlockByLabel } from "test-utils/widget-assertions";
|
||||
import { expectBlockValue } from "test-utils/widget-assertions";
|
||||
|
||||
const { useWidgetAPI } = vi.hoisted(() => ({ useWidgetAPI: vi.fn() }));
|
||||
|
||||
@@ -12,12 +12,6 @@ vi.mock("utils/proxy/use-widget-api", () => ({ default: useWidgetAPI }));
|
||||
|
||||
import Component from "./component";
|
||||
|
||||
function expectBlockValue(container, label, value) {
|
||||
const block = findServiceBlockByLabel(container, label);
|
||||
expect(block, `missing block for ${label}`).toBeTruthy();
|
||||
expect(block.textContent).toContain(String(value));
|
||||
}
|
||||
|
||||
describe("widgets/channelsdvrserver/component", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
@@ -4,7 +4,7 @@ import { screen } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { renderWithProviders } from "test-utils/render-with-providers";
|
||||
import { findServiceBlockByLabel } from "test-utils/widget-assertions";
|
||||
import { expectBlockValue } from "test-utils/widget-assertions";
|
||||
|
||||
const { useWidgetAPI } = vi.hoisted(() => ({ useWidgetAPI: vi.fn() }));
|
||||
|
||||
@@ -12,12 +12,6 @@ vi.mock("utils/proxy/use-widget-api", () => ({ default: useWidgetAPI }));
|
||||
|
||||
import Component from "./component";
|
||||
|
||||
function expectBlockValue(container, label, value) {
|
||||
const block = findServiceBlockByLabel(container, label);
|
||||
expect(block, `missing block for ${label}`).toBeTruthy();
|
||||
expect(block.textContent).toContain(String(value));
|
||||
}
|
||||
|
||||
describe("widgets/checkmk/component", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
@@ -4,7 +4,7 @@ import { screen } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { renderWithProviders } from "test-utils/render-with-providers";
|
||||
import { findServiceBlockByLabel } from "test-utils/widget-assertions";
|
||||
import { expectBlockValue } from "test-utils/widget-assertions";
|
||||
|
||||
const { useWidgetAPI } = vi.hoisted(() => ({ useWidgetAPI: vi.fn() }));
|
||||
|
||||
@@ -12,12 +12,6 @@ vi.mock("utils/proxy/use-widget-api", () => ({ default: useWidgetAPI }));
|
||||
|
||||
import Component from "./component";
|
||||
|
||||
function expectBlockValue(container, label, value) {
|
||||
const block = findServiceBlockByLabel(container, label);
|
||||
expect(block, `missing block for ${label}`).toBeTruthy();
|
||||
expect(block.textContent).toContain(String(value));
|
||||
}
|
||||
|
||||
describe("widgets/cloudflared/component", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
@@ -65,7 +65,7 @@ const components = {
|
||||
jackett: dynamic(() => import("./jackett/component")),
|
||||
jdownloader: dynamic(() => import("./jdownloader/component")),
|
||||
jellyfin: dynamic(() => import("./jellyfin/component")),
|
||||
jellyseerr: dynamic(() => import("./jellyseerr/component")),
|
||||
jellyseerr: dynamic(() => import("./seerr/component")),
|
||||
jellystat: dynamic(() => import("./jellystat/component")),
|
||||
kavita: dynamic(() => import("./kavita/component")),
|
||||
komga: dynamic(() => import("./komga/component")),
|
||||
@@ -97,7 +97,7 @@ const components = {
|
||||
ombi: dynamic(() => import("./ombi/component")),
|
||||
opendtu: dynamic(() => import("./opendtu/component")),
|
||||
opnsense: dynamic(() => import("./opnsense/component")),
|
||||
overseerr: dynamic(() => import("./overseerr/component")),
|
||||
overseerr: dynamic(() => import("./seerr/component")),
|
||||
openmediavault: dynamic(() => import("./openmediavault/component")),
|
||||
openwrt: dynamic(() => import("./openwrt/component")),
|
||||
paperlessngx: dynamic(() => import("./paperlessngx/component")),
|
||||
@@ -124,8 +124,10 @@ const components = {
|
||||
rutorrent: dynamic(() => import("./rutorrent/component")),
|
||||
sabnzbd: dynamic(() => import("./sabnzbd/component")),
|
||||
scrutiny: dynamic(() => import("./scrutiny/component")),
|
||||
seerr: dynamic(() => import("./seerr/component")),
|
||||
slskd: dynamic(() => import("./slskd/component")),
|
||||
sonarr: dynamic(() => import("./sonarr/component")),
|
||||
sparkyfitness: dynamic(() => import("./sparkyfitness/component")),
|
||||
speedtest: dynamic(() => import("./speedtest/component")),
|
||||
spoolman: dynamic(() => import("./spoolman/component")),
|
||||
stash: dynamic(() => import("./stash/component")),
|
||||
@@ -138,6 +140,7 @@ const components = {
|
||||
tautulli: dynamic(() => import("./tautulli/component")),
|
||||
technitium: dynamic(() => import("./technitium/component")),
|
||||
tdarr: dynamic(() => import("./tdarr/component")),
|
||||
tracearr: dynamic(() => import("./tracearr/component")),
|
||||
traefik: dynamic(() => import("./traefik/component")),
|
||||
transmission: dynamic(() => import("./transmission/component")),
|
||||
trilium: dynamic(() => import("./trilium/component")),
|
||||
|
||||
@@ -4,7 +4,7 @@ import { screen } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { renderWithProviders } from "test-utils/render-with-providers";
|
||||
import { findServiceBlockByLabel } from "test-utils/widget-assertions";
|
||||
import { expectBlockValue } from "test-utils/widget-assertions";
|
||||
|
||||
const { useWidgetAPI } = vi.hoisted(() => ({ useWidgetAPI: vi.fn() }));
|
||||
|
||||
@@ -12,12 +12,6 @@ vi.mock("utils/proxy/use-widget-api", () => ({ default: useWidgetAPI }));
|
||||
|
||||
import Component from "./component";
|
||||
|
||||
function expectBlockValue(container, label, value) {
|
||||
const block = findServiceBlockByLabel(container, label);
|
||||
expect(block, `missing block for ${label}`).toBeTruthy();
|
||||
expect(block.textContent).toContain(String(value));
|
||||
}
|
||||
|
||||
describe("widgets/crowdsec/component", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
@@ -25,13 +25,25 @@ async function login(widget, service) {
|
||||
}),
|
||||
});
|
||||
|
||||
const dataParsed = JSON.parse(data);
|
||||
let dataParsed;
|
||||
try {
|
||||
dataParsed = JSON.parse(data);
|
||||
} catch {
|
||||
logger.error("Failed to parse Crowdsec login response, status: %d", status);
|
||||
cache.del(`${sessionTokenCacheKey}.${service}`);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!(status === 200) || !dataParsed.token) {
|
||||
if (status !== 200 || !dataParsed.token) {
|
||||
logger.error("Failed to login to Crowdsec API, status: %d", status);
|
||||
cache.del(`${sessionTokenCacheKey}.${service}`);
|
||||
return null;
|
||||
}
|
||||
cache.put(`${sessionTokenCacheKey}.${service}`, dataParsed.token, new Date(dataParsed.expire) - new Date());
|
||||
|
||||
const ttl = Math.max(new Date(dataParsed.expire) - new Date(), 1);
|
||||
cache.put(`${sessionTokenCacheKey}.${service}`, dataParsed.token, ttl);
|
||||
|
||||
return dataParsed.token;
|
||||
}
|
||||
|
||||
export default async function crowdsecProxyHandler(req, res) {
|
||||
@@ -48,11 +60,10 @@ export default async function crowdsecProxyHandler(req, res) {
|
||||
return res.status(400).json({ error: "Invalid widget configuration" });
|
||||
}
|
||||
|
||||
if (!cache.get(`${sessionTokenCacheKey}.${service}`)) {
|
||||
await login(widget, service);
|
||||
let token = cache.get(`${sessionTokenCacheKey}.${service}`);
|
||||
if (!token) {
|
||||
token = await login(widget, service);
|
||||
}
|
||||
|
||||
const token = cache.get(`${sessionTokenCacheKey}.${service}`);
|
||||
if (!token) {
|
||||
return res.status(500).json({ error: "Failed to authenticate with Crowdsec" });
|
||||
}
|
||||
@@ -71,7 +82,20 @@ export default async function crowdsecProxyHandler(req, res) {
|
||||
|
||||
logger.debug("Calling Crowdsec API endpoint: %s", endpoint);
|
||||
|
||||
const [status, , data] = await httpProxy(url, params);
|
||||
let [status, , data] = await httpProxy(url, params);
|
||||
|
||||
if (status === 401) {
|
||||
logger.debug("Crowdsec API returned 401, refreshing token and retrying request");
|
||||
cache.del(`${sessionTokenCacheKey}.${service}`);
|
||||
const refreshedToken = await login(widget, service);
|
||||
|
||||
if (!refreshedToken) {
|
||||
return res.status(500).json({ error: "Failed to authenticate with Crowdsec" });
|
||||
}
|
||||
|
||||
params.headers.Authorization = `Bearer ${refreshedToken}`;
|
||||
[status, , data] = await httpProxy(url, params);
|
||||
}
|
||||
|
||||
if (status !== 200) {
|
||||
logger.error("Error calling Crowdsec API: %d. Data: %s", status, data);
|
||||
|
||||
@@ -89,4 +89,76 @@ describe("widgets/crowdsec/proxy", () => {
|
||||
expect(res.statusCode).toBe(500);
|
||||
expect(res.body).toEqual({ error: "Failed to authenticate with Crowdsec" });
|
||||
});
|
||||
|
||||
it("re-authenticates and retries once when API returns 401", async () => {
|
||||
getServiceWidget.mockResolvedValue({
|
||||
type: "crowdsec",
|
||||
url: "http://cs",
|
||||
username: "machine",
|
||||
password: "pw",
|
||||
});
|
||||
|
||||
httpProxy
|
||||
.mockResolvedValueOnce([
|
||||
200,
|
||||
"application/json",
|
||||
JSON.stringify({ token: "tok-old", expire: new Date(Date.now() + 60_000).toISOString() }),
|
||||
])
|
||||
.mockResolvedValueOnce([401, "application/json", Buffer.from("bad token")])
|
||||
.mockResolvedValueOnce([
|
||||
200,
|
||||
"application/json",
|
||||
JSON.stringify({ token: "tok-new", expire: new Date(Date.now() + 60_000).toISOString() }),
|
||||
])
|
||||
.mockResolvedValueOnce([200, "application/json", Buffer.from("data")]);
|
||||
|
||||
const req = { query: { group: "g", service: "svc", endpoint: "alerts", index: "0" } };
|
||||
const res = createMockRes();
|
||||
|
||||
await crowdsecProxyHandler(req, res);
|
||||
|
||||
expect(httpProxy).toHaveBeenCalledTimes(4);
|
||||
expect(httpProxy.mock.calls[3][1].headers.Authorization).toBe("Bearer tok-new");
|
||||
expect(res.statusCode).toBe(200);
|
||||
expect(res.body).toEqual(Buffer.from("data"));
|
||||
});
|
||||
|
||||
it("returns 500 when 401 refresh fails to get a new token", async () => {
|
||||
getServiceWidget.mockResolvedValue({
|
||||
type: "crowdsec",
|
||||
url: "http://cs",
|
||||
username: "machine",
|
||||
password: "pw",
|
||||
});
|
||||
|
||||
httpProxy
|
||||
.mockResolvedValueOnce([
|
||||
200,
|
||||
"application/json",
|
||||
JSON.stringify({ token: "tok-old", expire: new Date(Date.now() + 60_000).toISOString() }),
|
||||
])
|
||||
.mockResolvedValueOnce([401, "application/json", Buffer.from("bad token")])
|
||||
.mockResolvedValueOnce([500, "application/json", JSON.stringify({ error: "no token" })]);
|
||||
|
||||
const req = { query: { group: "g", service: "svc", endpoint: "alerts", index: "0" } };
|
||||
const res = createMockRes();
|
||||
|
||||
await crowdsecProxyHandler(req, res);
|
||||
|
||||
expect(res.statusCode).toBe(500);
|
||||
expect(res.body).toEqual({ error: "Failed to authenticate with Crowdsec" });
|
||||
});
|
||||
|
||||
it("returns 500 when login response is not JSON", async () => {
|
||||
getServiceWidget.mockResolvedValue({ type: "crowdsec", url: "http://cs", username: "machine", password: "pw" });
|
||||
httpProxy.mockResolvedValueOnce([200, "text/plain", "not-json"]);
|
||||
|
||||
const req = { query: { group: "g", service: "svc", endpoint: "alerts", index: "0" } };
|
||||
const res = createMockRes();
|
||||
|
||||
await crowdsecProxyHandler(req, res);
|
||||
|
||||
expect(res.statusCode).toBe(500);
|
||||
expect(res.body).toEqual({ error: "Failed to authenticate with Crowdsec" });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,7 +4,7 @@ import { screen } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { renderWithProviders } from "test-utils/render-with-providers";
|
||||
import { findServiceBlockByLabel } from "test-utils/widget-assertions";
|
||||
import { expectBlockValue } from "test-utils/widget-assertions";
|
||||
|
||||
const { useWidgetAPI } = vi.hoisted(() => ({ useWidgetAPI: vi.fn() }));
|
||||
|
||||
@@ -16,12 +16,6 @@ vi.mock("../../components/widgets/queue/queueEntry", () => ({
|
||||
|
||||
import Component from "./component";
|
||||
|
||||
function expectBlockValue(container, label, value) {
|
||||
const block = findServiceBlockByLabel(container, label);
|
||||
expect(block, `missing block for ${label}`).toBeTruthy();
|
||||
expect(block.textContent).toContain(String(value));
|
||||
}
|
||||
|
||||
describe("widgets/deluge/component", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
@@ -4,19 +4,13 @@ import { screen } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { renderWithProviders } from "test-utils/render-with-providers";
|
||||
import { findServiceBlockByLabel } from "test-utils/widget-assertions";
|
||||
import { expectBlockValue } from "test-utils/widget-assertions";
|
||||
|
||||
const { useWidgetAPI } = vi.hoisted(() => ({ useWidgetAPI: vi.fn() }));
|
||||
vi.mock("utils/proxy/use-widget-api", () => ({ default: useWidgetAPI }));
|
||||
|
||||
import Component from "./component";
|
||||
|
||||
function expectBlockValue(container, label, value) {
|
||||
const block = findServiceBlockByLabel(container, label);
|
||||
expect(block, `missing block for ${label}`).toBeTruthy();
|
||||
expect(block.textContent).toContain(String(value));
|
||||
}
|
||||
|
||||
describe("widgets/diskstation/component", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
@@ -4,19 +4,13 @@ import { screen } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { renderWithProviders } from "test-utils/render-with-providers";
|
||||
import { findServiceBlockByLabel } from "test-utils/widget-assertions";
|
||||
import { expectBlockValue } from "test-utils/widget-assertions";
|
||||
|
||||
const { useWidgetAPI } = vi.hoisted(() => ({ useWidgetAPI: vi.fn() }));
|
||||
vi.mock("utils/proxy/use-widget-api", () => ({ default: useWidgetAPI }));
|
||||
|
||||
import Component from "./component";
|
||||
|
||||
function expectBlockValue(container, label, value) {
|
||||
const block = findServiceBlockByLabel(container, label);
|
||||
expect(block, `missing block for ${label}`).toBeTruthy();
|
||||
expect(block.textContent).toContain(String(value));
|
||||
}
|
||||
|
||||
describe("widgets/dispatcharr/component", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
@@ -4,19 +4,13 @@ import { screen } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { renderWithProviders } from "test-utils/render-with-providers";
|
||||
import { findServiceBlockByLabel } from "test-utils/widget-assertions";
|
||||
import { expectBlockValue } from "test-utils/widget-assertions";
|
||||
|
||||
const { useWidgetAPI } = vi.hoisted(() => ({ useWidgetAPI: vi.fn() }));
|
||||
vi.mock("utils/proxy/use-widget-api", () => ({ default: useWidgetAPI }));
|
||||
|
||||
import Component from "./component";
|
||||
|
||||
function expectBlockValue(container, label, value) {
|
||||
const block = findServiceBlockByLabel(container, label);
|
||||
expect(block, `missing block for ${label}`).toBeTruthy();
|
||||
expect(block.textContent).toContain(String(value));
|
||||
}
|
||||
|
||||
describe("widgets/dockhand/component", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
@@ -4,19 +4,13 @@ import { screen } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { renderWithProviders } from "test-utils/render-with-providers";
|
||||
import { findServiceBlockByLabel } from "test-utils/widget-assertions";
|
||||
import { expectBlockValue } from "test-utils/widget-assertions";
|
||||
|
||||
const { useWidgetAPI } = vi.hoisted(() => ({ useWidgetAPI: vi.fn() }));
|
||||
vi.mock("utils/proxy/use-widget-api", () => ({ default: useWidgetAPI }));
|
||||
|
||||
import Component from "./component";
|
||||
|
||||
function expectBlockValue(container, label, value) {
|
||||
const block = findServiceBlockByLabel(container, label);
|
||||
expect(block, `missing block for ${label}`).toBeTruthy();
|
||||
expect(block.textContent).toContain(String(value));
|
||||
}
|
||||
|
||||
describe("widgets/downloadstation/component", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
@@ -4,19 +4,13 @@ import { screen } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { renderWithProviders } from "test-utils/render-with-providers";
|
||||
import { findServiceBlockByLabel } from "test-utils/widget-assertions";
|
||||
import { expectBlockValue } from "test-utils/widget-assertions";
|
||||
|
||||
const { useWidgetAPI } = vi.hoisted(() => ({ useWidgetAPI: vi.fn() }));
|
||||
vi.mock("utils/proxy/use-widget-api", () => ({ default: useWidgetAPI }));
|
||||
|
||||
import Component from "./component";
|
||||
|
||||
function expectBlockValue(container, label, value) {
|
||||
const block = findServiceBlockByLabel(container, label);
|
||||
expect(block, `missing block for ${label}`).toBeTruthy();
|
||||
expect(block.textContent).toContain(String(value));
|
||||
}
|
||||
|
||||
describe("widgets/esphome/component", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
@@ -4,19 +4,13 @@ import { screen } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { renderWithProviders } from "test-utils/render-with-providers";
|
||||
import { findServiceBlockByLabel } from "test-utils/widget-assertions";
|
||||
import { expectBlockValue } from "test-utils/widget-assertions";
|
||||
|
||||
const { useWidgetAPI } = vi.hoisted(() => ({ useWidgetAPI: vi.fn() }));
|
||||
vi.mock("utils/proxy/use-widget-api", () => ({ default: useWidgetAPI }));
|
||||
|
||||
import Component from "./component";
|
||||
|
||||
function expectBlockValue(container, label, value) {
|
||||
const block = findServiceBlockByLabel(container, label);
|
||||
expect(block, `missing block for ${label}`).toBeTruthy();
|
||||
expect(block.textContent).toContain(String(value));
|
||||
}
|
||||
|
||||
describe("widgets/evcc/component", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
@@ -4,19 +4,13 @@ import { screen } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { renderWithProviders } from "test-utils/render-with-providers";
|
||||
import { findServiceBlockByLabel } from "test-utils/widget-assertions";
|
||||
import { expectBlockValue } from "test-utils/widget-assertions";
|
||||
|
||||
const { useWidgetAPI } = vi.hoisted(() => ({ useWidgetAPI: vi.fn() }));
|
||||
vi.mock("utils/proxy/use-widget-api", () => ({ default: useWidgetAPI }));
|
||||
|
||||
import Component from "./component";
|
||||
|
||||
function expectBlockValue(container, label, value) {
|
||||
const block = findServiceBlockByLabel(container, label);
|
||||
expect(block, `missing block for ${label}`).toBeTruthy();
|
||||
expect(block.textContent).toContain(String(value));
|
||||
}
|
||||
|
||||
describe("widgets/filebrowser/component", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
@@ -4,19 +4,13 @@ import { screen } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { renderWithProviders } from "test-utils/render-with-providers";
|
||||
import { findServiceBlockByLabel } from "test-utils/widget-assertions";
|
||||
import { expectBlockValue } from "test-utils/widget-assertions";
|
||||
|
||||
const { useWidgetAPI } = vi.hoisted(() => ({ useWidgetAPI: vi.fn() }));
|
||||
vi.mock("utils/proxy/use-widget-api", () => ({ default: useWidgetAPI }));
|
||||
|
||||
import Component from "./component";
|
||||
|
||||
function expectBlockValue(container, label, value) {
|
||||
const block = findServiceBlockByLabel(container, label);
|
||||
expect(block, `missing block for ${label}`).toBeTruthy();
|
||||
expect(block.textContent).toContain(String(value));
|
||||
}
|
||||
|
||||
describe("widgets/fileflows/component", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
@@ -4,19 +4,13 @@ import { screen } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { renderWithProviders } from "test-utils/render-with-providers";
|
||||
import { findServiceBlockByLabel } from "test-utils/widget-assertions";
|
||||
import { expectBlockValue } from "test-utils/widget-assertions";
|
||||
|
||||
const { useWidgetAPI } = vi.hoisted(() => ({ useWidgetAPI: vi.fn() }));
|
||||
vi.mock("utils/proxy/use-widget-api", () => ({ default: useWidgetAPI }));
|
||||
|
||||
import Component from "./component";
|
||||
|
||||
function expectBlockValue(container, label, value) {
|
||||
const block = findServiceBlockByLabel(container, label);
|
||||
expect(block, `missing block for ${label}`).toBeTruthy();
|
||||
expect(block.textContent).toContain(String(value));
|
||||
}
|
||||
|
||||
describe("widgets/flood/component", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
@@ -4,19 +4,13 @@ import { screen } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { renderWithProviders } from "test-utils/render-with-providers";
|
||||
import { findServiceBlockByLabel } from "test-utils/widget-assertions";
|
||||
import { expectBlockValue } from "test-utils/widget-assertions";
|
||||
|
||||
const { useWidgetAPI } = vi.hoisted(() => ({ useWidgetAPI: vi.fn() }));
|
||||
vi.mock("utils/proxy/use-widget-api", () => ({ default: useWidgetAPI }));
|
||||
|
||||
import Component from "./component";
|
||||
|
||||
function expectBlockValue(container, label, value) {
|
||||
const block = findServiceBlockByLabel(container, label);
|
||||
expect(block, `missing block for ${label}`).toBeTruthy();
|
||||
expect(block.textContent).toContain(String(value));
|
||||
}
|
||||
|
||||
describe("widgets/freshrss/component", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
@@ -4,19 +4,13 @@ import { screen } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { renderWithProviders } from "test-utils/render-with-providers";
|
||||
import { findServiceBlockByLabel } from "test-utils/widget-assertions";
|
||||
import { expectBlockValue } from "test-utils/widget-assertions";
|
||||
|
||||
const { useWidgetAPI } = vi.hoisted(() => ({ useWidgetAPI: vi.fn() }));
|
||||
vi.mock("utils/proxy/use-widget-api", () => ({ default: useWidgetAPI }));
|
||||
|
||||
import Component from "./component";
|
||||
|
||||
function expectBlockValue(container, label, value) {
|
||||
const block = findServiceBlockByLabel(container, label);
|
||||
expect(block, `missing block for ${label}`).toBeTruthy();
|
||||
expect(block.textContent).toContain(String(value));
|
||||
}
|
||||
|
||||
describe("widgets/frigate/component", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
@@ -4,19 +4,13 @@ import { screen } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { renderWithProviders } from "test-utils/render-with-providers";
|
||||
import { findServiceBlockByLabel } from "test-utils/widget-assertions";
|
||||
import { expectBlockValue } from "test-utils/widget-assertions";
|
||||
|
||||
const { useWidgetAPI } = vi.hoisted(() => ({ useWidgetAPI: vi.fn() }));
|
||||
vi.mock("utils/proxy/use-widget-api", () => ({ default: useWidgetAPI }));
|
||||
|
||||
import Component, { fritzboxDefaultFields } from "./component";
|
||||
|
||||
function expectBlockValue(container, label, value) {
|
||||
const block = findServiceBlockByLabel(container, label);
|
||||
expect(block, `missing block for ${label}`).toBeTruthy();
|
||||
expect(block.textContent).toContain(String(value));
|
||||
}
|
||||
|
||||
describe("widgets/fritzbox/component", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
@@ -4,19 +4,13 @@ import { screen } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { renderWithProviders } from "test-utils/render-with-providers";
|
||||
import { findServiceBlockByLabel } from "test-utils/widget-assertions";
|
||||
import { expectBlockValue } from "test-utils/widget-assertions";
|
||||
|
||||
const { useWidgetAPI } = vi.hoisted(() => ({ useWidgetAPI: vi.fn() }));
|
||||
vi.mock("utils/proxy/use-widget-api", () => ({ default: useWidgetAPI }));
|
||||
|
||||
import Component from "./component";
|
||||
|
||||
function expectBlockValue(container, label, value) {
|
||||
const block = findServiceBlockByLabel(container, label);
|
||||
expect(block, `missing block for ${label}`).toBeTruthy();
|
||||
expect(block.textContent).toContain(String(value));
|
||||
}
|
||||
|
||||
describe("widgets/gamedig/component", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
@@ -4,19 +4,13 @@ import { screen } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { renderWithProviders } from "test-utils/render-with-providers";
|
||||
import { findServiceBlockByLabel } from "test-utils/widget-assertions";
|
||||
import { expectBlockValue } from "test-utils/widget-assertions";
|
||||
|
||||
const { useWidgetAPI } = vi.hoisted(() => ({ useWidgetAPI: vi.fn() }));
|
||||
vi.mock("utils/proxy/use-widget-api", () => ({ default: useWidgetAPI }));
|
||||
|
||||
import Component from "./component";
|
||||
|
||||
function expectBlockValue(container, label, value) {
|
||||
const block = findServiceBlockByLabel(container, label);
|
||||
expect(block, `missing block for ${label}`).toBeTruthy();
|
||||
expect(block.textContent).toContain(String(value));
|
||||
}
|
||||
|
||||
describe("widgets/gatus/component", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
@@ -4,19 +4,13 @@ import { screen } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { renderWithProviders } from "test-utils/render-with-providers";
|
||||
import { findServiceBlockByLabel } from "test-utils/widget-assertions";
|
||||
import { expectBlockValue } from "test-utils/widget-assertions";
|
||||
|
||||
const { useWidgetAPI } = vi.hoisted(() => ({ useWidgetAPI: vi.fn() }));
|
||||
vi.mock("utils/proxy/use-widget-api", () => ({ default: useWidgetAPI }));
|
||||
|
||||
import Component from "./component";
|
||||
|
||||
function expectBlockValue(container, label, value) {
|
||||
const block = findServiceBlockByLabel(container, label);
|
||||
expect(block, `missing block for ${label}`).toBeTruthy();
|
||||
expect(block.textContent).toContain(String(value));
|
||||
}
|
||||
|
||||
describe("widgets/ghostfolio/component", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
@@ -4,19 +4,13 @@ import { screen } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { renderWithProviders } from "test-utils/render-with-providers";
|
||||
import { findServiceBlockByLabel } from "test-utils/widget-assertions";
|
||||
import { expectBlockValue } from "test-utils/widget-assertions";
|
||||
|
||||
const { useWidgetAPI } = vi.hoisted(() => ({ useWidgetAPI: vi.fn() }));
|
||||
vi.mock("utils/proxy/use-widget-api", () => ({ default: useWidgetAPI }));
|
||||
|
||||
import Component from "./component";
|
||||
|
||||
function expectBlockValue(container, label, value) {
|
||||
const block = findServiceBlockByLabel(container, label);
|
||||
expect(block, `missing block for ${label}`).toBeTruthy();
|
||||
expect(block.textContent).toContain(String(value));
|
||||
}
|
||||
|
||||
describe("widgets/gitea/component", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
@@ -4,19 +4,13 @@ import { screen } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { renderWithProviders } from "test-utils/render-with-providers";
|
||||
import { findServiceBlockByLabel } from "test-utils/widget-assertions";
|
||||
import { expectBlockValue } from "test-utils/widget-assertions";
|
||||
|
||||
const { useWidgetAPI } = vi.hoisted(() => ({ useWidgetAPI: vi.fn() }));
|
||||
vi.mock("utils/proxy/use-widget-api", () => ({ default: useWidgetAPI }));
|
||||
|
||||
import Component from "./component";
|
||||
|
||||
function expectBlockValue(container, label, value) {
|
||||
const block = findServiceBlockByLabel(container, label);
|
||||
expect(block, `missing block for ${label}`).toBeTruthy();
|
||||
expect(block.textContent).toContain(String(value));
|
||||
}
|
||||
|
||||
describe("widgets/gitlab/component", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
@@ -8,7 +8,9 @@ import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||
|
||||
const statusMap = {
|
||||
running: <ResolvedIcon icon="mdi-circle" width={32} height={32} />,
|
||||
healthy: <ResolvedIcon icon="mdi-circle" width={32} height={32} />,
|
||||
paused: <ResolvedIcon icon="mdi-circle-outline" width={32} height={32} />,
|
||||
stopped: <ResolvedIcon icon="mdi-circle-double" width={32} height={32} />,
|
||||
};
|
||||
|
||||
const defaultInterval = 1000;
|
||||
|
||||
@@ -11,6 +11,15 @@ vi.mock("utils/proxy/use-widget-api", () => ({ default: useWidgetAPI }));
|
||||
// Avoid pulling Next/Image + ThemeContext requirements into these unit tests.
|
||||
vi.mock("components/resolvedicon", () => ({ default: () => <span data-testid="resolvedicon" /> }));
|
||||
|
||||
vi.mock("next-i18next", () => ({
|
||||
useTranslation: () => ({
|
||||
t: (key, opts) => (key === "common.bytes" ? `${key}:${opts?.value}` : key),
|
||||
}),
|
||||
}));
|
||||
|
||||
// Avoid pulling Next/Image + ThemeContext requirements into these unit tests.
|
||||
vi.mock("components/resolvedicon", () => ({ default: () => <span data-testid="resolvedicon" /> }));
|
||||
|
||||
import Component from "./containers";
|
||||
|
||||
describe("widgets/glances/metrics/containers", () => {
|
||||
@@ -21,4 +30,78 @@ describe("widgets/glances/metrics/containers", () => {
|
||||
});
|
||||
expect(screen.getByText("-")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders a placeholder while loading", () => {
|
||||
useWidgetAPI.mockReturnValue({ data: undefined, error: undefined });
|
||||
renderWithProviders(<Component service={{ widget: { chart: false, version: 3 } }} />, {
|
||||
settings: { hideErrors: false },
|
||||
});
|
||||
expect(screen.getByText("-")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders nothing when there is an error", () => {
|
||||
useWidgetAPI.mockReturnValue({ data: undefined, error: new Error("fail") });
|
||||
renderWithProviders(<Component service={{ widget: { chart: false, version: 3 } }} />, {
|
||||
settings: { hideErrors: false },
|
||||
});
|
||||
expect(screen.queryByText("resources.cpu")).not.toBeInTheDocument();
|
||||
expect(screen.queryByText("-")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders container rows using v3 keys and formats values", () => {
|
||||
useWidgetAPI.mockReturnValue({
|
||||
data: [
|
||||
{
|
||||
Id: "one",
|
||||
Status: "running",
|
||||
name: "alpha",
|
||||
cpu_percent: 12.34,
|
||||
memory: { usage: 1000, inactive_file: 400 },
|
||||
},
|
||||
{
|
||||
Id: "two",
|
||||
Status: "paused",
|
||||
name: "beta",
|
||||
cpu_percent: 99.99,
|
||||
memory: { usage: 2000, inactive_file: 1000 },
|
||||
},
|
||||
],
|
||||
error: undefined,
|
||||
});
|
||||
|
||||
renderWithProviders(<Component service={{ widget: { chart: false, version: 3 } }} />, {
|
||||
settings: { hideErrors: false },
|
||||
});
|
||||
|
||||
// data.splice(1) keeps only one item when chart is false
|
||||
expect(screen.getByText("resources.cpu")).toBeInTheDocument();
|
||||
expect(screen.getByText("resources.mem")).toBeInTheDocument();
|
||||
|
||||
expect(screen.getByText("alpha")).toBeInTheDocument();
|
||||
expect(screen.queryByText("beta")).not.toBeInTheDocument();
|
||||
|
||||
expect(screen.getByText("12.3%")).toBeInTheDocument();
|
||||
expect(screen.getByText("common.bytes:600")).toBeInTheDocument();
|
||||
expect(screen.getAllByTestId("resolvedicon")).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("limits rows to 5 when chart is enabled", () => {
|
||||
const data = Array.from({ length: 6 }).map((_, index) => ({
|
||||
Id: `id-${index}`,
|
||||
Status: "healthy",
|
||||
name: `item-${index}`,
|
||||
cpu_percent: index + 0.1,
|
||||
memory: { usage: 100 * (index + 1), inactive_file: 0 },
|
||||
}));
|
||||
|
||||
useWidgetAPI.mockReturnValue({ data, error: undefined });
|
||||
|
||||
renderWithProviders(<Component service={{ widget: { chart: true, version: 3 } }} />, {
|
||||
settings: { hideErrors: false },
|
||||
});
|
||||
|
||||
expect(screen.getByText("item-0")).toBeInTheDocument();
|
||||
expect(screen.getByText("item-4")).toBeInTheDocument();
|
||||
expect(screen.queryByText("item-5")).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -46,7 +46,7 @@ export default function Component({ service }) {
|
||||
let listYPosition = "bottom-4";
|
||||
if (chart) {
|
||||
headerYPosition = "-top-6";
|
||||
listYPosition = "-top-3";
|
||||
listYPosition = "-top-2";
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
@@ -4,19 +4,13 @@ import { screen } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { renderWithProviders } from "test-utils/render-with-providers";
|
||||
import { findServiceBlockByLabel } from "test-utils/widget-assertions";
|
||||
import { expectBlockValue } from "test-utils/widget-assertions";
|
||||
|
||||
const { useWidgetAPI } = vi.hoisted(() => ({ useWidgetAPI: vi.fn() }));
|
||||
vi.mock("utils/proxy/use-widget-api", () => ({ default: useWidgetAPI }));
|
||||
|
||||
import Component from "./component";
|
||||
|
||||
function expectBlockValue(container, label, value) {
|
||||
const block = findServiceBlockByLabel(container, label);
|
||||
expect(block, `missing block for ${label}`).toBeTruthy();
|
||||
expect(block.textContent).toContain(String(value));
|
||||
}
|
||||
|
||||
describe("widgets/gluetun/component", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
@@ -4,19 +4,13 @@ import { screen } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { renderWithProviders } from "test-utils/render-with-providers";
|
||||
import { findServiceBlockByLabel } from "test-utils/widget-assertions";
|
||||
import { expectBlockValue } from "test-utils/widget-assertions";
|
||||
|
||||
const { useWidgetAPI } = vi.hoisted(() => ({ useWidgetAPI: vi.fn() }));
|
||||
vi.mock("utils/proxy/use-widget-api", () => ({ default: useWidgetAPI }));
|
||||
|
||||
import Component from "./component";
|
||||
|
||||
function expectBlockValue(container, label, value) {
|
||||
const block = findServiceBlockByLabel(container, label);
|
||||
expect(block, `missing block for ${label}`).toBeTruthy();
|
||||
expect(block.textContent).toContain(String(value));
|
||||
}
|
||||
|
||||
describe("widgets/gotify/component", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
@@ -4,19 +4,13 @@ import { screen } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { renderWithProviders } from "test-utils/render-with-providers";
|
||||
import { findServiceBlockByLabel } from "test-utils/widget-assertions";
|
||||
import { expectBlockValue } from "test-utils/widget-assertions";
|
||||
|
||||
const { useWidgetAPI } = vi.hoisted(() => ({ useWidgetAPI: vi.fn() }));
|
||||
vi.mock("utils/proxy/use-widget-api", () => ({ default: useWidgetAPI }));
|
||||
|
||||
import Component from "./component";
|
||||
|
||||
function expectBlockValue(container, label, value) {
|
||||
const block = findServiceBlockByLabel(container, label);
|
||||
expect(block, `missing block for ${label}`).toBeTruthy();
|
||||
expect(block.textContent).toContain(String(value));
|
||||
}
|
||||
|
||||
describe("widgets/grafana/component", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
@@ -4,19 +4,13 @@ import { screen } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { renderWithProviders } from "test-utils/render-with-providers";
|
||||
import { findServiceBlockByLabel } from "test-utils/widget-assertions";
|
||||
import { expectBlockValue } from "test-utils/widget-assertions";
|
||||
|
||||
const { useWidgetAPI } = vi.hoisted(() => ({ useWidgetAPI: vi.fn() }));
|
||||
vi.mock("utils/proxy/use-widget-api", () => ({ default: useWidgetAPI }));
|
||||
|
||||
import Component from "./component";
|
||||
|
||||
function expectBlockValue(container, label, value) {
|
||||
const block = findServiceBlockByLabel(container, label);
|
||||
expect(block, `missing block for ${label}`).toBeTruthy();
|
||||
expect(block.textContent).toContain(String(value));
|
||||
}
|
||||
|
||||
describe("widgets/hdhomerun/component", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user