more index cleanups to optimise space
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -5,11 +5,20 @@ import (
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
"vctp/internal/settings"
|
||||
)
|
||||
|
||||
func newLegacyGateHandler(enabled bool) *Handler {
|
||||
cfg := &settings.Settings{Values: &settings.SettingsYML{}}
|
||||
cfg.Values.Settings.EnableLegacyAPI = enabled
|
||||
return &Handler{
|
||||
Logger: newTestLogger(),
|
||||
Settings: cfg,
|
||||
}
|
||||
}
|
||||
|
||||
func TestDenyLegacyAPIDisabledByDefault(t *testing.T) {
|
||||
t.Setenv(legacyAPIEnvVar, "")
|
||||
h := &Handler{Logger: newTestLogger()}
|
||||
h := newLegacyGateHandler(false)
|
||||
rr := httptest.NewRecorder()
|
||||
|
||||
denied := h.denyLegacyAPI(rr, "/api/event/vm/create")
|
||||
@@ -24,14 +33,13 @@ func TestDenyLegacyAPIDisabledByDefault(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDenyLegacyAPIEnabledViaEnv(t *testing.T) {
|
||||
t.Setenv(legacyAPIEnvVar, "1")
|
||||
h := &Handler{Logger: newTestLogger()}
|
||||
func TestDenyLegacyAPIEnabledViaSettings(t *testing.T) {
|
||||
h := newLegacyGateHandler(true)
|
||||
rr := httptest.NewRecorder()
|
||||
|
||||
denied := h.denyLegacyAPI(rr, "/api/event/vm/create")
|
||||
if denied {
|
||||
t.Fatal("expected legacy API to be allowed when env var is set")
|
||||
t.Fatal("expected legacy API to be allowed when setting is enabled")
|
||||
}
|
||||
if rr.Body.Len() != 0 {
|
||||
t.Fatalf("expected no response body write, got: %s", rr.Body.String())
|
||||
@@ -39,10 +47,8 @@ func TestDenyLegacyAPIEnabledViaEnv(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestVmCreateEventHonorsLegacyGate(t *testing.T) {
|
||||
h := &Handler{Logger: newTestLogger()}
|
||||
|
||||
t.Run("disabled", func(t *testing.T) {
|
||||
t.Setenv(legacyAPIEnvVar, "")
|
||||
h := newLegacyGateHandler(false)
|
||||
req := httptest.NewRequest(http.MethodPost, "/api/event/vm/create", strings.NewReader("{invalid"))
|
||||
rr := httptest.NewRecorder()
|
||||
h.VmCreateEvent(rr, req)
|
||||
@@ -52,7 +58,7 @@ func TestVmCreateEventHonorsLegacyGate(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("enabled", func(t *testing.T) {
|
||||
t.Setenv(legacyAPIEnvVar, "1")
|
||||
h := newLegacyGateHandler(true)
|
||||
req := httptest.NewRequest(http.MethodPost, "/api/event/vm/create", strings.NewReader("{invalid"))
|
||||
rr := httptest.NewRecorder()
|
||||
h.VmCreateEvent(rr, req)
|
||||
|
||||
Reference in New Issue
Block a user