Merge branch 'master' into mark-as-unread
Этот коммит содержится в:
@@ -8,7 +8,6 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
@@ -167,7 +166,7 @@ func UserFromBot(b *Bot) *User {
|
||||
return &User{
|
||||
Id: b.UserId,
|
||||
Username: b.Username,
|
||||
Email: fmt.Sprintf("%s@localhost", strings.ToLower(b.Username)),
|
||||
Email: NormalizeEmail(fmt.Sprintf("%s@localhost", b.Username)),
|
||||
FirstName: b.DisplayName,
|
||||
Roles: SYSTEM_USER_ROLE_ID,
|
||||
}
|
||||
|
||||
@@ -157,14 +157,17 @@ type PostActionIntegration struct {
|
||||
}
|
||||
|
||||
type PostActionIntegrationRequest struct {
|
||||
UserId string `json:"user_id"`
|
||||
ChannelId string `json:"channel_id"`
|
||||
TeamId string `json:"team_id"`
|
||||
PostId string `json:"post_id"`
|
||||
TriggerId string `json:"trigger_id"`
|
||||
Type string `json:"type"`
|
||||
DataSource string `json:"data_source"`
|
||||
Context map[string]interface{} `json:"context,omitempty"`
|
||||
UserId string `json:"user_id"`
|
||||
UserName string `json:"user_name"`
|
||||
ChannelId string `json:"channel_id"`
|
||||
ChannelName string `json:"channel_name"`
|
||||
TeamId string `json:"team_id"`
|
||||
TeamName string `json:"team_domain"`
|
||||
PostId string `json:"post_id"`
|
||||
TriggerId string `json:"trigger_id"`
|
||||
Type string `json:"type"`
|
||||
DataSource string `json:"data_source"`
|
||||
Context map[string]interface{} `json:"context,omitempty"`
|
||||
}
|
||||
|
||||
type PostActionIntegrationResponse struct {
|
||||
|
||||
@@ -9,10 +9,12 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/mattermost/mattermost-server/services/timezones"
|
||||
@@ -851,3 +853,27 @@ func UsersWithGroupsAndCountFromJson(data io.Reader) *UsersWithGroupsAndCount {
|
||||
json.Unmarshal(bodyBytes, uwg)
|
||||
return uwg
|
||||
}
|
||||
|
||||
var passwordRandomSource = rand.NewSource(time.Now().Unix())
|
||||
var passwordSpecialChars = "!$%^&*(),."
|
||||
var passwordNumbers = "0123456789"
|
||||
var passwordUpperCaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
var passwordLowerCaseLetters = "abcdefghijklmnopqrstuvwxyz"
|
||||
var passwordAllChars = passwordSpecialChars + passwordNumbers + passwordUpperCaseLetters + passwordLowerCaseLetters
|
||||
|
||||
func GeneratePassword(minimumLength int) string {
|
||||
r := rand.New(passwordRandomSource)
|
||||
|
||||
// Make sure we are guaranteed at least one of each type to meet any possible password complexity requirements.
|
||||
password := string([]rune(passwordUpperCaseLetters)[r.Intn(len(passwordUpperCaseLetters))]) +
|
||||
string([]rune(passwordNumbers)[r.Intn(len(passwordNumbers))]) +
|
||||
string([]rune(passwordLowerCaseLetters)[r.Intn(len(passwordLowerCaseLetters))]) +
|
||||
string([]rune(passwordSpecialChars)[r.Intn(len(passwordSpecialChars))])
|
||||
|
||||
for len(password) < minimumLength {
|
||||
i := r.Intn(len(passwordAllChars))
|
||||
password = password + string([]rune(passwordAllChars)[i])
|
||||
}
|
||||
|
||||
return password
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -350,3 +351,25 @@ func TestUserSlice(t *testing.T) {
|
||||
assert.Equal(t, 1, len(nonBotUsers))
|
||||
})
|
||||
}
|
||||
|
||||
func TestGeneratePassword(t *testing.T) {
|
||||
passwordRandomSource = rand.NewSource(12345)
|
||||
|
||||
t.Run("Should be the minimum length or 4, whichever is less", func(t *testing.T) {
|
||||
password1 := GeneratePassword(5)
|
||||
assert.Len(t, password1, 5)
|
||||
password2 := GeneratePassword(10)
|
||||
assert.Len(t, password2, 10)
|
||||
password3 := GeneratePassword(1)
|
||||
assert.Len(t, password3, 4)
|
||||
})
|
||||
|
||||
t.Run("Should contain at least one of symbols, upper case, lower case and numbers", func(t *testing.T) {
|
||||
password := GeneratePassword(4)
|
||||
require.Len(t, password, 4)
|
||||
assert.Contains(t, []rune(passwordUpperCaseLetters), []rune(password)[0])
|
||||
assert.Contains(t, []rune(passwordNumbers), []rune(password)[1])
|
||||
assert.Contains(t, []rune(passwordLowerCaseLetters), []rune(password)[2])
|
||||
assert.Contains(t, []rune(passwordSpecialChars), []rune(password)[3])
|
||||
})
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user