diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index c497dad..73671d8 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -6,7 +6,7 @@ on: - 'v[0-9]+.[0-9]+.[0-9]+' env: - GO_VERSION: '1.21.1' + GO_VERSION: '1.24.3' PB_BUILD_VERSION: unknown # Needed for using Make targets. SSH_AUTH_SOCK: /tmp/ssh_agent.sock diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 9cac3d4..b72d432 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -6,7 +6,7 @@ on: - 'v[0-9]+.[0-9]+.[0-9]+' env: - GO_VERSION: '1.21.1' + GO_VERSION: '1.24.3' jobs: test: @@ -96,6 +96,6 @@ jobs: with: distribution: goreleaser version: latest - args: release --rm-dist + args: release --clean env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bc6328e..a8d9ef2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,7 +9,7 @@ on: - 'main' env: - GO_VERSION: '1.21.1' + GO_VERSION: '1.24.3' PB_BUILD_VERSION: pipeline-${{ github.sha }} jobs: diff --git a/Dockerfile b/Dockerfile index 263a440..9cacfbe 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,5 @@ FROM docker.io/library/golang:alpine as builder -ARG PB_BUILD_VERSION - ARG CLI_VERSION=0.0.6 ARG CLI_PLATFORM=linux_amd64 @@ -13,7 +11,7 @@ RUN set -ex \ && apk add --no-cache build-base ca-certificates curl \ && go mod download \ && go mod verify \ - && PB_BUILD_VERSION="$PB_BUILD_VERSION" make build \ + && make build \ && chmod +x /build/out/pushbits \ && curl -q -s -S -L -o /tmp/pbcli_${CLI_VERSION}.tar.gz https://github.com/pushbits/cli/releases/download/v${CLI_VERSION}/pbcli_${CLI_VERSION}_${CLI_PLATFORM}.tar.gz \ && tar -C /usr/local/bin -xvf /tmp/pbcli_${CLI_VERSION}.tar.gz pbcli \ diff --git a/Makefile b/Makefile index 5a0afd4..218b0cf 100644 --- a/Makefile +++ b/Makefile @@ -3,16 +3,12 @@ OUT_DIR := ./out TESTS_DIR := ./tests GO_FILES := $(shell find . -type f \( -iname '*.go' \)) - -PB_BUILD_VERSION ?= $(shell git describe --tags) -ifeq ($(PB_BUILD_VERSION),) - _ := $(error Cannot determine build version) -endif +GO_MODULE := github.com/pushbits/server .PHONY: build build: mkdir -p $(OUT_DIR) - go build -ldflags="-w -s -X main.version=$(PB_BUILD_VERSION)" -o $(OUT_DIR)/pushbits ./cmd/pushbits + go build -ldflags="-w -s" -o $(OUT_DIR)/pushbits ./cmd/pushbits .PHONY: clean clean: @@ -21,26 +17,32 @@ clean: .PHONY: test test: - stdout=$$(gofumpt -l . 2>&1); if [ "$$stdout" ]; then exit 1; fi + if [ -n "$$(gofumpt -l $(GO_FILES))" ]; then echo "Code is not properly formatted"; exit 1; fi + if [ -n "$$(goimports -l -local $(GO_MODULE) $(GO_FILES))" ]; then echo "Imports are not properly formatted"; exit 1; fi go vet ./... misspell -error $(GO_FILES) + gocyclo -over 10 $(GO_FILES) staticcheck ./... - errcheck -exclude errcheck_excludes.txt ./... + errcheck -ignoregenerated -exclude errcheck_excludes.txt ./... gocritic check -disable='#experimental,#opinionated' -@ifElseChain.minThreshold 3 ./... revive -set_exit_status -exclude ./docs ./... + nilaway ./... go test -v -cover ./... - gosec -exclude-dir=tests ./... + gosec -exclude-generated -exclude-dir=tests ./... govulncheck ./... @printf '\n%s\n' "> Test successful" .PHONY: setup setup: go install github.com/client9/misspell/cmd/misspell@latest + go install github.com/fzipp/gocyclo/cmd/gocyclo@latest go install github.com/go-critic/go-critic/cmd/gocritic@latest go install github.com/kisielk/errcheck@latest go install github.com/mgechev/revive@latest go install github.com/securego/gosec/v2/cmd/gosec@latest go install github.com/swaggo/swag/cmd/swag@latest + go install go.uber.org/nilaway/cmd/nilaway@latest + go install golang.org/x/tools/cmd/goimports@latest go install golang.org/x/vuln/cmd/govulncheck@latest go install honnef.co/go/tools/cmd/staticcheck@latest go install mvdan.cc/gofumpt@latest @@ -56,7 +58,6 @@ swag: build .PHONY: docker_build_dev docker_build_dev: podman build \ - --build-arg=PB_BUILD_VERSION=dev \ -t local/pushbits . .PHONY: run_postgres_debug diff --git a/cmd/pushbits/main.go b/cmd/pushbits/main.go index 7c81a61..d0f4654 100644 --- a/cmd/pushbits/main.go +++ b/cmd/pushbits/main.go @@ -4,6 +4,7 @@ package main import ( "os" "os/signal" + "runtime/debug" "syscall" "github.com/pushbits/server/internal/authentication/credentials" @@ -15,8 +16,6 @@ import ( "github.com/pushbits/server/internal/runner" ) -var version string - func setupCleanup(db *database.Database, dp *dispatcher.Dispatcher) { c := make(chan os.Signal, 2) signal.Notify(c, os.Interrupt, syscall.SIGTERM) @@ -29,8 +28,18 @@ func setupCleanup(db *database.Database, dp *dispatcher.Dispatcher) { }() } +func printStarupMessage() { + buildInfo, ok := debug.ReadBuildInfo() + if !ok { + log.L.Fatalln("Build info not available") + return + } + + log.L.Printf("Starting PushBits %s", buildInfo.Main.Version) +} + // @title PushBits Server API Documentation -// @version 0.10.1 +// @version 0.10.5 // @description Documentation for the PushBits server API. // @contact.name The PushBits Developers @@ -45,11 +54,7 @@ func setupCleanup(db *database.Database, dp *dispatcher.Dispatcher) { // @securityDefinitions.basic BasicAuth func main() { - if len(version) == 0 { - log.L.Panic("Version not set") - } else { - log.L.Printf("Starting PushBits %s", version) - } + printStarupMessage() c := configuration.Get() @@ -63,6 +68,11 @@ func main() { db, err := database.Create(cm, c.Database.Dialect, c.Database.Connection) if err != nil { log.L.Fatal(err) + return + } + if db == nil { + log.L.Fatal("db is nil but error was nil") + return } defer db.Close() @@ -73,6 +83,11 @@ func main() { dp, err := dispatcher.Create(c.Matrix.Homeserver, c.Matrix.Username, c.Matrix.Password, c.Formatting) if err != nil { log.L.Fatal(err) + return + } + if dp == nil { + log.L.Fatal("dp is nil but error was nil") + return } defer dp.Close() @@ -81,15 +96,18 @@ func main() { err = db.RepairChannels(dp, &c.RepairBehavior) if err != nil { log.L.Fatal(err) + return } engine, err := router.Create(c.Debug, c.HTTP.TrustedProxies, cm, db, dp, &c.Alertmanager) if err != nil { log.L.Fatal(err) + return } err = runner.Run(engine, c) if err != nil { log.L.Fatal(err) + return } } diff --git a/go.mod b/go.mod index 0d5c5da..1047b30 100644 --- a/go.mod +++ b/go.mod @@ -1,76 +1,70 @@ module github.com/pushbits/server -go 1.21 +go 1.24 require ( - github.com/alexedwards/argon2id v0.0.0-20230305115115-4b3c3280a736 - github.com/gin-contrib/location v0.0.2 - github.com/gin-gonic/gin v1.9.1 - github.com/gomarkdown/markdown v0.0.0-20230922112808-5421fefb8386 - github.com/jinzhu/configor v1.2.1 + github.com/alexedwards/argon2id v1.0.0 + github.com/gin-contrib/location v1.0.3 + github.com/gin-gonic/gin v1.10.1 + github.com/gomarkdown/markdown v0.0.0-20250207164621-7a1f277a159e + github.com/jinzhu/configor v1.2.2 github.com/sirupsen/logrus v1.9.3 - github.com/stretchr/testify v1.8.4 - github.com/swaggo/swag v1.16.2 + github.com/stretchr/testify v1.10.0 gopkg.in/yaml.v2 v2.4.0 - gorm.io/driver/mysql v1.5.1 - gorm.io/driver/postgres v1.5.2 - gorm.io/driver/sqlite v1.5.3 - gorm.io/gorm v1.25.4 - maunium.net/go/mautrix v0.16.1 + gorm.io/driver/mysql v1.5.7 + gorm.io/driver/postgres v1.6.0 + gorm.io/driver/sqlite v1.5.7 + gorm.io/gorm v1.25.12 + maunium.net/go/mautrix v0.24.0 ) require ( - github.com/BurntSushi/toml v1.3.2 // indirect - github.com/KyleBanks/depth v1.2.1 // indirect - github.com/bytedance/sonic v1.10.1 // indirect - github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect - github.com/chenzhuoyu/iasm v0.9.0 // indirect + filippo.io/edwards25519 v1.1.0 // indirect + github.com/BurntSushi/toml v1.4.0 // indirect + github.com/bytedance/sonic v1.13.2 // indirect + github.com/bytedance/sonic/loader v0.2.4 // indirect + github.com/cloudwego/base64x v0.1.5 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/gabriel-vasile/mimetype v1.4.2 // indirect - github.com/gin-contrib/sse v0.1.0 // indirect - github.com/go-openapi/jsonpointer v0.20.0 // indirect - github.com/go-openapi/jsonreference v0.20.2 // indirect - github.com/go-openapi/spec v0.20.9 // indirect - github.com/go-openapi/swag v0.22.4 // indirect + github.com/gabriel-vasile/mimetype v1.4.8 // indirect + github.com/gin-contrib/sse v1.0.0 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect - github.com/go-playground/validator/v10 v10.15.4 // indirect - github.com/go-sql-driver/mysql v1.7.1 // indirect - github.com/goccy/go-json v0.10.2 // indirect + github.com/go-playground/validator/v10 v10.26.0 // indirect + github.com/go-sql-driver/mysql v1.8.1 // indirect + github.com/goccy/go-json v0.10.5 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect - github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect - github.com/jackc/pgx/v5 v5.4.3 // indirect + github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect + github.com/jackc/pgx/v5 v5.7.2 // indirect + github.com/jackc/puddle/v2 v2.2.2 // indirect github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect - github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect - github.com/klauspost/cpuid/v2 v2.2.5 // indirect - github.com/leodido/go-urn v1.2.4 // indirect - github.com/mailru/easyjson v0.7.7 // indirect - github.com/mattn/go-colorable v0.1.13 // indirect - github.com/mattn/go-isatty v0.0.19 // indirect - github.com/mattn/go-sqlite3 v1.14.17 // indirect + github.com/klauspost/cpuid/v2 v2.2.10 // indirect + github.com/kr/pretty v0.3.1 // indirect + github.com/leodido/go-urn v1.4.0 // indirect + github.com/mattn/go-colorable v0.1.14 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/mattn/go-sqlite3 v1.14.28 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect - github.com/pelletier/go-toml/v2 v2.1.0 // indirect + github.com/pelletier/go-toml/v2 v2.2.3 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rogpeppe/go-internal v1.10.0 // indirect - github.com/rs/zerolog v1.30.0 // indirect - github.com/tidwall/gjson v1.17.0 // indirect + github.com/rs/zerolog v1.34.0 // indirect + github.com/tidwall/gjson v1.18.0 // indirect github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/pretty v1.2.1 // indirect github.com/tidwall/sjson v1.2.5 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect - github.com/ugorji/go/codec v1.2.11 // indirect - go.mau.fi/util v0.1.0 // indirect - golang.org/x/arch v0.5.0 // indirect - golang.org/x/crypto v0.13.0 // indirect - golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect - golang.org/x/net v0.15.0 // indirect - golang.org/x/sys v0.12.0 // indirect - golang.org/x/text v0.13.0 // indirect - golang.org/x/tools v0.13.0 // indirect - google.golang.org/protobuf v1.31.0 // indirect + github.com/ugorji/go/codec v1.2.12 // indirect + go.mau.fi/util v0.8.7 // indirect + golang.org/x/arch v0.15.0 // indirect + golang.org/x/crypto v0.38.0 // indirect + golang.org/x/exp v0.0.0-20250506013437-ce4c2cf36ca6 // indirect + golang.org/x/net v0.40.0 // indirect + golang.org/x/sync v0.14.0 // indirect + golang.org/x/sys v0.33.0 // indirect + golang.org/x/text v0.25.0 // indirect + google.golang.org/protobuf v1.36.6 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - maunium.net/go/maulogger/v2 v2.4.1 // indirect ) diff --git a/go.sum b/go.sum index 319e5dc..e2569a8 100644 --- a/go.sum +++ b/go.sum @@ -1,159 +1,136 @@ -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8= -github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= -github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc= -github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE= -github.com/alexedwards/argon2id v0.0.0-20230305115115-4b3c3280a736 h1:qZaEtLxnqY5mJ0fVKbk31NVhlgi0yrKm51Pq/I5wcz4= -github.com/alexedwards/argon2id v0.0.0-20230305115115-4b3c3280a736/go.mod h1:mTeFRcTdnpzOlRjMoFYC/80HwVUreupyAiqPkCZQOXc= -github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= -github.com/bytedance/sonic v1.10.0-rc/go.mod h1:ElCzW+ufi8qKqNW0FY314xriJhyJhuoJ3gFZdAHF7NM= -github.com/bytedance/sonic v1.10.1 h1:7a1wuFXL1cMy7a3f7/VFcEtriuXQnUBhtoVfOZiaysc= -github.com/bytedance/sonic v1.10.1/go.mod h1:iZcSUejdk5aukTND/Eu/ivjQuEL0Cu9/rf50Hi0u/g4= -github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= -github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= -github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d h1:77cEq6EriyTZ0g/qfRdp61a3Uu/AWrgIq2s0ClJV1g0= -github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d/go.mod h1:8EPpVsBuRksnlj1mLy4AWzRNQYxauNi62uWcE3to6eA= -github.com/chenzhuoyu/iasm v0.9.0 h1:9fhXjVzq5hUy2gkhhgHl95zG2cEAhw9OSGs8toWWAwo= -github.com/chenzhuoyu/iasm v0.9.0/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog= +filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= +filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= +github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= +github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0= +github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= +github.com/alexedwards/argon2id v1.0.0 h1:wJzDx66hqWX7siL/SRUmgz3F8YMrd/nfX/xHHcQQP0w= +github.com/alexedwards/argon2id v1.0.0/go.mod h1:tYKkqIjzXvZdzPvADMWOEZ+l6+BD6CtBXMj5fnJppiw= +github.com/bytedance/sonic v1.12.8 h1:4xYRVRlXIgvSZ4e8iVTlMF5szgpXd4AfvuWgA8I8lgs= +github.com/bytedance/sonic v1.12.8/go.mod h1:uVvFidNmlt9+wa31S1urfwwthTWteBgG0hWuoKAXTx8= +github.com/bytedance/sonic v1.13.2 h1:8/H1FempDZqC4VqjptGo14QQlJx8VdZJegxs6wwfqpQ= +github.com/bytedance/sonic v1.13.2/go.mod h1:o68xyaF9u2gvVBuGHPlUVCy+ZfmNNO5ETf1+KgkJhz4= +github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= +github.com/bytedance/sonic/loader v0.2.3 h1:yctD0Q3v2NOGfSWPLPvG2ggA2kV6TS6s4wioyEqssH0= +github.com/bytedance/sonic/loader v0.2.3/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI= +github.com/bytedance/sonic/loader v0.2.4 h1:ZWCw4stuXUsn1/+zQDqeE7JKP+QO47tz7QCNan80NzY= +github.com/bytedance/sonic/loader v0.2.4/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI= +github.com/cloudwego/base64x v0.1.5 h1:XPciSp1xaq2VCSt6lF0phncD4koWyULpl5bUxbfCyP4= +github.com/cloudwego/base64x v0.1.5/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w= +github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= -github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA= -github.com/gin-contrib/location v0.0.2 h1:QZKh1+K/LLR4KG/61eIO3b7MLuKi8tytQhV6texLgP4= -github.com/gin-contrib/location v0.0.2/go.mod h1:NGoidiRlf0BlA/VKSVp+g3cuSMeTmip/63PhEjRhUAc= -github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= -github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= -github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M= -github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg= -github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU= -github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= -github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= -github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs= -github.com/go-openapi/jsonpointer v0.20.0 h1:ESKJdU9ASRfaPNOPRx12IUyA1vn3R9GiE3KYD14BXdQ= -github.com/go-openapi/jsonpointer v0.20.0/go.mod h1:6PGzBjjIIumbLYysB73Klnms1mwnU4G3YHOECG3CedA= -github.com/go-openapi/jsonreference v0.20.0/go.mod h1:Ag74Ico3lPc+zR+qjn4XBUmXymS4zJbYVCZmcgkasdo= -github.com/go-openapi/jsonreference v0.20.2 h1:3sVjiK66+uXK/6oQ8xgcRKcFgQ5KXa2KvnJRumpMGbE= -github.com/go-openapi/jsonreference v0.20.2/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En5Ap4rVB5KVcIDZG2k= -github.com/go-openapi/spec v0.20.9 h1:xnlYNQAwKd2VQRRfwTEI0DcK+2cbuvI/0c7jx3gA8/8= -github.com/go-openapi/spec v0.20.9/go.mod h1:2OpW+JddWPrpXSCIX8eOx7lZ5iyuWj3RYR6VaaBKcWA= -github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= -github.com/go-openapi/swag v0.19.15/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= -github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= -github.com/go-openapi/swag v0.22.4 h1:QLMzNJnMGPRNDCbySlcj1x01tzU8/9LTTL9hZZZogBU= -github.com/go-openapi/swag v0.22.4/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= -github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= +github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM= +github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8= +github.com/gin-contrib/location v1.0.2 h1:FQ3bYuxtXjv/E8unfwfqdUXPms9JR64qBEul8TOw6IA= +github.com/gin-contrib/location v1.0.2/go.mod h1:g+5CKBkpOHL+PkrH2j6wK1u46MTOKZvBM27Vg4/IFuc= +github.com/gin-contrib/location v1.0.3 h1:iy5FY2JsunZ73Lnq8YZsx7wkGFY1xcyRdKiRh/8Uptg= +github.com/gin-contrib/location v1.0.3/go.mod h1:fMoqRQxX0d5ycvxzP7e5VtqfID00RPb4jMGDh3oT0pk= +github.com/gin-contrib/sse v1.0.0 h1:y3bT1mUWUxDpW4JLQg/HnTqV4rozuW4tC9eFKTxYI9E= +github.com/gin-contrib/sse v1.0.0/go.mod h1:zNuFdwarAygJBht0NTKiSi3jRf6RbqeILZ9Sp6Slhe0= +github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU= +github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y= +github.com/gin-gonic/gin v1.10.1 h1:T0ujvqyCSqRopADpgPgiTT63DUQVSfojyME59Ei63pQ= +github.com/gin-gonic/gin v1.10.1/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y= github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= -github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= -github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= -github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI= -github.com/go-playground/validator/v10 v10.15.4 h1:zMXza4EpOdooxPel5xDqXEdXG5r+WggpvnAKMsalBjs= -github.com/go-playground/validator/v10 v10.15.4/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= +github.com/go-playground/validator/v10 v10.24.0 h1:KHQckvo8G6hlWnrPX4NJJ+aBfWNAE/HH+qdL2cBpCmg= +github.com/go-playground/validator/v10 v10.24.0/go.mod h1:GGzBIJMuE98Ic/kJsBXbz1x/7cByt++cQ+YOuDM5wus= +github.com/go-playground/validator/v10 v10.26.0 h1:SP05Nqhjcvz81uJaRfEV0YBSSSGMc/iMaVtFbr3Sw2k= +github.com/go-playground/validator/v10 v10.26.0/go.mod h1:I5QpIEbmr8On7W0TktmJAumgzX4CA1XNl4ZmDuVHKKo= github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= -github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI= -github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= -github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= -github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= +github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y= +github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg= +github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4= +github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= -github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/gomarkdown/markdown v0.0.0-20230922112808-5421fefb8386 h1:EcQR3gusLHN46TAD+G+EbaaqJArt5vHhNpXAa12PQf4= -github.com/gomarkdown/markdown v0.0.0-20230922112808-5421fefb8386/go.mod h1:JDGcbDT52eL4fju3sZ4TeHGsQwhG9nbDV21aMyhwPoA= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= -github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/gomarkdown/markdown v0.0.0-20250207164621-7a1f277a159e h1:ESHlT0RVZphh4JGBz49I5R6nTdC8Qyc08vU25GQHzzQ= +github.com/gomarkdown/markdown v0.0.0-20250207164621-7a1f277a159e/go.mod h1:JDGcbDT52eL4fju3sZ4TeHGsQwhG9nbDV21aMyhwPoA= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= -github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk= -github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= -github.com/jackc/pgx/v5 v5.4.3 h1:cxFyXhxlvAifxnkKKdlxv8XqUf59tDlYjnV5YYfsJJY= -github.com/jackc/pgx/v5 v5.4.3/go.mod h1:Ig06C2Vu0t5qXC60W8sqIthScaEnFvojjj9dSljmHRA= -github.com/jinzhu/configor v1.2.1 h1:OKk9dsR8i6HPOCZR8BcMtcEImAFjIhbJFZNyn5GCZko= -github.com/jinzhu/configor v1.2.1/go.mod h1:nX89/MOmDba7ZX7GCyU/VIaQ2Ar2aizBl2d3JLF/rDc= +github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo= +github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= +github.com/jackc/pgx/v5 v5.7.2 h1:mLoDLV6sonKlvjIEsV56SkWNCnuNv531l94GaIzO+XI= +github.com/jackc/pgx/v5 v5.7.2/go.mod h1:ncY89UGWxg82EykZUwSpUKEfccBGGYq1xjrOpsbsfGQ= +github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo= +github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= +github.com/jinzhu/configor v1.2.2 h1:sLgh6KMzpCmaQB4e+9Fu/29VErtBUqsS2t8C9BNIVsA= +github.com/jinzhu/configor v1.2.2/go.mod h1:iFFSfOBKP3kC2Dku0ZGB3t3aulfQgTGJknodhFavsU8= github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= -github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= -github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= -github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= -github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg= -github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= +github.com/klauspost/cpuid/v2 v2.2.9 h1:66ze0taIn2H33fBvCkXuv9BmCwDfafmiIVpKV9kKGuY= +github.com/klauspost/cpuid/v2 v2.2.9/go.mod h1:rqkxqrZ1EhYM9G+hXH7YdowN5R5RGN6NK4QwQ3WMXF8= +github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE= +github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0= github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= -github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= -github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= -github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= -github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= -github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= -github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= -github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= -github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= -github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= +github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= -github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= +github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE= +github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= -github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/mattn/go-sqlite3 v1.14.17 h1:mCRHCLDUBXgpKAqIKsaAaAsrAlbkeomtRFKXh2L6YIM= -github.com/mattn/go-sqlite3 v1.14.17/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-sqlite3 v1.14.24 h1:tpSp2G2KyMnnQu99ngJ47EIkWVmliIizyZBfPrBWDRM= +github.com/mattn/go-sqlite3 v1.14.24/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= +github.com/mattn/go-sqlite3 v1.14.28 h1:ThEiQrnbtumT+QMknw63Befp/ce/nUPgBPMlRFEum7A= +github.com/mattn/go-sqlite3 v1.14.28/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= -github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= -github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4= -github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= +github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M= +github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= -github.com/rs/zerolog v1.30.0 h1:SymVODrcRsaRaSInD9yQtKbtWqwsfoPcRff/oRXLj4c= -github.com/rs/zerolog v1.30.0/go.mod h1:/tk+P47gFdPXq4QYjvCmT5/Gsug2nagsFWBWhAiSi1w= +github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0= +github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8= +github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= +github.com/rs/zerolog v1.34.0 h1:k43nTLIwcTVQAncfCw4KZ2VY6ukYoZaBPNOE8txlOeY= +github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6wYQ= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/swaggo/swag v1.16.2 h1:28Pp+8DkQoV+HLzLx8RGJZXNGKbFqnuvSbAAtoxiY04= -github.com/swaggo/swag v1.16.2/go.mod h1:6YzXnDcpr0767iOejs318CwYkCQqyGer6BizOg03f+E= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= -github.com/tidwall/gjson v1.17.0 h1:/Jocvlh98kcTfpN2+JzGQWQcqrPQwDrVEMApx/M5ZwM= -github.com/tidwall/gjson v1.17.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/gjson v1.18.0 h1:FIDeeyB800efLX89e5a8Y0BNH+LOngJyGrIWxG2FKQY= +github.com/tidwall/gjson v1.18.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= @@ -163,99 +140,107 @@ github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY= github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= -github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= -github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= -github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU= -github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= +github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE= +github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -go.mau.fi/util v0.1.0 h1:BwIFWIOEeO7lsiI2eWKFkWTfc5yQmoe+0FYyOFVyaoE= -go.mau.fi/util v0.1.0/go.mod h1:AxuJUMCxpzgJ5eV9JbPWKRH8aAJJidxetNdUj7qcb84= -golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= -golang.org/x/arch v0.5.0 h1:jpGode6huXQxcskEIpOCvrU+tzo81b6+oFLUYXWtH/Y= -golang.org/x/arch v0.5.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= +go.mau.fi/util v0.8.4 h1:mVKlJcXWfVo8ZW3f4vqtjGpqtZqJvX4ETekxawt2vnQ= +go.mau.fi/util v0.8.4/go.mod h1:MOfGTs1CBuK6ERTcSL4lb5YU7/ujz09eOPVEDckuazY= +go.mau.fi/util v0.8.7 h1:ywKarPxouJQEEijTs4mPlxC7F4AWEKokEpWc+2TYy6c= +go.mau.fi/util v0.8.7/go.mod h1:j6R3cENakc1f8HpQeFl0N15UiSTcNmIfDBNJUbL71RY= +golang.org/x/arch v0.14.0 h1:z9JUEZWr8x4rR0OU6c4/4t6E6jOZ8/QBS2bBYBm4tx4= +golang.org/x/arch v0.14.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= +golang.org/x/arch v0.15.0 h1:QtOrQd0bTUnhNVNndMpLHNWrDmYzZ2KDqSrEymqInZw= +golang.org/x/arch v0.15.0/go.mod h1:JmwW7aLIoRUKgaTzhkiEFxvcEiQGyOg9BMonBJUS7EE= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= -golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck= -golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= -golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g= -golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k= +golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= +golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus= +golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M= +golang.org/x/crypto v0.38.0 h1:jt+WWG8IZlBnVbomuhg2Mdq0+BBQaHbtqHEFEigjUV8= +golang.org/x/crypto v0.38.0/go.mod h1:MvrbAqul58NNYPKnOra203SB9vpuZW0e+RRZV+Ggqjw= +golang.org/x/exp v0.0.0-20250210185358-939b2ce775ac h1:l5+whBCLH3iH2ZNHYLbAe58bo7yrN4mVcnkHDYz5vvs= +golang.org/x/exp v0.0.0-20250210185358-939b2ce775ac/go.mod h1:hH+7mtFmImwwcMvScyxUhjuVHR3HGaDPMn9rMSUUbxo= +golang.org/x/exp v0.0.0-20250506013437-ce4c2cf36ca6 h1:y5zboxd6LQAqYIhHnB48p0ByQ/GnQx2BE33L8BOHQkI= +golang.org/x/exp v0.0.0-20250506013437-ce4c2cf36ca6/go.mod h1:U6Lno4MTRCDY+Ba7aCcauB9T60gsv5s4ralQzP72ZoQ= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= -golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= -golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8= -golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= +golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8= +golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk= +golang.org/x/net v0.40.0 h1:79Xs7wF06Gbdcg4kdCCIQArK11Z1hr5POQ6+fIYHNuY= +golang.org/x/net v0.40.0/go.mod h1:y0hY0exeL2Pku80/zKK7tpntoX23cqL3Oa6njdgRtds= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w= +golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.14.0 h1:woo0S4Yywslg6hp4eUFjTVOyKt0RookbpAHG4c1HmhQ= +golang.org/x/sync v0.14.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= +golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= +golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= -golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= +golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= +golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= +golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM= +golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY= +golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4= +golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= -golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ= -golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= -google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM= +google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= +google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY= +google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gorm.io/driver/mysql v1.5.1 h1:WUEH5VF9obL/lTtzjmML/5e6VfFR/788coz2uaVCAZw= -gorm.io/driver/mysql v1.5.1/go.mod h1:Jo3Xu7mMhCyj8dlrb3WoCaRd1FhsVh+yMXb1jUInf5o= -gorm.io/driver/postgres v1.5.2 h1:ytTDxxEv+MplXOfFe3Lzm7SjG09fcdb3Z/c056DTBx0= -gorm.io/driver/postgres v1.5.2/go.mod h1:fmpX0m2I1PKuR7mKZiEluwrP3hbs+ps7JIGMUBpCgl8= -gorm.io/driver/sqlite v1.5.3 h1:7/0dUgX28KAcopdfbRWWl68Rflh6osa4rDh+m51KL2g= -gorm.io/driver/sqlite v1.5.3/go.mod h1:qxAuCol+2r6PannQDpOP1FP6ag3mKi4esLnB/jHed+4= -gorm.io/gorm v1.25.1/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k= -gorm.io/gorm v1.25.4 h1:iyNd8fNAe8W9dvtlgeRI5zSVZPsq3OpcTu37cYcpCmw= -gorm.io/gorm v1.25.4/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k= -maunium.net/go/maulogger/v2 v2.4.1 h1:N7zSdd0mZkB2m2JtFUsiGTQQAdP0YeFWT7YMc80yAL8= -maunium.net/go/maulogger/v2 v2.4.1/go.mod h1:omPuYwYBILeVQobz8uO3XC8DIRuEb5rXYlQSuqrbCho= -maunium.net/go/mautrix v0.16.1 h1:Wb3CvOCe8A/NLsFeZYxKrgXKiqeZUQEBD1zqm7n/kWk= -maunium.net/go/mautrix v0.16.1/go.mod h1:2Jf15tulVtr6LxoiRL4smRXwpkGWUNfBFhwh/aXDBuk= +gorm.io/driver/mysql v1.5.7 h1:MndhOPYOfEp2rHKgkZIhJ16eVUIRf2HmzgoPmh7FCWo= +gorm.io/driver/mysql v1.5.7/go.mod h1:sEtPWMiqiN1N1cMXoXmBbd8C6/l+TESwriotuRRpkDM= +gorm.io/driver/postgres v1.5.11 h1:ubBVAfbKEUld/twyKZ0IYn9rSQh448EdelLYk9Mv314= +gorm.io/driver/postgres v1.5.11/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI= +gorm.io/driver/postgres v1.6.0 h1:2dxzU8xJ+ivvqTRph34QX+WrRaJlmfyPqXmoGVjMBa4= +gorm.io/driver/postgres v1.6.0/go.mod h1:vUw0mrGgrTK+uPHEhAdV4sfFELrByKVGnaVRkXDhtWo= +gorm.io/driver/sqlite v1.5.7 h1:8NvsrhP0ifM7LX9G4zPB97NwovUakUxc+2V2uuf3Z1I= +gorm.io/driver/sqlite v1.5.7/go.mod h1:U+J8craQU6Fzkcvu8oLeAQmi50TkwPEhHDEjQZXDah4= +gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8= +gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8= +gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ= +maunium.net/go/mautrix v0.23.0 h1:HNlR19eew5lvrNSL2muhExaGhYdaGk5FfEiA82QqUP4= +maunium.net/go/mautrix v0.23.0/go.mod h1:AGnnaz3ylGikUo1I1MJVn9QLsl2No1/ZNnGDyO0QD5s= +maunium.net/go/mautrix v0.24.0 h1:kBeyWhgL1W8/d8BEFlBSlgIpItPgP1l37hzF8cN3R70= +maunium.net/go/mautrix v0.24.0/go.mod h1:HqA1HUutQYJkrYRPkK64itARDz79PCec1oWVEB72HVQ= nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50= -rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= diff --git a/internal/api/alertmanager/handler.go b/internal/api/alertmanager/handler.go index bfc45f0..80b6f25 100644 --- a/internal/api/alertmanager/handler.go +++ b/internal/api/alertmanager/handler.go @@ -6,6 +6,7 @@ import ( "net/url" "github.com/gin-gonic/gin" + "github.com/pushbits/server/internal/api" "github.com/pushbits/server/internal/authentication" "github.com/pushbits/server/internal/log" @@ -38,6 +39,10 @@ type HandlerSettings struct { // @Router /alert [post] func (h *Handler) CreateAlert(ctx *gin.Context) { application := authentication.GetApplication(ctx) + if application == nil { + return + } + log.L.Printf("Sending alert notification for application %s.", application.Name) var hook model.AlertmanagerWebhook diff --git a/internal/api/api_test.go b/internal/api/api_test.go new file mode 100644 index 0000000..9030ec2 --- /dev/null +++ b/internal/api/api_test.go @@ -0,0 +1,101 @@ +package api + +import ( + "fmt" + "os" + "testing" + + "github.com/gin-gonic/gin" + + "github.com/pushbits/server/internal/authentication/credentials" + "github.com/pushbits/server/internal/configuration" + "github.com/pushbits/server/internal/database" + "github.com/pushbits/server/internal/log" + "github.com/pushbits/server/internal/model" + "github.com/pushbits/server/tests/mockups" +) + +// TestContext holds all test-related objects +type TestContext struct { + ApplicationHandler *ApplicationHandler + Users []*model.User + Database *database.Database + NotificationHandler *NotificationHandler + UserHandler *UserHandler + Config *configuration.Configuration +} + +var GlobalTestContext *TestContext + +func cleanup() { + err := os.Remove("pushbits-test.db") + if err != nil { + log.L.Warnln("Cannot delete test database: ", err) + } +} + +func TestMain(m *testing.M) { + cleanup() + + gin.SetMode(gin.TestMode) + + GlobalTestContext = CreateTestContext(nil) + + m.Run() + + cleanup() +} + +// GetTestContext initializes and verifies all required test components +func GetTestContext(_ *testing.T) *TestContext { + if GlobalTestContext == nil { + GlobalTestContext = CreateTestContext(nil) + } + + return GlobalTestContext +} + +// CreateTestContext initializes and verifies all required test components +func CreateTestContext(_ *testing.T) *TestContext { + ctx := &TestContext{} + + config := configuration.Configuration{} + config.Database.Connection = "pushbits-test.db" + config.Database.Dialect = "sqlite3" + config.Crypto.Argon2.Iterations = 4 + config.Crypto.Argon2.Parallelism = 4 + config.Crypto.Argon2.Memory = 131072 + config.Crypto.Argon2.SaltLength = 16 + config.Crypto.Argon2.KeyLength = 32 + config.Admin.Name = "user" + config.Admin.Password = "pushbits" + ctx.Config = &config + + db, err := mockups.GetEmptyDatabase(ctx.Config.Crypto) + if err != nil { + cleanup() + panic(fmt.Errorf("cannot set up database: %w", err)) + } + ctx.Database = db + + ctx.ApplicationHandler = &ApplicationHandler{ + DB: ctx.Database, + DP: &mockups.MockDispatcher{}, + } + + ctx.Users = mockups.GetUsers(ctx.Config) + + ctx.NotificationHandler = &NotificationHandler{ + DB: ctx.Database, + DP: &mockups.MockDispatcher{}, + } + + ctx.UserHandler = &UserHandler{ + AH: ctx.ApplicationHandler, + CM: credentials.CreateManager(false, ctx.Config.Crypto), + DB: ctx.Database, + DP: &mockups.MockDispatcher{}, + } + + return ctx +} diff --git a/internal/api/application.go b/internal/api/application.go index 774bb01..959b941 100644 --- a/internal/api/application.go +++ b/internal/api/application.go @@ -28,6 +28,10 @@ func (h *ApplicationHandler) generateToken(compat bool) string { } func (h *ApplicationHandler) registerApplication(ctx *gin.Context, a *model.Application, u *model.User) error { + if a == nil || u == nil { + return errors.New("nil parameters provided") + } + log.L.Printf("Registering application %s.", a.Name) channelID, err := h.DP.RegisterApplication(a.ID, a.Name, u.MatrixID) @@ -46,6 +50,10 @@ func (h *ApplicationHandler) registerApplication(ctx *gin.Context, a *model.Appl } func (h *ApplicationHandler) createApplication(ctx *gin.Context, u *model.User, name string, compat bool) (*model.Application, error) { + if u == nil { + return nil, errors.New("nil parameters provided") + } + log.L.Printf("Creating application %s.", name) application := model.Application{} @@ -71,6 +79,10 @@ func (h *ApplicationHandler) createApplication(ctx *gin.Context, u *model.User, } func (h *ApplicationHandler) deleteApplication(ctx *gin.Context, a *model.Application, u *model.User) error { + if a == nil || u == nil { + return errors.New("nil parameters provided") + } + log.L.Printf("Deleting application %s (ID %d).", a.Name, a.ID) err := h.DP.DeregisterApplication(a, u) @@ -87,6 +99,10 @@ func (h *ApplicationHandler) deleteApplication(ctx *gin.Context, a *model.Applic } func (h *ApplicationHandler) updateApplication(ctx *gin.Context, a *model.Application, updateApplication *model.UpdateApplication) error { + if a == nil || updateApplication == nil { + return errors.New("nil parameters provided") + } + log.L.Printf("Updating application %s (ID %d).", a.Name, a.ID) if updateApplication.Name != nil { @@ -186,7 +202,7 @@ func (h *ApplicationHandler) GetApplications(ctx *gin.Context) { // @Router /application/{id} [get] func (h *ApplicationHandler) GetApplication(ctx *gin.Context) { application, err := getApplication(ctx, h.DB) - if err != nil { + if err != nil || application == nil { return } @@ -218,7 +234,7 @@ func (h *ApplicationHandler) GetApplication(ctx *gin.Context) { // @Router /application/{id} [delete] func (h *ApplicationHandler) DeleteApplication(ctx *gin.Context) { application, err := getApplication(ctx, h.DB) - if err != nil { + if err != nil || application == nil { return } @@ -250,7 +266,7 @@ func (h *ApplicationHandler) DeleteApplication(ctx *gin.Context) { // @Router /application/{id} [put] func (h *ApplicationHandler) UpdateApplication(ctx *gin.Context) { application, err := getApplication(ctx, h.DB) - if err != nil { + if err != nil || application == nil { return } diff --git a/internal/api/application_test.go b/internal/api/application_test.go index eefaf53..28f7f95 100644 --- a/internal/api/application_test.go +++ b/internal/api/application_test.go @@ -4,122 +4,54 @@ import ( "encoding/json" "fmt" "io" - "os" "testing" - "github.com/gin-gonic/gin" - "github.com/pushbits/server/internal/authentication/credentials" - "github.com/pushbits/server/internal/configuration" - "github.com/pushbits/server/internal/database" - "github.com/pushbits/server/internal/log" - "github.com/pushbits/server/internal/model" - "github.com/pushbits/server/tests" - "github.com/pushbits/server/tests/mockups" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" -) -var ( - TestApplicationHandler *ApplicationHandler - TestUsers []*model.User - TestDatabase *database.Database - TestNotificationHandler *NotificationHandler - TestUserHandler *UserHandler - TestConfig *configuration.Configuration + "github.com/pushbits/server/internal/model" + "github.com/pushbits/server/tests" ) // Collect all created applications to check & delete them later -var SuccessAplications map[uint][]model.Application - -func TestMain(m *testing.M) { - cleanUp() - // Get main config and adapt - config := &configuration.Configuration{} - - config.Database.Connection = "pushbits-test.db" - config.Database.Dialect = "sqlite3" - config.Crypto.Argon2.Iterations = 4 - config.Crypto.Argon2.Parallelism = 4 - config.Crypto.Argon2.Memory = 131072 - config.Crypto.Argon2.SaltLength = 16 - config.Crypto.Argon2.KeyLength = 32 - config.Admin.Name = "user" - config.Admin.Password = "pushbits" - - TestConfig = config - - // Set up test environment - db, err := mockups.GetEmptyDatabase(config.Crypto) - if err != nil { - cleanUp() - log.L.Println("Cannot set up database: ", err) - os.Exit(1) - } - TestDatabase = db - - appHandler, err := getApplicationHandler(config) - if err != nil { - cleanUp() - log.L.Println("Cannot set up application handler: ", err) - os.Exit(1) - } - - TestApplicationHandler = appHandler - TestUsers = mockups.GetUsers(config) - SuccessAplications = make(map[uint][]model.Application) - - TestNotificationHandler = &NotificationHandler{ - DB: TestDatabase, - DP: &mockups.MockDispatcher{}, - } - - TestUserHandler = &UserHandler{ - AH: TestApplicationHandler, - CM: credentials.CreateManager(false, config.Crypto), - DB: TestDatabase, - DP: &mockups.MockDispatcher{}, - } - - // Run - m.Run() - log.L.Println("Clean up after Test") - cleanUp() -} +var SuccessApplications = make(map[uint][]model.Application) func TestApi_RegisterApplicationWithoutUser(t *testing.T) { + ctx := GetTestContext(t) + assert := assert.New(t) - gin.SetMode(gin.TestMode) reqWoUser := tests.Request{Name: "Invalid JSON Data", Method: "POST", Endpoint: "/application", Data: `{"name": "test1", "strict_compatibility": true}`, Headers: map[string]string{"Content-Type": "application/json"}} _, c, err := reqWoUser.GetRequest() if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } - assert.Panicsf(func() { TestApplicationHandler.CreateApplication(c) }, "CreateApplication did not panic although user is not in context") + assert.Panicsf(func() { ctx.ApplicationHandler.CreateApplication(c) }, "CreateApplication did not panic although user is not in context") } func TestApi_RegisterApplication(t *testing.T) { + ctx := GetTestContext(t) + assert := assert.New(t) require := require.New(t) - gin.SetMode(gin.TestMode) testCases := make([]tests.Request, 0) testCases = append(testCases, tests.Request{Name: "Invalid Form Data", Method: "POST", Endpoint: "/application", Data: "k=1&v=abc", ShouldStatus: 400}) testCases = append(testCases, tests.Request{Name: "Invalid JSON Data", Method: "POST", Endpoint: "/application", Data: `{"name": "test1", "strict_compatibility": "oh yes"}`, Headers: map[string]string{"Content-Type": "application/json"}, ShouldStatus: 400}) testCases = append(testCases, tests.Request{Name: "Valid JSON Data", Method: "POST", Endpoint: "/application", Data: `{"name": "test2", "strict_compatibility": true}`, Headers: map[string]string{"Content-Type": "application/json"}, ShouldStatus: 200}) - for _, user := range TestUsers { - SuccessAplications[user.ID] = make([]model.Application, 0) + for _, user := range ctx.Users { + SuccessApplications[user.ID] = make([]model.Application, 0) for _, req := range testCases { var application model.Application w, c, err := req.GetRequest() if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } c.Set("user", user) - TestApplicationHandler.CreateApplication(c) + ctx.ApplicationHandler.CreateApplication(c) // Parse body only for successful requests if req.ShouldStatus >= 200 && req.ShouldStatus < 300 { @@ -128,7 +60,7 @@ func TestApi_RegisterApplication(t *testing.T) { err = json.Unmarshal(body, &application) require.NoErrorf(err, "Cannot unmarshal request body") - SuccessAplications[user.ID] = append(SuccessAplications[user.ID], application) + SuccessApplications[user.ID] = append(SuccessApplications[user.ID], application) } assert.Equalf(w.Code, req.ShouldStatus, "CreateApplication (Test case: \"%s\") Expected status code %v but received %v.", req.Name, req.ShouldStatus, w.Code) @@ -137,24 +69,25 @@ func TestApi_RegisterApplication(t *testing.T) { } func TestApi_GetApplications(t *testing.T) { + ctx := GetTestContext(t) + var applications []model.Application assert := assert.New(t) require := require.New(t) - gin.SetMode(gin.TestMode) testCases := make([]tests.Request, 0) testCases = append(testCases, tests.Request{Name: "Valid Request", Method: "GET", Endpoint: "/application", ShouldStatus: 200}) - for _, user := range TestUsers { + for _, user := range ctx.Users { for _, req := range testCases { w, c, err := req.GetRequest() if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } c.Set("user", user) - TestApplicationHandler.GetApplications(c) + ctx.ApplicationHandler.GetApplications(c) // Parse body only for successful requests if req.ShouldStatus >= 200 && req.ShouldStatus < 300 { @@ -167,7 +100,7 @@ func TestApi_GetApplications(t *testing.T) { } assert.Truef(validateAllApplications(user, applications), "Did not find application created previously") - assert.Equalf(len(applications), len(SuccessAplications[user.ID]), "Created %d application(s) but got %d back", len(SuccessAplications[user.ID]), len(applications)) + assert.Equalf(len(applications), len(SuccessApplications[user.ID]), "Created %d application(s) but got %d back", len(SuccessApplications[user.ID]), len(applications)) } assert.Equalf(w.Code, req.ShouldStatus, "GetApplications (Test case: \"%s\") Expected status code %v but received %v.", req.Name, req.ShouldStatus, w.Code) @@ -176,22 +109,24 @@ func TestApi_GetApplications(t *testing.T) { } func TestApi_GetApplicationsWithoutUser(t *testing.T) { + ctx := GetTestContext(t) + assert := assert.New(t) - gin.SetMode(gin.TestMode) testCase := tests.Request{Name: "Valid Request", Method: "GET", Endpoint: "/application"} _, c, err := testCase.GetRequest() if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } - assert.Panicsf(func() { TestApplicationHandler.GetApplications(c) }, "GetApplications did not panic although user is not in context") + assert.Panicsf(func() { ctx.ApplicationHandler.GetApplications(c) }, "GetApplications did not panic although user is not in context") } func TestApi_GetApplicationErrors(t *testing.T) { + ctx := GetTestContext(t) + assert := assert.New(t) - gin.SetMode(gin.TestMode) // Arbitrary test cases testCases := make(map[uint]tests.Request) @@ -199,16 +134,16 @@ func TestApi_GetApplicationErrors(t *testing.T) { testCases[5555] = tests.Request{Name: "Requesting unknown application 5555", Method: "GET", Endpoint: "/application/5555", ShouldStatus: 404} testCases[99999999999999999] = tests.Request{Name: "Requesting unknown application 99999999999999999", Method: "GET", Endpoint: "/application/99999999999999999", ShouldStatus: 404} - for _, user := range TestUsers { + for _, user := range ctx.Users { for id, req := range testCases { w, c, err := req.GetRequest() if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } c.Set("user", user) c.Set("id", id) - TestApplicationHandler.GetApplication(c) + ctx.ApplicationHandler.GetApplication(c) assert.Equalf(w.Code, req.ShouldStatus, "GetApplication (Test case: \"%s\") Expected status code %v but have %v.", req.Name, req.ShouldStatus, w.Code) } @@ -216,25 +151,26 @@ func TestApi_GetApplicationErrors(t *testing.T) { } func TestApi_GetApplication(t *testing.T) { + ctx := GetTestContext(t) + var application model.Application assert := assert.New(t) require := require.New(t) - gin.SetMode(gin.TestMode) // Previously generated applications - for _, user := range TestUsers { - for _, app := range SuccessAplications[user.ID] { + for _, user := range ctx.Users { + for _, app := range SuccessApplications[user.ID] { req := tests.Request{Name: fmt.Sprintf("Requesting application %s (%d)", app.Name, app.ID), Method: "GET", Endpoint: fmt.Sprintf("/application/%d", app.ID), ShouldStatus: 200} w, c, err := req.GetRequest() if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } c.Set("user", user) c.Set("id", app.ID) - TestApplicationHandler.GetApplication(c) + ctx.ApplicationHandler.GetApplication(c) // Parse body only for successful requests if req.ShouldStatus >= 200 && req.ShouldStatus < 300 { @@ -255,14 +191,15 @@ func TestApi_GetApplication(t *testing.T) { } func TestApi_UpdateApplication(t *testing.T) { + ctx := GetTestContext(t) + assert := assert.New(t) require := require.New(t) - gin.SetMode(gin.TestMode) - for _, user := range TestUsers { + for _, user := range ctx.Users { testCases := make(map[uint]tests.Request) // Previously generated applications - for _, app := range SuccessAplications[user.ID] { + for _, app := range SuccessApplications[user.ID] { newName := app.Name + "-new_name" updateApp := model.UpdateApplication{ Name: &newName, @@ -282,12 +219,12 @@ func TestApi_UpdateApplication(t *testing.T) { for id, req := range testCases { w, c, err := req.GetRequest() if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } c.Set("user", user) c.Set("id", id) - TestApplicationHandler.UpdateApplication(c) + ctx.ApplicationHandler.UpdateApplication(c) assert.Equalf(w.Code, req.ShouldStatus, "UpdateApplication (Test case: \"%s\") Expected status code %v but have %v.", req.Name, req.ShouldStatus, w.Code) } @@ -295,13 +232,14 @@ func TestApi_UpdateApplication(t *testing.T) { } func TestApi_DeleteApplication(t *testing.T) { - assert := assert.New(t) - gin.SetMode(gin.TestMode) + ctx := GetTestContext(t) - for _, user := range TestUsers { + assert := assert.New(t) + + for _, user := range ctx.Users { testCases := make(map[uint]tests.Request) // Previously generated applications - for _, app := range SuccessAplications[user.ID] { + for _, app := range SuccessApplications[user.ID] { testCases[app.ID] = tests.Request{Name: fmt.Sprintf("Delete application %s (%d)", app.Name, app.ID), Method: "DELETE", Endpoint: fmt.Sprintf("/application/%d", app.ID), ShouldStatus: 200} } // Arbitrary test cases @@ -310,35 +248,25 @@ func TestApi_DeleteApplication(t *testing.T) { for id, req := range testCases { w, c, err := req.GetRequest() if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } c.Set("user", user) c.Set("id", id) - TestApplicationHandler.DeleteApplication(c) + ctx.ApplicationHandler.DeleteApplication(c) assert.Equalf(w.Code, req.ShouldStatus, "DeleteApplication (Test case: \"%s\") Expected status code %v but have %v.", req.Name, req.ShouldStatus, w.Code) } } } -// GetApplicationHandler creates and returns an application handler -func getApplicationHandler(_ *configuration.Configuration) (*ApplicationHandler, error) { - dispatcher := &mockups.MockDispatcher{} - - return &ApplicationHandler{ - DB: TestDatabase, - DP: dispatcher, - }, nil -} - // True if all created applications are in list func validateAllApplications(user *model.User, apps []model.Application) bool { - if _, ok := SuccessAplications[user.ID]; !ok { + if _, ok := SuccessApplications[user.ID]; !ok { return len(apps) == 0 } - for _, successApp := range SuccessAplications[user.ID] { + for _, successApp := range SuccessApplications[user.ID] { foundApp := false for _, app := range apps { if app.ID == successApp.ID { @@ -354,10 +282,3 @@ func validateAllApplications(user *model.User, apps []model.Application) bool { return true } - -func cleanUp() { - err := os.Remove("pushbits-test.db") - if err != nil { - log.L.Warnln("Cannot delete test database: ", err) - } -} diff --git a/internal/api/context.go b/internal/api/context.go index 34fe836..59d42ce 100644 --- a/internal/api/context.go +++ b/internal/api/context.go @@ -41,6 +41,11 @@ func getApplication(ctx *gin.Context, db Database) (*model.Application, error) { if success := SuccessOrAbort(ctx, http.StatusNotFound, err); !success { return nil, err } + if application == nil { + err := errors.New("application not found") + ctx.AbortWithError(http.StatusNotFound, err) + return nil, err + } return application, nil } diff --git a/internal/api/context_test.go b/internal/api/context_test.go index d93b941..4325e8f 100644 --- a/internal/api/context_test.go +++ b/internal/api/context_test.go @@ -3,19 +3,20 @@ package api import ( "testing" - "github.com/gin-gonic/gin" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/pushbits/server/internal/log" "github.com/pushbits/server/internal/model" "github.com/pushbits/server/tests" "github.com/pushbits/server/tests/mockups" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestApi_getID(t *testing.T) { + GetTestContext(t) + assert := assert.New(t) require := require.New(t) - gin.SetMode(gin.TestMode) testValue := uint(1337) testCases := make(map[interface{}]tests.Request) @@ -32,7 +33,7 @@ func TestApi_getID(t *testing.T) { for id, req := range testCases { w, c, err := req.GetRequest() if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } c.Set("id", id) @@ -54,13 +55,14 @@ func TestApi_getID(t *testing.T) { } func TestApi_getApplication(t *testing.T) { + ctx := GetTestContext(t) + assert := assert.New(t) require := require.New(t) - gin.SetMode(gin.TestMode) applications := mockups.GetAllApplications() - err := mockups.AddApplicationsToDb(TestDatabase, applications) + err := mockups.AddApplicationsToDb(ctx.Database, applications) if err != nil { log.L.Fatalln("Cannot add mock applications to database: ", err) } @@ -74,30 +76,32 @@ func TestApi_getApplication(t *testing.T) { for id, req := range testCases { w, c, err := req.GetRequest() if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } c.Set("id", id) - app, err := getApplication(c, TestDatabase) + app, err := getApplication(c, ctx.Database) if req.ShouldStatus >= 200 && req.ShouldStatus < 300 { - require.NoErrorf(err, "getApplication with id %v (%t) returned an error although it should not: %v", id, id, err) - assert.Equalf(app.ID, id, "getApplication id was set to %d but resulting app id is %d", id, app.ID) + require.NoErrorf(err, "getApplication with id %v returned an unexpected error: %v", id, err) + require.NotNilf(app, "Expected a valid app for id %v, but got nil", id) + assert.Equalf(app.ID, id, "Expected app ID %d, but got %d", id, app.ID) } else { - assert.Errorf(err, "getApplication with id %v (%t) returned no error although it should", id, id) + require.Errorf(err, "Expected an error for id %v, but got none", id) + assert.Nilf(app, "Expected app to be nil for id %v, but got %+v", id, app) } - assert.Equalf(w.Code, req.ShouldStatus, "getApplication id was set to %v (%T) and should result in status code %d but code is %d", id, id, req.ShouldStatus, w.Code) - + assert.Equalf(w.Code, req.ShouldStatus, "Expected status code %d for id %v, but got %d", req.ShouldStatus, id, w.Code) } } func TestApi_getUser(t *testing.T) { + ctx := GetTestContext(t) + assert := assert.New(t) require := require.New(t) - gin.SetMode(gin.TestMode) - _, err := mockups.AddUsersToDb(TestDatabase, TestUsers) + _, err := mockups.AddUsersToDb(ctx.Database, ctx.Users) assert.NoErrorf(err, "Adding users to database failed: %v", err) // No testing of invalid ids as that is tested in TestApi_getID already @@ -109,20 +113,22 @@ func TestApi_getUser(t *testing.T) { for id, req := range testCases { w, c, err := req.GetRequest() if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } c.Set("id", id) - user, err := getUser(c, TestDatabase) + user, err := getUser(c, ctx.Database) if req.ShouldStatus >= 200 && req.ShouldStatus < 300 { - require.NoErrorf(err, "getUser with id %v (%t) returned an error although it should not: %v", id, id, err) - assert.Equalf(user.ID, id, "getUser id was set to %d but resulting app id is %d", id, user.ID) - + require.NoErrorf(err, "getUser with id %v returned an unexpected error: %v", id, err) + require.NotNilf(user, "Expected a valid user for id %v, but got nil", id) + assert.Equalf(user.ID, id, "Expected user ID %d, but got %d", id, user.ID) } else { - assert.Errorf(err, "getUser with id %v (%t) returned no error although it should", id, id) + require.Errorf(err, "Expected an error for id %v, but got none", id) + assert.Nilf(user, "Expected user to be nil for id %v, but got %+v", id, user) } - assert.Equalf(w.Code, req.ShouldStatus, "getUser id was set to %v (%T) and should result in status code %d but code is %d", id, id, req.ShouldStatus, w.Code) + assert.Equalf(w.Code, req.ShouldStatus, "Expected status code %d for id %v, but got %d", req.ShouldStatus, id, w.Code) + } } diff --git a/internal/api/health_test.go b/internal/api/health_test.go index f8322da..2f283c2 100644 --- a/internal/api/health_test.go +++ b/internal/api/health_test.go @@ -3,14 +3,17 @@ package api import ( "testing" - "github.com/pushbits/server/tests" "github.com/stretchr/testify/assert" + + "github.com/pushbits/server/tests" ) func TestApi_Health(t *testing.T) { + ctx := GetTestContext(t) + assert := assert.New(t) handler := HealthHandler{ - DB: TestDatabase, + DB: ctx.Database, } testCases := make([]tests.Request, 0) @@ -19,7 +22,7 @@ func TestApi_Health(t *testing.T) { for _, req := range testCases { w, c, err := req.GetRequest() if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } handler.Health(c) diff --git a/internal/api/notification.go b/internal/api/notification.go index 53ca239..d8ba341 100644 --- a/internal/api/notification.go +++ b/internal/api/notification.go @@ -44,6 +44,10 @@ type NotificationHandler struct { // @Router /message [post] func (h *NotificationHandler) CreateNotification(ctx *gin.Context) { application := authentication.GetApplication(ctx) + if application == nil { + return + } + log.L.Printf("Sending notification for application %s.", application.Name) var notification model.Notification @@ -78,6 +82,10 @@ func (h *NotificationHandler) CreateNotification(ctx *gin.Context) { // @Router /message/{message_id} [DELETE] func (h *NotificationHandler) DeleteNotification(ctx *gin.Context) { application := authentication.GetApplication(ctx) + if application == nil { + return + } + log.L.Printf("Deleting notification for application %s.", application.Name) id, err := getMessageID(ctx) diff --git a/internal/api/notification_test.go b/internal/api/notification_test.go index de7c087..4c33756 100644 --- a/internal/api/notification_test.go +++ b/internal/api/notification_test.go @@ -5,17 +5,18 @@ import ( "io" "testing" - "github.com/gin-gonic/gin" - "github.com/pushbits/server/internal/model" - "github.com/pushbits/server/tests" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "github.com/pushbits/server/internal/model" + "github.com/pushbits/server/tests" ) func TestApi_CreateNotification(t *testing.T) { + ctx := GetTestContext(t) + assert := assert.New(t) require := require.New(t) - gin.SetMode(gin.TestMode) testApplication := model.Application{ ID: 1, @@ -36,11 +37,11 @@ func TestApi_CreateNotification(t *testing.T) { var notification model.Notification w, c, err := req.GetRequest() if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } c.Set("app", &testApplication) - TestNotificationHandler.CreateNotification(c) + ctx.NotificationHandler.CreateNotification(c) // Parse body only for successful requests if req.ShouldStatus >= 200 && req.ShouldStatus < 300 { @@ -64,8 +65,9 @@ func TestApi_CreateNotification(t *testing.T) { } func TestApi_DeleteNotification(t *testing.T) { + ctx := GetTestContext(t) + assert := assert.New(t) - gin.SetMode(gin.TestMode) testApplication := model.Application{ ID: 1, @@ -83,12 +85,12 @@ func TestApi_DeleteNotification(t *testing.T) { for id, req := range testCases { w, c, err := req.GetRequest() if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } c.Set("app", &testApplication) c.Set("messageid", id) - TestNotificationHandler.DeleteNotification(c) + ctx.NotificationHandler.DeleteNotification(c) assert.Equalf(w.Code, req.ShouldStatus, "(Test case: \"%s\") Expected status code %v but have %v.", req.Name, req.ShouldStatus, w.Code) } diff --git a/internal/api/user.go b/internal/api/user.go index 009a4f4..b9e9a7a 100644 --- a/internal/api/user.go +++ b/internal/api/user.go @@ -38,6 +38,10 @@ func (h *UserHandler) requireMultipleAdmins(ctx *gin.Context) error { } func (h *UserHandler) deleteApplications(ctx *gin.Context, u *model.User) error { + if ctx == nil || u == nil { + return errors.New("nil parameters provided") + } + applications, err := h.DB.GetApplications(u) if success := SuccessOrAbort(ctx, http.StatusInternalServerError, err); !success { return err @@ -55,6 +59,10 @@ func (h *UserHandler) deleteApplications(ctx *gin.Context, u *model.User) error } func (h *UserHandler) updateChannels(ctx *gin.Context, u *model.User, matrixID string) error { + if ctx == nil || u == nil { + return errors.New("nil parameters provided") + } + applications, err := h.DB.GetApplications(u) if success := SuccessOrAbort(ctx, http.StatusInternalServerError, err); !success { return err @@ -83,15 +91,7 @@ func (h *UserHandler) updateChannels(ctx *gin.Context, u *model.User, matrixID s return nil } -func (h *UserHandler) updateUser(ctx *gin.Context, u *model.User, updateUser model.UpdateUser) error { - if updateUser.MatrixID != nil && u.MatrixID != *updateUser.MatrixID { - if err := h.updateChannels(ctx, u, *updateUser.MatrixID); err != nil { - return err - } - } - - log.L.Printf("Updating user %s.", u.Name) - +func (h *UserHandler) updateUserFields(ctx *gin.Context, u *model.User, updateUser model.UpdateUser) error { if updateUser.Name != nil { u.Name = *updateUser.Name } @@ -100,7 +100,6 @@ func (h *UserHandler) updateUser(ctx *gin.Context, u *model.User, updateUser mod if success := SuccessOrAbort(ctx, http.StatusBadRequest, err); !success { return err } - u.PasswordHash = hash } if updateUser.MatrixID != nil { @@ -109,6 +108,25 @@ func (h *UserHandler) updateUser(ctx *gin.Context, u *model.User, updateUser mod if updateUser.IsAdmin != nil { u.IsAdmin = *updateUser.IsAdmin } + return nil +} + +func (h *UserHandler) updateUser(ctx *gin.Context, u *model.User, updateUser model.UpdateUser) error { + if u == nil { + return errors.New("nil parameters provided") + } + + if updateUser.MatrixID != nil && u.MatrixID != *updateUser.MatrixID { + if err := h.updateChannels(ctx, u, *updateUser.MatrixID); err != nil { + return err + } + } + + log.L.Printf("Updating user %s.", u.Name) + + if err := h.updateUserFields(ctx, u, updateUser); err != nil { + return err + } err := h.DB.UpdateUser(u) if success := SuccessOrAbort(ctx, http.StatusInternalServerError, err); !success { @@ -149,10 +167,12 @@ func (h *UserHandler) CreateUser(ctx *gin.Context) { log.L.Printf("Creating user %s.", createUser.Name) user, err := h.DB.CreateUser(createUser) - if success := SuccessOrAbort(ctx, http.StatusInternalServerError, err); !success { return } + if user == nil { + return + } ctx.JSON(http.StatusOK, user.IntoExternalUser()) } @@ -170,6 +190,10 @@ func (h *UserHandler) CreateUser(ctx *gin.Context) { // @Security BasicAuth // @Router /user [get] func (h *UserHandler) GetUsers(ctx *gin.Context) { + if ctx == nil { + return + } + users, err := h.DB.GetUsers() if success := SuccessOrAbort(ctx, http.StatusInternalServerError, err); !success { return @@ -199,7 +223,7 @@ func (h *UserHandler) GetUsers(ctx *gin.Context) { // @Router /user/{id} [get] func (h *UserHandler) GetUser(ctx *gin.Context) { user, err := getUser(ctx, h.DB) - if err != nil { + if err != nil || user == nil { return } @@ -221,7 +245,7 @@ func (h *UserHandler) GetUser(ctx *gin.Context) { // @Router /user/{id} [delete] func (h *UserHandler) DeleteUser(ctx *gin.Context) { user, err := getUser(ctx, h.DB) - if err != nil { + if err != nil || user == nil { return } @@ -265,7 +289,7 @@ func (h *UserHandler) DeleteUser(ctx *gin.Context) { // @Router /user/{id} [put] func (h *UserHandler) UpdateUser(ctx *gin.Context) { user, err := getUser(ctx, h.DB) - if err != nil { + if err != nil || user == nil { return } @@ -275,6 +299,9 @@ func (h *UserHandler) UpdateUser(ctx *gin.Context) { } requestingUser := authentication.GetUser(ctx) + if requestingUser == nil { + return + } // Last privileged user must not be taken privileges. Assumes that the current user has privileges. if user.ID == requestingUser.ID && updateUser.IsAdmin != nil && !(*updateUser.IsAdmin) { diff --git a/internal/api/user_test.go b/internal/api/user_test.go index 81551c0..7875d69 100644 --- a/internal/api/user_test.go +++ b/internal/api/user_test.go @@ -6,24 +6,27 @@ import ( "strconv" "testing" - "github.com/pushbits/server/internal/model" - "github.com/pushbits/server/tests" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "github.com/pushbits/server/internal/model" + "github.com/pushbits/server/tests" ) func TestApi_CreateUser(t *testing.T) { + ctx := GetTestContext(t) + assert := assert.New(t) testCases := make([]tests.Request, 0) // Add all test users - for _, user := range TestUsers { + for _, user := range ctx.Users { createUser := &model.CreateUser{} createUser.ExternalUser.Name = user.Name createUser.ExternalUser.MatrixID = "@" + user.Name + ":matrix.org" createUser.ExternalUser.IsAdmin = user.IsAdmin - createUser.UserCredentials.Password = TestConfig.Admin.Password + createUser.UserCredentials.Password = ctx.Config.Admin.Password testCase := tests.Request{ Name: "Already existing user " + user.Name, @@ -45,16 +48,18 @@ func TestApi_CreateUser(t *testing.T) { for _, req := range testCases { w, c, err := req.GetRequest() if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } - TestUserHandler.CreateUser(c) + ctx.UserHandler.CreateUser(c) assert.Equalf(w.Code, req.ShouldStatus, "(Test case: \"%s\") Expected status code %v but have %v.", req.Name, req.ShouldStatus, w.Code) } } func TestApi_GetUsers(t *testing.T) { + ctx := GetTestContext(t) + assert := assert.New(t) require := require.New(t) @@ -65,10 +70,10 @@ func TestApi_GetUsers(t *testing.T) { w, c, err := request.GetRequest() if err != nil { - t.Fatalf((err.Error())) + t.Fatalf("error getting request: %v", err) } - TestUserHandler.GetUsers(c) + ctx.UserHandler.GetUsers(c) assert.Equalf(w.Code, 200, "Response code should be 200 but is %d", w.Code) // Get users from body @@ -79,7 +84,7 @@ func TestApi_GetUsers(t *testing.T) { require.NoErrorf(err, "Can not unmarshal users") // Check existence of all known users - for _, user := range TestUsers { + for _, user := range ctx.Users { found := false for _, userExt := range users { if user.ID == userExt.ID && user.Name == userExt.Name { @@ -92,13 +97,15 @@ func TestApi_GetUsers(t *testing.T) { } func TestApi_UpdateUser(t *testing.T) { - assert := assert.New(t) - admin := getAdmin() + ctx := GetTestContext(t) + assert := assert.New(t) + + admin := getAdmin(ctx) testCases := make(map[uint]tests.Request) // Add all test users - for _, user := range TestUsers { + for _, user := range ctx.Users { updateUser := &model.UpdateUser{} user.Name += "+1" user.IsAdmin = !user.IsAdmin @@ -120,12 +127,12 @@ func TestApi_UpdateUser(t *testing.T) { for id, req := range testCases { w, c, err := req.GetRequest() if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } c.Set("id", id) c.Set("user", admin) - TestUserHandler.UpdateUser(c) + ctx.UserHandler.UpdateUser(c) assert.Equalf(w.Code, req.ShouldStatus, "(Test case: \"%s\") Expected status code %v but have %v.", req.Name, req.ShouldStatus, w.Code) } @@ -134,15 +141,17 @@ func TestApi_UpdateUser(t *testing.T) { for id, req := range testCases { _, c, err := req.GetRequest() if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } c.Set("id", id) - assert.Panicsf(func() { TestUserHandler.UpdateUser(c) }, "User not set should panic but did not") + assert.Panicsf(func() { ctx.UserHandler.UpdateUser(c) }, "User not set should panic but did not") } } func TestApi_GetUser(t *testing.T) { + ctx := GetTestContext(t) + assert := assert.New(t) require := require.New(t) @@ -151,7 +160,7 @@ func TestApi_GetUser(t *testing.T) { testCases[uint(9999999)] = tests.Request{Name: "Unknown id", Method: "GET", Endpoint: "/user/99999999", ShouldStatus: 404} // Check if we can get all existing users - for _, user := range TestUsers { + for _, user := range ctx.Users { testCases[user.ID] = tests.Request{ Name: "Valid user " + user.Name, Method: "GET", @@ -166,7 +175,7 @@ func TestApi_GetUser(t *testing.T) { require.NoErrorf(err, "(Test case %s) Could not make request", testCase.Name) c.Set("id", id) - TestUserHandler.GetUser(c) + ctx.UserHandler.GetUser(c) assert.Equalf(testCase.ShouldStatus, w.Code, "(Test case %s) Expected status code %d but have %d", testCase.Name, testCase.ShouldStatus, w.Code) @@ -191,13 +200,16 @@ func TestApi_GetUser(t *testing.T) { } func TestApi_DeleteUser(t *testing.T) { + ctx := GetTestContext(t) + assert := assert.New(t) require := require.New(t) + testCases := make(map[interface{}]tests.Request) testCases["abcde"] = tests.Request{Name: "Invalid user - string", Method: "DELETE", Endpoint: "/user/abcde", ShouldStatus: 500} testCases[uint(999999)] = tests.Request{Name: "Unknown user", Method: "DELETE", Endpoint: "/user/999999", ShouldStatus: 404} - for _, user := range TestUsers { + for _, user := range ctx.Users { shouldStatus := 200 testCases[user.ID] = tests.Request{ Name: "Valid user " + user.Name, @@ -212,14 +224,14 @@ func TestApi_DeleteUser(t *testing.T) { require.NoErrorf(err, "(Test case %s) Could not make request", testCase.Name) c.Set("id", id) - TestUserHandler.DeleteUser(c) + ctx.UserHandler.DeleteUser(c) assert.Equalf(testCase.ShouldStatus, w.Code, "(Test case %s) Expected status code %d but have %d", testCase.Name, testCase.ShouldStatus, w.Code) } } -func getAdmin() *model.User { - for _, user := range TestUsers { +func getAdmin(ctx *TestContext) *model.User { + for _, user := range ctx.Users { if user.IsAdmin { return user } diff --git a/internal/api/util_test.go b/internal/api/util_test.go index 2870575..3dc6d8a 100644 --- a/internal/api/util_test.go +++ b/internal/api/util_test.go @@ -5,12 +5,15 @@ import ( "fmt" "testing" - "github.com/pushbits/server/tests" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "github.com/pushbits/server/tests" ) func TestApi_SuccessOrAbort(t *testing.T) { + GetTestContext(t) + assert := assert.New(t) require := require.New(t) @@ -37,10 +40,12 @@ func TestApi_SuccessOrAbort(t *testing.T) { } func TestApi_IsCurrentUser(t *testing.T) { + ctx := GetTestContext(t) + assert := assert.New(t) require := require.New(t) - for _, user := range TestUsers { + for _, user := range ctx.Users { testCases := make(map[uint]tests.Request) testCases[user.ID] = tests.Request{Name: fmt.Sprintf("User %s - success", user.Name), Endpoint: "/", ShouldStatus: 200} diff --git a/internal/authentication/authentication.go b/internal/authentication/authentication.go index 2592b29..886ecc0 100644 --- a/internal/authentication/authentication.go +++ b/internal/authentication/authentication.go @@ -61,7 +61,7 @@ func (a *Authenticator) requireUserProperty(has hasUserProperty) gin.HandlerFunc // RequireUser returns a Gin middleware which requires valid user credentials to be supplied with the request. func (a *Authenticator) RequireUser() gin.HandlerFunc { - return a.requireUserProperty(func(user *model.User) bool { + return a.requireUserProperty(func(_ *model.User) bool { return true }) } diff --git a/internal/authentication/credentials/hibp.go b/internal/authentication/credentials/hibp.go index 6e05a8c..c7f03d7 100644 --- a/internal/authentication/credentials/hibp.go +++ b/internal/authentication/credentials/hibp.go @@ -33,6 +33,9 @@ func IsPasswordPwned(password string) (bool, error) { if err != nil { return false, err } + if resp == nil { + return false, fmt.Errorf("received nil response from http request") + } if resp.StatusCode != http.StatusOK { log.L.Fatalf("Request failed with HTTP %s.", resp.Status) diff --git a/internal/authentication/token.go b/internal/authentication/token.go index 7e91d6f..9b53cd1 100644 --- a/internal/authentication/token.go +++ b/internal/authentication/token.go @@ -13,9 +13,9 @@ var ( ) func randIntn(n int) int { - max := big.NewInt(int64(n)) + maxValue := big.NewInt(int64(n)) - res, err := rand.Int(rand.Reader, max) + res, err := rand.Int(rand.Reader, maxValue) if err != nil { panic("random source is not available") } diff --git a/internal/configuration/configuration.go b/internal/configuration/configuration.go index 1a6a247..ec7fbef 100644 --- a/internal/configuration/configuration.go +++ b/internal/configuration/configuration.go @@ -3,6 +3,7 @@ package configuration import ( "github.com/jinzhu/configor" + "github.com/pushbits/server/internal/log" "github.com/pushbits/server/internal/pberrors" ) diff --git a/internal/configuration/configuration_test.go b/internal/configuration/configuration_test.go index b279005..ba30b50 100644 --- a/internal/configuration/configuration_test.go +++ b/internal/configuration/configuration_test.go @@ -7,10 +7,11 @@ import ( "testing" "github.com/jinzhu/configor" - "github.com/pushbits/server/internal/log" - "github.com/pushbits/server/internal/pberrors" "github.com/stretchr/testify/assert" "gopkg.in/yaml.v2" + + "github.com/pushbits/server/internal/log" + "github.com/pushbits/server/internal/pberrors" ) type Pair struct { diff --git a/internal/dispatcher/application.go b/internal/dispatcher/application.go index b1b9e4e..59e2654 100644 --- a/internal/dispatcher/application.go +++ b/internal/dispatcher/application.go @@ -1,6 +1,7 @@ package dispatcher import ( + "context" "fmt" "github.com/pushbits/server/internal/configuration" @@ -20,7 +21,7 @@ func buildRoomTopic(id uint) string { func (d *Dispatcher) RegisterApplication(id uint, name, user string) (string, error) { log.L.Printf("Registering application %s, notifications will be relayed to user %s.\n", name, user) - resp, err := d.mautrixClient.CreateRoom(&mautrix.ReqCreateRoom{ + resp, err := d.mautrixClient.CreateRoom(context.Background(), &mautrix.ReqCreateRoom{ Visibility: "private", Invite: []mId.UserID{mId.UserID(user)}, IsDirect: true, @@ -44,7 +45,7 @@ func (d *Dispatcher) DeregisterApplication(a *model.Application, u *model.User) // The user might have left the channel, but we can still try to remove them. - if _, err := d.mautrixClient.KickUser(mId.RoomID(a.MatrixID), &mautrix.ReqKickUser{ + if _, err := d.mautrixClient.KickUser(context.Background(), mId.RoomID(a.MatrixID), &mautrix.ReqKickUser{ Reason: "This application was deleted", UserID: mId.UserID(u.MatrixID), }); err != nil { @@ -52,12 +53,12 @@ func (d *Dispatcher) DeregisterApplication(a *model.Application, u *model.User) return err } - if _, err := d.mautrixClient.LeaveRoom(mId.RoomID(a.MatrixID)); err != nil { + if _, err := d.mautrixClient.LeaveRoom(context.Background(), mId.RoomID(a.MatrixID)); err != nil { log.L.Print(err) return err } - if _, err := d.mautrixClient.ForgetRoom(mId.RoomID(a.MatrixID)); err != nil { + if _, err := d.mautrixClient.ForgetRoom(context.Background(), mId.RoomID(a.MatrixID)); err != nil { log.L.Print(err) return err } @@ -66,7 +67,7 @@ func (d *Dispatcher) DeregisterApplication(a *model.Application, u *model.User) } func (d *Dispatcher) sendRoomEvent(roomID, eventType string, content interface{}) error { - if _, err := d.mautrixClient.SendStateEvent(mId.RoomID(roomID), event.NewEventType(eventType), "", content); err != nil { + if _, err := d.mautrixClient.SendStateEvent(context.Background(), mId.RoomID(roomID), event.NewEventType(eventType), "", content); err != nil { log.L.Print(err) return err } @@ -107,7 +108,7 @@ func (d *Dispatcher) UpdateApplication(a *model.Application, behavior *configura // IsOrphan checks if the user is still connected to the channel. func (d *Dispatcher) IsOrphan(a *model.Application, u *model.User) (bool, error) { - resp, err := d.mautrixClient.JoinedMembers(mId.RoomID(a.MatrixID)) + resp, err := d.mautrixClient.JoinedMembers(context.Background(), mId.RoomID(a.MatrixID)) if err != nil { return false, err } @@ -123,7 +124,7 @@ func (d *Dispatcher) IsOrphan(a *model.Application, u *model.User) (bool, error) // RepairApplication re-invites the user to the channel. func (d *Dispatcher) RepairApplication(a *model.Application, u *model.User) error { - _, err := d.mautrixClient.InviteUser(mId.RoomID(a.MatrixID), &mautrix.ReqInviteUser{ + _, err := d.mautrixClient.InviteUser(context.Background(), mId.RoomID(a.MatrixID), &mautrix.ReqInviteUser{ UserID: mId.UserID(u.MatrixID), }) if err != nil { diff --git a/internal/dispatcher/dispatcher.go b/internal/dispatcher/dispatcher.go index 1bce2d4..92b190a 100644 --- a/internal/dispatcher/dispatcher.go +++ b/internal/dispatcher/dispatcher.go @@ -2,6 +2,8 @@ package dispatcher import ( + "context" + "maunium.net/go/mautrix" "maunium.net/go/mautrix/id" @@ -24,7 +26,7 @@ func Create(homeserver, username, password string, formatting configuration.Form return nil, err } - _, err = matrixClient.Login(&mautrix.ReqLogin{ + _, err = matrixClient.Login(context.Background(), &mautrix.ReqLogin{ Type: mautrix.AuthTypePassword, Identifier: mautrix.UserIdentifier{Type: mautrix.IdentifierTypeUser, User: username}, Password: password, @@ -42,7 +44,7 @@ func Create(homeserver, username, password string, formatting configuration.Form func (d *Dispatcher) Close() { log.L.Printf("Logging out.") - _, err := d.mautrixClient.Logout() + _, err := d.mautrixClient.Logout(context.Background()) if err != nil { log.L.Printf("Error while logging out: %s", err) } diff --git a/internal/dispatcher/notification.go b/internal/dispatcher/notification.go index 8949a72..70105ef 100644 --- a/internal/dispatcher/notification.go +++ b/internal/dispatcher/notification.go @@ -1,6 +1,7 @@ package dispatcher import ( + "context" "fmt" "html" "strings" @@ -15,6 +16,37 @@ import ( "github.com/pushbits/server/internal/pberrors" ) +type notificationContentType string + +const ( + contentTypePlain notificationContentType = "text/plain" + contentTypeMarkdown notificationContentType = "text/markdown" + contentTypeHTML notificationContentType = "text/html" +) + +func getContentType(extras map[string]any) notificationContentType { + if optionsDisplayRaw, ok := extras["client::display"]; ok { + if optionsDisplay, ok2 := optionsDisplayRaw.(map[string]interface{}); ok2 { + if ctRaw, ok3 := optionsDisplay["contentType"]; ok3 { + contentTypeString := strings.ToLower(fmt.Sprintf("%v", ctRaw)) + switch contentTypeString { + case "text/markdown": + return contentTypeMarkdown + case "text/html": + return contentTypeHTML + case "text/plain": + return contentTypePlain + default: + log.L.Printf("Unknown content type specified: %s, defaulting to text/plain", contentTypeString) + return contentTypePlain + } + } + } + } + + return contentTypePlain +} + // MessageFormat is a matrix message format type MessageFormat string @@ -59,10 +91,10 @@ func (d *Dispatcher) SendNotification(a *model.Application, n *model.Notificatio plainMessage := strings.TrimSpace(n.Message) plainTitle := strings.TrimSpace(n.Title) message := d.getFormattedMessage(n) - title := d.getFormattedTitle(n) + title := d.getFormattedTitle(n) // Does not append

