Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ldap authentication #134

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y libldap2-dev libsasl2-dev
python -m pip install --upgrade pip wheel
python -m pip install flake8 pytest pytest-django
python -m pip install -r requirements/requirements.txt
Expand Down
6 changes: 6 additions & 0 deletions client/accounts/forms.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django import forms
from django.conf import settings
from django.contrib.auth import forms as auth_forms

from .emails import send_user_creation_email
Expand All @@ -19,6 +20,11 @@ def __init__(self, *args, **kwargs):
self.request = kwargs.pop('request')
super().__init__(*args, **kwargs)

def clean(self):
if settings.AP_PREDICT_LDAP:
self.add_error(None, 'Registration is disabled when using LDAP')
return super().clean()

def save(self, commit=True):
user = super().save(commit=commit)
if commit:
Expand Down
8 changes: 7 additions & 1 deletion client/accounts/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def test_can_register(client):


@pytest.mark.django_db
def test_register(client):
def test_register(client, settings):
num_mails = len(mail.outbox)
data = {'email': '[email protected]',
'institution': 'uon',
Expand All @@ -69,6 +69,12 @@ def test_register(client):

assert not User.objects.filter(email=data['email']).exists()

settings.AP_PREDICT_LDAP = True
response = client.post('/accounts/register/', data=data)
assert 'Registration is disabled when using LDAP' in str(response.content)
assert not User.objects.filter(email=data['email'])

settings.AP_PREDICT_LDAP = False
client.post('/accounts/register/', data=data)
assert User.objects.filter(email=data['email']).exists()
assert len(mail.outbox) == num_mails + 1
Expand Down
1 change: 1 addition & 0 deletions client/accounts/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@
),

]

app_name = 'accounts'
58 changes: 45 additions & 13 deletions client/config/develop_settings.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,61 @@
import os

from dotenv import load_dotenv

Check warning on line 3 in client/config/develop_settings.py

View check run for this annotation

Codecov / codecov/patch

client/config/develop_settings.py#L3

Added line #L3 was not covered by tests


load_dotenv()

Check warning on line 6 in client/config/develop_settings.py

View check run for this annotation

Codecov / codecov/patch

client/config/develop_settings.py#L6

Added line #L6 was not covered by tests

from .production_settings import * # noqa
from .production_settings import BASE_DIR
from .production_settings import BASE_DIR # noqa

Check warning on line 9 in client/config/develop_settings.py

View check run for this annotation

Codecov / codecov/patch

client/config/develop_settings.py#L9

Added line #L9 was not covered by tests


MEDIA_ROOT = "."

Check warning on line 12 in client/config/develop_settings.py

View check run for this annotation

Codecov / codecov/patch

client/config/develop_settings.py#L12

Added line #L12 was not covered by tests


# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['*']
ALLOWED_HOSTS = ["*"]

Check warning on line 18 in client/config/develop_settings.py

View check run for this annotation

Codecov / codecov/patch

client/config/develop_settings.py#L18

Added line #L18 was not covered by tests

AP_PREDICT_SQLITE = bool(int(os.environ.get("AP_PREDICT_SQLITE", "0")))

Check warning on line 20 in client/config/develop_settings.py

View check run for this annotation

Codecov / codecov/patch

client/config/develop_settings.py#L20

Added line #L20 was not covered by tests
if AP_PREDICT_SQLITE:
DATABASES = {

Check warning on line 22 in client/config/develop_settings.py

View check run for this annotation

Codecov / codecov/patch

client/config/develop_settings.py#L22

Added line #L22 was not covered by tests
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
"OPTIONS": {
# 'timeout': 20,
},
}
}

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'core.context_processors.common',
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [os.path.join(BASE_DIR, "templates")],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
"core.context_processors.common",
],
},
},
]


LOGGING = {

Check warning on line 49 in client/config/develop_settings.py

View check run for this annotation

Codecov / codecov/patch

client/config/develop_settings.py#L49

Added line #L49 was not covered by tests
"version": 1,
"disable_existing_loggers": False,
"handlers": {
"console": {
"class": "logging.StreamHandler",
},
},
"root": {
"handlers": ["console"],
"level": "DEBUG",
},
}
Loading
Loading