Web client refinement (#16)

* fix(files/handler): add base64 decode for content

* fix(singleuser): pick user name from jwt token and encode content

* fix(singleuser): add public path check, abstract user info from token

* fix(singleuser): update singleuser client

* fix(server): fix test and enable auth by default

* feat(client/web): add web client

* fix(client/web): refine css styles

* fix(client/web): refine styles

* fix(client/web): refine styles, add test and fix bugs

* test(client/web): add web client tests

* fix(client/web): refactor client interface and enhance the robustness

* chore(client/web): ignore js bundles

* test(files): call sync before check

Co-authored-by: Jia He <jiah@nvidia.com>
This commit is contained in:
Hexxa 2020-12-16 23:39:26 +08:00 committed by GitHub
parent 0265baf1b1
commit ba6a5373d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
53 changed files with 9192 additions and 158 deletions

View file

@ -49,7 +49,7 @@ func DefaultConfig() (string, error) {
OpenTTL: 60, // 1 min
},
Users: &UsersCfg{
EnableAuth: false,
EnableAuth: true,
DefaultAdmin: "",
DefaultAdminPwd: "",
CookieTTL: 3600 * 24 * 7, // 1 week
@ -61,10 +61,10 @@ func DefaultConfig() (string, error) {
},
Server: &ServerCfg{
Debug: false,
Host: "127.0.0.1",
Host: "0.0.0.0",
Port: 8888,
ReadTimeout: 2000,
WriteTimeout: 2000,
WriteTimeout: 1000 * 3600 * 24, // 1 day
MaxHeaderBytes: 512,
},
}

View file

@ -124,7 +124,7 @@ func initHandlers(router *gin.Engine, cfg gocfg.ICfg, deps *depidx.Deps) (*gin.E
// middleware
router.Use(userHdrs.Auth())
// tmp static server
router.Use(static.Serve("/", static.LocalFile("../static", false)))
router.Use(static.Serve("/", static.LocalFile("../public", false)))
// handler
v1 := router.Group("/v1")
@ -132,6 +132,7 @@ func initHandlers(router *gin.Engine, cfg gocfg.ICfg, deps *depidx.Deps) (*gin.E
usersAPI := v1.Group("/users")
usersAPI.POST("/login", userHdrs.Login)
usersAPI.POST("/logout", userHdrs.Logout)
usersAPI.GET("/isauthed", userHdrs.IsAuthed)
usersAPI.PATCH("/pwd", userHdrs.SetPwd)
filesAPI := v1.Group("/fs")

View file

@ -2,6 +2,7 @@ package server
import (
"crypto/sha1"
"encoding/base64"
"fmt"
"math/rand"
"net/http"
@ -60,7 +61,8 @@ func TestFileHandlers(t *testing.T) {
return false
}
res, _, errs = cl.UploadChunk(filePath, content, 0)
base64Content := base64.StdEncoding.EncodeToString([]byte(content))
res, _, errs = cl.UploadChunk(filePath, base64Content, 0)
if len(errs) > 0 {
t.Error(errs)
return false
@ -172,7 +174,9 @@ func TestFileHandlers(t *testing.T) {
right = len(contentBytes)
}
res, _, errs = cl.UploadChunk(filePath, string(contentBytes[i:right]), int64(i))
chunk := contentBytes[i:right]
chunkBase64 := base64.StdEncoding.EncodeToString(chunk)
res, _, errs = cl.UploadChunk(filePath, chunkBase64, int64(i))
i = right
if len(errs) > 0 {
t.Fatal(errs)
@ -193,6 +197,11 @@ func TestFileHandlers(t *testing.T) {
}
}
err = fs.Sync()
if err != nil {
t.Fatal(err)
}
// check uploaded file
fsFilePath := filepath.Join(fileshdr.FsDir, filePath)
info, err = fs.Stat(fsFilePath)
@ -245,6 +254,11 @@ func TestFileHandlers(t *testing.T) {
assertUploadOK(t, filePath, content)
}
err = fs.Sync()
if err != nil {
t.Fatal(err)
}
_, lResp, errs := cl.List(dirPath)
if len(errs) > 0 {
t.Fatal(errs)
@ -292,6 +306,11 @@ func TestFileHandlers(t *testing.T) {
}
}
err = fs.Sync()
if err != nil {
t.Fatal(err)
}
_, lResp, errs := cl.List(dstDir)
if len(errs) > 0 {
t.Fatal(errs)

View file

@ -54,14 +54,14 @@ func TestSingleUserHandlers(t *testing.T) {
token := client.GetCookie(resp.Cookies(), su.TokenCookie)
resp, _, errs = suCl.SetPwd(adminName, adminPwd, adminNewPwd, token)
resp, _, errs = suCl.SetPwd(adminPwd, adminNewPwd, token)
if len(errs) > 0 {
t.Fatal(errs)
} else if resp.StatusCode != 200 {
t.Fatal(resp.StatusCode)
}
resp, _, errs = suCl.Logout(adminName, token)
resp, _, errs = suCl.Logout(token)
if len(errs) > 0 {
t.Fatal(errs)
} else if resp.StatusCode != 200 {