mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Refactor context flash msg and global variables (#33375)
1. add `GetSiteCookieFlashMessage` to help to parse flash message 2. clarify `handleRepoHomeFeed` logic 3. remove unnecessary global variables, use `sync.OnceValue` instead 4. add some tests for `IsUsableUsername` and `IsUsableRepoName`
This commit is contained in:
@@ -502,10 +502,10 @@ func (u *User) IsMailable() bool {
|
||||
return u.IsActive
|
||||
}
|
||||
|
||||
// IsUserExist checks if given user name exist,
|
||||
// the user name should be noncased unique.
|
||||
// IsUserExist checks if given username exist,
|
||||
// the username should be non-cased unique.
|
||||
// If uid is presented, then check will rule out that one,
|
||||
// it is used when update a user name in settings page.
|
||||
// it is used when update a username in settings page.
|
||||
func IsUserExist(ctx context.Context, uid int64, name string) (bool, error) {
|
||||
if len(name) == 0 {
|
||||
return false, nil
|
||||
@@ -515,7 +515,7 @@ func IsUserExist(ctx context.Context, uid int64, name string) (bool, error) {
|
||||
Get(&User{LowerName: strings.ToLower(name)})
|
||||
}
|
||||
|
||||
// Note: As of the beginning of 2022, it is recommended to use at least
|
||||
// SaltByteLength as of the beginning of 2022, it is recommended to use at least
|
||||
// 64 bits of salt, but NIST is already recommending to use to 128 bits.
|
||||
// (16 bytes = 16 * 8 = 128 bits)
|
||||
const SaltByteLength = 16
|
||||
|
@@ -25,6 +25,21 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestIsUsableUsername(t *testing.T) {
|
||||
assert.NoError(t, user_model.IsUsableUsername("a"))
|
||||
assert.NoError(t, user_model.IsUsableUsername("foo.wiki"))
|
||||
assert.NoError(t, user_model.IsUsableUsername("foo.git"))
|
||||
|
||||
assert.Error(t, user_model.IsUsableUsername("a--b"))
|
||||
assert.Error(t, user_model.IsUsableUsername("-1_."))
|
||||
assert.Error(t, user_model.IsUsableUsername(".profile"))
|
||||
assert.Error(t, user_model.IsUsableUsername("-"))
|
||||
assert.Error(t, user_model.IsUsableUsername("🌞"))
|
||||
assert.Error(t, user_model.IsUsableUsername("the..repo"))
|
||||
assert.Error(t, user_model.IsUsableUsername("foo.RSS"))
|
||||
assert.Error(t, user_model.IsUsableUsername("foo.PnG"))
|
||||
}
|
||||
|
||||
func TestOAuth2Application_LoadUser(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
app := unittest.AssertExistsAndLoadBean(t, &auth.OAuth2Application{ID: 1})
|
||||
|
Reference in New Issue
Block a user