Implement privileged event filtering and add comprehensive tests
Some checks failed
Go / build (push) Has been cancelled
Go / release (push) Has been cancelled

- Refactored the HandleReq function to improve the handling of privileged events, ensuring that only authorized users can access them based on their authentication status and associated tags.
- Introduced a new test suite for privileged event filtering, covering various scenarios including authorized access, unauthorized access, and edge cases with malformed tags.
- Enhanced the publisher logic to deny delivery of privileged events to unauthenticated subscribers.
- Bumped version to v0.17.18.
This commit is contained in:
2025-10-24 19:53:34 +01:00
parent bc8a557f07
commit 28ab665285
4 changed files with 557 additions and 35 deletions

View File

@@ -6,12 +6,13 @@ import (
"testing"
"time"
"encoding/json"
"lol.mleku.dev/chk"
"lol.mleku.dev/log"
"lukechampine.com/frand"
"next.orly.dev/pkg/encoders/event/examples"
"next.orly.dev/pkg/encoders/hex"
"encoding/json"
"next.orly.dev/pkg/encoders/tag"
"next.orly.dev/pkg/utils"
"next.orly.dev/pkg/utils/bufpool"
@@ -75,13 +76,15 @@ func TestExamplesCache(t *testing.T) {
c := bufpool.Get()
c = c[:0]
c = append(c, b...)
log.I.F("c: %s", c)
log.I.F("b: %s", b)
ev := New()
if err = json.Unmarshal(b, ev); chk.E(err) {
if _, err = ev.Unmarshal(c); chk.E(err) {
t.Fatal(err)
}
var b2 []byte
// can't use encoding/json.Marshal as it improperly escapes <, > and &.
if b2, err = json.Marshal(ev); err != nil {
if b2, err = ev.MarshalJSON(); err != nil {
t.Fatal(err)
}
if !utils.FastEqual(c, b2) {