feat(admin): enable multi-users (#67)
* feat(userstore): support ListUsers * feat(userstore): support del users * feat(multiusers): support list users and delete user apis * feat(client/web): add new apis to web client * fix(ui/panes): move each pane out of the container * feat(ui): add admin pane * feat(users): support force set password api * feat(ui/admin-pane): add functions to admin pane * feat(users): support self API and move uploading folder to home * fix(users): remove home folder when deleting user * fix(ui): remove useless function * feat(ui/panes): hide admin menu if user is not admin * fix(server/files): list home path is incorrect * fix(server): 1.listHome return incorrect cwd 2.addUser init folder with incorrect uid 3.check ns before using * test(server): add regression test cases * test(users, files): add e2e test for concurrent operations * fix(test): clean ups
This commit is contained in:
parent
916ec7c2dc
commit
aefaca98b3
28 changed files with 1562 additions and 478 deletions
|
@ -1,8 +1,14 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
// "path"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"path"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/ihexxa/gocfg"
|
||||
|
@ -64,3 +70,104 @@ func compareFileContent(fs fspkg.ISimpleFS, uid, filePath string, expectedConten
|
|||
|
||||
return string(gotContent) == expectedContent, nil
|
||||
}
|
||||
|
||||
func assertUploadOK(t *testing.T, filePath, content, addr string, token *http.Cookie) bool {
|
||||
cl := client.NewFilesClient(addr, token)
|
||||
|
||||
fileSize := int64(len([]byte(content)))
|
||||
res, _, errs := cl.Create(filePath, fileSize)
|
||||
if len(errs) > 0 {
|
||||
t.Error(errs)
|
||||
return false
|
||||
} else if res.StatusCode != 200 {
|
||||
t.Error(res.StatusCode)
|
||||
return false
|
||||
}
|
||||
|
||||
base64Content := base64.StdEncoding.EncodeToString([]byte(content))
|
||||
res, _, errs = cl.UploadChunk(filePath, base64Content, 0)
|
||||
if len(errs) > 0 {
|
||||
t.Error(errs)
|
||||
return false
|
||||
} else if res.StatusCode != 200 {
|
||||
t.Error(res.StatusCode)
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func assertDownloadOK(t *testing.T, filePath, content, addr string, token *http.Cookie) bool {
|
||||
var (
|
||||
res *http.Response
|
||||
body string
|
||||
errs []error
|
||||
fileSize = int64(len([]byte(content)))
|
||||
)
|
||||
|
||||
cl := client.NewFilesClient(addr, token)
|
||||
|
||||
rd := rand.Intn(3)
|
||||
switch rd {
|
||||
case 0:
|
||||
res, body, errs = cl.Download(filePath, map[string]string{})
|
||||
case 1:
|
||||
res, body, errs = cl.Download(filePath, map[string]string{
|
||||
"Range": fmt.Sprintf("bytes=0-%d", fileSize-1),
|
||||
})
|
||||
case 2:
|
||||
res, body, errs = cl.Download(filePath, map[string]string{
|
||||
"Range": fmt.Sprintf("bytes=0-%d, %d-%d", (fileSize-1)/2, (fileSize-1)/2+1, fileSize-1),
|
||||
})
|
||||
}
|
||||
|
||||
fileName := path.Base(filePath)
|
||||
contentDispositionHeader := res.Header.Get("Content-Disposition")
|
||||
if len(errs) > 0 {
|
||||
t.Error(errs)
|
||||
return false
|
||||
}
|
||||
if res.StatusCode != 200 && res.StatusCode != 206 {
|
||||
t.Error(res.StatusCode)
|
||||
return false
|
||||
}
|
||||
if contentDispositionHeader != fmt.Sprintf(`attachment; filename="%s"`, fileName) {
|
||||
t.Errorf("incorrect Content-Disposition header: %s", contentDispositionHeader)
|
||||
return false
|
||||
}
|
||||
|
||||
switch rd {
|
||||
case 0:
|
||||
if body != content {
|
||||
t.Errorf("body not equal got(%s) expect(%s)\n", body, content)
|
||||
return false
|
||||
}
|
||||
case 1:
|
||||
if body[2:] != content { // body returned by gorequest contains the first CRLF
|
||||
t.Errorf("body not equal got(%s) expect(%s)\n", body[2:], content)
|
||||
return false
|
||||
}
|
||||
default:
|
||||
body = body[2:] // body returned by gorequest contains the first CRLF
|
||||
realBody := ""
|
||||
boundaryEnd := strings.Index(body, "\r\n")
|
||||
boundary := body[0:boundaryEnd]
|
||||
bodyParts := strings.Split(body, boundary)
|
||||
|
||||
for i, bodyPart := range bodyParts {
|
||||
if i == 0 || i == len(bodyParts)-1 {
|
||||
continue
|
||||
}
|
||||
start := strings.Index(bodyPart, "\r\n\r\n")
|
||||
|
||||
fmt.Printf("<%s>", bodyPart[start+4:len(bodyPart)-2]) // ignore the last CRLF
|
||||
realBody += bodyPart[start+4 : len(bodyPart)-2]
|
||||
}
|
||||
if realBody != content {
|
||||
t.Errorf("multi body not equal got(%s) expect(%s)\n", realBody, content)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue