2026-07-16 10:08:54 +03:00
|
|
|
package gateway
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"net/http/httptest"
|
|
|
|
|
"testing"
|
|
|
|
|
|
2026-07-16 15:25:23 +03:00
|
|
|
"github.com/gofiber/fiber/v3"
|
2026-07-16 10:08:54 +03:00
|
|
|
|
|
|
|
|
"micrach/config"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestPingUsesLastAuthorizationHeader(t *testing.T) {
|
|
|
|
|
previousConfig := config.App
|
|
|
|
|
t.Cleanup(func() {
|
|
|
|
|
config.App = previousConfig
|
|
|
|
|
})
|
|
|
|
|
config.App.Gateway.ApiKey = "configured-key"
|
|
|
|
|
|
|
|
|
|
app := fiber.New()
|
|
|
|
|
app.Get("/api/ping", Ping)
|
|
|
|
|
|
|
|
|
|
req := httptest.NewRequest("GET", "/api/ping", nil)
|
|
|
|
|
req.Header.Add("Authorization", "wrong-key")
|
|
|
|
|
req.Header.Add("Authorization", "configured-key")
|
|
|
|
|
|
|
|
|
|
resp, err := app.Test(req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("test ping request: %v", err)
|
|
|
|
|
}
|
|
|
|
|
if resp.StatusCode != fiber.StatusOK {
|
|
|
|
|
t.Fatalf("expected status %d when final Authorization header matches, got %d", fiber.StatusOK, resp.StatusCode)
|
|
|
|
|
}
|
|
|
|
|
}
|