Implement Knowledge City platform, organizer and DAV integration
Capture accumulated application, UI, CLI, regression tests and design documentation changes, including task project mapping and default CalDAV list naming. Keep deployment data, backups, local credentials and build artifacts out of Git. Move the Compose enrollment token to an ignored local environment file.
This commit is contained in:
1 parent
288e6e94ac
commit
c1175d389f
699 files changed
+110197
-4117
No files matched your search
@@ -0,0 +1,109 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"pageswiki/internal/store"
|
||||
)
|
||||
|
||||
func TestObjectScopeDoesNotExtendDomainAuthority(t *testing.T) {
|
||||
s, token, domain := pathMutationServerFixture(t)
|
||||
principal, err := s.store.PrincipalForSession(domain, token)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
object, err := s.store.CreateObject("page")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := s.store.DB.Exec(`INSERT INTO paths(domain_uuid,path,object_uuid,created_at) VALUES('foreign-domain','/private',?,1)`, object); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
rev, err := s.store.SaveRevision(object, "foreign secret", "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, capability := range []string{"read", "write", "create", "link", "delete"} {
|
||||
if err := s.authorizePrincipalObject(domain, principal.UUID, capability, object); !errors.Is(err, store.ErrAccessDenied) {
|
||||
t.Fatalf("broad Domain %s authorized a foreign Object: %v", capability, err)
|
||||
}
|
||||
}
|
||||
if err := s.authorizePrincipalRevision(domain, principal.UUID, "read", rev); !errors.Is(err, store.ErrAccessDenied) {
|
||||
t.Fatalf("foreign Revision bypassed Object scope: %v", err)
|
||||
}
|
||||
w := pathMutationRequest(s.handleSaveRevisionAPI, token, "POST", "/_/api/v1/revision/save", map[string]string{"object_uuid": object, "body": "overwrite"})
|
||||
if w.Code != http.StatusForbidden {
|
||||
t.Fatalf("foreign save = %d %s", w.Code, w.Body.String())
|
||||
}
|
||||
w = pathMutationRequest(s.handleBindPathAPI, token, "POST", "/_/api/v1/path/bind", map[string]string{"object_uuid": object, "path": "/stolen"})
|
||||
if w.Code != http.StatusForbidden || s.store.PathExistsInDomain(domain, "/stolen") {
|
||||
t.Fatalf("foreign binding = %d", w.Code)
|
||||
}
|
||||
var role string
|
||||
if err := s.store.DB.QueryRow(`SELECT b.role_uuid FROM auth_role_bindings b JOIN domain_memberships m ON m.uuid=b.membership_uuid WHERE m.domain_uuid=? AND m.principal_uuid=? LIMIT 1`, domain, principal.UUID).Scan(&role); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := s.store.DB.Exec(`INSERT INTO auth_capability_grants(uuid,role_uuid,capability,target_type,target_id,created_at_ms) VALUES('wild-object',?,'read','object','*',1)`, role); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.authorizePrincipalObject(domain, principal.UUID, "read", object); !errors.Is(err, store.ErrAccessDenied) {
|
||||
t.Fatalf("wildcard Object grant crossed a Domain: %v", err)
|
||||
}
|
||||
if _, err := s.store.DB.Exec(`INSERT INTO auth_capability_grants(uuid,role_uuid,capability,target_type,target_id,created_at_ms) VALUES('exact-object',?,'read','object',?,1)`, role, object); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.authorizePrincipalRevision(domain, principal.UUID, "read", rev); err != nil {
|
||||
t.Fatalf("explicit Object grant was lost: %v", err)
|
||||
}
|
||||
if _, err = s.store.DB.Exec(`INSERT INTO locality_access_policies VALUES('foreign-domain','quartier','private','/private',1,'source-admin',3)`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = s.authorizePrincipalRevision(domain, principal.UUID, "read", rev); !errors.Is(err, store.ErrAccessDenied) {
|
||||
t.Fatalf("foreign exact grant bypassed source ACL: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestObjectScopeCreateSaveBindAndRelocation(t *testing.T) {
|
||||
s, token, domain := pathMutationServerFixture(t)
|
||||
principal, err := s.store.PrincipalForSession(domain, token)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
w := pathMutationRequest(s.handleCreateObjectAPI, token, "POST", "/_/api/v1/object/create", map[string]string{"kind": "page"})
|
||||
var created struct{ UUID string }
|
||||
if w.Code != http.StatusOK || json.Unmarshal(w.Body.Bytes(), &created) != nil || created.UUID == "" {
|
||||
t.Fatalf("create = %d %s", w.Code, w.Body.String())
|
||||
}
|
||||
if allowed, err := s.store.ObjectInDomainAuthorityScope(domain, created.UUID); err != nil || !allowed {
|
||||
t.Fatalf("created provenance = %v %v", allowed, err)
|
||||
}
|
||||
if allowed, err := s.store.ObjectInDomainAuthorityScope("foreign-domain", created.UUID); err != nil || allowed {
|
||||
t.Fatalf("creation leaked authority = %v %v", allowed, err)
|
||||
}
|
||||
w = pathMutationRequest(s.handleSaveRevisionAPI, token, "POST", "/_/api/v1/revision/save", map[string]string{"object_uuid": created.UUID, "body": "first"})
|
||||
if w.Code != http.StatusOK {
|
||||
t.Fatalf("save unbound created Object = %d %s", w.Code, w.Body.String())
|
||||
}
|
||||
w = pathMutationRequest(s.handleBindPathAPI, token, "POST", "/_/api/v1/path/bind", map[string]string{"object_uuid": created.UUID, "path": "/created"})
|
||||
if w.Code != http.StatusOK {
|
||||
t.Fatalf("bind created Object = %d %s", w.Code, w.Body.String())
|
||||
}
|
||||
if _, err := s.store.DB.Exec(`UPDATE paths SET domain_uuid='foreign-domain' WHERE object_uuid=?`, created.UUID); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.authorizePrincipalObject(domain, principal.UUID, "read", created.UUID); !errors.Is(err, store.ErrAccessDenied) {
|
||||
t.Fatalf("creation provenance survived foreign relocation: %v", err)
|
||||
}
|
||||
legacy, err := s.store.CreateObject("page")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, id := range []string{legacy, "nonexistent"} {
|
||||
if err := s.authorizePrincipalObject(domain, principal.UUID, "read", id); !errors.Is(err, store.ErrAccessDenied) {
|
||||
t.Fatalf("unproven Object authorized: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user