Skip to content

Commit bf23a19

Browse files
committed
Merge branch 'main' into fork-on-edit
2 parents 170d6b6 + 6bd8fe5 commit bf23a19

File tree

290 files changed

+5098
-2211
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

290 files changed

+5098
-2211
lines changed

.github/workflows/pull-e2e-tests.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ jobs:
1212
uses: ./.github/workflows/files-changed.yml
1313

1414
test-e2e:
15-
if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.frontend == 'true' || needs.files-changed.outputs.actions == 'true'
15+
# the "test-e2e" won't pass, and it seems that there is no useful test, so skip
16+
# if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.frontend == 'true' || needs.files-changed.outputs.actions == 'true'
17+
if: false
1618
needs: files-changed
1719
runs-on: ubuntu-latest
1820
steps:

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ _test
2222
.vscode
2323
__debug_bin*
2424

25+
# Visual Studio
26+
/.vs/
27+
2528
*.cgo1.go
2629
*.cgo2.c
2730
_cgo_defun.c

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,4 @@ Rowan Bohde <[email protected]> (@bohde)
6464
hiifong <[email protected]> (@hiifong)
6565
metiftikci <[email protected]> (@metiftikci)
6666
Christopher Homberger <[email protected]> (@ChristopherHX)
67+
Tobias Balle-Petersen <[email protected]> (@tobiasbp)

assets/go-licenses.json

Lines changed: 2 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/admin_auth_ldap.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"strings"
1010

1111
"code.gitea.io/gitea/models/auth"
12+
"code.gitea.io/gitea/modules/util"
1213
"code.gitea.io/gitea/services/auth/source/ldap"
1314

1415
"github.com/urfave/cli/v2"
@@ -210,8 +211,8 @@ func newAuthService() *authService {
210211
}
211212
}
212213

