fix: pass tests

This commit is contained in:
Tobiasz Heller 2024-04-27 15:24:58 +02:00
parent c36c698f45
commit 919d2f244b
9 changed files with 13 additions and 40 deletions

1
.env
View File

@ -15,6 +15,7 @@ SECURITY_RATE_LIMIT_BE=100
SECURITY_RATE_LIMIT_MOBILE=100
PASS_ADDR=:8082
FAKE_MOBILE_PUSH=true
AWS_ACCESS_KEY_ID=test
AWS_SECRET_ACCESS_KEY=test

View File

@ -41,7 +41,7 @@ tests-e2e: ## run end to end tests
go test ./e2e-tests/mobile/... -count=1
go test ./e2e-tests/support/... -count=1
go test ./e2e-tests/system/... -count=1
go test ./e2e-tests/pass/... -count=1
PASS_ADDR="localhost:8088" go test ./e2e-tests/pass/... -count=1
vendor-licenses: ## report vendor licenses
go-licenses report ./cmd/api --template licenses.tpl > licenses.json 2> licenses-errors

View File

@ -9,7 +9,7 @@ import (
)
func main() {
logging.WithDefaultField("service_name", "pass")
logging.Init(logging.Fields{"service_name": "pass"})
var cfg config.PassConfig
err := envconfig.Process("", &cfg)

View File

@ -89,10 +89,11 @@ services:
group_add:
- '1000'
ports:
- "8084:8082"
- "8088:8082"
environment:
# overwrite AWS_ENDPOINT from .env file. One in env is used to running app from local also.
AWS_ENDPOINT: http://localstack-main:4566
AWS_REGION: us-east-1
env_file:
- .env
depends_on:
@ -113,7 +114,7 @@ services:
timeout: 5s
retries: 5
volumes:
- "./tests/localstack_init.sh:/etc/localstack/init/ready.d/localstack_init.sh" # ready hook
- "./e2e-tests/localstack_init.sh:/etc/localstack/init/ready.d/localstack_init.sh" # ready hook
- "./data/localstack:/var/lib/localstack"
- "/var/run/docker.sock:/var/run/docker.sock"

View File

@ -106,7 +106,7 @@ func getMobileToken(fcm string) (string, error) {
MobileSyncConfirmToken string `json:"mobile_sync_confirm_token"`
}
if err := request("GET", fmt.Sprintf("/mobile/sync/%s/token", fcm), "", nil, &resp); err != nil {
return "", fmt.Errorf("failed to get mobile token")
return "", fmt.Errorf("failed to get mobile token: %w", err)
}
return resp.MobileSyncConfirmToken, nil

View File

@ -7,8 +7,6 @@ import (
"time"
"github.com/gorilla/websocket"
"github.com/sirupsen/logrus"
"github.com/twofas/2fas-server/internal/common/logging"
"github.com/twofas/2fas-server/internal/pass/connection"
"github.com/twofas/2fas-server/internal/pass/sign"
@ -128,7 +126,7 @@ func (p *Pairing) ServePairingWS(w http.ResponseWriter, r *http.Request, extID s
}
}
func (p *Pairing) isExtensionPaired(ctx context.Context, extID string, log *logrus.Entry) (PairingInfo, bool) {
func (p *Pairing) isExtensionPaired(ctx context.Context, extID string, log logging.FieldLogger) (PairingInfo, bool) {
pairingInfo, err := p.store.GetPairingInfo(ctx, extID)
if err != nil {
log.Warn("Failed to get pairing info")

View File

@ -59,9 +59,7 @@ func NewServer(cfg config.PassConfig) *Server {
router := gin.New()
router.Use(recovery.RecoveryMiddleware())
router.Use(httphelpers.RequestIdMiddleware())
router.Use(httphelpers.CorrelationIdMiddleware())
// TODO: don't log auth headers.
router.Use(httphelpers.LoggingMiddleware())
router.Use(httphelpers.RequestJsonLogger())
router.GET("/health", func(context *gin.Context) {

View File

@ -8,10 +8,6 @@ import (
"testing"
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/kms"
"github.com/golang-jwt/jwt/v5"
"github.com/google/uuid"
)
@ -70,16 +66,6 @@ func createTestService(t *testing.T) Service {
}
func TestSignAndVerify(t *testing.T) {
sess, err := session.NewSession(&aws.Config{
Region: aws.String("us-east-1"),
Credentials: credentials.NewStaticCredentials("test", "test", ""),
S3ForcePathStyle: aws.Bool(true),
Endpoint: aws.String("http://localhost:4566"),
})
if err != nil {
t.Fatal(err)
}
kmsClient := kms.New(sess)
srv := createTestService(t)
now := time.Now()
@ -128,18 +114,7 @@ func TestSignAndVerify(t *testing.T) {
{
name: "invalid signature",
tokenFn: func() string {
resp, err := kmsClient.CreateKey(&kms.CreateKeyInput{
KeySpec: aws.String("ECC_NIST_P256"),
KeyUsage: aws.String("SIGN_VERIFY"),
})
if err != nil {
t.Fatal(err)
}
serviceWithAnotherKey, err := NewService(*resp.KeyMetadata.KeyId, kmsClient)
if err != nil {
t.Fatal(err)
}
serviceWithAnotherKey := createTestService(t)
token, err := serviceWithAnotherKey.SignAndEncode(Message{
ConnectionID: uuid.New().String(),
ExpiresAt: now.Add(-time.Hour),

View File

@ -75,7 +75,7 @@ func (s *Syncing) ServeSyncingRequestWS(w http.ResponseWriter, r *http.Request,
if err := s.sendTokenAndCloseConn(fcmToken, conn); err != nil {
log.Errorf("Failed to send token: %v", err)
}
log.Infof("Paring ws finished")
log.Infof("Sync ws finished")
return nil
}
@ -89,7 +89,7 @@ func (s *Syncing) ServeSyncingRequestWS(w http.ResponseWriter, r *http.Request,
for {
select {
case <-maxWaitC:
log.Info("Closing paring ws after timeout")
log.Info("Closing sync ws after timeout")
return nil
case <-connectedCheckTicker.C:
if syncConfirmed := s.isSyncConfirmed(r.Context(), fcmToken); syncConfirmed {
@ -97,7 +97,7 @@ func (s *Syncing) ServeSyncingRequestWS(w http.ResponseWriter, r *http.Request,
log.Errorf("Failed to send token: %v", err)
return nil
}
log.Infof("Paring ws finished")
log.Infof("Sync ws finished")
return nil
}
}