This commit is contained in:
2025-08-23 17:57:39 -04:00
parent fe85abff04
commit 9ca9c53baf
6 changed files with 59 additions and 9 deletions

View File

@ -4,6 +4,7 @@ import (
"bytes"
"context"
"encoding/json"
"io"
"net/http"
"net/http/httptest"
"testing"
@ -54,6 +55,7 @@ func (suite *IntegrationTestSuite) SetupSuite() {
"INTERNAL_HMAC_KEY": "test-hmac-key-for-integration-tests",
"AUTH_PROVIDER": "header",
"AUTH_HEADER_USER_EMAIL": "X-User-Email",
"JWT_SECRET": "test-jwt-secret-for-integration-tests",
"RATE_LIMIT_ENABLED": "false", // Disable for tests
"METRICS_ENABLED": "false",
},
@ -97,7 +99,7 @@ func (suite *IntegrationTestSuite) setupServer() {
// Initialize services
appService := services.NewApplicationService(appRepo, logger)
tokenService := services.NewTokenService(tokenRepo, appRepo, permRepo, grantRepo, suite.cfg.GetString("INTERNAL_HMAC_KEY"), suite.cfg, logger)
authService := services.NewAuthenticationService(suite.cfg, logger)
authService := services.NewAuthenticationService(suite.cfg, logger, permRepo)
// Initialize handlers
healthHandler := handlers.NewHealthHandler(suite.db, logger)
@ -396,7 +398,6 @@ func (suite *IntegrationTestSuite) TestStaticTokenWorkflow() {
suite.T().Run("VerifyStaticToken", func(t *testing.T) {
verifyReq := domain.VerifyRequest{
AppID: testApp.AppID,
Type: domain.TokenTypeStatic,
Token: createdToken.Token,
Permissions: []string{"repo.read"},
}
@ -483,6 +484,14 @@ func (suite *IntegrationTestSuite) TestUserTokenWorkflow() {
require.NoError(t, err)
defer resp.Body.Close()
// Debug: Print response body if not 200
if resp.StatusCode != http.StatusOK {
bodyBytes, _ := io.ReadAll(resp.Body)
resp.Body.Close()
resp.Body = io.NopCloser(bytes.NewReader(bodyBytes))
t.Logf("Login failed with status %d, body: %s", resp.StatusCode, string(bodyBytes))
}
assert.Equal(t, http.StatusOK, resp.StatusCode)
// The response should contain either a token directly or a redirect URL