|
| 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 | +} |
0 commit comments