Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion controller/user_ctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ type UserController struct {
}

func (userCtl UserController) Login(ctx context.Context, w *api.JiaozifsResponse, r *http.Request, body api.LoginJSONRequestBody) {

// get user encryptedPassword by username
ep, err := userCtl.Repo.UserRepo().GetEPByName(ctx, body.Name)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion integrationtest/branch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func BranchSpec(ctx context.Context, urlStr string) func(c convey.C) {
prefix := "feat/"

createUser(ctx, c, client, userName)
loginAndSwitch(ctx, c, client, userName)
loginAndSwitch(ctx, c, client, "mike login", userName, false)
createRepo(ctx, c, client, repoName)

c.Convey("create branch", func(c convey.C) {
Expand Down
2 changes: 1 addition & 1 deletion integrationtest/commit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func GetEntriesInRefSpec(ctx context.Context, urlStr string) func(c convey.C) {
branchName := "feat/get_entries_test"

createUser(ctx, c, client, userName)
loginAndSwitch(ctx, c, client, userName)
loginAndSwitch(ctx, c, client, "kitty login", userName, false)
createRepo(ctx, c, client, repoName)
createBranch(ctx, c, client, userName, repoName, "main", branchName)
createWip(ctx, c, client, "feat get entries test0", userName, repoName, branchName)
Expand Down
14 changes: 10 additions & 4 deletions integrationtest/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,25 @@ func createUser(ctx context.Context, c convey.C, client *api.Client, userName st
})
}

func loginAndSwitch(ctx context.Context, c convey.C, client *api.Client, userName string) {
c.Convey("login "+userName, func() {
func loginAndSwitch(ctx context.Context, c convey.C, client *api.Client, title, userName string, useCookie bool) {
c.Convey("login "+title, func() {
resp, err := client.Login(ctx, api.LoginJSONRequestBody{
Name: userName,
Password: "12345678",
})
convey.So(err, convey.ShouldBeNil)
convey.So(resp.StatusCode, convey.ShouldEqual, http.StatusOK)
loginResult, err := api.ParseLoginResponse(resp)
convey.So(err, convey.ShouldBeNil)

client.RequestEditors = nil
client.RequestEditors = append(client.RequestEditors, func(ctx context.Context, req *http.Request) error {
for _, cookie := range resp.Cookies() {
req.AddCookie(cookie)
if useCookie {
for _, cookie := range resp.Cookies() {
req.AddCookie(cookie)
}
} else {
req.Header.Add("Authorization", "Bearer "+loginResult.JSON200.Token)
}
return nil
})
Expand Down
2 changes: 1 addition & 1 deletion integrationtest/objects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func ObjectSpec(ctx context.Context, urlStr string) func(c convey.C) {
branchName := "feat/obj_test"

createUser(ctx, c, client, userName)
loginAndSwitch(ctx, c, client, userName)
loginAndSwitch(ctx, c, client, "molly login", userName, false)
createRepo(ctx, c, client, repoName)
createBranch(ctx, c, client, userName, repoName, "main", branchName)
createWip(ctx, c, client, "feat get obj test", userName, repoName, branchName)
Expand Down
2 changes: 1 addition & 1 deletion integrationtest/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func RepoSpec(ctx context.Context, urlStr string) func(c convey.C) {
userName := "jimmy"
repoName := "happyrun"
createUser(ctx, c, client, userName)
loginAndSwitch(ctx, c, client, userName)
loginAndSwitch(ctx, c, client, "jimmy login", userName, false)

c.Convey("create repo", func(c convey.C) {
c.Convey("forbidden create repo name", func() {
Expand Down
10 changes: 9 additions & 1 deletion integrationtest/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,20 @@ func UserSpec(ctx context.Context, urlStr string) func(c convey.C) {
convey.So(resp.StatusCode, convey.ShouldEqual, http.StatusUnauthorized)
})

loginAndSwitch(ctx, c, client, userName)
loginAndSwitch(ctx, c, client, "admin login", userName, false)

c.Convey("usr profile", func() {
resp, err := client.GetUserInfo(ctx)
convey.So(err, convey.ShouldBeNil)
convey.So(resp.StatusCode, convey.ShouldEqual, http.StatusOK)
})

loginAndSwitch(ctx, c, client, "admin login again", userName, true)

c.Convey("usr profile with cookie", func() {
resp, err := client.GetUserInfo(ctx)
convey.So(err, convey.ShouldBeNil)
convey.So(resp.StatusCode, convey.ShouldEqual, http.StatusOK)
})
}
}
2 changes: 1 addition & 1 deletion integrationtest/wip_object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func WipObjectSpec(ctx context.Context, urlStr string) func(c convey.C) {
branchName := "feat/wip_obj_test"

createUser(ctx, c, client, userName)
loginAndSwitch(ctx, c, client, userName)
loginAndSwitch(ctx, c, client, "jude login", userName, false)
createRepo(ctx, c, client, repoName)
createBranch(ctx, c, client, userName, repoName, "main", branchName)
createWip(ctx, c, client, "get wip obj test", userName, repoName, branchName)
Expand Down
2 changes: 1 addition & 1 deletion integrationtest/wip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func WipSpec(ctx context.Context, urlStr string) func(c convey.C) {
branchNameForDelete := "feat/wip_test2"

createUser(ctx, c, client, userName)
loginAndSwitch(ctx, c, client, userName)
loginAndSwitch(ctx, c, client, "july login", userName, false)
createRepo(ctx, c, client, repoName)
createBranch(ctx, c, client, userName, repoName, "main", branchName)
createBranch(ctx, c, client, userName, repoName, "main", branchNameForDelete)
Expand Down