fix(clients): fix incorrect client naming
This commit is contained in:
parent
f0293fbc4c
commit
48b0ff2df0
14 changed files with 106 additions and 41 deletions
|
@ -11,24 +11,24 @@ import (
|
|||
"github.com/parnurzeal/gorequest"
|
||||
)
|
||||
|
||||
type SingleUserClient struct {
|
||||
type UsersClient struct {
|
||||
addr string
|
||||
r *gorequest.SuperAgent
|
||||
}
|
||||
|
||||
func NewSingleUserClient(addr string) *SingleUserClient {
|
||||
func NewUsersClient(addr string) *UsersClient {
|
||||
gr := gorequest.New()
|
||||
return &SingleUserClient{
|
||||
return &UsersClient{
|
||||
addr: addr,
|
||||
r: gr,
|
||||
}
|
||||
}
|
||||
|
||||
func (cl *SingleUserClient) url(urlpath string) string {
|
||||
func (cl *UsersClient) url(urlpath string) string {
|
||||
return fmt.Sprintf("%s%s", cl.addr, urlpath)
|
||||
}
|
||||
|
||||
func (cl *SingleUserClient) Login(user, pwd string) (*http.Response, string, []error) {
|
||||
func (cl *UsersClient) Login(user, pwd string) (*http.Response, string, []error) {
|
||||
return cl.r.Post(cl.url("/v1/users/login")).
|
||||
Send(multiusers.LoginReq{
|
||||
User: user,
|
||||
|
@ -37,13 +37,13 @@ func (cl *SingleUserClient) Login(user, pwd string) (*http.Response, string, []e
|
|||
End()
|
||||
}
|
||||
|
||||
func (cl *SingleUserClient) Logout(token *http.Cookie) (*http.Response, string, []error) {
|
||||
func (cl *UsersClient) Logout(token *http.Cookie) (*http.Response, string, []error) {
|
||||
return cl.r.Post(cl.url("/v1/users/logout")).
|
||||
AddCookie(token).
|
||||
End()
|
||||
}
|
||||
|
||||
func (cl *SingleUserClient) SetPwd(oldPwd, newPwd string, token *http.Cookie) (*http.Response, string, []error) {
|
||||
func (cl *UsersClient) SetPwd(oldPwd, newPwd string, token *http.Cookie) (*http.Response, string, []error) {
|
||||
return cl.r.Patch(cl.url("/v1/users/pwd")).
|
||||
Send(multiusers.SetPwdReq{
|
||||
OldPwd: oldPwd,
|
||||
|
@ -53,7 +53,7 @@ func (cl *SingleUserClient) SetPwd(oldPwd, newPwd string, token *http.Cookie) (*
|
|||
End()
|
||||
}
|
||||
|
||||
func (cl *SingleUserClient) ForceSetPwd(userID, newPwd string, token *http.Cookie) (*http.Response, string, []error) {
|
||||
func (cl *UsersClient) ForceSetPwd(userID, newPwd string, token *http.Cookie) (*http.Response, string, []error) {
|
||||
return cl.r.Patch(cl.url("/v1/users/pwd/force-set")).
|
||||
Send(multiusers.ForceSetPwdReq{
|
||||
ID: userID,
|
||||
|
@ -63,7 +63,7 @@ func (cl *SingleUserClient) ForceSetPwd(userID, newPwd string, token *http.Cooki
|
|||
End()
|
||||
}
|
||||
|
||||
func (cl *SingleUserClient) SetUser(ID uint64, role string, quota *db.Quota, token *http.Cookie) (*http.Response, string, []error) {
|
||||
func (cl *UsersClient) SetUser(ID uint64, role string, quota *db.Quota, token *http.Cookie) (*http.Response, string, []error) {
|
||||
return cl.r.Patch(cl.url("/v1/users/")).
|
||||
Send(multiusers.SetUserReq{
|
||||
ID: ID,
|
||||
|
@ -74,7 +74,7 @@ func (cl *SingleUserClient) SetUser(ID uint64, role string, quota *db.Quota, tok
|
|||
End()
|
||||
}
|
||||
|
||||
func (cl *SingleUserClient) AddUser(name, pwd, role string, token *http.Cookie) (*http.Response, *multiusers.AddUserResp, []error) {
|
||||
func (cl *UsersClient) AddUser(name, pwd, role string, token *http.Cookie) (*http.Response, *multiusers.AddUserResp, []error) {
|
||||
resp, body, errs := cl.r.Post(cl.url("/v1/users/")).
|
||||
AddCookie(token).
|
||||
Send(multiusers.AddUserReq{
|
||||
|
@ -97,14 +97,14 @@ func (cl *SingleUserClient) AddUser(name, pwd, role string, token *http.Cookie)
|
|||
return resp, auResp, errs
|
||||
}
|
||||
|
||||
func (cl *SingleUserClient) DelUser(id string, token *http.Cookie) (*http.Response, string, []error) {
|
||||
func (cl *UsersClient) DelUser(id string, token *http.Cookie) (*http.Response, string, []error) {
|
||||
return cl.r.Delete(cl.url("/v1/users/")).
|
||||
AddCookie(token).
|
||||
Param(handlers.UserIDParam, id).
|
||||
End()
|
||||
}
|
||||
|
||||
func (cl *SingleUserClient) ListUsers(token *http.Cookie) (*http.Response, *multiusers.ListUsersResp, []error) {
|
||||
func (cl *UsersClient) ListUsers(token *http.Cookie) (*http.Response, *multiusers.ListUsersResp, []error) {
|
||||
resp, body, errs := cl.r.Get(cl.url("/v1/users/list")).
|
||||
AddCookie(token).
|
||||
End()
|
||||
|
@ -121,7 +121,7 @@ func (cl *SingleUserClient) ListUsers(token *http.Cookie) (*http.Response, *mult
|
|||
return resp, lsResp, errs
|
||||
}
|
||||
|
||||
func (cl *SingleUserClient) AddRole(role string, token *http.Cookie) (*http.Response, string, []error) {
|
||||
func (cl *UsersClient) AddRole(role string, token *http.Cookie) (*http.Response, string, []error) {
|
||||
return cl.r.Post(cl.url("/v1/roles/")).
|
||||
AddCookie(token).
|
||||
Send(multiusers.AddRoleReq{
|
||||
|
@ -130,7 +130,7 @@ func (cl *SingleUserClient) AddRole(role string, token *http.Cookie) (*http.Resp
|
|||
End()
|
||||
}
|
||||
|
||||
func (cl *SingleUserClient) DelRole(role string, token *http.Cookie) (*http.Response, string, []error) {
|
||||
func (cl *UsersClient) DelRole(role string, token *http.Cookie) (*http.Response, string, []error) {
|
||||
return cl.r.Delete(cl.url("/v1/roles/")).
|
||||
AddCookie(token).
|
||||
Send(multiusers.DelRoleReq{
|
||||
|
@ -139,7 +139,7 @@ func (cl *SingleUserClient) DelRole(role string, token *http.Cookie) (*http.Resp
|
|||
End()
|
||||
}
|
||||
|
||||
func (cl *SingleUserClient) ListRoles(token *http.Cookie) (*http.Response, *multiusers.ListRolesResp, []error) {
|
||||
func (cl *UsersClient) ListRoles(token *http.Cookie) (*http.Response, *multiusers.ListRolesResp, []error) {
|
||||
resp, body, errs := cl.r.Get(cl.url("/v1/roles/list")).
|
||||
AddCookie(token).
|
||||
End()
|
||||
|
@ -156,7 +156,7 @@ func (cl *SingleUserClient) ListRoles(token *http.Cookie) (*http.Response, *mult
|
|||
return resp, lsResp, errs
|
||||
}
|
||||
|
||||
func (cl *SingleUserClient) Self(token *http.Cookie) (*http.Response, *multiusers.SelfResp, []error) {
|
||||
func (cl *UsersClient) Self(token *http.Cookie) (*http.Response, *multiusers.SelfResp, []error) {
|
||||
resp, body, errs := cl.r.Get(cl.url("/v1/users/self")).
|
||||
AddCookie(token).
|
||||
End()
|
||||
|
@ -173,7 +173,7 @@ func (cl *SingleUserClient) Self(token *http.Cookie) (*http.Response, *multiuser
|
|||
return resp, selfResp, errs
|
||||
}
|
||||
|
||||
func (cl *SingleUserClient) SetPreferences(prefers *db.Preferences, token *http.Cookie) (*http.Response, string, []error) {
|
||||
func (cl *UsersClient) SetPreferences(prefers *db.Preferences, token *http.Cookie) (*http.Response, string, []error) {
|
||||
return cl.r.Patch(cl.url("/v1/users/preferences")).
|
||||
Send(multiusers.SetPreferencesReq{
|
||||
Preferences: prefers,
|
||||
|
@ -182,13 +182,13 @@ func (cl *SingleUserClient) SetPreferences(prefers *db.Preferences, token *http.
|
|||
End()
|
||||
}
|
||||
|
||||
func (cl *SingleUserClient) IsAuthed(token *http.Cookie) (*http.Response, string, []error) {
|
||||
func (cl *UsersClient) IsAuthed(token *http.Cookie) (*http.Response, string, []error) {
|
||||
return cl.r.Get(cl.url("/v1/users/isauthed")).
|
||||
AddCookie(token).
|
||||
End()
|
||||
}
|
||||
|
||||
func (cl *SingleUserClient) ResetUsedSpace(userID uint64, token *http.Cookie) (*http.Response, string, []error) {
|
||||
func (cl *UsersClient) ResetUsedSpace(userID uint64, token *http.Cookie) (*http.Response, string, []error) {
|
||||
return cl.r.Put(cl.url("/v1/users/used-space")).
|
||||
Send(multiusers.ResetUsedSpaceReq{
|
||||
UserID: userID,
|
||||
|
|
|
@ -164,6 +164,7 @@ export interface IFilesClient {
|
|||
generateHash: (filePath: string) => Promise<Response>;
|
||||
download: (url: string) => Promise<Response>;
|
||||
search: (keywords: string[]) => Promise<Response<SearchItemsResp>>;
|
||||
reindex: () => Promise<Response>;
|
||||
}
|
||||
|
||||
export interface ISettingsClient {
|
||||
|
|
|
@ -268,6 +268,20 @@ export class UserForm extends React.Component<
|
|||
|
||||
<div className="hr"></div>
|
||||
|
||||
<div>
|
||||
<Flexbox
|
||||
children={List([
|
||||
<span>{this.props.msg.pkg.get("action.reindex.desc")}</span>,
|
||||
<button className="button-default" onClick={resetUsedSpace}>
|
||||
{this.props.msg.pkg.get("action.reindex")}
|
||||
</button>,
|
||||
])}
|
||||
childrenStyles={List([{}, { justifyContent: "flex-end" }])}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="hr"></div>
|
||||
|
||||
<Flexbox
|
||||
className="margin-t-m"
|
||||
children={List([
|
||||
|
@ -491,6 +505,10 @@ export class AdminPane extends React.Component<Props, State, {}> {
|
|||
}
|
||||
};
|
||||
|
||||
reindex = async () => {
|
||||
return updater().reindex();
|
||||
}
|
||||
|
||||
addUser = async () => {
|
||||
if (this.state.newUserPwd1 !== this.state.newUserPwd2) {
|
||||
Env().alertMsg(this.props.msg.pkg.get("settings.pwd.notSame"));
|
||||
|
|
|
@ -1034,6 +1034,11 @@ export class Updater {
|
|||
return "";
|
||||
};
|
||||
|
||||
reindex = async (): Promise<string> => {
|
||||
const resp = await this.filesClient.reindex();
|
||||
return resp.status === 200 ? "" : errServer;
|
||||
}
|
||||
|
||||
hasResult = (): boolean => {
|
||||
return this.props.filesInfo.searchResults.size > 0;
|
||||
};
|
||||
|
|
|
@ -158,5 +158,7 @@ export const msgs: Map<string, string> = Map({
|
|||
"term.results": "Results",
|
||||
"term.noResult": "No result found",
|
||||
"action.go": "Go",
|
||||
"hint.keywords": "Please input keyword(s), separated by spaces"
|
||||
"hint.keywords": "Please input keyword(s), separated by spaces",
|
||||
"action.reindex": "Reindex",
|
||||
"action.reindex.desc": "Reconstruct the searching index",
|
||||
});
|
||||
|
|
|
@ -155,5 +155,7 @@ export const msgs: Map<string, string> = Map({
|
|||
"term.results": "结果",
|
||||
"term.noResult": "未找到结果",
|
||||
"action.go": "前往",
|
||||
"hint.keywords": "请输入关键字,以空格分隔"
|
||||
"hint.keywords": "请输入关键字,以空格分隔",
|
||||
"action.reindex": "重新索引",
|
||||
"action.reindex.desc": "重新建立搜索索引",
|
||||
});
|
||||
|
|
|
@ -48,7 +48,7 @@ func TestConcurrency(t *testing.T) {
|
|||
t.Fatal("fail to start server")
|
||||
}
|
||||
|
||||
usersCl := client.NewSingleUserClient(addr)
|
||||
usersCl := client.NewUsersClient(addr)
|
||||
resp, _, errs := usersCl.Login(adminName, adminPwd)
|
||||
if len(errs) > 0 {
|
||||
t.Fatal(errs)
|
||||
|
@ -67,7 +67,7 @@ func TestConcurrency(t *testing.T) {
|
|||
|
||||
filesCount := 10
|
||||
mockClient := func(name, pwd string, wg *sync.WaitGroup) {
|
||||
usersCl := client.NewSingleUserClient(addr)
|
||||
usersCl := client.NewUsersClient(addr)
|
||||
resp, _, errs := usersCl.Login(name, pwd)
|
||||
if len(errs) > 0 {
|
||||
t.Fatal(errs)
|
||||
|
|
|
@ -62,7 +62,7 @@ func TestFileHandlers(t *testing.T) {
|
|||
t.Fatal("fail to start server")
|
||||
}
|
||||
|
||||
usersCl := client.NewSingleUserClient(addr)
|
||||
usersCl := client.NewUsersClient(addr)
|
||||
resp, _, errs := usersCl.Login(adminName, adminPwd)
|
||||
if len(errs) > 0 {
|
||||
t.Fatal(errs)
|
||||
|
@ -405,7 +405,7 @@ func TestFileHandlers(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
userUsersCl := client.NewSingleUserClient(addr)
|
||||
userUsersCl := client.NewUsersClient(addr)
|
||||
resp, _, errs := userUsersCl.Login("demo", "Quicksh@re")
|
||||
if len(errs) > 0 {
|
||||
t.Fatal(errs)
|
||||
|
@ -918,6 +918,19 @@ func TestFileHandlers(t *testing.T) {
|
|||
t.Fatal("search result not match")
|
||||
}
|
||||
|
||||
userFilesClient, err := loginFilesClient(addr, "demo", "Quicksh@re")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
resp, searchItemsResp, errs = userFilesClient.SearchItems(keywords)
|
||||
if len(errs) > 0 {
|
||||
t.Fatal(errs)
|
||||
} else if resp.StatusCode != 200 {
|
||||
t.Fatal(resp.StatusCode)
|
||||
} else if len(searchItemsResp.Results) > 0 {
|
||||
t.Fatal("shoud return empty results")
|
||||
}
|
||||
|
||||
// delete paths
|
||||
for pathname := range toDelete {
|
||||
resp, _, errs := cl.Delete(pathname)
|
||||
|
|
|
@ -114,7 +114,7 @@ func TestPermissions(t *testing.T) {
|
|||
tmpAdmin, tmpAdminPwd := "tmpAdmin", "1234"
|
||||
tmpNewRole := "tmpNewRole"
|
||||
|
||||
cl := client.NewSingleUserClient(addr)
|
||||
cl := client.NewUsersClient(addr)
|
||||
token := &http.Cookie{}
|
||||
if requireAuth {
|
||||
resp, _, errs := cl.Login(user, pwd)
|
||||
|
@ -290,7 +290,7 @@ func TestPermissions(t *testing.T) {
|
|||
// Mkdir
|
||||
// Move
|
||||
|
||||
cl := client.NewSingleUserClient(addr)
|
||||
cl := client.NewUsersClient(addr)
|
||||
token := &http.Cookie{}
|
||||
|
||||
if requireAuth {
|
||||
|
@ -381,7 +381,7 @@ func TestPermissions(t *testing.T) {
|
|||
})
|
||||
|
||||
uploadSample := func() {
|
||||
cl := client.NewSingleUserClient(addr)
|
||||
cl := client.NewUsersClient(addr)
|
||||
token := &http.Cookie{}
|
||||
|
||||
resp, _, errs := cl.Login("user2", "1234")
|
||||
|
@ -411,7 +411,7 @@ func TestPermissions(t *testing.T) {
|
|||
// GenerateHash
|
||||
// Search
|
||||
|
||||
cl := client.NewSingleUserClient(addr)
|
||||
cl := client.NewUsersClient(addr)
|
||||
token := &http.Cookie{}
|
||||
if requireAuth {
|
||||
resp, _, errs := cl.Login(user, pwd)
|
||||
|
@ -575,7 +575,7 @@ func TestPermissions(t *testing.T) {
|
|||
|
||||
// sharing permission tests
|
||||
enableSharing := func() {
|
||||
cl := client.NewSingleUserClient(addr)
|
||||
cl := client.NewUsersClient(addr)
|
||||
token := &http.Cookie{}
|
||||
|
||||
resp, _, errs := cl.Login("share", "1234")
|
||||
|
@ -631,7 +631,7 @@ func TestPermissions(t *testing.T) {
|
|||
// ListSharingIDs
|
||||
// GetSharingDir
|
||||
|
||||
cl := client.NewSingleUserClient(addr)
|
||||
cl := client.NewUsersClient(addr)
|
||||
token := &http.Cookie{}
|
||||
homePath := "/"
|
||||
desc := user
|
||||
|
@ -727,7 +727,7 @@ func TestPermissions(t *testing.T) {
|
|||
// SetClientCfg
|
||||
// ReportErrors
|
||||
|
||||
cl := client.NewSingleUserClient(addr)
|
||||
cl := client.NewUsersClient(addr)
|
||||
token := &http.Cookie{}
|
||||
desc := user
|
||||
errReports := &settings.ClientErrorReports{
|
||||
|
|
|
@ -62,7 +62,7 @@ func TestSettingsHandlers(t *testing.T) {
|
|||
t.Fatal("fail to start server")
|
||||
}
|
||||
|
||||
usersCl := client.NewSingleUserClient(addr)
|
||||
usersCl := client.NewUsersClient(addr)
|
||||
resp, _, errs := usersCl.Login(adminName, adminPwd)
|
||||
if len(errs) > 0 {
|
||||
t.Fatal(errs)
|
||||
|
|
|
@ -63,7 +63,7 @@ func TestSpaceLimit(t *testing.T) {
|
|||
t.Fatal("fail to start server")
|
||||
}
|
||||
|
||||
usersCl := client.NewSingleUserClient(addr)
|
||||
usersCl := client.NewUsersClient(addr)
|
||||
resp, _, errs := usersCl.Login(adminName, adminPwd)
|
||||
if len(errs) > 0 {
|
||||
t.Fatal(errs)
|
||||
|
@ -100,7 +100,7 @@ func TestSpaceLimit(t *testing.T) {
|
|||
}
|
||||
|
||||
t.Run("test space limiting: Upload", func(t *testing.T) {
|
||||
usersCl := client.NewSingleUserClient(addr)
|
||||
usersCl := client.NewUsersClient(addr)
|
||||
resp, _, errs := usersCl.Login(getUserName(0), userPwd)
|
||||
if len(errs) > 0 {
|
||||
t.Fatal(errs)
|
||||
|
@ -230,7 +230,7 @@ func TestSpaceLimit(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("ResetUsedSpace", func(t *testing.T) {
|
||||
usersCl := client.NewSingleUserClient(addr)
|
||||
usersCl := client.NewUsersClient(addr)
|
||||
resp, _, errs := usersCl.Login("test", "test")
|
||||
if len(errs) > 0 {
|
||||
t.Fatal(errs)
|
||||
|
|
|
@ -72,7 +72,7 @@ func TestUsersHandlers(t *testing.T) {
|
|||
defer srv.Shutdown()
|
||||
fs := srv.depsFS()
|
||||
|
||||
usersCl := client.NewSingleUserClient(addr)
|
||||
usersCl := client.NewUsersClient(addr)
|
||||
settingsCl := client.NewSettingsClient(addr)
|
||||
|
||||
if !isServerReady(addr) {
|
||||
|
@ -82,7 +82,7 @@ func TestUsersHandlers(t *testing.T) {
|
|||
var err error
|
||||
|
||||
t.Run("test inited users", func(t *testing.T) {
|
||||
usersCl := client.NewSingleUserClient(addr)
|
||||
usersCl := client.NewUsersClient(addr)
|
||||
resp, _, errs := usersCl.Login(adminName, adminPwd)
|
||||
if len(errs) > 0 {
|
||||
t.Fatal(errs)
|
||||
|
@ -164,7 +164,7 @@ func TestUsersHandlers(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, user := range users {
|
||||
usersCl := client.NewSingleUserClient(addr)
|
||||
usersCl := client.NewUsersClient(addr)
|
||||
resp, _, errs := usersCl.Login(user.Name, user.Pwd)
|
||||
if len(errs) > 0 {
|
||||
t.Fatal(errs)
|
||||
|
@ -451,7 +451,7 @@ func TestUsersHandlers(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("Login, SetPreferences, Self, Logout", func(t *testing.T) {
|
||||
usersCl := client.NewSingleUserClient(addr)
|
||||
usersCl := client.NewUsersClient(addr)
|
||||
resp, _, errs := usersCl.Login(adminName, adminNewPwd)
|
||||
if len(errs) > 0 {
|
||||
t.Fatal(errs)
|
||||
|
|
|
@ -2,6 +2,7 @@ package server
|
|||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
|
@ -16,6 +17,7 @@ import (
|
|||
"github.com/ihexxa/quickshare/src/client"
|
||||
"github.com/ihexxa/quickshare/src/db"
|
||||
fspkg "github.com/ihexxa/quickshare/src/fs"
|
||||
q "github.com/ihexxa/quickshare/src/handlers"
|
||||
)
|
||||
|
||||
func startTestServer(config string) *Server {
|
||||
|
@ -57,7 +59,7 @@ func getUserName(id int) string {
|
|||
}
|
||||
|
||||
func addUsers(t *testing.T, addr, userPwd string, userCount int, adminToken *http.Cookie) map[string]string {
|
||||
usersCl := client.NewSingleUserClient(addr)
|
||||
usersCl := client.NewUsersClient(addr)
|
||||
users := map[string]string{}
|
||||
for i := range make([]int, userCount) {
|
||||
userName := getUserName(i)
|
||||
|
@ -220,3 +222,25 @@ func assertResp(t *testing.T, resp *http.Response, errs []error, expectedCode in
|
|||
t.Fatal(desc, resp.StatusCode, expectedCode)
|
||||
}
|
||||
}
|
||||
|
||||
func joinErrs(errs []error) error {
|
||||
msgs := []string{}
|
||||
for _, err := range errs {
|
||||
msgs = append(msgs, err.Error())
|
||||
}
|
||||
|
||||
return errors.New(strings.Join(msgs, ","))
|
||||
}
|
||||
|
||||
func loginFilesClient(addr, user, pwd string) (*client.FilesClient, error) {
|
||||
usersCl := client.NewUsersClient(addr)
|
||||
resp, _, errs := usersCl.Login(user, pwd)
|
||||
if len(errs) > 0 {
|
||||
return nil, joinErrs(errs)
|
||||
} else if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("unexpected code(%d)", resp.StatusCode)
|
||||
}
|
||||
|
||||
token := client.GetCookie(resp.Cookies(), q.TokenCookie)
|
||||
return client.NewFilesClient(addr, token), nil
|
||||
}
|
||||
|
|
BIN
src/server/testdata/test_quickshare.db
vendored
BIN
src/server/testdata/test_quickshare.db
vendored
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue