feat:runscope test
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gitea.hostxtra.co.uk/mrhid6/vantage/server/internal/models"
|
||||
)
|
||||
|
||||
func runFixture() *models.WorkflowRun {
|
||||
return &models.WorkflowRun{
|
||||
RunID: "r1",
|
||||
ServerRuns: []models.ServerRun{
|
||||
{ServerID: "stg-1", Hostname: "staging-web"},
|
||||
{ServerID: "prod-1", Hostname: "prod-db"},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// A run document names every host it touched, hostname included. A restricted
|
||||
// caller must see only its own, and must be told some entries are missing
|
||||
// without being told how many — the targets_restricted precedent.
|
||||
func TestScopeRunHidesOutOfScopeServerRuns(t *testing.T) {
|
||||
got := scopeRun(runFixture(), map[string]bool{"stg-1": true}, true)
|
||||
if len(got.ServerRuns) != 1 || got.ServerRuns[0].ServerID != "stg-1" {
|
||||
t.Fatalf("server_runs = %v, want only stg-1", got.ServerRuns)
|
||||
}
|
||||
for _, sr := range got.ServerRuns {
|
||||
if sr.Hostname == "prod-db" {
|
||||
t.Error("out-of-scope hostname survived filtering")
|
||||
}
|
||||
}
|
||||
if !got.ServersRestricted {
|
||||
t.Error("servers_restricted = false with an entry dropped")
|
||||
}
|
||||
}
|
||||
|
||||
func TestScopeRunLeavesUnrestrictedCallerWhole(t *testing.T) {
|
||||
got := scopeRun(runFixture(), nil, false)
|
||||
if len(got.ServerRuns) != 2 {
|
||||
t.Fatalf("server_runs = %v, want both", got.ServerRuns)
|
||||
}
|
||||
if got.ServersRestricted {
|
||||
t.Error("unrestricted caller told entries were restricted")
|
||||
}
|
||||
}
|
||||
|
||||
// A restricted caller whose scope happens to cover the whole run must not be
|
||||
// told anything was hidden — the flag is about disclosure, not about being
|
||||
// restricted in general.
|
||||
func TestScopeRunNoFlagWhenNothingDropped(t *testing.T) {
|
||||
got := scopeRun(runFixture(), map[string]bool{"stg-1": true, "prod-1": true}, true)
|
||||
if got.ServersRestricted {
|
||||
t.Error("servers_restricted set with nothing dropped")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user