mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-17 05:41:25 +02:00
+10
-1
@@ -2,6 +2,11 @@ sudo: false
|
||||
language: python
|
||||
python:
|
||||
- "2.7"
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- ldap-utils
|
||||
- slapd
|
||||
|
||||
env:
|
||||
- DB="POSTGRESQL"
|
||||
@@ -17,6 +22,7 @@ before_install:
|
||||
install:
|
||||
- python setup.py -q develop
|
||||
- pip install -q psycopg2 mysqlclient
|
||||
- pip install -q -r ldap-requirements.txt
|
||||
- pip install -q -r test-requirements.txt
|
||||
|
||||
before_script:
|
||||
@@ -24,6 +30,10 @@ before_script:
|
||||
- mysql -e "create database IF NOT EXISTS modoboa_test;" -uroot
|
||||
- mysql -e "CREATE USER 'modoboa'@'localhost' IDENTIFIED BY 'modoboa'" -uroot;
|
||||
- mysql -e "GRANT ALL PRIVILEGES ON * . * TO 'modoboa'@'localhost';" -uroot;
|
||||
- mkdir /tmp/slapd
|
||||
- slapd -f test_data/slapd.conf -h ldap://localhost:3389 &
|
||||
- sleep 3
|
||||
- ldapadd -h localhost:3389 -D cn=admin,dc=example,dc=com -w test -f test_data/base.ldif
|
||||
|
||||
script:
|
||||
- python ./tests.py
|
||||
@@ -32,4 +42,3 @@ script:
|
||||
|
||||
after_success:
|
||||
- codecov
|
||||
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
python-ldap
|
||||
django-auth-ldap
|
||||
@@ -1,8 +1,11 @@
|
||||
"""Tests for core application."""
|
||||
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.test import override_settings
|
||||
|
||||
from modoboa.lib import parameters
|
||||
from modoboa.lib.tests import ModoTestCase
|
||||
|
||||
from . import factories
|
||||
from . import models
|
||||
|
||||
@@ -36,6 +39,33 @@ class AuthenticationTestCase(ModoTestCase):
|
||||
self.assertTrue(response.url.endswith(reverse("admin:domain_list")))
|
||||
|
||||
|
||||
@override_settings(AUTHENTICATION_BACKENDS=(
|
||||
'modoboa.lib.authbackends.LDAPBackend',
|
||||
'modoboa.lib.authbackends.SimpleBackend',
|
||||
))
|
||||
class LDAPAuthenticationTestCase(ModoTestCase):
|
||||
|
||||
"""Validate LDAP authentication scenarios."""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
"""Create test data."""
|
||||
super(AuthenticationTestCase, cls).setUpTestData()
|
||||
parameters.save_admin(
|
||||
"AUTHENTICATION_TYPE", "ldap")
|
||||
parameters.save_admin("LDAP_SERVER_PORT", "3389")
|
||||
|
||||
def test_searchbind_authentication(self):
|
||||
"""Test the bind&search method."""
|
||||
self.client.logout()
|
||||
parameters.save_admin("LDAP_BIND_DN", "cn=admin,dc=example,dc=com")
|
||||
parameters.save_admin("LDAP_BIND_PASSWORD", "test")
|
||||
parameters.save_admin("LDAP_SEARCH_BASE", "ou=users,dc=example,dc=com")
|
||||
self.assertTrue(
|
||||
self.client.login(username="testuser@example.com", password="test")
|
||||
)
|
||||
|
||||
|
||||
class ProfileTestCase(ModoTestCase):
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -34,6 +34,11 @@ try:
|
||||
|
||||
class LDAPBackend(orig_LDAPBackend):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
"""Load LDAP settings."""
|
||||
parameters.apply_to_django_settings()
|
||||
super(LDAPBackend, self).__init__(*args, **kwargs)
|
||||
|
||||
def get_or_create_user(self, username, ldap_user):
|
||||
"""
|
||||
This must return a (User, created) 2-tuple for the given
|
||||
@@ -72,7 +77,8 @@ try:
|
||||
def authenticate(self, username, password):
|
||||
auth_type = parameters.get_admin("AUTHENTICATION_TYPE", app="core")
|
||||
if auth_type == "ldap":
|
||||
return super(LDAPBackend, self).authenticate(username, password)
|
||||
return super(LDAPBackend, self).authenticate(
|
||||
username, password)
|
||||
return None
|
||||
|
||||
except ImportError:
|
||||
|
||||
+1
-3
@@ -2,7 +2,7 @@ from django.conf import settings
|
||||
from django.conf.urls import patterns, include, url
|
||||
|
||||
from modoboa.core.extensions import exts_pool
|
||||
from modoboa.lib import parameters, events
|
||||
from modoboa.lib import events
|
||||
|
||||
|
||||
urlpatterns = patterns(
|
||||
@@ -28,8 +28,6 @@ urlpatterns += patterns(
|
||||
*events.raiseQueryEvent("ExtraUprefsRoutes")
|
||||
)
|
||||
|
||||
parameters.apply_to_django_settings()
|
||||
|
||||
# API urls
|
||||
urlpatterns += patterns(
|
||||
"",
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
dn: dc=example,dc=com
|
||||
objectClass: dcObject
|
||||
objectClass: organizationalUnit
|
||||
|
||||
ou: users
|
||||
|
||||
dn: cn=testuser,ou=users,dc=example,dc=com
|
||||
objectClass: inetOrgPerson
|
||||
objectClass: organizationalPerson
|
||||
objectClass: person
|
||||
objectClass: top
|
||||
cn: testuser
|
||||
givenName: Test
|
||||
sn: User
|
||||
mail: testuser@example.com
|
||||
userPassword: {SSHA}AIzygLSXlArhAMzddUriXQxf7UlkqopP
|
||||
@@ -0,0 +1,17 @@
|
||||
# See slapd.conf(5) for details on configuration options.
|
||||
include /etc/ldap/schema/core.schema
|
||||
include /etc/ldap/schema/cosine.schema
|
||||
include /etc/ldap/schema/inetorgperson.schema
|
||||
include /etc/ldap/schema/nis.schema
|
||||
|
||||
pidfile /tmp/slapd/slapd.pid
|
||||
argsfile /tmp/slapd/slapd.args
|
||||
|
||||
modulepath /usr/lib/openldap
|
||||
|
||||
database ldif
|
||||
directory /tmp/slapd
|
||||
|
||||
suffix "dc=example,dc=com"
|
||||
rootdn "cn=admin,dc=example,dc=com"
|
||||
rootpw {SSHA}AIzygLSXlArhAMzddUriXQxf7UlkqopP
|
||||
Reference in New Issue
Block a user