feat: expand companion platform, device controls, and memoir workflows
ci / verify (push) Canceled after 0s
ci / verify (push) Canceled after 0s
Add customer and operator login, BLE provisioning, device fleet controls, call memory, memoir generation, and refreshed family and maintenance portals. Include API contracts, migrations, firmware sources, tests, assets, and deployment documentation.
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
package identity
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestValidateDisplayName(t *testing.T) {
|
||||
for _, name := range []string{"", " ", "名字\n另一行", strings.Repeat("名", 81), string([]byte{0xff})} {
|
||||
if _, err := ValidateDisplayName(name); !errors.Is(err, ErrInvalidDisplayName) {
|
||||
t.Errorf("accepted invalid nickname %q", name)
|
||||
}
|
||||
}
|
||||
if name, err := ValidateDisplayName(" 家庭成员 "); err != nil || name != "家庭成员" {
|
||||
t.Fatalf("normalization %q %v", name, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDisplayNameOnlyChangesAuthenticatedIdentity(t *testing.T) {
|
||||
url := os.Getenv("TEST_DATABASE_URL")
|
||||
if url == "" {
|
||||
t.Skip("TEST_DATABASE_URL is not set")
|
||||
}
|
||||
ctx := context.Background()
|
||||
pool, err := pgxpool.New(ctx, url)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer pool.Close()
|
||||
repo := NewRepository(pool)
|
||||
owner := Principal{Issuer: localIssuer, Subject: ownerSubject}
|
||||
outsider := Principal{Issuer: localIssuer, Subject: outsiderSubject}
|
||||
before, err := repo.CurrentUser(ctx, owner)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
other, err := repo.CurrentUser(ctx, outsider)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer repo.UpdateDisplayName(ctx, owner, before.Accounts[0].DisplayName)
|
||||
if err := repo.UpdateDisplayName(ctx, owner, "测试家人"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
after, err := repo.CurrentUser(ctx, owner)
|
||||
if err != nil || after.Accounts[0].DisplayName != "测试家人" {
|
||||
t.Fatalf("nickname not saved: %v", err)
|
||||
}
|
||||
unchanged, err := repo.CurrentUser(ctx, outsider)
|
||||
if err != nil || unchanged.Accounts[0].DisplayName != other.Accounts[0].DisplayName {
|
||||
t.Fatal("another identity was modified")
|
||||
}
|
||||
if err := repo.UpdateDisplayName(ctx, Principal{}, "其他"); !errors.Is(err, ErrAccessDenied) {
|
||||
t.Fatalf("empty principal accepted: %v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user