mirror of
https://github.com/DeBrosOfficial/network.git
synced 2025-10-06 20:09:07 +00:00
- Require API key or JWT by default for client connections - Auto-derive namespace from JWT claim or API key format `ak_<rand>:<namespace>` - Deny calls if per-call namespace override mismatches resolved namespace - Guard Storage, PubSub, Database, and NetworkInfo operations with access checks - Add context helpers for consistent namespace override handling - Update docs and add end-to-end and unit tests for authentication logic
24 lines
754 B
Go
24 lines
754 B
Go
package storage
|
|
|
|
import "testing"
|
|
|
|
func TestRequestResponseJSON(t *testing.T) {
|
|
req := &StorageRequest{Type: MessageTypePut, Key: "k", Value: []byte("v"), Namespace: "ns"}
|
|
b, err := req.Marshal()
|
|
if err != nil { t.Fatal(err) }
|
|
var out StorageRequest
|
|
if err := out.Unmarshal(b); err != nil { t.Fatal(err) }
|
|
if out.Type != MessageTypePut || out.Key != "k" || out.Namespace != "ns" {
|
|
t.Fatalf("roundtrip mismatch: %+v", out)
|
|
}
|
|
|
|
resp := &StorageResponse{Success: true, Keys: []string{"a"}, Exists: true}
|
|
b, err = resp.Marshal()
|
|
if err != nil { t.Fatal(err) }
|
|
var outR StorageResponse
|
|
if err := outR.Unmarshal(b); err != nil { t.Fatal(err) }
|
|
if !outR.Success || !outR.Exists || len(outR.Keys) != 1 {
|
|
t.Fatalf("resp mismatch: %+v", outR)
|
|
}
|
|
}
|