Backport #37327 by @prettysunflower Nyallo~ In pull request #36901, a change is made so that the link to authentication sources is now escaped with the QueryEscape filter. https://github.com/go-gitea/gitea/pull/36901/changes#diff-34c39c9736a8b62e293c0c0b24c4b5b8c1c792790018c5809f9ff2cbc12b16b1R4 The problem is that [QueryEscape replace spaces with the `+` character](https://cs.opensource.google/go/go/+/refs/tags/go1.26.2:src/net/url/url.go;l=234;drc=917949cc1d16c652cb09ba369718f45e5d814d8f), and this is not unescaped when a user tries to log in with an authentication source that contains a space, which throws an error. This commit fixes that by unescaping the provider name in the URL. --- Example of the error, on my instance, when I try to log in with `prettysunflower's auth` ``` 2026/04/21 00:11:41 routers/web/auth/oauth.go:42:SignInOAuth() [E] SignIn: oauth2 source not found, name: "prettysunflower's+auth" /go/src/code.gitea.io/gitea/routers/web/auth/oauth.go:42 (0x2cfa5c5) /usr/local/go/src/reflect/value.go:586 (0x51e245) /usr/local/go/src/reflect/value.go:369 (0x51d0f8) /go/src/code.gitea.io/gitea/modules/web/handler.go:181 (0x1a6aaf6) /usr/local/go/src/net/http/server.go:2286 (0x94dc88) /usr/local/go/src/net/http/server.go:2286 (0x94dc88) /go/src/code.gitea.io/gitea/modules/web/handler.go:188 (0x1a6ab65) /usr/local/go/src/net/http/server.go:2286 (0x94dc88) /go/src/code.gitea.io/gitea/modules/web/handler.go:188 (0x1a6ab65) /usr/local/go/src/net/http/server.go:2286 (0x94dc88) /go/src/code.gitea.io/gitea/modules/web/handler.go:188 (0x1a6ab65) /usr/local/go/src/net/http/server.go:2286 (0x94dc88) /go/src/code.gitea.io/gitea/services/context/context.go:217 (0x2df1b23) /usr/local/go/src/net/http/server.go:2286 (0x94dc88) /go/src/code.gitea.io/gitea/modules/web/handler.go:145 (0x1a6afb5) /usr/local/go/src/net/http/server.go:2286 (0x94dc88) /go/pkg/mod/gitea.com/go-chi/session@v0.0.0-20251124165456-68e0254e989e/session.go:258 (0x197eb82) /usr/local/go/src/net/http/server.go:2286 (0x94dc88) /go/src/code.gitea.io/gitea/modules/web/handler.go:145 (0x1a6afb5) /usr/local/go/src/net/http/server.go:2286 (0x94dc88) /go/pkg/mod/github.com/go-chi/chi/v5@v5.2.5/chain.go:31 (0x1a61d05) /go/pkg/mod/github.com/go-chi/chi/v5@v5.2.5/mux.go:479 (0x1a64fae) /usr/local/go/src/net/http/server.go:2286 (0x94dc88) /go/pkg/mod/github.com/go-chi/chi/v5@v5.2.5/mux.go:73 (0x1a628c2) /go/pkg/mod/github.com/go-chi/chi/v5@v5.2.5/mux.go:321 (0x1a6421a) /usr/local/go/src/net/http/server.go:2286 (0x94dc88) /go/pkg/mod/github.com/go-chi/chi/v5@v5.2.5/chain.go:31 (0x1a61d05) /go/pkg/mod/github.com/go-chi/chi/v5@v5.2.5/mux.go:479 (0x1a64fae) /usr/local/go/src/net/http/server.go:2286 (0x94dc88) /go/pkg/mod/github.com/go-chi/chi/v5@v5.2.5/middleware/get_head.go:37 (0x2c33a67) /usr/local/go/src/net/http/server.go:2286 (0x94dc88) /go/src/code.gitea.io/gitea/modules/web/handler.go:145 (0x1a6afb5) /usr/local/go/src/net/http/server.go:2286 (0x94dc88) /go/pkg/mod/github.com/go-chi/chi/v5@v5.2.5/mux.go:73 (0x1a628c2) /go/pkg/mod/github.com/go-chi/chi/v5@v5.2.5/mux.go:321 (0x1a6421a) /usr/local/go/src/net/http/server.go:2286 (0x94dc88) /go/src/code.gitea.io/gitea/routers/common/maintenancemode.go:50 (0x2b752da) /usr/local/go/src/net/http/server.go:2286 (0x94dc88) /go/src/code.gitea.io/gitea/modules/web/handler.go:145 (0x1a6afb5) /usr/local/go/src/net/http/server.go:2286 (0x94dc88) /go/pkg/mod/github.com/go-chi/chi/v5@v5.2.5/chain.go:31 (0x1a61d05) /go/pkg/mod/github.com/go-chi/chi/v5@v5.2.5/mux.go:479 (0x1a64fae) /usr/local/go/src/net/http/server.go:2286 (0x94dc88) /go/src/code.gitea.io/gitea/modules/web/routing/logger_manager.go:124 (0x127d1ec) /usr/local/go/src/net/http/server.go:2286 (0x94dc88) /go/src/code.gitea.io/gitea/modules/web/handler.go:145 (0x1a6afb5) /usr/local/go/src/net/http/server.go:2286 (0x94dc88) /go/pkg/mod/github.com/chi-middleware/proxy@v1.1.1/middleware.go:37 (0x2b76acf) /usr/local/go/src/net/http/server.go:2286 (0x94dc88) /go/src/code.gitea.io/gitea/modules/web/handler.go:145 (0x1a6afb5) /usr/local/go/src/net/http/server.go:2286 (0x94dc88) /go/src/code.gitea.io/gitea/routers/common/middleware.go:89 (0x2b78cd6) /usr/local/go/src/net/http/server.go:2286 (0x94dc88) /go/src/code.gitea.io/gitea/modules/web/handler.go:145 (0x1a6afb5) /usr/local/go/src/net/http/server.go:2286 (0x94dc88) /go/src/code.gitea.io/gitea/routers/common/middleware.go:104 (0x2b7890f) /usr/local/go/src/net/http/server.go:2286 (0x94dc88) /go/src/code.gitea.io/gitea/modules/web/handler.go:145 (0x1a6afb5) /usr/local/go/src/net/http/server.go:2286 (0x94dc88) /go/pkg/mod/github.com/go-chi/chi/v5@v5.2.5/mux.go:90 (0x1a62881) /go/src/code.gitea.io/gitea/modules/web/router.go:286 (0x1a6d2a2) /go/src/code.gitea.io/gitea/modules/web/router.go:221 (0x1a6cbc6) /usr/local/go/src/net/http/server.go:3311 (0x96e36d) /usr/local/go/src/net/http/server.go:2073 (0x94bd6f) /usr/local/go/src/runtime/asm_amd64.s:1771 (0x49af20) ``` Signed-off-by: prettysunflower <me@prettysunflower.moe> Signed-off-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: prettysunflower <me@prettysunflower.moe> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: silverwind <me@silverwind.io>
Integration tests
Integration tests can be run with make commands for the appropriate backends, namely:
make test-sqlite
make test-pgsql
make test-mysql
make test-mssql
Make sure to perform a clean build before running tests:
make clean build
Run tests via local act_runner
Run all jobs
act_runner exec -W ./.github/workflows/pull-db-tests.yml --event=pull_request --default-actions-url="https://github.com" -i catthehacker/ubuntu:runner-latest
Warning: This file defines many jobs, so it will be resource-intensive and therefor not recommended.
Run single job
act_runner exec -W ./.github/workflows/pull-db-tests.yml --event=pull_request --default-actions-url="https://github.com" -i catthehacker/ubuntu:runner-latest -j <job_name>
You can list all job names via:
act_runner exec -W ./.github/workflows/pull-db-tests.yml --event=pull_request --default-actions-url="https://github.com" -i catthehacker/ubuntu:runner-latest -l
Run sqlite integration tests
Start tests
make test-sqlite
Run MySQL integration tests
Setup a MySQL database inside docker
docker run -e "MYSQL_DATABASE=test" -e "MYSQL_ALLOW_EMPTY_PASSWORD=yes" -p 3306:3306 --rm --name mysql mysql:latest #(just ctrl-c to stop db and clean the container)
docker run -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" --rm --name elasticsearch elasticsearch:7.6.0 #(in a second terminal, just ctrl-c to stop db and clean the container)
Start tests based on the database container
TEST_MYSQL_HOST=localhost:3306 TEST_MYSQL_DBNAME=test TEST_MYSQL_USERNAME=root TEST_MYSQL_PASSWORD='' make test-mysql
Run pgsql integration tests
Setup a pgsql database inside docker
docker run -e "POSTGRES_DB=test" -e "POSTGRES_USER=postgres" -e "POSTGRES_PASSWORD=postgres" -p 5432:5432 --rm --name pgsql postgres:latest #(just ctrl-c to stop db and clean the container)
Setup minio inside docker
docker run --rm -p 9000:9000 -e MINIO_ROOT_USER=123456 -e MINIO_ROOT_PASSWORD=12345678 --name minio bitnamilegacy/minio:2023.8.31
Start tests based on the database container
TEST_MINIO_ENDPOINT=localhost:9000 TEST_PGSQL_HOST=localhost:5432 TEST_PGSQL_DBNAME=postgres TEST_PGSQL_USERNAME=postgres TEST_PGSQL_PASSWORD=postgres make test-pgsql
Run mssql integration tests
Setup a mssql database inside docker
docker run -e "ACCEPT_EULA=Y" -e "MSSQL_PID=Standard" -e "SA_PASSWORD=MwantsaSecurePassword1" -p 1433:1433 --rm --name mssql microsoft/mssql-server-linux:latest #(just ctrl-c to stop db and clean the container)
Start tests based on the database container
TEST_MSSQL_HOST=localhost:1433 TEST_MSSQL_DBNAME=gitea_test TEST_MSSQL_USERNAME=sa TEST_MSSQL_PASSWORD=MwantsaSecurePassword1 make test-mssql
Running individual tests
Example command to run GPG test:
For SQLite:
make test-sqlite#GPG
For other databases(replace mssql to mysql, or pgsql):
TEST_MSSQL_HOST=localhost:1433 TEST_MSSQL_DBNAME=test TEST_MSSQL_USERNAME=sa TEST_MSSQL_PASSWORD=MwantsaSecurePassword1 make test-mssql#GPG
Setting timeouts for declaring long-tests and long-flushes
We appreciate that some testing machines may not be very powerful and the default timeouts for declaring a slow test or a slow clean-up flush may not be appropriate.
You can set the following environment variables:
GITEA_TEST_SLOW_RUN="10s" GITEA_TEST_SLOW_FLUSH="1s" make test-sqlite