Files

51 lines
2.4 KiB
Go

// Copyright (c) 2026 Storm Dragon
// SPDX-License-Identifier: GPL-3.0-or-later
package tentaclewire
import "testing"
func TestSessionNegotiationRequiresIndependentGrants(t *testing.T) {
cases := []struct {
name string
minor int
apis, grants []string
valid bool
}{
{"legacy", 0, []string{"commands", "presentation"}, []string{"commands", "presentation"}, true},
{"legacy order", 0, []string{"presentation", "commands"}, []string{"presentation", "commands"}, false},
{"events only", 1, []string{"session-events", "commands"}, nil, true},
{"explicit sets", 1, []string{"remote-access", "interaction", "session-events", "commands", "presentation"}, []string{"output-observe", "interaction", "presentation"}, true},
{"missing events", 1, []string{"remote-access", "commands"}, []string{"output-observe"}, false},
{"grant without API", 1, []string{"session-events", "commands"}, []string{"output-observe"}, false},
{"API without grant", 1, []string{"session-events", "commands", "remote-access"}, nil, false},
{"unknown grant", 1, []string{"session-events", "commands", "remote-access"}, []string{"execute"}, false},
{"duplicate grant", 1, []string{"session-events", "commands", "remote-access"}, []string{"output-observe", "output-observe"}, false},
{"duplicate API", 1, []string{"session-events", "commands", "commands"}, nil, false},
{"missing prerequisite", 1, []string{"session-events", "commands", "interaction"}, []string{"interaction"}, false},
{"legacy capability in 1.1", 1, []string{"session-events", "commands"}, []string{"commands"}, false},
{"future version", 2, []string{"session-events", "commands"}, nil, false},
}
for _, item := range cases {
t.Run(item.name, func(t *testing.T) {
if ValidNegotiation(item.minor, item.apis, item.grants) != item.valid {
t.Fatal("wrong negotiation result")
}
})
}
}
func TestRemoteRevocationIdentifiesExactlyOneActionOrLease(t *testing.T) {
token := "0123456789abcdef0123456789abcdef"
for _, item := range []struct {
action, lease string
valid bool
}{
{token, "", true}, {"", token, true}, {token, token, false}, {"", "", false}, {"short", "", false},
} {
event := SessionEvent{Sequence: 1, Epoch: 1, Kind: "remote.revoked", Reason: "expired", Action: item.action, Lease: item.lease}
if ValidSessionEvent(event) != item.valid {
t.Fatalf("unexpected validation for %+v", item)
}
}
}