simpleadmin-web/internal/live/live_test.go
Astra 9e4bc63201 GroupVerify: Verification page, overrides and public Verified tags
Shown only where GroupVerify is: staff get the Verification page once its gv_* tables are in
the database, and the public site shows "Verified" only while it's on (enabled, with a group)
and not missing from css_plugins list, which the poller reads once a minute over RCON.

- Verification page: plugin state and version, Steam group, saved member list, overrides.
- Overrides (@zio/verify, not on yourself unless Root): give, change, remove; player drawer
  shows why a player is or isn't verified.
- Root sets the group and turns it on/off: saved to gv_settings, and sent as css_gv_* when the
  plugin is loaded so it applies at once.
- gv_* times use GroupVerify's own timezone setting.
- MySQL integration test (SAW_TEST_DSN), unit tests for plugin list parsing and the show rule.
2026-10-02 17:59:26 +01:00

62 lines
2.1 KiB
Go

package live
import "testing"
const sample = `wpb {"v":1,"hostname":"zio.sh | Random Skills","map":"de_mirage","maxPlayers":24,"scoreT":7,"scoreCt":9,"warmup":false}
L 09/25/2026 - 20:00:00: something else the server logged
wpb {"userid":2,"name":"astra","steamid":"76561198012345601","team":3,"kills":21,"deaths":9,"ping":12,"bot":false}
wpb {"userid":5,"name":"BOT Kurt","steamid":"0","team":2,"kills":3,"deaths":10,"ping":0,"bot":true}
wpb end
`
func TestParse(t *testing.T) {
st, err := Parse(sample)
if err != nil {
t.Fatal(err)
}
if !st.Online || st.Map != "de_mirage" || st.ScoreT != 7 || st.ScoreCT != 9 || len(st.Players) != 2 {
t.Fatalf("unexpected %+v", st)
}
if h := st.Humans(); len(h) != 1 || h[0].UserID != 2 {
t.Fatalf("humans %+v", h)
}
if p, ok := st.Find("76561198012345601"); !ok || p.Kills != 21 {
t.Fatalf("find %+v %v", p, ok)
}
if _, ok := st.Find("0"); ok {
t.Fatal("bots must not be found by SteamID")
}
}
func TestParseErrors(t *testing.T) {
if _, err := Parse("Unknown command \"css_webpanel_status\"\n"); err == nil {
t.Fatal("missing plugin should be an error")
}
if _, err := Parse(`wpb {"v":1,"map":"x"}` + "\n"); err == nil {
t.Fatal("output without end marker should be an error")
}
}
func TestParsePlugins(t *testing.T) {
out := ` List of all plugins currently loaded by CounterStrikeSharp: 3 plugins loaded.
[#1:LOADED]: "CS2-SimpleAdmin (RELEASE)" (1.8.2b-zio10) by daffyy
Simple admin plugin
[#2:LOADED]: "GroupVerify" (0.2.0) by astra
Verifies players by Steam group membership or a manual override
[#3:UNLOADED]: "NoGoZones" (0.14.0) by astra
Termination Reason: whatever
`
loaded, ok := ParsePlugins(out)
if !ok {
t.Fatal("not recognised as a plugin list")
}
if loaded["GroupVerify"] != "0.2.0" || loaded["CS2-SimpleAdmin (RELEASE)"] != "1.8.2b-zio10" {
t.Fatalf("loaded %v", loaded)
}
if _, ok := loaded["NoGoZones"]; ok {
t.Fatal("unloaded plugins must not count as loaded")
}
if _, ok := ParsePlugins("Unknown command \"css_plugins\"\n"); ok {
t.Fatal("an error reply isn't a plugin list")
}
}