213-
// parseAuthSource assigns values on authSource according to command line flags.
214-
func parseAuthSource(c *cli.Context, authSource *auth.Source) {
214+
// parseAuthSourceLdap assigns values on authSource according to command line flags.
215+
func parseAuthSourceLdap(c *cli.Context, authSource *auth.Source) {
215216
if c.IsSet("name") {
216217
authSource.Name = c.String("name")
217218
}
@@ -227,6 +228,7 @@ func parseAuthSource(c *cli.Context, authSource *auth.Source) {
227228
if c.IsSet("disable-synchronize-users") {
228229
authSource.IsSyncEnabled = !c.Bool("disable-synchronize-users")
229230
}
231+
authSource.TwoFactorPolicy = util.Iif(c.Bool("skip-local-2fa"), "skip", "")
230232
}
231233

232234
// parseLdapConfig assigns values on config according to command line flags.
@@ -298,9 +300,6 @@ func parseLdapConfig(c *cli.Context, config *ldap.Source) error {
298300
if c.IsSet("allow-deactivate-all") {
299301
config.AllowDeactivateAll = c.Bool("allow-deactivate-all")
300302
}
301-
if c.IsSet("skip-local-2fa") {
302-
config.SkipLocalTwoFA = c.Bool("skip-local-2fa")
303-
}
304303
if c.IsSet("enable-groups") {
305304
config.GroupsEnabled = c.Bool("enable-groups")
306305
}
@@ -376,7 +375,7 @@ func (a *authService) addLdapBindDn(c *cli.Context) error {
376375
},
377376
}
378377

379-
parseAuthSource(c, authSource)
378+
parseAuthSourceLdap(c, authSource)
380379
if err := parseLdapConfig(c, authSource.Cfg.(*ldap.Source)); err != nil {
381380
return err
382381
}
@@ -398,7 +397,7 @@ func (a *authService) updateLdapBindDn(c *cli.Context) error {
398397
return err
399398
}
400399

401-
parseAuthSource(c, authSource)
400+
parseAuthSourceLdap(c, authSource)
402401
if err := parseLdapConfig(c, authSource.Cfg.(*ldap.Source)); err != nil {
403402
return err
404403
}
@@ -427,7 +426,7 @@ func (a *authService) addLdapSimpleAuth(c *cli.Context) error {
427426
},
428427
}
429428

430-
parseAuthSource(c, authSource)
429+
parseAuthSourceLdap(c, authSource)
431430
if err := parseLdapConfig(c, authSource.Cfg.(*ldap.Source)); err != nil {
432431
return err
433432
}
@@ -449,7 +448,7 @@ func (a *authService) updateLdapSimpleAuth(c *cli.Context) error {
449448
return err
450449
}
451450

452-
parseAuthSource(c, authSource)
451+
parseAuthSourceLdap(c, authSource)
453452
if err := parseLdapConfig(c, authSource.Cfg.(*ldap.Source)); err != nil {
454453
return err
455454
}

cmd/admin_auth_oauth.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"net/url"
1010

1111
auth_model "code.gitea.io/gitea/models/auth"
12+
"code.gitea.io/gitea/modules/util"
1213
"code.gitea.io/gitea/services/auth/source/oauth2"
1314

1415
"github.com/urfave/cli/v2"
@@ -156,7 +157,6 @@ func parseOAuth2Config(c *cli.Context) *oauth2.Source {
156157
OpenIDConnectAutoDiscoveryURL: c.String("auto-discover-url"),
157158
CustomURLMapping: customURLMapping,
158159
IconURL: c.String("icon-url"),
159-
SkipLocalTwoFA: c.Bool("skip-local-2fa"),
160160
Scopes: c.StringSlice("scopes"),
161161
RequiredClaimName: c.String("required-claim-name"),
162162
RequiredClaimValue: c.String("required-claim-value"),
@@ -185,10 +185,11 @@ func runAddOauth(c *cli.Context) error {
185185
}
186186

187187
return auth_model.CreateSource(ctx, &auth_model.Source{
188-
Type: auth_model.OAuth2,
189-
Name: c.String("name"),
190-
IsActive: true,
191-
Cfg: config,
188+
Type: auth_model.OAuth2,
189+
Name: c.String("name"),
190+
IsActive: true,
191+
Cfg: config,
192+
TwoFactorPolicy: util.Iif(c.Bool("skip-local-2fa"), "skip", ""),
192193
})
193194
}
194195

@@ -294,6 +295,6 @@ func runUpdateOauth(c *cli.Context) error {
294295

295296
oAuth2Config.CustomURLMapping = customURLMapping
296297
source.Cfg = oAuth2Config
297-
298+
source.TwoFactorPolicy = util.Iif(c.Bool("skip-local-2fa"), "skip", "")
298299
return auth_model.UpdateSource(ctx, source)
299300
}

cmd/admin_auth_stmp.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,6 @@ func parseSMTPConfig(c *cli.Context, conf *smtp.Source) error {
117117
if c.IsSet("disable-helo") {
118118
conf.DisableHelo = c.Bool("disable-helo")
119119
}
120-
if c.IsSet("skip-local-2fa") {
121-
conf.SkipLocalTwoFA = c.Bool("skip-local-2fa")
122-
}
123120
return nil
124121
}
125122

@@ -156,10 +153,11 @@ func runAddSMTP(c *cli.Context) error {
156153
}
157154

158155
return auth_model.CreateSource(ctx, &auth_model.Source{
159-
Type: auth_model.SMTP,
160-
Name: c.String("name"),
161-
IsActive: active,
162-
Cfg: &smtpConfig,
156+
Type: auth_model.SMTP,
157+
Name: c.String("name"),
158+
IsActive: active,
159+
Cfg: &smtpConfig,
160+
TwoFactorPolicy: util.Iif(c.Bool("skip-local-2fa"), "skip", ""),
163161
})
164162
}
165163

@@ -195,6 +193,6 @@ func runUpdateSMTP(c *cli.Context) error {
195193
}
196194

197195
source.Cfg = smtpConfig
198-
196+
source.TwoFactorPolicy = util.Iif(c.Bool("skip-local-2fa"), "skip", "")
199197
return auth_model.UpdateSource(ctx, source)
200198
}

