31 lines
746 B
Go
31 lines
746 B
Go
package models
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestPublicUserOmitsPhone(t *testing.T) {
|
|
u := &User{ID: "u1", Email: "user@test.local", Phone: "+15551234567", Name: "Tester"}
|
|
|
|
pub, err := json.Marshal(u.Public())
|
|
if err != nil {
|
|
t.Fatalf("marshal public: %v", err)
|
|
}
|
|
if strings.Contains(string(pub), "phone") || strings.Contains(string(pub), "+15551234567") {
|
|
t.Fatalf("PublicUser leaks phone: %s", pub)
|
|
}
|
|
|
|
self, err := json.Marshal(u.Self())
|
|
if err != nil {
|
|
t.Fatalf("marshal self: %v", err)
|
|
}
|
|
if !strings.Contains(string(self), "+15551234567") {
|
|
t.Fatalf("SelfUser missing phone: %s", self)
|
|
}
|
|
if !strings.Contains(string(self), `"phone"`) {
|
|
t.Fatalf("SelfUser phone not serialized: %s", self)
|
|
}
|
|
}
|