anymore text := fmt.Sprintf("%s\n\n%s", plainTitle, plainMessage) - formattedText := fmt.Sprintf("%s %s", title, message) + formattedText := fmt.Sprintf("%s

%s", title, message) // Append

here messageEvent := &MessageEvent{ Body: text, @@ -71,7 +103,7 @@ func (d *Dispatcher) SendNotification(a *model.Application, n *model.Notificatio Format: MessageFormatHTML, } - evt, err := d.mautrixClient.SendMessageEvent(mId.RoomID(a.MatrixID), event.EventMessage, &messageEvent) + evt, err := d.mautrixClient.SendMessageEvent(context.Background(), mId.RoomID(a.MatrixID), event.EventMessage, &messageEvent) if err != nil { log.L.Errorln(err) return "", err @@ -103,7 +135,6 @@ func (d *Dispatcher) DeleteNotification(a *model.Application, n *model.DeleteNot newFormattedBody := fmt.Sprintf("%s
- deleted", oldFormattedBody) _, err = d.replaceMessage(a, newBody, newFormattedBody, deleteMessage.ID.String(), oldBody, oldFormattedBody) - if err != nil { return err } @@ -116,37 +147,41 @@ func (d *Dispatcher) DeleteNotification(a *model.Application, n *model.DeleteNot // HTML-formats the title func (d *Dispatcher) getFormattedTitle(n *model.Notification) string { trimmedTitle := strings.TrimSpace(n.Title) - title := html.EscapeString(trimmedTitle) + var title string + + contentType := getContentType(n.Extras) + + switch contentType { + case contentTypeMarkdown: + title = string(markdown.ToHTML([]byte(trimmedTitle), nil, nil)) + case contentTypeHTML: + title = trimmedTitle + case contentTypePlain: + title = html.EscapeString(trimmedTitle) + title = "" + title + "" + } if d.formatting.ColoredTitle { title = d.coloredText(d.priorityToColor(n.Priority), title) } - return "" + title + "

" + return title } // Converts different syntaxes to a HTML-formatted message func (d *Dispatcher) getFormattedMessage(n *model.Notification) string { trimmedMessage := strings.TrimSpace(n.Message) - message := strings.ReplaceAll(html.EscapeString(trimmedMessage), "\n", "
") // default to text/plain + var message string - if optionsDisplayRaw, ok := n.Extras["client::display"]; ok { - optionsDisplay, ok := optionsDisplayRaw.(map[string]interface{}) + contentType := getContentType(n.Extras) - if ok { - if contentTypeRaw, ok := optionsDisplay["contentType"]; ok { - contentType := fmt.Sprintf("%v", contentTypeRaw) - log.L.Printf("Message content type: %s", contentType) - - switch contentType { - case "html", "text/html": - message = strings.ReplaceAll(trimmedMessage, "\n", "
") - case "markdown", "md", "text/md", "text/markdown": - // Allow HTML in Markdown - message = string(markdown.ToHTML([]byte(trimmedMessage), nil, nil)) - } - } - } + switch contentType { + case contentTypeMarkdown: + message = string(markdown.ToHTML([]byte(trimmedMessage), nil, nil)) + case contentTypeHTML: + message = trimmedMessage + case contentTypePlain: + message = strings.ReplaceAll(html.EscapeString(trimmedMessage), "\n", "
") } return message @@ -186,7 +221,7 @@ func (d *Dispatcher) getMessage(a *model.Application, id string) (*event.Event, maxPages := 10 // Maximum pages to request (10 messages per page) for i := 0; i < maxPages; i++ { - messages, err := d.mautrixClient.Messages(mId.RoomID(a.MatrixID), start, end, 'b', nil, 10) + messages, err := d.mautrixClient.Messages(context.Background(), mId.RoomID(a.MatrixID), start, end, 'b', nil, 10) if err != nil { return nil, err } @@ -225,7 +260,7 @@ func (d *Dispatcher) replaceMessage(a *model.Application, newBody, newFormattedB Format: MessageFormatHTML, } - sendEvent, err := d.mautrixClient.SendMessageEvent(mId.RoomID(a.MatrixID), event.EventMessage, &replaceEvent) + sendEvent, err := d.mautrixClient.SendMessageEvent(context.Background(), mId.RoomID(a.MatrixID), event.EventMessage, &replaceEvent) if err != nil { log.L.Errorln(err) return nil, err @@ -260,7 +295,7 @@ func (d *Dispatcher) respondToMessage(a *model.Application, body, formattedBody } notificationEvent.RelatesTo = ¬ificationRelation - sendEvent, err := d.mautrixClient.SendMessageEvent(mId.RoomID(a.MatrixID), event.EventMessage, ¬ificationEvent) + sendEvent, err := d.mautrixClient.SendMessageEvent(context.Background(), mId.RoomID(a.MatrixID), event.EventMessage, ¬ificationEvent) if err != nil { log.L.Errorln(err) return nil, err diff --git a/internal/runner/runner.go b/internal/runner/runner.go index 05befb3..a945fcb 100644 --- a/internal/runner/runner.go +++ b/internal/runner/runner.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/gin-gonic/gin" + "github.com/pushbits/server/internal/configuration" ) diff --git a/tests/mockups/helper.go b/tests/mockups/helper.go index 8fbbb7e..e4b4edb 100644 --- a/tests/mockups/helper.go +++ b/tests/mockups/helper.go @@ -5,8 +5,8 @@ import ( "encoding/base64" ) -func randStr(len int) string { - buff := make([]byte, len) +func randStr(length int) string { + buff := make([]byte, length) _, err := rand.Read(buff) if err != nil { @@ -16,5 +16,5 @@ func randStr(len int) string { str := base64.StdEncoding.EncodeToString(buff) // Base 64 can be longer than len - return str[:len] + return str[:length] }