Skip to content

Commit 4b01a54

Browse files
committed
Add LDAP login source and test user sign-in
1 parent 957becb commit 4b01a54

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

.drone.yml

+3
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ pipeline:
142142
environment:
143143
TAGS: bindata
144144
GOPATH: /srv/app
145+
TEST_LDAP: "1"
145146
commands:
146147
- make integration-test-coverage
147148
when:
@@ -155,6 +156,7 @@ pipeline:
155156
environment:
156157
TAGS: bindata
157158
GOPATH: /srv/app
159+
TEST_LDAP: "1"
158160
commands:
159161
- make test-mysql
160162
when:
@@ -167,6 +169,7 @@ pipeline:
167169
environment:
168170
TAGS: bindata
169171
GOPATH: /srv/app
172+
TEST_LDAP: "1"
170173
commands:
171174
- make test-pgsql
172175
when:

integrations/auth_ldap_test.go

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright 2018 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package integrations
6+
7+
import (
8+
"net/http"
9+
"os"
10+
"testing"
11+
)
12+
13+
func skipLDAPTests() bool {
14+
return os.Getenv("TEST_LDAP") != "1"
15+
}
16+
17+
func getLDAPServerHost() string {
18+
host := os.Getenv("TEST_LDAP_HOST")
19+
if len(host) == 0 {
20+
host = "ldap"
21+
}
22+
return host
23+
}
24+
25+
func addAuthSourceLDAP(t *testing.T) {
26+
session := loginUser(t, "user1")
27+
csrf := GetCSRF(t, session, "/admin/auths/new")
28+
req := NewRequestWithValues(t, "POST", "/admin/auths/new", map[string]string{
29+
"_csrf": csrf,
30+
"type": "2",
31+
"name": "ldap",
32+
"host": getLDAPServerHost(),
33+
"port": "389",
34+
"bind_dn": "uid=gitea,ou=service,dc=planetexpress,dc=com",
35+
"bind_password": "password",
36+
"user_base": "ou=people,dc=planetexpress,dc=com",
37+
"filter": "(&(objectClass=inetOrgPerson)(memberOf=cn=git,ou=people,dc=planetexpress,dc=com)(uid=%s))",
38+
"admin_filter": "(memberOf=cn=admin_staff,ou=people,dc=planetexpress,dc=com)",
39+
"attribute_username": "uid",
40+
"attribute_name": "cn",
41+
"attribute_surname": "sn",
42+
"attribute_mail": "mail",
43+
"is_sync_enabled": "on",
44+
"is_active": "on",
45+
})
46+
session.MakeRequest(t, req, http.StatusFound)
47+
}
48+
49+
func TestLDAPUserSignin(t *testing.T) {
50+
if skipLDAPTests() {
51+
t.Skip()
52+
return
53+
}
54+
prepareTestEnv(t)
55+
addAuthSourceLDAP(t)
56+
loginUserWithPassword(t, "fry", "fry")
57+
}

models/fixtures/login_source.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[] # empty

0 commit comments

Comments
 (0)