-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
79 changed files
with
1,414 additions
and
672 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,3 +63,4 @@ Kemal Zebari <[email protected]> (@kemzeb) | |
Rowan Bohde <[email protected]> (@bohde) | ||
hiifong <[email protected]> (@hiifong) | ||
metiftikci <[email protected]> (@metiftikci) | ||
Christopher Homberger <[email protected]> (@ChristopherHX) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,32 +13,54 @@ import ( | |
user_model "code.gitea.io/gitea/models/user" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestAdminUserCreate(t *testing.T) { | ||
app := NewMainApp(AppVersion{}) | ||
|
||
reset := func() { | ||
assert.NoError(t, db.TruncateBeans(db.DefaultContext, &user_model.User{})) | ||
assert.NoError(t, db.TruncateBeans(db.DefaultContext, &user_model.EmailAddress{})) | ||
require.NoError(t, db.TruncateBeans(db.DefaultContext, &user_model.User{})) | ||
require.NoError(t, db.TruncateBeans(db.DefaultContext, &user_model.EmailAddress{})) | ||
} | ||
|
||
type createCheck struct{ IsAdmin, MustChangePassword bool } | ||
createUser := func(name, args string) createCheck { | ||
assert.NoError(t, app.Run(strings.Fields(fmt.Sprintf("./gitea admin user create --username %s --email %[email protected] %s --password foobar", name, name, args)))) | ||
u := unittest.AssertExistsAndLoadBean(t, &user_model.User{LowerName: name}) | ||
return createCheck{u.IsAdmin, u.MustChangePassword} | ||
} | ||
reset() | ||
assert.Equal(t, createCheck{IsAdmin: false, MustChangePassword: false}, createUser("u", ""), "first non-admin user doesn't need to change password") | ||
|
||
reset() | ||
assert.Equal(t, createCheck{IsAdmin: true, MustChangePassword: false}, createUser("u", "--admin"), "first admin user doesn't need to change password") | ||
|
||
reset() | ||
assert.Equal(t, createCheck{IsAdmin: true, MustChangePassword: true}, createUser("u", "--admin --must-change-password")) | ||
assert.Equal(t, createCheck{IsAdmin: true, MustChangePassword: true}, createUser("u2", "--admin")) | ||
assert.Equal(t, createCheck{IsAdmin: true, MustChangePassword: false}, createUser("u3", "--admin --must-change-password=false")) | ||
assert.Equal(t, createCheck{IsAdmin: false, MustChangePassword: true}, createUser("u4", "")) | ||
assert.Equal(t, createCheck{IsAdmin: false, MustChangePassword: false}, createUser("u5", "--must-change-password=false")) | ||
t.Run("MustChangePassword", func(t *testing.T) { | ||
type check struct { | ||
IsAdmin bool | ||
MustChangePassword bool | ||
} | ||
createCheck := func(name, args string) check { | ||
require.NoError(t, app.Run(strings.Fields(fmt.Sprintf("./gitea admin user create --username %s --email %[email protected] %s --password foobar", name, name, args)))) | ||
u := unittest.AssertExistsAndLoadBean(t, &user_model.User{LowerName: name}) | ||
return check{IsAdmin: u.IsAdmin, MustChangePassword: u.MustChangePassword} | ||
} | ||
reset() | ||
assert.Equal(t, check{IsAdmin: false, MustChangePassword: false}, createCheck("u", ""), "first non-admin user doesn't need to change password") | ||
|
||
reset() | ||
assert.Equal(t, check{IsAdmin: true, MustChangePassword: false}, createCheck("u", "--admin"), "first admin user doesn't need to change password") | ||
|
||
reset() | ||
assert.Equal(t, check{IsAdmin: true, MustChangePassword: true}, createCheck("u", "--admin --must-change-password")) | ||
assert.Equal(t, check{IsAdmin: true, MustChangePassword: true}, createCheck("u2", "--admin")) | ||
assert.Equal(t, check{IsAdmin: true, MustChangePassword: false}, createCheck("u3", "--admin --must-change-password=false")) | ||
assert.Equal(t, check{IsAdmin: false, MustChangePassword: true}, createCheck("u4", "")) | ||
assert.Equal(t, check{IsAdmin: false, MustChangePassword: false}, createCheck("u5", "--must-change-password=false")) | ||
}) | ||
|
||
t.Run("UserType", func(t *testing.T) { | ||
createUser := func(name, args string) error { | ||
return app.Run(strings.Fields(fmt.Sprintf("./gitea admin user create --username %s --email %[email protected] %s", name, name, args))) | ||
} | ||
|
||
reset() | ||
assert.ErrorContains(t, createUser("u", "--user-type invalid"), "invalid user type") | ||
assert.ErrorContains(t, createUser("u", "--user-type bot --password 123"), "can only be set for individual users") | ||
assert.ErrorContains(t, createUser("u", "--user-type bot --must-change-password"), "can only be set for individual users") | ||
|
||
assert.NoError(t, createUser("u", "--user-type bot")) | ||
u := unittest.AssertExistsAndLoadBean(t, &user_model.User{LowerName: "u"}) | ||
assert.Equal(t, user_model.UserTypeBot, u.Type) | ||
assert.Equal(t, "", u.Passwd) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright 2025 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
//go:build windows | ||
|
||
package main | ||
|
||
// Golang has the ability to load OS's timezone data from most UNIX systems (https://github.com/golang/go/blob/master/src/time/zoneinfo_unix.go) | ||
// Even if the timezone data is missing, users could install the related packages to get it. | ||
// But on Windows, although `zoneinfo_windows.go` tries to load the timezone data from Windows registry, | ||
// some users still suffer from the issue that the timezone data is missing: https://github.com/go-gitea/gitea/issues/33235 | ||
// So we import the tzdata package to make sure the timezone data is included in the binary. | ||
// | ||
// For non-Windows package builders, they could still use the "TAGS=timetzdata" to include the tzdata package in the binary. | ||
// If we decided to add the tzdata for other platforms, modify the "go:build" directive above. | ||
import _ "time/tzdata" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.