cmd/admin_user_create.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ var microcmdUserCreate = &cli.Command{
8181
Name: "restricted",
8282
Usage: "Make a restricted user account",
8383
},
84+
&cli.StringFlag{
85+
Name: "fullname",
86+
Usage: `The full, human-readable name of the user`,
87+
},
8488
},
8589
}
8690

@@ -191,6 +195,7 @@ func runCreateUser(c *cli.Context) error {
191195
Passwd: password,
192196
MustChangePassword: mustChangePassword,
193197
Visibility: visibility,
198+
FullName: c.String("fullname"),
194199
}
195200

196201
overwriteDefault := &user_model.CreateUserOverwriteOptions{

cmd/admin_user_create_test.go

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,17 @@ func TestAdminUserCreate(t *testing.T) {
5050
assert.Equal(t, check{IsAdmin: false, MustChangePassword: false}, createCheck("u5", "--must-change-password=false"))
5151
})
5252

53-
createUser := func(name, args string) error {
54-
return app.Run(strings.Fields(fmt.Sprintf("./gitea admin user create --username %s --email %s@gitea.local %s", name, name, args)))
53+
createUser := func(name string, args ...string) error {
54+
return app.Run(append([]string{"./gitea", "admin", "user", "create", "--username", name, "--email", name + "@gitea.local"}, args...))
5555
}
5656

5757
t.Run("UserType", func(t *testing.T) {
5858
reset()
59-
assert.ErrorContains(t, createUser("u", "--user-type invalid"), "invalid user type")
60-
assert.ErrorContains(t, createUser("u", "--user-type bot --password 123"), "can only be set for individual users")
61-
assert.ErrorContains(t, createUser("u", "--user-type bot --must-change-password"), "can only be set for individual users")
59+
assert.ErrorContains(t, createUser("u", "--user-type", "invalid"), "invalid user type")
60+
assert.ErrorContains(t, createUser("u", "--user-type", "bot", "--password", "123"), "can only be set for individual users")
61+
assert.ErrorContains(t, createUser("u", "--user-type", "bot", "--must-change-password"), "can only be set for individual users")
6262

63-
assert.NoError(t, createUser("u", "--user-type bot"))
63+
assert.NoError(t, createUser("u", "--user-type", "bot"))
6464
u := unittest.AssertExistsAndLoadBean(t, &user_model.User{LowerName: "u"})
6565
assert.Equal(t, user_model.UserTypeBot, u.Type)
6666
assert.Empty(t, u.Passwd)
@@ -75,7 +75,7 @@ func TestAdminUserCreate(t *testing.T) {
7575

7676
// using "--access-token" only means "all" access
7777
reset()
78-
assert.NoError(t, createUser("u", "--random-password --access-token"))
78+
assert.NoError(t, createUser("u", "--random-password", "--access-token"))
7979
assert.Equal(t, 1, unittest.GetCount(t, &user_model.User{}))
8080
assert.Equal(t, 1, unittest.GetCount(t, &auth_model.AccessToken{}))
8181
accessToken := unittest.AssertExistsAndLoadBean(t, &auth_model.AccessToken{Name: "gitea-admin"})
@@ -85,7 +85,7 @@ func TestAdminUserCreate(t *testing.T) {
8585

8686
// using "--access-token" with name & scopes
8787
reset()
88-
assert.NoError(t, createUser("u", "--random-password --access-token --access-token-name new-token-name --access-token-scopes read:issue,read:user"))
88+
assert.NoError(t, createUser("u", "--random-password", "--access-token", "--access-token-name", "new-token-name", "--access-token-scopes", "read:issue,read:user"))
8989
assert.Equal(t, 1, unittest.GetCount(t, &user_model.User{}))
9090
assert.Equal(t, 1, unittest.GetCount(t, &auth_model.AccessToken{}))
9191
accessToken = unittest.AssertExistsAndLoadBean(t, &auth_model.AccessToken{Name: "new-token-name"})
@@ -98,23 +98,38 @@ func TestAdminUserCreate(t *testing.T) {
9898

9999
// using "--access-token-name" without "--access-token"
100100
reset()
101-
err = createUser("u", "--random-password --access-token-name new-token-name")
101+
err = createUser("u", "--random-password", "--access-token-name", "new-token-name")
102102
assert.Equal(t, 0, unittest.GetCount(t, &user_model.User{}))
103103
assert.Equal(t, 0, unittest.GetCount(t, &auth_model.AccessToken{}))
104104
assert.ErrorContains(t, err, "access-token-name and access-token-scopes flags are only valid when access-token flag is set")
105105

106106
// using "--access-token-scopes" without "--access-token"
107107
reset()
108-
err = createUser("u", "--random-password --access-token-scopes read:issue")
108+
err = createUser("u", "--random-password", "--access-token-scopes", "read:issue")
109109
assert.Equal(t, 0, unittest.GetCount(t, &user_model.User{}))
110110
assert.Equal(t, 0, unittest.GetCount(t, &auth_model.AccessToken{}))
111111
assert.ErrorContains(t, err, "access-token-name and access-token-scopes flags are only valid when access-token flag is set")
112112

113113
// empty permission
114114
reset()
115-
err = createUser("u", "--random-password --access-token --access-token-scopes public-only")
115+
err = createUser("u", "--random-password", "--access-token", "--access-token-scopes", "public-only")
116116
assert.Equal(t, 0, unittest.GetCount(t, &user_model.User{}))
117117
assert.Equal(t, 0, unittest.GetCount(t, &auth_model.AccessToken{}))
118118
assert.ErrorContains(t, err, "access token does not have any permission")
119119
})
120+
121+
t.Run("UserFields", func(t *testing.T) {
122+
reset()
123+
assert.NoError(t, createUser("u-FullNameWithSpace", "--random-password", "--fullname", "First O'Middle Last"))
124+
unittest.AssertExistsAndLoadBean(t, &user_model.User{
125+
Name: "u-FullNameWithSpace",
126+
LowerName: "u-fullnamewithspace",
127+
FullName: "First O'Middle Last",
128+
129+
})
130+
131+
assert.NoError(t, createUser("u-FullNameEmpty", "--random-password", "--fullname", ""))
132+
u := unittest.AssertExistsAndLoadBean(t, &user_model.User{LowerName: "u-fullnameempty"})
133+
assert.Empty(t, u.FullName)
134+
})
120135
}

custom/conf/app.example.ini

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -59,29 +59,23 @@ RUN_USER = ; git
5959
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6060
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6161
;;
62-
;; The protocol the server listens on. One of 'http', 'https', 'http+unix', 'fcgi' or 'fcgi+unix'. Defaults to 'http'
63-
;; Note: Value must be lowercase.
62+
;; The protocol the server listens on. One of "http", "https", "http+unix", "fcgi" or "fcgi+unix".
6463
;PROTOCOL = http
6564
;;
66-
;; Expect PROXY protocol headers on connections
67-
;USE_PROXY_PROTOCOL = false
68-
;;
69-
;; Use PROXY protocol in TLS Bridging mode
70-
;PROXY_PROTOCOL_TLS_BRIDGING = false
71-
;;
72-
; Timeout to wait for PROXY protocol header (set to 0 to have no timeout)
73-
;PROXY_PROTOCOL_HEADER_TIMEOUT=5s
74-
;;
75-
; Accept PROXY protocol headers with UNKNOWN type
76-
;PROXY_PROTOCOL_ACCEPT_UNKNOWN=false
77-
;;
78-
;; Set the domain for the server
65+
;; Set the domain for the server.
7966
;DOMAIN = localhost
8067
;;
81-
;; The AppURL used by Gitea to generate absolute links, defaults to "{PROTOCOL}://{DOMAIN}:{HTTP_PORT}/".
82-
;; Most users should set it to the real website URL of their Gitea instance.
68+
;; The AppURL is used to generate public URL links, defaults to "{PROTOCOL}://{DOMAIN}:{HTTP_PORT}/".
69+
;; Most users should set it to the real website URL of their Gitea instance when there is a reverse proxy.
8370
;ROOT_URL =
8471
;;
72+
;; Controls how to detect the public URL.
73+
;; Although it defaults to "legacy" (to avoid breaking existing users), most instances should use the "auto" behavior,
74+
;; especially when the Gitea instance needs to be accessed in a container network.
75+
;; * legacy: detect the public URL from "Host" header if "X-Forwarded-Proto" header exists, otherwise use "ROOT_URL".
76+
;; * auto: always use "Host" header, and also use "X-Forwarded-Proto" header if it exists. If no "Host" header, use "ROOT_URL".
77+
;PUBLIC_URL_DETECTION = legacy
78+
;;
8579
;; For development purpose only. It makes Gitea handle sub-path ("/sub-path/owner/repo/...") directly when debugging without a reverse proxy.
8680
;; DO NOT USE IT IN PRODUCTION!!!
8781
;USE_SUB_URL_PATH = false
@@ -90,13 +84,25 @@ RUN_USER = ; git
9084
;STATIC_URL_PREFIX =
9185
;;
9286
;; The address to listen on. Either a IPv4/IPv6 address or the path to a unix socket.
93-
;; If PROTOCOL is set to `http+unix` or `fcgi+unix`, this should be the name of the Unix socket file to use.
87+
;; If PROTOCOL is set to "http+unix" or "fcgi+unix", this should be the name of the Unix socket file to use.
9488
;; Relative paths will be made absolute against the _`AppWorkPath`_.
9589
;HTTP_ADDR = 0.0.0.0
9690
;;
97-
;; The port to listen on. Leave empty when using a unix socket.
91+
;; The port to listen on for "http" or "https" protocol. Leave empty when using a unix socket.
9892
;HTTP_PORT = 3000
9993
;;
94+
;; Expect PROXY protocol headers on connections
95+
;USE_PROXY_PROTOCOL = false
96+
;;
97+
;; Use PROXY protocol in TLS Bridging mode
98+
;PROXY_PROTOCOL_TLS_BRIDGING = false
99+
;;
100+
;; Timeout to wait for PROXY protocol header (set to 0 to have no timeout)
101+
;PROXY_PROTOCOL_HEADER_TIMEOUT = 5s
102+
;;
103+
;; Accept PROXY protocol headers with UNKNOWN type
104+
;PROXY_PROTOCOL_ACCEPT_UNKNOWN = false
105+
;;
100106
;; If REDIRECT_OTHER_PORT is true, and PROTOCOL is set to https an http server
101107
;; will be started on PORT_TO_REDIRECT and it will redirect plain, non-secure http requests to the main
102108
;; ROOT_URL. Defaults are false for REDIRECT_OTHER_PORT and 80 for
@@ -518,6 +524,10 @@ INTERNAL_TOKEN =
518524
;;
519525
;; On user registration, record the IP address and user agent of the user to help identify potential abuse.
520526
;; RECORD_USER_SIGNUP_METADATA = false
527+
;;
528+
;; Set the two-factor auth behavior.
529+
;; Set to "enforced", to force users to enroll into Two-Factor Authentication, users without 2FA have no access to repositories via API or web.
530+
;TWO_FACTOR_AUTH =
521531

522532
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
523533
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -1149,6 +1159,10 @@ LEVEL = Info
11491159
;;
11501160
;; Retarget child pull requests to the parent pull request branch target on merge of parent pull request. It only works on merged PRs where the head and base branch target the same repo.
11511161
;RETARGET_CHILDREN_ON_MERGE = true
1162+
;;
1163+
;; Delay mergeable check until page view or API access, for pull requests that have not been updated in the specified days when their base branches get updated.
1164+
;; Use "-1" to always check all pull requests (old behavior). Use "0" to always delay the checks.
1165+
;DELAY_CHECK_FOR_INACTIVE_DAYS = 7
11521166

11531167
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11541168
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -2438,6 +2452,8 @@ LEVEL = Info
24382452
;DEFAULT_GIT_TREES_PER_PAGE = 1000
24392453
;; Default max size of a blob returned by the blobs API (default is 10MiB)
24402454
;DEFAULT_MAX_BLOB_SIZE = 10485760
2455+
;; Default max combined size of all blobs returned by the files API (default is 100MiB)
2456+
;DEFAULT_MAX_RESPONSE_SIZE = 104857600
24412457

24422458
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
24432459
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

0 commit comments

Comments
 (0)