mirror of
https://github.com/TwiN/gatus.git
synced 2024-11-24 17:04:42 +01:00
6bb65f4eec
Fixes #468
47 lines
1.4 KiB
Go
47 lines
1.4 KiB
Go
package api
|
|
|
|
import (
|
|
"io"
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/TwiN/gatus/v5/security"
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
func TestConfigHandler_ServeHTTP(t *testing.T) {
|
|
securityConfig := &security.Config{
|
|
OIDC: &security.OIDCConfig{
|
|
IssuerURL: "https://sso.gatus.io/",
|
|
RedirectURL: "http://localhost:80/authorization-code/callback",
|
|
Scopes: []string{"openid"},
|
|
AllowedSubjects: []string{"user1@example.com"},
|
|
},
|
|
}
|
|
handler := ConfigHandler{securityConfig: securityConfig}
|
|
// Create a fake router. We're doing this because I need the gate to be initialized.
|
|
app := fiber.New()
|
|
app.Get("/api/v1/config", handler.GetConfig)
|
|
err := securityConfig.ApplySecurityMiddleware(app)
|
|
if err != nil {
|
|
t.Error("expected err to be nil, but was", err)
|
|
}
|
|
// Test the config handler
|
|
request, _ := http.NewRequest("GET", "/api/v1/config", http.NoBody)
|
|
response, err := app.Test(request)
|
|
if err != nil {
|
|
t.Error("expected err to be nil, but was", err)
|
|
}
|
|
defer response.Body.Close()
|
|
if response.StatusCode != http.StatusOK {
|
|
t.Error("expected code to be 200, but was", response.StatusCode)
|
|
}
|
|
body, err := io.ReadAll(response.Body)
|
|
if err != nil {
|
|
t.Error("expected err to be nil, but was", err)
|
|
}
|
|
if string(body) != `{"oidc":true,"authenticated":false}` {
|
|
t.Error("expected body to be `{\"oidc\":true,\"authenticated\":false}`, but was", string(body))
|
|
}
|
|
}
|