Files
phishingclub/backend/service/remoteBrowser_test.go
2026-12-01 21:25:01 +01:00

43 lines
1.5 KiB
Go

package service
import (
"testing"
"github.com/google/uuid"
"github.com/phishingclub/phishingclub/data"
"go.uber.org/zap/zapcore"
)
func TestLiveSessionAudit(t *testing.T) {
auditLogger, buf := bufferLogger(zapcore.InfoLevel)
rb := &RemoteBrowser{Common: Common{Logger: auditLogger}}
admin := adminSession(uuid.New(), data.RoleSuperAdministrator)
other := adminSession(uuid.New(), data.RoleCompanyUser)
// an allowed list is polled by the page and writes nothing
if err := rb.AuthorizeLiveSession(admin, "ListLiveSessions"); err != nil {
t.Fatal(err)
}
if err := rb.AuthorizeLiveSession(other, "WatchLiveSession"); err == nil {
t.Fatal("expected a role without permissions to be refused")
}
rb.AuditLiveSession(admin, "WatchLiveSession", "cr-1", "camp-1", "control")
rb.AuditLiveSession(admin, "CloseLiveSession", "cr-1", "", "")
if got := auditEventsNamed(t, buf.String(), "RemoteBrowser.ListLiveSessions"); len(got) != 0 {
t.Fatalf("an allowed list must write nothing: %v", got)
}
watch := auditEventsNamed(t, buf.String(), "RemoteBrowser.WatchLiveSession")
if len(watch) != 2 || watch[0]["result"] != "denied" || watch[1]["result"] != "success" {
t.Fatalf("watch events: %v", watch)
}
d, _ := watch[1]["details"].(map[string]any)
if d["campaignRecipientId"] != "cr-1" || d["campaignId"] != "camp-1" || d["mode"] != "control" {
t.Fatalf("watch details: %v", d)
}
cl := auditEventsNamed(t, buf.String(), "RemoteBrowser.CloseLiveSession")
if len(cl) != 1 || cl[0]["result"] != "success" {
t.Fatalf("close events: %v", cl)
}
}