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.
71 lines
2.9 KiB
Go
71 lines
2.9 KiB
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
)
|
|
|
|
func TestObjectPurgeRequiresEveryLocalAliasGrant(t *testing.T) {
|
|
s, token, domain, role := restrictedPathMutationFixture(t)
|
|
object, err := s.store.CreatePageAtPathInDomain(domain, "/allowed")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := s.store.BindPathInDomain(domain, "/hidden", object); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := s.store.SaveRevision(object, "keep", "initial"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
grantMutationPath(t, s, role, "delete", "/allowed")
|
|
w := pathMutationRequest(s.handleDeleteObjectAPI, token, "POST", "/_/api/v1/object/delete", map[string]string{"object_uuid": object})
|
|
if w.Code != http.StatusForbidden {
|
|
t.Fatalf("one alias authorized a global purge: %d %s", w.Code, w.Body.String())
|
|
}
|
|
if !s.store.PathExistsInDomain(domain, "/allowed") || !s.store.PathExistsInDomain(domain, "/hidden") {
|
|
t.Fatal("denied Object purge deleted Paths")
|
|
}
|
|
grantMutationPath(t, s, role, "delete", "/hidden")
|
|
w = pathMutationRequest(s.handleDeleteObjectAPI, token, "POST", "/_/api/v1/object/delete", map[string]string{"object_uuid": object})
|
|
if w.Code != http.StatusNoContent {
|
|
t.Fatalf("fully authorized purge = %d %s", w.Code, w.Body.String())
|
|
}
|
|
if s.store.PathExistsInDomain(domain, "/allowed") || s.store.PathExistsInDomain(domain, "/hidden") {
|
|
t.Fatal("successful purge retained Paths")
|
|
}
|
|
var revisions int
|
|
if err := s.store.DB.QueryRow(`SELECT COUNT(*) FROM revisions WHERE object_uuid=?`, object).Scan(&revisions); err != nil || revisions != 0 {
|
|
t.Fatalf("successful purge silently became unlink: %d Revisions, %v", revisions, err)
|
|
}
|
|
}
|
|
|
|
func TestObjectPurgeRejectsOtherDomainAndUnboundObjects(t *testing.T) {
|
|
s, token, domain := pathMutationServerFixture(t)
|
|
object, err := s.store.CreatePageAtPathInDomain(domain, "/local")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := s.store.DB.Exec(`INSERT INTO paths(domain_uuid,path,object_uuid,created_at) VALUES('another-domain','/remote',?,1)`, object); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
unbound, err := s.store.CreateObject("page")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, object := range []string{object, unbound, "unknown-object"} {
|
|
w := pathMutationRequest(s.handleDeleteObjectAPI, token, "POST", "/_/api/v1/object/delete", map[string]string{"object_uuid": object})
|
|
if w.Code != http.StatusForbidden {
|
|
t.Fatalf("Domain admin purged shared/unowned Object %s: %d %s", object, w.Code, w.Body.String())
|
|
}
|
|
}
|
|
if !s.store.PathExistsInDomain(domain, "/local") || !s.store.PathExistsInDomain("another-domain", "/remote") {
|
|
t.Fatal("denied shared Object purge lost a binding")
|
|
}
|
|
for _, method := range []string{"GET", "PUT", "DELETE"} {
|
|
w := pathMutationRequest(s.handleDeleteObjectAPI, token, method, "/_/api/v1/object/delete", map[string]string{"object_uuid": object})
|
|
if w.Code != http.StatusMethodNotAllowed || w.Header().Get("Allow") != "POST" {
|
|
t.Fatalf("%s Object purge = %d", method, w.Code)
|
|
}
|
|
}
|
|
}
|