mirror of
https://github.com/pushbits/server.git
synced 2025-05-28 16:26:37 +02:00
Merge remote-tracking branch 'origin/main' into alertmanager-interface
This commit is contained in:
commit
a0ec05ab2c
18 changed files with 65 additions and 56 deletions
2
.github/workflows/documentation.yml
vendored
2
.github/workflows/documentation.yml
vendored
|
@ -20,7 +20,7 @@ jobs:
|
|||
- name: Export GOBIN
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: 1.16
|
||||
go-version: 1.17
|
||||
|
||||
- name: Install Poetry
|
||||
run: curl -sSL https://install.python-poetry.org | python3 -
|
||||
|
|
4
.github/workflows/publish.yml
vendored
4
.github/workflows/publish.yml
vendored
|
@ -18,7 +18,7 @@ jobs:
|
|||
- name: Export GOBIN
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: 1.16
|
||||
go-version: 1.17
|
||||
|
||||
- name: Install Poetry
|
||||
run: curl -sSL https://install.python-poetry.org | python3 -
|
||||
|
@ -88,7 +88,7 @@ jobs:
|
|||
- name: Export GOBIN
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: 1.16
|
||||
go-version: 1.17
|
||||
|
||||
- name: Run GoReleaser
|
||||
uses: goreleaser/goreleaser-action@v2
|
||||
|
|
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
|
@ -23,7 +23,7 @@ jobs:
|
|||
- name: Export GOBIN
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: 1.16
|
||||
go-version: 1.17
|
||||
|
||||
- name: Install Poetry
|
||||
run: curl -sSL https://install.python-poetry.org | python3 -
|
||||
|
|
13
Makefile
13
Makefile
|
@ -5,6 +5,8 @@ DOCS_DIR := ./docs
|
|||
OUT_DIR := ./out
|
||||
TESTS_DIR := ./tests
|
||||
|
||||
GO_FILES := $(shell find . -type f \( -iname '*.go' ! -path "./tests/semgrep-rules/*" \))
|
||||
|
||||
PB_BUILD_VERSION ?= $(shell git describe --tags)
|
||||
ifeq ($(PB_BUILD_VERSION),)
|
||||
_ := $(error Cannot determine build version)
|
||||
|
@ -26,9 +28,9 @@ clean:
|
|||
.PHONY: test
|
||||
test:
|
||||
touch $(SEMGREP_MODFILE) # See [1].
|
||||
go fmt ./...
|
||||
stdout=$$(gofumpt -l $(GO_FILES) 2>&1); if [ "$$stdout" ]; then exit 1; fi
|
||||
go vet ./...
|
||||
gocyclo -over 10 $(shell find . -type f \( -iname '*.go' ! -path "./tests/semgrep-rules/*" \))
|
||||
gocyclo -over 10 $(GO_FILES)
|
||||
staticcheck ./...
|
||||
go test -v -cover ./...
|
||||
gosec -exclude-dir=tests ./...
|
||||
|
@ -42,9 +44,14 @@ setup:
|
|||
go install github.com/fzipp/gocyclo/cmd/gocyclo@latest
|
||||
go install github.com/securego/gosec/v2/cmd/gosec@latest
|
||||
go install github.com/swaggo/swag/cmd/swag@latest
|
||||
go install honnef.co/go/tools/cmd/staticcheck@v0.2.2
|
||||
go install honnef.co/go/tools/cmd/staticcheck@latest
|
||||
go install mvdan.cc/gofumpt@latest
|
||||
poetry install
|
||||
|
||||
.PHONY: fmt
|
||||
fmt:
|
||||
gofumpt -l -w $(GO_FILES)
|
||||
|
||||
.PHONY: swag
|
||||
swag:
|
||||
swag init --parseDependency=true --exclude $(TESTS_DIR) -g cmd/pushbits/main.go
|
||||
|
|
|
@ -17,7 +17,7 @@ import (
|
|||
var version string
|
||||
|
||||
func setupCleanup(db *database.Database, dp *dispatcher.Dispatcher) {
|
||||
c := make(chan os.Signal)
|
||||
c := make(chan os.Signal, 2)
|
||||
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||
|
||||
go func() {
|
||||
|
|
38
go.mod
38
go.mod
|
@ -1,26 +1,54 @@
|
|||
module github.com/pushbits/server
|
||||
|
||||
go 1.16
|
||||
go 1.17
|
||||
|
||||
require (
|
||||
github.com/alexedwards/argon2id v0.0.0-20201228115903-cf543ebc1f7b
|
||||
github.com/gin-contrib/location v0.0.2
|
||||
github.com/gin-gonic/gin v1.7.7
|
||||
github.com/golang/protobuf v1.4.3 // indirect
|
||||
github.com/gomarkdown/markdown v0.0.0-20210408062403-ad838ccf8cdd
|
||||
github.com/google/go-cmp v0.5.0 // indirect
|
||||
github.com/jinzhu/configor v1.2.1
|
||||
<<<<<<< HEAD
|
||||
github.com/json-iterator/go v1.1.10 // indirect
|
||||
github.com/leodido/go-urn v1.2.1 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.1 // indirect
|
||||
=======
|
||||
>>>>>>> origin/main
|
||||
github.com/sirupsen/logrus v1.8.1
|
||||
github.com/stretchr/testify v1.7.0
|
||||
github.com/ugorji/go v1.2.4 // indirect
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0
|
||||
gorm.io/driver/mysql v1.0.4
|
||||
gorm.io/driver/sqlite v1.2.6
|
||||
gorm.io/gorm v1.22.3
|
||||
maunium.net/go/mautrix v0.10.10
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/BurntSushi/toml v0.3.1 // indirect
|
||||
github.com/btcsuite/btcutil v1.0.2 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||
github.com/go-playground/locales v0.13.0 // indirect
|
||||
github.com/go-playground/universal-translator v0.17.0 // indirect
|
||||
github.com/go-playground/validator/v10 v10.4.1 // indirect
|
||||
github.com/go-sql-driver/mysql v1.5.0 // indirect
|
||||
github.com/golang/protobuf v1.4.3 // indirect
|
||||
github.com/google/go-cmp v0.5.0 // indirect
|
||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||
github.com/jinzhu/now v1.1.2 // indirect
|
||||
github.com/json-iterator/go v1.1.10 // indirect
|
||||
github.com/leodido/go-urn v1.2.1 // indirect
|
||||
github.com/mattn/go-isatty v0.0.12 // indirect
|
||||
github.com/mattn/go-sqlite3 v1.14.10 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.1 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/ugorji/go/codec v1.2.4 // indirect
|
||||
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 // indirect
|
||||
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f // indirect
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
|
||||
google.golang.org/protobuf v1.23.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
|
||||
)
|
||||
|
|
13
go.sum
13
go.sum
|
@ -23,8 +23,6 @@ github.com/gin-contrib/location v0.0.2/go.mod h1:NGoidiRlf0BlA/VKSVp+g3cuSMeTmip
|
|||
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.7.0 h1:jGB9xAJQ12AIGNB4HguylppmDK1Am9ppF7XnGXXJuoU=
|
||||
github.com/gin-gonic/gin v1.7.0/go.mod h1:jD2toBW3GZUr5UMcdrwQA10I7RuaFOl/SGeDjXkfUtY=
|
||||
github.com/gin-gonic/gin v1.7.7 h1:3DoBmSbJbZAWqXJC3SLjAPfutPJJRN1U5pALB7EeTTs=
|
||||
github.com/gin-gonic/gin v1.7.7/go.mod h1:axIBovoeJpVj8S3BwE0uPMTeReE4+AfFtqpqaZ1qq1U=
|
||||
github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
|
||||
|
@ -63,7 +61,6 @@ 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/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.1 h1:g39TucaRWyV3dwDO++eEc6qf8TVIQ/Da48WmqjZ3i7E=
|
||||
github.com/jinzhu/now v1.1.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
||||
github.com/jinzhu/now v1.1.2 h1:eVKgfIdy9b6zbWBMgFpfDPoAMifwSZagU9HmEU6zgiI=
|
||||
github.com/jinzhu/now v1.1.2/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
||||
|
@ -77,9 +74,6 @@ github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
|
|||
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
|
||||
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
|
||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||
github.com/mattn/go-sqlite3 v1.14.5/go.mod h1:WVKg1VTActs4Qso6iwGbiFih2UIHo0ENGwNd0Lj+XmI=
|
||||
github.com/mattn/go-sqlite3 v1.14.6 h1:dNPt6NO46WmLVt2DLNpwczCmdV5boIZ6g/tlDrlRUbg=
|
||||
github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
|
||||
github.com/mattn/go-sqlite3 v1.14.9/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
|
||||
github.com/mattn/go-sqlite3 v1.14.10 h1:MLn+5bFRlWMGoSRmJour3CL1w/qL96mvipqpwQW/Sfk=
|
||||
github.com/mattn/go-sqlite3 v1.14.10/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
|
||||
|
@ -119,7 +113,6 @@ golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnf
|
|||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20200115085410-6d4e4cb37c7d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY=
|
||||
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
|
||||
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 h1:0es+/5331RGQPcXlMfP+WrnIIS6dNnNRe0WB02W0F4M=
|
||||
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
|
@ -136,8 +129,6 @@ golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||
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-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210608053332-aa57babbf139 h1:C+AwYEtBp/VQwoLntUmQ/yx3MS9vmZaKNdw5eOpoQe8=
|
||||
golang.org/x/sys v0.0.0-20210608053332-aa57babbf139/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 h1:SrN+KX8Art/Sf4HNj6Zcz06G7VEz+7w9tdXTPOZ7+l4=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
||||
|
@ -169,12 +160,8 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie
|
|||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gorm.io/driver/mysql v1.0.4 h1:TATTzt+kR+IV0+h3iUB3dHUe8omCvQ0rOkmfCsUBohk=
|
||||
gorm.io/driver/mysql v1.0.4/go.mod h1:MEgp8tk2n60cSBCq5iTcPDw3ns8Gs+zOva9EUhkknTs=
|
||||
gorm.io/driver/sqlite v1.1.4 h1:PDzwYE+sI6De2+mxAneV9Xs11+ZyKV6oxD3wDGkaNvM=
|
||||
gorm.io/driver/sqlite v1.1.4/go.mod h1:mJCeTFr7+crvS+TRnWc5Z3UvwxUN1BGBLMrf5LA9DYw=
|
||||
gorm.io/driver/sqlite v1.2.6 h1:SStaH/b+280M7C8vXeZLz/zo9cLQmIGwwj3cSj7p6l4=
|
||||
gorm.io/driver/sqlite v1.2.6/go.mod h1:gyoX0vHiiwi0g49tv+x2E7l8ksauLK0U/gShcdUsjWY=
|
||||
gorm.io/gorm v1.20.7/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw=
|
||||
gorm.io/gorm v1.20.12 h1:ebZ5KrSHzet+sqOCVdH9mTjW91L298nX3v5lVxAzSUY=
|
||||
gorm.io/gorm v1.20.12/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw=
|
||||
gorm.io/gorm v1.22.3 h1:/JS6z+GStEQvJNW3t1FTwJwG/gZ+A7crFdRqtvG5ehA=
|
||||
gorm.io/gorm v1.22.3/go.mod h1:F+OptMscr0P2F2qU97WT1WimdH9GaQPoDW7AYd5i2Y0=
|
||||
|
|
|
@ -19,12 +19,14 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var TestApplicationHandler *ApplicationHandler
|
||||
var TestUsers []*model.User
|
||||
var TestDatabase *database.Database
|
||||
var TestNotificationHandler *NotificationHandler
|
||||
var TestUserHandler *UserHandler
|
||||
var TestConfig *configuration.Configuration
|
||||
var (
|
||||
TestApplicationHandler *ApplicationHandler
|
||||
TestUsers []*model.User
|
||||
TestDatabase *database.Database
|
||||
TestNotificationHandler *NotificationHandler
|
||||
TestUserHandler *UserHandler
|
||||
TestConfig *configuration.Configuration
|
||||
)
|
||||
|
||||
// Collect all created applications to check & delete them later
|
||||
var SuccessAplications map[uint][]model.Application
|
||||
|
@ -95,7 +97,6 @@ func TestApi_RegisterApplicationWithoutUser(t *testing.T) {
|
|||
}
|
||||
|
||||
assert.Panicsf(func() { TestApplicationHandler.CreateApplication(c) }, "CreateApplication did not panic altough user is not in context")
|
||||
|
||||
}
|
||||
|
||||
func TestApi_RegisterApplication(t *testing.T) {
|
||||
|
@ -186,7 +187,6 @@ func TestApi_GetApplicationsWithoutUser(t *testing.T) {
|
|||
}
|
||||
|
||||
assert.Panicsf(func() { TestApplicationHandler.GetApplications(c) }, "GetApplications did not panic altough user is not in context")
|
||||
|
||||
}
|
||||
|
||||
func TestApi_GetApplicationErrors(t *testing.T) {
|
||||
|
|
|
@ -13,8 +13,7 @@ import (
|
|||
)
|
||||
|
||||
// The NotificationDatabase interface for encapsulating database access.
|
||||
type NotificationDatabase interface {
|
||||
}
|
||||
type NotificationDatabase interface{}
|
||||
|
||||
// The NotificationDispatcher interface for relaying notifications.
|
||||
type NotificationDispatcher interface {
|
||||
|
|
|
@ -61,7 +61,6 @@ func TestApi_CreateNotification(t *testing.T) {
|
|||
|
||||
assert.Equalf(w.Code, req.ShouldStatus, "(Test case: \"%s\") Expected status code %v but have %v.", req.Name, req.ShouldStatus, w.Code)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestApi_DeleteNotification(t *testing.T) {
|
||||
|
@ -93,5 +92,4 @@ func TestApi_DeleteNotification(t *testing.T) {
|
|||
|
||||
assert.Equalf(w.Code, req.ShouldStatus, "(Test case: \"%s\") Expected status code %v but have %v.", req.Name, req.ShouldStatus, w.Code)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -216,7 +216,6 @@ func TestApi_DeleteUser(t *testing.T) {
|
|||
|
||||
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 {
|
||||
|
|
|
@ -19,8 +19,7 @@ func TestApi_SuccessOrAbort(t *testing.T) {
|
|||
testCases[errors.New("this is an error")] = tests.Request{Name: "Error - 500", Endpoint: "/", ShouldStatus: 500}
|
||||
testCases[errors.New("this is an error")] = tests.Request{Name: "Error - 200", Endpoint: "/", ShouldStatus: 200}
|
||||
testCases[errors.New("this is an error")] = tests.Request{Name: "Error - 404", Endpoint: "/", ShouldStatus: 404}
|
||||
testCases[errors.New("this is an error")] = tests.Request{Name: "Error - 1001", Endpoint: "/", ShouldStatus: 1001}
|
||||
testCases[nil] = tests.Request{Name: "No Error - 1001", Endpoint: "/", ShouldStatus: 1001}
|
||||
testCases[nil] = tests.Request{Name: "No Error - 200", Endpoint: "/", ShouldStatus: 200}
|
||||
testCases[nil] = tests.Request{Name: "No Error - 404", Endpoint: "/", ShouldStatus: 404}
|
||||
|
||||
for forcedErr, testCase := range testCases {
|
||||
|
@ -62,5 +61,4 @@ func TestApi_IsCurrentUser(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ func (m *Manager) CreatePasswordHash(password string) ([]byte, error) {
|
|||
}
|
||||
|
||||
hash, err := argon2id.CreateHash(password, m.argon2Params)
|
||||
|
||||
if err != nil {
|
||||
log.L.Fatal(err)
|
||||
panic(err)
|
||||
|
@ -32,7 +31,6 @@ func (m *Manager) CreatePasswordHash(password string) ([]byte, error) {
|
|||
// ComparePassword compares a hashed password with its possible plaintext equivalent.
|
||||
func ComparePassword(hash, password []byte) bool {
|
||||
match, err := argon2id.ComparePasswordAndHash(string(password), string(hash))
|
||||
|
||||
if err != nil {
|
||||
log.L.Fatal(err)
|
||||
return false
|
||||
|
|
|
@ -146,7 +146,7 @@ func writeMinimalConfig() error {
|
|||
return err
|
||||
}
|
||||
|
||||
return ioutil.WriteFile("config_unittest.yml", configString, 0644)
|
||||
return ioutil.WriteFile("config_unittest.yml", configString, 0o644)
|
||||
}
|
||||
|
||||
// Writes a config with default values to config.yml
|
||||
|
@ -174,13 +174,13 @@ func writeValidConfig() error {
|
|||
return err
|
||||
}
|
||||
|
||||
return ioutil.WriteFile("config_unittest.yml", configString, 0644)
|
||||
return ioutil.WriteFile("config_unittest.yml", configString, 0o644)
|
||||
}
|
||||
|
||||
// Writes a config that is empty
|
||||
func writeEmptyConfig() error {
|
||||
cleanUp()
|
||||
return ioutil.WriteFile("config_unittest.yml", []byte(""), 0644)
|
||||
return ioutil.WriteFile("config_unittest.yml", []byte(""), 0o644)
|
||||
}
|
||||
|
||||
// Writes a config with invalid entries
|
||||
|
@ -197,7 +197,7 @@ func writeInvalidConfig() error {
|
|||
return err
|
||||
}
|
||||
|
||||
return ioutil.WriteFile("config_unittest.yml", configString, 0644)
|
||||
return ioutil.WriteFile("config_unittest.yml", configString, 0o644)
|
||||
}
|
||||
|
||||
func cleanUp() error {
|
||||
|
|
|
@ -28,7 +28,7 @@ func createFileDir(file string) {
|
|||
|
||||
if _, err := os.Stat(dir); os.IsNotExist(err) {
|
||||
// nosemgrep: tests.semgrep-rules.go.lang.correctness.permissions.incorrect-default-permission
|
||||
if err := os.MkdirAll(dir, 0750); err != nil {
|
||||
if err := os.MkdirAll(dir, 0o750); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,7 +84,6 @@ func (d *Dispatcher) DeleteNotification(a *model.Application, n *model.DeleteNot
|
|||
|
||||
// get the message we want to delete
|
||||
deleteMessage, err := d.getMessage(a, n.ID)
|
||||
|
||||
if err != nil {
|
||||
log.L.Println(err)
|
||||
return pberrors.ErrorMessageNotFound
|
||||
|
@ -219,7 +218,6 @@ func (d *Dispatcher) replaceMessage(a *model.Application, newBody, newFormattedB
|
|||
}
|
||||
|
||||
sendEvent, err := d.mautrixClient.SendMessageEvent(mId.RoomID(a.MatrixID), event.EventMessage, &replaceEvent)
|
||||
|
||||
if err != nil {
|
||||
log.L.Println(err)
|
||||
return nil, err
|
||||
|
@ -231,7 +229,6 @@ func (d *Dispatcher) replaceMessage(a *model.Application, newBody, newFormattedB
|
|||
// Sends a notification in response to another matrix message event
|
||||
func (d *Dispatcher) respondToMessage(a *model.Application, body, formattedBody string, respondMessage *event.Event) (*mautrix.RespSendEvent, error) {
|
||||
oldBody, oldFormattedBody, err := bodiesFromMessage(respondMessage)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -23,12 +23,11 @@ func ReadConfig(filename string, removeFile bool) (config *configuration.Configu
|
|||
}
|
||||
|
||||
file, err := ioutil.ReadFile(filename)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile("config.yml", file, 0644)
|
||||
err = ioutil.WriteFile("config.yml", file, 0o644)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -7,8 +7,7 @@ import (
|
|||
)
|
||||
|
||||
// MockDispatcher is a dispatcher used for testing - it does not need any storage interface
|
||||
type MockDispatcher struct {
|
||||
}
|
||||
type MockDispatcher struct{}
|
||||
|
||||
func (d *MockDispatcher) RegisterApplication(id uint, name, token, user string) (string, error) {
|
||||
return fmt.Sprintf("%d-%s", id, name), nil
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue