mirror of
https://github.com/twofas/2fas-server.git
synced 2024-12-24 01:50:24 +01:00
various fixes to enable tests
This commit is contained in:
parent
ba6c0abfeb
commit
b36c04678c
7
Makefile
7
Makefile
@ -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
|
||||
|
@ -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
|
||||
|
@ -2,6 +2,7 @@ package db
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/twofas/2fas-server/config"
|
||||
"gorm.io/gorm/logger"
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user