various fixes to enable tests

This commit is contained in:
Tobiasz Heller 2023-05-29 20:03:01 +02:00
parent ba6c0abfeb
commit b36c04678c
7 changed files with 38 additions and 16 deletions

View File

@ -25,7 +25,12 @@ test: ## run unit tests
tests-e2e: ## run end to end tests
go test ./tests/...
## There is some race condition when running tests as go test -count=1 ./tests/... Come back at some point and fix it
go test ./tests/browser_extension/... -count=1
go test ./tests/icons/... -count=1
go test ./tests/mobile/... -count=1
go test ./tests/support/... -count=1
go test ./tests/system/... -count=1
vendor-licenses: ## report vendor licenses

View File

@ -6,7 +6,8 @@ services:
context: .
dockerfile: docker/api/Dockerfile
depends_on:
- mysql
mysql:
condition: service_healthy
volumes:
- ./migrations:/migrations
- go-modules:/go/pkg/mod
@ -35,6 +36,10 @@ services:
- "127.0.0.1:3306:3306"
environment:
- MYSQL_ROOT_PASSWORD=root
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
timeout: 20s
retries: 10
redis:
image: bitnami/redis:latest

View File

@ -2,6 +2,7 @@ package db
import (
"fmt"
"github.com/twofas/2fas-server/config"
"gorm.io/gorm/logger"

View File

@ -2,9 +2,10 @@ package logging
import (
"encoding/json"
"github.com/sirupsen/logrus"
"reflect"
"sync"
"github.com/sirupsen/logrus"
)
type Fields map[string]interface{}
@ -44,28 +45,35 @@ func Info(args ...interface{}) {
defaultFieldsMutex.Lock()
defer defaultFieldsMutex.Unlock()
customLogger.WithFields(defaultFields).Info(args)
customLogger.WithFields(defaultFields).Info(args...)
}
func Infof(format string, args ...interface{}) {
defaultFieldsMutex.Lock()
defer defaultFieldsMutex.Unlock()
customLogger.WithFields(defaultFields).Infof(format, args...)
}
func Error(args ...interface{}) {
defaultFieldsMutex.Lock()
defer defaultFieldsMutex.Unlock()
customLogger.WithFields(defaultFields).Error(args)
customLogger.WithFields(defaultFields).Error(args...)
}
func Warning(args ...interface{}) {
defaultFieldsMutex.Lock()
defer defaultFieldsMutex.Unlock()
customLogger.WithFields(defaultFields).Warning(args)
customLogger.WithFields(defaultFields).Warning(args...)
}
func Fatal(args ...interface{}) {
defaultFieldsMutex.Lock()
defer defaultFieldsMutex.Unlock()
customLogger.WithFields(defaultFields).Fatal(args)
customLogger.WithFields(defaultFields).Fatal(args...)
}
func WithField(key string, value interface{}) *logrus.Entry {

View File

@ -3,13 +3,14 @@ package push
import (
"context"
"encoding/json"
"io/ioutil"
"time"
firebase "firebase.google.com/go/v4"
"firebase.google.com/go/v4/messaging"
"github.com/twofas/2fas-server/internal/api/mobile/domain"
"github.com/twofas/2fas-server/internal/common/logging"
"google.golang.org/api/option"
"io/ioutil"
"time"
)
type Pusher interface {
@ -57,7 +58,7 @@ func (p *FcmPushClient) Send(ctx context.Context, message *messaging.Message) er
return err
}
logging.Info("FCM notification has been sent: %s", response)
logging.Infof("FCM notification has been sent: %s", response)
return nil
}

View File

@ -1,13 +1,14 @@
package security
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
"github.com/twofas/2fas-server/config"
httpsec "github.com/twofas/2fas-server/internal/common/http"
"net/http"
"net/http/httptest"
"testing"
)
func Test_DoNotAllowUntrustedIp(t *testing.T) {
@ -24,5 +25,5 @@ func Test_DoNotAllowUntrustedIp(t *testing.T) {
ctx.Request.Header.Set("X-Forwarded-For", "192.168.0.2")
whitelistMiddleware(ctx)
assert.Equal(t, recorder.Code, 401)
assert.Equal(t, recorder.Code, http.StatusForbidden)
}

View File

@ -5,12 +5,13 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"io/ioutil"
"net/http"
"net/url"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
const DebugHttpRequests = false