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 SECURITY_RATE_LIMIT_MOBILE=100
PASS_ADDR=:8082 PASS_ADDR=:8082
FAKE_MOBILE_PUSH=true
AWS_ACCESS_KEY_ID=test AWS_ACCESS_KEY_ID=test
AWS_SECRET_ACCESS_KEY=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/mobile/... -count=1
go test ./e2e-tests/support/... -count=1 go test ./e2e-tests/support/... -count=1
go test ./e2e-tests/system/... -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 vendor-licenses: ## report vendor licenses
go-licenses report ./cmd/api --template licenses.tpl > licenses.json 2> licenses-errors go-licenses report ./cmd/api --template licenses.tpl > licenses.json 2> licenses-errors

View File

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

View File

@ -89,10 +89,11 @@ services:
group_add: group_add:
- '1000' - '1000'
ports: ports:
- "8084:8082" - "8088:8082"
environment: environment:
# overwrite AWS_ENDPOINT from .env file. One in env is used to running app from local also. # overwrite AWS_ENDPOINT from .env file. One in env is used to running app from local also.
AWS_ENDPOINT: http://localstack-main:4566 AWS_ENDPOINT: http://localstack-main:4566
AWS_REGION: us-east-1
env_file: env_file:
- .env - .env
depends_on: depends_on:
@ -113,7 +114,7 @@ services:
timeout: 5s timeout: 5s
retries: 5 retries: 5
volumes: 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" - "./data/localstack:/var/lib/localstack"
- "/var/run/docker.sock:/var/run/docker.sock" - "/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"` MobileSyncConfirmToken string `json:"mobile_sync_confirm_token"`
} }
if err := request("GET", fmt.Sprintf("/mobile/sync/%s/token", fcm), "", nil, &resp); err != nil { 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 return resp.MobileSyncConfirmToken, nil

View File

@ -7,8 +7,6 @@ import (
"time" "time"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
"github.com/sirupsen/logrus"
"github.com/twofas/2fas-server/internal/common/logging" "github.com/twofas/2fas-server/internal/common/logging"
"github.com/twofas/2fas-server/internal/pass/connection" "github.com/twofas/2fas-server/internal/pass/connection"
"github.com/twofas/2fas-server/internal/pass/sign" "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) pairingInfo, err := p.store.GetPairingInfo(ctx, extID)
if err != nil { if err != nil {
log.Warn("Failed to get pairing info") log.Warn("Failed to get pairing info")

View File

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

View File

@ -8,10 +8,6 @@ import (
"testing" "testing"
"time" "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/golang-jwt/jwt/v5"
"github.com/google/uuid" "github.com/google/uuid"
) )
@ -70,16 +66,6 @@ func createTestService(t *testing.T) Service {
} }
func TestSignAndVerify(t *testing.T) { 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) srv := createTestService(t)
now := time.Now() now := time.Now()
@ -128,18 +114,7 @@ func TestSignAndVerify(t *testing.T) {
{ {
name: "invalid signature", name: "invalid signature",
tokenFn: func() string { tokenFn: func() string {
resp, err := kmsClient.CreateKey(&kms.CreateKeyInput{ serviceWithAnotherKey := createTestService(t)
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)
}
token, err := serviceWithAnotherKey.SignAndEncode(Message{ token, err := serviceWithAnotherKey.SignAndEncode(Message{
ConnectionID: uuid.New().String(), ConnectionID: uuid.New().String(),
ExpiresAt: now.Add(-time.Hour), 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 { if err := s.sendTokenAndCloseConn(fcmToken, conn); err != nil {
log.Errorf("Failed to send token: %v", err) log.Errorf("Failed to send token: %v", err)
} }
log.Infof("Paring ws finished") log.Infof("Sync ws finished")
return nil return nil
} }
@ -89,7 +89,7 @@ func (s *Syncing) ServeSyncingRequestWS(w http.ResponseWriter, r *http.Request,
for { for {
select { select {
case <-maxWaitC: case <-maxWaitC:
log.Info("Closing paring ws after timeout") log.Info("Closing sync ws after timeout")
return nil return nil
case <-connectedCheckTicker.C: case <-connectedCheckTicker.C:
if syncConfirmed := s.isSyncConfirmed(r.Context(), fcmToken); syncConfirmed { 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) log.Errorf("Failed to send token: %v", err)
return nil return nil
} }
log.Infof("Paring ws finished") log.Infof("Sync ws finished")
return nil return nil
} }
} }