Skip to content

Commit a38947e

Browse files
committed
Merge branch 'add-ldap-configuration-edit-tests' into move-login-out-of-models
2 parents 28c8f31 + 699bd42 commit a38947e

29 files changed

+221
-68
lines changed

.drone.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ steps:
404404

405405
- name: update
406406
pull: default
407-
image: alpine:3.14
407+
image: alpine:3.13
408408
commands:
409409
- ./build/update-locales.sh
410410

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,18 @@ been added to each release, please refer to the [blog](https://blog.gitea.io).
216216
* Remove utf8 option from installation page (#16126)
217217
* Use Wants= over Requires= in systemd file (#15897)
218218

219+
## [1.14.5](https://github.com/go-gitea/gitea/releases/tag/v1.14.5) - 2021-07-16
220+
221+
* SECURITY
222+
* Hide mirror passwords on repo settings page (#16022) (#16355)
223+
* Update bluemonday to v1.0.15 (#16379) (#16380)
224+
* BUGFIXES
225+
* Retry rename on lock induced failures (#16435) (#16439)
226+
* Validate issue index before querying DB (#16406) (#16410)
227+
* Fix crash following ldap authentication update (#16447) (#16449)
228+
* ENHANCEMENTS
229+
* Redirect on bad CSRF instead of presenting bad page (#14937) (#16378)
230+
219231
## [1.14.4](https://github.com/go-gitea/gitea/releases/tag/v1.14.4) - 2021-07-06
220232

221233
* BUGFIXES

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
###################################
33
#Build stage
4-
FROM golang:1.16-alpine3.14 AS build-env
4+
FROM golang:1.16-alpine3.13 AS build-env
55

66
ARG GOPROXY
77
ENV GOPROXY ${GOPROXY:-direct}
@@ -25,7 +25,7 @@ RUN if [ -n "${GITEA_VERSION}" ]; then git checkout "${GITEA_VERSION}"; fi \
2525
# Begin env-to-ini build
2626
RUN go build contrib/environment-to-ini/environment-to-ini.go
2727

28-
FROM alpine:3.14
28+
FROM alpine:3.13
2929
LABEL maintainer="[email protected]"
3030

3131
EXPOSE 22 3000

Dockerfile.rootless

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
###################################
33
#Build stage
4-
FROM golang:1.16-alpine3.14 AS build-env
4+
FROM golang:1.16-alpine3.13 AS build-env
55

66
ARG GOPROXY
77
ENV GOPROXY ${GOPROXY:-direct}
@@ -25,7 +25,7 @@ RUN if [ -n "${GITEA_VERSION}" ]; then git checkout "${GITEA_VERSION}"; fi \
2525
# Begin env-to-ini build
2626
RUN go build contrib/environment-to-ini/environment-to-ini.go
2727

28-
FROM alpine:3.14
28+
FROM alpine:3.13
2929
LABEL maintainer="[email protected]"
3030

3131
EXPOSE 2222 3000

custom/conf/app.example.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,9 @@ PATH =
652652
;; Default value for AllowCreateOrganization
653653
;; Every new user will have rights set to create organizations depending on this setting
654654
;DEFAULT_ALLOW_CREATE_ORGANIZATION = true
655+
;; Default value for IsRestricted
656+
;; Every new user will have restricted permissions depending on this setting
657+
;DEFAULT_USER_IS_RESTRICTED = false
655658
;;
656659
;; Either "public", "limited" or "private", default is "public"
657660
;; Limited is for users visible only to signed users

docs/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ params:
1818
description: Git with a cup of tea
1919
author: The Gitea Authors
2020
website: https://docs.gitea.io
21-
version: 1.14.4
21+
version: 1.14.5
2222
minGoVersion: 1.14
2323
goVersion: 1.16
2424
minNodeVersion: 12.17

docs/content/doc/advanced/adding-legal-pages.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ You absolutely must not place a general ToS or privacy statement that implies th
3232
Create or append to `/path/to/custom/templates/custom/extra_links_footer.tmpl`:
3333

3434
```go
35-
<a class="item" href="{{AppSubUrl}}/privacy.html">Privacy Policy</a>
35+
<a class="item" href="{{AppSubUrl}}/assets/privacy.html">Privacy Policy</a>
3636
```
3737

3838
Restart Gitea to see the changes.

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ relation to port exhaustion.
502502
- `HCAPTCHA_SITEKEY`: **""**: Sign up at https://www.hcaptcha.com/ to get a sitekey for hcaptcha.
503503
- `DEFAULT_KEEP_EMAIL_PRIVATE`: **false**: By default set users to keep their email address private.
504504
- `DEFAULT_ALLOW_CREATE_ORGANIZATION`: **true**: Allow new users to create organizations by default.
505+
- `DEFAULT_USER_IS_RESTRICTED`: **false**: Give new users restricted permissions by default
505506
- `DEFAULT_ENABLE_DEPENDENCIES`: **true**: Enable this to have dependencies enabled by default.
506507
- `ALLOW_CROSS_REPOSITORY_DEPENDENCIES` : **true** Enable this to allow dependencies on issues from any repository where the user is granted access.
507508
- `ENABLE_USER_HEATMAP`: **true**: Enable this to display the heatmap on users profiles.

docs/content/doc/advanced/customizing-gitea.en-us.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ For instance, let's say you are in Germany and must add the famously legally-req
102102
just place it under your "$GITEA_CUSTOM/public/" directory (for instance `$GITEA_CUSTOM/public/impressum.html`) and put a link to it in either `$GITEA_CUSTOM/templates/custom/extra_links.tmpl` or `$GITEA_CUSTOM/templates/custom/extra_links_footer.tmpl`.
103103

104104
To match the current style, the link should have the class name "item", and you can use `{{AppSubUrl}}` to get the base URL:
105-
`<a class="item" href="{{AppSubUrl}}/impressum.html">Impressum</a>`
105+
`<a class="item" href="{{AppSubUrl}}/assets/impressum.html">Impressum</a>`
106106

107107
For more information, see [Adding Legal Pages](https://docs.gitea.io/en-us/adding-legal-pages).
108108

@@ -174,21 +174,21 @@ You can display STL file directly in Gitea by adding:
174174
175175
if ($('.view-raw>a[href$=".stl" i]').length) {
176176
$("body").append(
177-
'<link href="/Madeleine.js/src/css/Madeleine.css" rel="stylesheet">'
177+
'<link href="/assets/Madeleine.js/src/css/Madeleine.css" rel="stylesheet">'
178178
);
179179
Promise.all([
180-
lS("/Madeleine.js/src/lib/stats.js"),
181-
lS("/Madeleine.js/src/lib/detector.js"),
182-
lS("/Madeleine.js/src/lib/three.min.js"),
183-
lS("/Madeleine.js/src/Madeleine.js"),
180+
lS("/assets/Madeleine.js/src/lib/stats.js"),
181+
lS("/assets/Madeleine.js/src/lib/detector.js"),
182+
lS("/assets/Madeleine.js/src/lib/three.min.js"),
183+
lS("/assets/Madeleine.js/src/Madeleine.js"),
184184
]).then(function () {
185185
$(".view-raw")
186186
.attr("id", "view-raw")
187187
.attr("style", "padding: 0;margin-bottom: -10px;");
188188
new Madeleine({
189189
target: "view-raw",
190190
data: $('.view-raw>a[href$=".stl" i]').attr("href"),
191-
path: "/Madeleine.js/src",
191+
path: "/assets/Madeleine.js/src",
192192
});
193193
$('.view-raw>a[href$=".stl"]').remove();
194194
});

docs/content/doc/advanced/customizing-gitea.zh-cn.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Gitea 引用 `custom` 目录中的自定义配置文件来覆盖配置、模板
6161
"custom/public/"目录下(比如 `custom/public/impressum.html`)并且将它与 `custom/templates/custom/extra_links.tmpl` 链接起来即可。
6262

6363
这个链接应当使用一个名为“item”的 class 来匹配当前样式,您可以使用 `{{AppSubUrl}}` 来获取 base URL:
64-
`<a class="item" href="{{AppSubUrl}}/impressum.html">Impressum</a>`
64+
`<a class="item" href="{{AppSubUrl}}/assets/impressum.html">Impressum</a>`
6565

6666
同理,您可以将页签添加到 `extra_tabs.tmpl` 中,使用同样的方式来添加页签。它的具体样式需要与
6767
`templates/repo/header.tmpl` 中已有的其他选项卡的样式匹配

docs/content/doc/advanced/external-renderers.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,5 +164,5 @@ And so you could write some CSS:
164164

165165
Add your stylesheet to your custom directory e.g `custom/public/css/my-style-XXXXX.css` and import it using a custom header file `custom/templates/custom/header.tmpl`:
166166
```html
167-
<link type="text/css" href="{{AppSubUrl}}/css/my-style-XXXXX.css" />
167+
<link type="text/css" href="{{AppSubUrl}}/assets/css/my-style-XXXXX.css" />
168168
```

docs/content/doc/usage/fail2ban-setup.en-us.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,12 @@ this to your Nginx configuration so that IPs don't show up as 127.0.0.1:
108108
```
109109
proxy_set_header X-Real-IP $remote_addr;
110110
```
111+
112+
The security options in `app.ini` need to be adjusted to allow the interpretation of the headers
113+
as well as the list of IP addresses and networks that describe trusted proxy servers
114+
(See the [configuration cheat sheet](https://docs.gitea.io/en-us/config-cheat-sheet/#security-security) for more information).
115+
116+
```
117+
REVERSE_PROXY_LIMIT = 1
118+
REVERSE_PROXY_TRUSTED_PROXIES = 127.0.0.1/8 ; 172.17.0.0/16 for the docker default network
119+
```

integrations/auth_ldap_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,60 @@ func TestLDAPUserSignin(t *testing.T) {
144144
assert.Equal(t, u.Email, htmlDoc.Find(`label[for="email"]`).Siblings().First().Text())
145145
}
146146

147+
func TestLDAPAuthChange(t *testing.T) {
148+
defer prepareTestEnv(t)()
149+
addAuthSourceLDAP(t, "")
150+
151+
session := loginUser(t, "user1")
152+
req := NewRequest(t, "GET", "/admin/auths")
153+
resp := session.MakeRequest(t, req, http.StatusOK)
154+
doc := NewHTMLParser(t, resp.Body)
155+
href, exists := doc.Find("table.table td a").Attr("href")
156+
if !exists {
157+
assert.True(t, exists, "No authentication source found")
158+
return
159+
}
160+
161+
req = NewRequest(t, "GET", href)
162+
resp = session.MakeRequest(t, req, http.StatusOK)
163+
doc = NewHTMLParser(t, resp.Body)
164+
csrf := doc.GetCSRF()
165+
host, _ := doc.Find(`input[name="host"]`).Attr("value")
166+
assert.Equal(t, host, getLDAPServerHost())
167+
binddn, _ := doc.Find(`input[name="bind_dn"]`).Attr("value")
168+
assert.Equal(t, binddn, "uid=gitea,ou=service,dc=planetexpress,dc=com")
169+
170+
req = NewRequestWithValues(t, "POST", href, map[string]string{
171+
"_csrf": csrf,
172+
"type": "2",
173+
"name": "ldap",
174+
"host": getLDAPServerHost(),
175+
"port": "389",
176+
"bind_dn": "uid=gitea,ou=service,dc=planetexpress,dc=com",
177+
"bind_password": "password",
178+
"user_base": "ou=people,dc=planetexpress,dc=com",
179+
"filter": "(&(objectClass=inetOrgPerson)(memberOf=cn=git,ou=people,dc=planetexpress,dc=com)(uid=%s))",
180+
"admin_filter": "(memberOf=cn=admin_staff,ou=people,dc=planetexpress,dc=com)",
181+
"restricted_filter": "(uid=leela)",
182+
"attribute_username": "uid",
183+
"attribute_name": "givenName",
184+
"attribute_surname": "sn",
185+
"attribute_mail": "mail",
186+
"attribute_ssh_public_key": "",
187+
"is_sync_enabled": "on",
188+
"is_active": "on",
189+
})
190+
session.MakeRequest(t, req, http.StatusFound)
191+
192+
req = NewRequest(t, "GET", href)
193+
resp = session.MakeRequest(t, req, http.StatusOK)
194+
doc = NewHTMLParser(t, resp.Body)
195+
host, _ = doc.Find(`input[name="host"]`).Attr("value")
196+
assert.Equal(t, host, getLDAPServerHost())
197+
binddn, _ = doc.Find(`input[name="bind_dn"]`).Attr("value")
198+
assert.Equal(t, binddn, "uid=gitea,ou=service,dc=planetexpress,dc=com")
199+
}
200+
147201
func TestLDAPUserSync(t *testing.T) {
148202
if skipLDAPTests() {
149203
t.Skip()

integrations/signup_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"strings"
1111
"testing"
1212

13+
"code.gitea.io/gitea/models"
1314
"code.gitea.io/gitea/modules/setting"
1415
"github.com/stretchr/testify/assert"
1516
"github.com/unknwon/i18n"
@@ -33,6 +34,28 @@ func TestSignup(t *testing.T) {
3334
MakeRequest(t, req, http.StatusOK)
3435
}
3536

37+
func TestSignupAsRestricted(t *testing.T) {
38+
defer prepareTestEnv(t)()
39+
40+
setting.Service.EnableCaptcha = false
41+
setting.Service.DefaultUserIsRestricted = true
42+
43+
req := NewRequestWithValues(t, "POST", "/user/sign_up", map[string]string{
44+
"user_name": "restrictedUser",
45+
"email": "[email protected]",
46+
"password": "examplePassword!1",
47+
"retype": "examplePassword!1",
48+
})
49+
MakeRequest(t, req, http.StatusFound)
50+
51+
// should be able to view new user's page
52+
req = NewRequest(t, "GET", "/restrictedUser")
53+
MakeRequest(t, req, http.StatusOK)
54+
55+
user2 := models.AssertExistsAndLoadBean(t, &models.User{Name: "restrictedUser"}).(*models.User)
56+
assert.True(t, user2.IsRestricted)
57+
}
58+
3659
func TestSignupEmail(t *testing.T) {
3760
defer prepareTestEnv(t)()
3861

models/helper.go

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
package models
66

77
import (
8+
"encoding/binary"
9+
810
jsoniter "github.com/json-iterator/go"
911
)
1012

@@ -32,13 +34,32 @@ func valuesUser(m map[int64]*User) []*User {
3234
return values
3335
}
3436

35-
// JSONUnmarshalIgnoreErroneousBOM - due to a bug in xorm (see https://gitea.com/xorm/xorm/pulls/1957) - it's
36-
// possible that a Blob may gain an unwanted prefix of 0xff 0xfe.
37-
func JSONUnmarshalIgnoreErroneousBOM(bs []byte, v interface{}) error {
37+
// JSONUnmarshalHandleDoubleEncode - due to a bug in xorm (see https://gitea.com/xorm/xorm/pulls/1957) - it's
38+
// possible that a Blob may be double encoded or gain an unwanted prefix of 0xff 0xfe.
39+
func JSONUnmarshalHandleDoubleEncode(bs []byte, v interface{}) error {
3840
json := jsoniter.ConfigCompatibleWithStandardLibrary
39-
err := json.Unmarshal(bs, &v)
41+
err := json.Unmarshal(bs, v)
42+
if err != nil {
43+
ok := true
44+
rs := []byte{}
45+
temp := make([]byte, 2)
46+
for _, rn := range string(bs) {
47+
if rn > 0xffff {
48+
ok = false
49+
break
50+
}
51+
binary.LittleEndian.PutUint16(temp, uint16(rn))
52+
rs = append(rs, temp...)
53+
}
54+
if ok {
55+
if rs[0] == 0xff && rs[1] == 0xfe {
56+
rs = rs[2:]
57+
}
58+
err = json.Unmarshal(rs, v)
59+
}
60+
}
4061
if err != nil && len(bs) > 2 && bs[0] == 0xff && bs[1] == 0xfe {
41-
err = json.Unmarshal(bs[2:], &v)
62+
err = json.Unmarshal(bs[2:], v)
4263
}
4364
return err
4465
}

models/migrations/v189.go

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,38 @@
55
package migrations
66

77
import (
8+
"encoding/binary"
89
"fmt"
910

1011
jsoniter "github.com/json-iterator/go"
1112
"xorm.io/xorm"
1213
)
1314

1415
func unwrapLDAPSourceCfg(x *xorm.Engine) error {
15-
jsonUnmarshalIgnoreErroneousBOM := func(bs []byte, v interface{}) error {
16+
jsonUnmarshalHandleDoubleEncode := func(bs []byte, v interface{}) error {
1617
json := jsoniter.ConfigCompatibleWithStandardLibrary
17-
err := json.Unmarshal(bs, &v)
18+
err := json.Unmarshal(bs, v)
19+
if err != nil {
20+
ok := true
21+
rs := []byte{}
22+
temp := make([]byte, 2)
23+
for _, rn := range string(bs) {
24+
if rn > 0xffff {
25+
ok = false
26+
break
27+
}
28+
binary.LittleEndian.PutUint16(temp, uint16(rn))
29+
rs = append(rs, temp...)
30+
}
31+
if ok {
32+
if rs[0] == 0xff && rs[1] == 0xfe {
33+
rs = rs[2:]
34+
}
35+
err = json.Unmarshal(rs, v)
36+
}
37+
}
1838
if err != nil && len(bs) > 2 && bs[0] == 0xff && bs[1] == 0xfe {
19-
err = json.Unmarshal(bs[2:], &v)
39+
err = json.Unmarshal(bs[2:], v)
2040
}
2141
return err
2242
}
@@ -59,7 +79,7 @@ func unwrapLDAPSourceCfg(x *xorm.Engine) error {
5979
wrapped := &WrappedSource{
6080
Source: map[string]interface{}{},
6181
}
62-
err := jsonUnmarshalIgnoreErroneousBOM([]byte(source.Cfg), &wrapped)
82+
err := jsonUnmarshalHandleDoubleEncode([]byte(source.Cfg), &wrapped)
6383
if err != nil {
6484
return fmt.Errorf("failed to unmarshal %s: %w", string(source.Cfg), err)
6585
}

0 commit comments

Comments
 (0)