Merge remote-tracking branch 'origin/main' into alertmanager-interface

This commit is contained in:
cubicroot 2022-04-21 18:59:17 +02:00
commit a0ec05ab2c
18 changed files with 65 additions and 56 deletions

View file

@ -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) {

View file

@ -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 {

View file

@ -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)
}
}

View file

@ -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 {

View file

@ -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) {
}
}
}
}

View file

@ -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

View file

@ -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 {

View file

@ -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)
}
}

View file

@ -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
}