Skip to content

Commit

Permalink
refactor: removed user login register code
Browse files Browse the repository at this point in the history
  • Loading branch information
Rajat-Dabade committed Jun 30, 2024
1 parent f2b54b8 commit 70467de
Show file tree
Hide file tree
Showing 9 changed files with 0 additions and 283 deletions.
51 changes: 0 additions & 51 deletions server/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,43 +523,6 @@ func (c *Client) PostSharing(sharing *model.Sharing) (bool, *Response) {
return true, BuildResponse(r)
}

func (c *Client) GetRegisterRoute() string {
return "/register"
}

func (c *Client) Register(request *model.RegisterRequest) (bool, *Response) {
r, err := c.DoAPIPost(c.GetRegisterRoute(), toJSON(&request))
if err != nil {
return false, BuildErrorResponse(r, err)
}
defer closeBody(r)

return true, BuildResponse(r)
}

func (c *Client) GetLoginRoute() string {
return "/login"
}

func (c *Client) Login(request *model.LoginRequest) (*model.LoginResponse, *Response) {
r, err := c.DoAPIPost(c.GetLoginRoute(), toJSON(&request))
if err != nil {
return nil, BuildErrorResponse(r, err)
}
defer closeBody(r)

data, err := model.LoginResponseFromJSON(r.Body)
if err != nil {
return nil, BuildErrorResponse(r, err)
}

if data.Token != "" {
c.Token = data.Token
}

return data, BuildResponse(r)
}

func (c *Client) GetMeRoute() string {
return "/users/me"
}
Expand Down Expand Up @@ -624,20 +587,6 @@ func (c *Client) GetUserList(ids []string) ([]model.User, *Response) {
return users, BuildResponse(r)
}

func (c *Client) GetUserChangePasswordRoute(id string) string {
return fmt.Sprintf("/users/%s/changepassword", id)
}

func (c *Client) UserChangePassword(id string, data *model.ChangePasswordRequest) (bool, *Response) {
r, err := c.DoAPIPost(c.GetUserChangePasswordRoute(id), toJSON(&data))
if err != nil {
return false, BuildErrorResponse(r, err)
}
defer closeBody(r)

return true, BuildResponse(r)
}

