[MM-16512] Migrate Token.Save to Sync by default (#11353)

* [MM-16512] Migrate Token.Save to Sync by default

* refactor: formatting

* test: add checks for errors while saving tokens

* test: fixup
Этот коммит содержится в:
krjn
2019-06-26 10:36:41 +00:00
коммит произвёл Sudheer
родитель 2327ab8854
Коммит 72d482de0e
11 изменённых файлов: 42 добавлений и 44 удалений

Просмотреть файл

@@ -335,8 +335,8 @@ func (a *App) SendInviteEmails(team *model.Team, senderName string, senderUserId
props["name"] = team.Name
data := model.MapToJson(props)
if result := <-a.Srv.Store.Token().Save(token); result.Err != nil {
mlog.Error(fmt.Sprintf("Failed to send invite email successfully err=%v", result.Err))
if err := a.Srv.Store.Token().Save(token); err != nil {
mlog.Error(fmt.Sprintf("Failed to send invite email successfully err=%v", err))
continue
}
bodyPage.Props["Link"] = fmt.Sprintf("%s/signup_user_complete/?d=%s&t=%s", siteURL, url.QueryEscape(data), url.QueryEscape(token.Token))

Просмотреть файл

@@ -593,8 +593,8 @@ func (a *App) CompleteSwitchWithOAuth(service string, userData io.Reader, email
func (a *App) CreateOAuthStateToken(extra string) (*model.Token, *model.AppError) {
token := model.NewToken(model.TOKEN_TYPE_OAUTH, extra)
if result := <-a.Srv.Store.Token().Save(token); result.Err != nil {
return nil, result.Err
if err := a.Srv.Store.Token().Save(token); err != nil {
return nil, err
}
return token, nil

Просмотреть файл

@@ -233,8 +233,7 @@ func TestAuthorizeOAuthUser(t *testing.T) {
defer th.TearDown()
token := model.NewToken("invalid", "")
result := <-th.App.Srv.Store.Token().Save(token)
require.Nil(t, result.Err)
require.Nil(t, th.App.Srv.Store.Token().Save(token))
state := makeState(token)

Просмотреть файл

@@ -205,7 +205,7 @@ func TestAddUserToTeamByToken(t *testing.T) {
TOKEN_TYPE_VERIFY_EMAIL,
model.MapToJson(map[string]string{"teamId": th.BasicTeam.Id}),
)
<-th.App.Srv.Store.Token().Save(token)
require.Nil(t, th.App.Srv.Store.Token().Save(token))
defer th.App.DeleteToken(token)
if _, err := th.App.AddUserToTeamByToken(ruser.Id, token.Token); err == nil {
t.Fatal("Should fail on bad token type")
@@ -218,7 +218,7 @@ func TestAddUserToTeamByToken(t *testing.T) {
model.MapToJson(map[string]string{"teamId": th.BasicTeam.Id}),
)
token.CreateAt = model.GetMillis() - TEAM_INVITATION_EXPIRY_TIME - 1
<-th.App.Srv.Store.Token().Save(token)
require.Nil(t, th.App.Srv.Store.Token().Save(token))
defer th.App.DeleteToken(token)
if _, err := th.App.AddUserToTeamByToken(ruser.Id, token.Token); err == nil {
t.Fatal("Should fail on expired token")
@@ -230,7 +230,7 @@ func TestAddUserToTeamByToken(t *testing.T) {
TOKEN_TYPE_TEAM_INVITATION,
model.MapToJson(map[string]string{"teamId": model.NewId()}),
)
<-th.App.Srv.Store.Token().Save(token)
require.Nil(t, th.App.Srv.Store.Token().Save(token))
defer th.App.DeleteToken(token)
if _, err := th.App.AddUserToTeamByToken(ruser.Id, token.Token); err == nil {
t.Fatal("Should fail on bad team id")
@@ -242,7 +242,7 @@ func TestAddUserToTeamByToken(t *testing.T) {
TOKEN_TYPE_TEAM_INVITATION,
model.MapToJson(map[string]string{"teamId": th.BasicTeam.Id}),
)
<-th.App.Srv.Store.Token().Save(token)
require.Nil(t, th.App.Srv.Store.Token().Save(token))
defer th.App.DeleteToken(token)
if _, err := th.App.AddUserToTeamByToken(model.NewId(), token.Token); err == nil {
t.Fatal("Should fail on bad user id")
@@ -254,7 +254,7 @@ func TestAddUserToTeamByToken(t *testing.T) {
TOKEN_TYPE_TEAM_INVITATION,
model.MapToJson(map[string]string{"teamId": th.BasicTeam.Id}),
)
<-th.App.Srv.Store.Token().Save(token)
require.Nil(t, th.App.Srv.Store.Token().Save(token))
if _, err := th.App.AddUserToTeamByToken(ruser.Id, token.Token); err != nil {
t.Log(err)
t.Fatal("Should add user to the team")
@@ -274,7 +274,7 @@ func TestAddUserToTeamByToken(t *testing.T) {
TOKEN_TYPE_TEAM_INVITATION,
model.MapToJson(map[string]string{"teamId": th.BasicTeam.Id}),
)
<-th.App.Srv.Store.Token().Save(token)
require.Nil(t, th.App.Srv.Store.Token().Save(token))
if _, err := th.App.AddUserToTeamByToken(ruser.Id, token.Token); err == nil {
t.Fatal("Should return an error when trying to join a group-constrained team.")
} else {
@@ -303,7 +303,7 @@ func TestAddUserToTeamByToken(t *testing.T) {
TOKEN_TYPE_TEAM_INVITATION,
model.MapToJson(map[string]string{"teamId": th.BasicTeam.Id}),
)
<-th.App.Srv.Store.Token().Save(token)
require.Nil(t, th.App.Srv.Store.Token().Save(token))
if _, err := th.App.AddUserToTeamByToken(ruser.Id, token.Token); err == nil || err.Where != "JoinUserToTeam" {
t.Log(err)

Просмотреть файл

@@ -1349,8 +1349,8 @@ func (a *App) CreatePasswordRecoveryToken(userId, email string) (*model.Token, *
token := model.NewToken(TOKEN_TYPE_PASSWORD_RECOVERY, string(jsonData))
if result := <-a.Srv.Store.Token().Save(token); result.Err != nil {
return nil, result.Err
if err := a.Srv.Store.Token().Save(token); err != nil {
return nil, err
}
return token, nil
@@ -1615,8 +1615,8 @@ func (a *App) CreateVerifyEmailToken(userId string, newEmail string) (*model.Tok
token := model.NewToken(TOKEN_TYPE_VERIFY_EMAIL, string(jsonData))
if result := <-a.Srv.Store.Token().Save(token); result.Err != nil {
return nil, result.Err
if err := a.Srv.Store.Token().Save(token); err != nil {
return nil, err
}
return token, nil

Просмотреть файл

@@ -571,7 +571,7 @@ func TestCreateUserWithToken(t *testing.T) {
TOKEN_TYPE_VERIFY_EMAIL,
model.MapToJson(map[string]string{"teamId": th.BasicTeam.Id, "email": user.Email}),
)
<-th.App.Srv.Store.Token().Save(token)
require.Nil(t, th.App.Srv.Store.Token().Save(token))
defer th.App.DeleteToken(token)
if _, err := th.App.CreateUserWithToken(&user, token.Token); err == nil {
t.Fatal("Should fail on bad token type")
@@ -584,7 +584,7 @@ func TestCreateUserWithToken(t *testing.T) {
model.MapToJson(map[string]string{"teamId": th.BasicTeam.Id, "email": user.Email}),
)
token.CreateAt = model.GetMillis() - TEAM_INVITATION_EXPIRY_TIME - 1
<-th.App.Srv.Store.Token().Save(token)
require.Nil(t, th.App.Srv.Store.Token().Save(token))
defer th.App.DeleteToken(token)
if _, err := th.App.CreateUserWithToken(&user, token.Token); err == nil {
t.Fatal("Should fail on expired token")
@@ -596,7 +596,7 @@ func TestCreateUserWithToken(t *testing.T) {
TOKEN_TYPE_TEAM_INVITATION,
model.MapToJson(map[string]string{"teamId": model.NewId(), "email": user.Email}),
)
<-th.App.Srv.Store.Token().Save(token)
require.Nil(t, th.App.Srv.Store.Token().Save(token))
defer th.App.DeleteToken(token)
if _, err := th.App.CreateUserWithToken(&user, token.Token); err == nil {
t.Fatal("Should fail on bad team id")
@@ -609,7 +609,7 @@ func TestCreateUserWithToken(t *testing.T) {
TOKEN_TYPE_TEAM_INVITATION,
model.MapToJson(map[string]string{"teamId": th.BasicTeam.Id, "email": invitationEmail}),
)
<-th.App.Srv.Store.Token().Save(token)
require.Nil(t, th.App.Srv.Store.Token().Save(token))
newUser, err := th.App.CreateUserWithToken(&user, token.Token)
if err != nil {
t.Log(err)