feat: polish workspace transfers and verify Craft server file workflows
This commit is contained in:
1 parent
7fd7ae6733
commit
c209f1effc
49 files changed
+1459
-670
No files matched your search
@@ -0,0 +1,89 @@
|
||||
package fbhttp
|
||||
|
||||
import (
|
||||
"github.com/filebrowser/filebrowser/v2/diskcache"
|
||||
"github.com/filebrowser/filebrowser/v2/frontend"
|
||||
"github.com/filebrowser/filebrowser/v2/img"
|
||||
"github.com/filebrowser/filebrowser/v2/settings"
|
||||
"github.com/filebrowser/filebrowser/v2/users"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// The browser operates on an isolated test filesystem through the production
|
||||
// HTTP handlers. Authentication is injected only in this test binary.
|
||||
func TestWorkspaceBrowserQA(t *testing.T) {
|
||||
if os.Getenv("FILEBROWSER_QA") != "1" {
|
||||
t.Skip("optional full browser QA")
|
||||
}
|
||||
root := t.TempDir()
|
||||
fixtures := os.Getenv("FILEBROWSER_QA_FIXTURES")
|
||||
if fixtures == "" {
|
||||
t.Fatal("missing fixture directory")
|
||||
}
|
||||
if err := os.CopyFS(root, os.DirFS(fixtures)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, id := range []string{"wordcraft", "gridcraft", "deckcraft", "pdfcraft"} {
|
||||
data, err := blankCraftDocument(id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ext := map[string]string{"wordcraft": "docx", "gridcraft": "xlsx", "deckcraft": "pptx", "pdfcraft": "pdf"}[id]
|
||||
if err := os.WriteFile(filepath.Join(root, "document."+ext), data, 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if data, err := os.ReadFile("testdata/deckcraft-blank.deckcraft"); err == nil {
|
||||
os.WriteFile(filepath.Join(root, "native.deckcraft"), data, 0600)
|
||||
}
|
||||
st := scopedUserStorage(t, root, users.Permissions{Admin: true, Create: true, Modify: true, Rename: true, Delete: true, Share: true, Download: true}, []byte("qa-key"))
|
||||
config, _ := st.Settings.Get()
|
||||
config.Branding.Name = "File Browser"
|
||||
config.Tus.ChunkSize = 1 << 20
|
||||
config.Tus.RetryCount = 1
|
||||
config.DownloadArchiveFormat = "zip"
|
||||
st.Settings.Save(config)
|
||||
serverConfig := &settings.Server{Root: root, AddonsPath: os.Getenv("FILEBROWSER_QA_ADDONS"), EnableThumbnails: true, ResizePreview: true, TypeDetectionByHeader: true}
|
||||
assets, err := fs.Sub(frontend.Assets(), "dist")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cache := diskcache.NewNoOp()
|
||||
uploads, err := NewUploadCache("")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer uploads.Close()
|
||||
handler, err := NewHandler(img.New(2), cache, uploads, st, serverConfig, assets)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
r = authorizeTestRequest(r, testSession(1, "QA", true))
|
||||
if r.URL.Path == "/api/session" {
|
||||
u, err := st.Users.Get(root, false, uint(1))
|
||||
if err != nil {
|
||||
http.Error(w, "user", 500)
|
||||
return
|
||||
}
|
||||
u.DisplayName = "QA Account"
|
||||
renderJSON(w, r, ssoUserInfo(u))
|
||||
return
|
||||
}
|
||||
handler.ServeHTTP(w, r)
|
||||
}))
|
||||
defer server.Close()
|
||||
command := exec.Command("node", os.Getenv("FILEBROWSER_QA_SCRIPT"))
|
||||
command.Env = append(os.Environ(), "FILEBROWSER_QA_URL="+server.URL, "FILEBROWSER_QA_ROOT="+root)
|
||||
output, err := command.CombinedOutput()
|
||||
if err != nil {
|
||||
t.Fatalf("%v\n%s", err, output)
|
||||
}
|
||||
t.Log(string(output))
|
||||
}
|
||||
Reference in new issue
Block a user