func (c *Client) CreateBoard(board *model.Board) (*model.Board, *Response) {
r, err := c.DoAPIPost(c.GetBoardsRoute(), toJSON(board))
if err != nil {
Expand Down
18 changes: 0 additions & 18 deletions server/integrationtests/board_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ func TestGetBoards(t *testing.T) {
t.Run("a non authenticated client should be rejected", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
th.Logout(th.Client)

teamID := "0"
newBoard := &model.Board{
Expand Down Expand Up @@ -117,7 +116,6 @@ func TestCreateBoard(t *testing.T) {
t.Run("a non authenticated user should be rejected", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
th.Logout(th.Client)

newBoard := &model.Board{
Title: "board title",
Expand Down Expand Up @@ -475,7 +473,6 @@ func TestSearchBoards(t *testing.T) {
t.Run("a non authenticated user should be rejected", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
th.Logout(th.Client)

boards, resp := th.Client.SearchBoardsForTeam(testTeamID, "term")
th.CheckUnauthorized(resp)
Expand Down Expand Up @@ -587,7 +584,6 @@ func TestGetBoard(t *testing.T) {
t.Run("a non authenticated user should be rejected", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
th.Logout(th.Client)

board, resp := th.Client.GetBoard("boar-id", "")
th.CheckUnauthorized(resp)
Expand Down Expand Up @@ -621,9 +617,6 @@ func TestGetBoard(t *testing.T) {
th.CheckOK(resp)
require.True(t, success)

// the client logs out
th.Logout(th.Client)

// we make sure that the client cannot currently retrieve the
// board with no session
board, resp = th.Client.GetBoard(rBoard.ID, "")
Expand Down Expand Up @@ -702,7 +695,6 @@ func TestGetBoardMetadata(t *testing.T) {
t.Run("a non authenticated user should be rejected", func(t *testing.T) {
th := SetupTestHelperWithLicense(t, LicenseEnterprise).InitBasic()
defer th.TearDown()
th.Logout(th.Client)

boardMetadata, resp := th.Client.GetBoardMetadata("boar-id", "")
th.CheckUnauthorized(resp)
Expand Down Expand Up @@ -861,9 +853,6 @@ func TestGetBoardMetadata(t *testing.T) {
th.CheckOK(resp)
require.True(t, success)

// the client logs out
th.Logout(th.Client)

// we make sure that the client cannot currently retrieve the
// board with no session
boardMetadata, resp := th.Client.GetBoardMetadata(rBoard.ID, "")
Expand All @@ -883,7 +872,6 @@ func TestPatchBoard(t *testing.T) {
t.Run("a non authenticated user should be rejected", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
th.Logout(th.Client)

initialTitle := "title 1"
newBoard := &model.Board{
Expand Down Expand Up @@ -998,7 +986,6 @@ func TestDeleteBoard(t *testing.T) {
t.Run("a non authenticated user should be rejected", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
th.Logout(th.Client)

newBoard := &model.Board{
Title: "title",
Expand Down Expand Up @@ -1076,7 +1063,6 @@ func TestUndeleteBoard(t *testing.T) {
t.Run("a non authenticated user should be rejected", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
th.Logout(th.Client)

newBoard := &model.Board{
Title: "title",
Expand Down Expand Up @@ -1225,7 +1211,6 @@ func TestGetMembersForBoard(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
board := createBoardWithUsers(th)
th.Logout(th.Client)

members, resp := th.Client.GetMembersForBoard(board.ID)
th.CheckUnauthorized(resp)
Expand Down Expand Up @@ -1270,7 +1255,6 @@ func TestAddMember(t *testing.T) {
t.Run("a non authenticated user should be rejected", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
th.Logout(th.Client)

newBoard := &model.Board{
Title: "title",
Expand Down Expand Up @@ -1490,7 +1474,6 @@ func TestUpdateMember(t *testing.T) {
SchemeEditor: true,
}

th.Logout(th.Client)
member, resp := th.Client.UpdateBoardMember(updatedMember)
th.CheckUnauthorized(resp)
require.Nil(t, member)
Expand Down Expand Up @@ -1665,7 +1648,6 @@ func TestDeleteMember(t *testing.T) {
BoardID: board.ID,
}

th.Logout(th.Client)
success, resp := th.Client.DeleteBoardMember(member)
th.CheckUnauthorized(resp)
require.False(t, success)
Expand Down
7 changes: 0 additions & 7 deletions server/integrationtests/cards_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ func TestCreateCard(t *testing.T) {
defer th.TearDown()

board := th.CreateBoard(testTeamID, model.BoardTypeOpen)
th.Logout(th.Client)

card := &model.Card{
Title: "basic card",
Expand Down Expand Up @@ -157,8 +156,6 @@ func TestGetCards(t *testing.T) {
})

t.Run("a non authenticated user should be rejected", func(t *testing.T) {
th.Logout(th.Client)

cards, resp := th.Client.GetCards(board.ID, 0, 10)
th.CheckUnauthorized(resp)
require.Nil(t, cards)
Expand All @@ -173,8 +170,6 @@ func TestPatchCard(t *testing.T) {
_, cards := th.CreateBoardAndCards(testTeamID, model.BoardTypeOpen, 1)
card := cards[0]

th.Logout(th.Client)

newTitle := "another title"
patch := &model.CardPatch{
Title: &newTitle,
Expand Down Expand Up @@ -243,8 +238,6 @@ func TestGetCard(t *testing.T) {
_, cards := th.CreateBoardAndCards(testTeamID, model.BoardTypeOpen, 1)
card := cards[0]

th.Logout(th.Client)

cardFetched, resp := th.Client.GetCard(card.ID)
th.CheckUnauthorized(resp)
require.Nil(t, cardFetched)
Expand Down
44 changes: 0 additions & 44 deletions server/integrationtests/clienttestlib.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,18 +361,12 @@ func (th *TestHelper) Start() *TestHelper {
func (th *TestHelper) InitBasic() *TestHelper {
th.Start()

// user1
th.RegisterAndLogin(th.Client, user1Username, "[email protected]", password, "")

// get token
team, resp := th.Client.GetTeam(model.GlobalTeamID)
th.CheckOK(resp)
require.NotNil(th.T, team)
require.NotNil(th.T, team.SignupToken)

// user2
th.RegisterAndLogin(th.Client2, user2Username, "[email protected]", password, team.SignupToken)

return th
}

Expand All @@ -399,44 +393,6 @@ func (th *TestHelper) TearDown() {
}
}

func (th *TestHelper) RegisterAndLogin(client *client.Client, username, email, password, token string) {
req := &model.RegisterRequest{
Username: username,
Email: email,
Password: password,
Token: token,
}

success, resp := th.Client.Register(req)
th.CheckOK(resp)
require.True(th.T, success)

th.Login(client, username, password)
}

func (th *TestHelper) Login(client *client.Client, username, password string) {
req := &model.LoginRequest{
Type: "normal",
Username: username,
Password: password,
}
data, resp := client.Login(req)
th.CheckOK(resp)
require.NotNil(th.T, data)
}

func (th *TestHelper) Login1() {
th.Login(th.Client, user1Username, password)
}

func (th *TestHelper) Login2() {
th.Login(th.Client2, user2Username, password)
}

func (th *TestHelper) Logout(client *client.Client) {
client.Token = ""
}

func (th *TestHelper) Me(client *client.Client) *model.User {
user, resp := client.GetMe()
th.CheckOK(resp)
Expand Down
2 changes: 0 additions & 2 deletions server/integrationtests/compliance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ func TestGetBoardsForCompliance(t *testing.T) {
defer th.TearDown()

_ = th.CreateBoards(testTeamID, model.BoardTypeOpen, 2)
th.Logout(th.Client)

bcr, resp := clients.Anon.GetBoardsForCompliance(testTeamID, 0, 0)

Expand Down Expand Up @@ -134,7 +133,6 @@ func TestGetBoardsComplianceHistory(t *testing.T) {
defer th.TearDown()

_ = th.CreateBoards(testTeamID, model.BoardTypeOpen, 2)
th.Logout(th.Client)

bchr, resp := clients.Anon.GetBoardsComplianceHistory(utils.GetMillis()-OneDay, true, testTeamID, 0, 0)

Expand Down
1 change: 0 additions & 1 deletion server/integrationtests/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ func TestUploadFile(t *testing.T) {
t.Run("a non authenticated user should be rejected", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
th.Logout(th.Client)

file, resp := th.Client.TeamUploadFile(testTeamID, "test-board-id", bytes.NewBuffer([]byte("test")))
th.CheckUnauthorized(resp)
Expand Down
13 changes: 0 additions & 13 deletions server/integrationtests/permissions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ func setupClients(th *TestHelper) Clients {

func setupLocalClients(th *TestHelper) Clients {
th.Client = client.NewClient(th.Server.Config().ServerRoot, "")
th.RegisterAndLogin(th.Client, "sysadmin", "[email protected]", password, "")

clients := Clients{
Anon: client.NewClient(th.Server.Config().ServerRoot, ""),
Expand All @@ -109,23 +108,11 @@ func setupLocalClients(th *TestHelper) Clients {
th.CheckOK(resp)
require.NotNil(th.T, team)
require.NotNil(th.T, team.SignupToken)

th.RegisterAndLogin(clients.NoTeamMember, userNoTeamMember, userNoTeamMember+"@sample.com", password, team.SignupToken)
userNoTeamMemberID = clients.NoTeamMember.GetUserID()

th.RegisterAndLogin(clients.TeamMember, userTeamMember, userTeamMember+"@sample.com", password, team.SignupToken)
userTeamMemberID = clients.TeamMember.GetUserID()

th.RegisterAndLogin(clients.Viewer, userViewer, userViewer+"@sample.com", password, team.SignupToken)
userViewerID = clients.Viewer.GetUserID()

th.RegisterAndLogin(clients.Commenter, userCommenter, userCommenter+"@sample.com", password, team.SignupToken)
userCommenterID = clients.Commenter.GetUserID()

th.RegisterAndLogin(clients.Editor, userEditor, userEditor+"@sample.com", password, team.SignupToken)
userEditorID = clients.Editor.GetUserID()

th.RegisterAndLogin(clients.Admin, userAdmin, userAdmin+"@sample.com", password, team.SignupToken)
userAdminID = clients.Admin.GetUserID()

return clients
Expand Down
3 changes: 0 additions & 3 deletions server/integrationtests/sharing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@ func TestSharing(t *testing.T) {
token := utils.NewID(utils.IDTypeToken)

t.Run("an unauthenticated client should not be able to get a sharing", func(t *testing.T) {
th.Logout(th.Client)

sharing, resp := th.Client.GetSharing("board-id")
th.CheckUnauthorized(resp)
require.Nil(t, sharing)
})

t.Run("Check no initial sharing", func(t *testing.T) {
th.Login1()

teamID := "0"
newBoard := &model.Board{
Expand Down
Loading

0 comments on commit 70467de

Please sign in to comment.