Unverified Commit 3961d833 authored by David Haynes's avatar David Haynes
Browse files

Merge branch '2.2-dev' into 109-my-links-to-index

parents 33f7ae4c cd3fbef5
Pipeline #888 passed with stage
in 56 seconds
...@@ -14,3 +14,4 @@ venv ...@@ -14,3 +14,4 @@ venv
.coverage .coverage
htmlcov/ htmlcov/
.idea .idea
__pycache__/
...@@ -10,7 +10,7 @@ variables: ...@@ -10,7 +10,7 @@ variables:
before_script: before_script:
- apt-get update -qy - apt-get update -qy
- apt-get install -y libldap2-dev libsasl2-dev mysql-client libmysqlclient-dev python-mysqldb - apt-get install -y mysql-client libmysqlclient-dev python-mysqldb
- pip install -r requirements/ci.txt - pip install -r requirements/ci.txt
- cd go/ - cd go/
- cp settings/settings.py.template settings/settings.py - cp settings/settings.py.template settings/settings.py
...@@ -31,11 +31,23 @@ Go-py2.7: ...@@ -31,11 +31,23 @@ Go-py2.7:
image: library/python:2.7 image: library/python:2.7
type: test type: test
script: script:
- python manage.py test - python manage.py test
Go-py3.4:
image: library/python:3.4
type: test
script:
- python manage.py test
Go-py3.5:
image: library/python:3.5
type: test
script:
- python manage.py test
Go-py3.6: Go-py3.6:
image: library/python:3.6 image: library/python:3.6
type: test type: test
script: script:
- coverage run --source=go --omit=*migrations/* manage.py test - coverage run --source=go --omit=*migrations/*,*admin.py,*manage.py,*wsgi.py,*settings.py,*secret.py,*__init__.py,*.pyc,*templates/*,*static/* manage.py test
- coverage html -i && grep pc_cov htmlcov/index.html | egrep -o "[0-9]+\%" | awk '{ print "covered " $1;}' - coverage html -i && grep pc_cov htmlcov/index.html | egrep -o "[0-9]+\%" | awk '{ print "covered " $1;}'
...@@ -2,8 +2,6 @@ FROM python:3.6 ...@@ -2,8 +2,6 @@ FROM python:3.6
ENV PYTHONUNBUFFERED 1 ENV PYTHONUNBUFFERED 1
RUN apt-get update RUN apt-get update
RUN apt-get install libsasl2-dev -y
RUN apt-get install libldap2-dev -y
RUN apt-get install netcat -y RUN apt-get install netcat -y
RUN mkdir /go RUN mkdir /go
......
# Future Imports
from __future__ import unicode_literals, absolute_import, print_function, division
# Django Imports
from django.test import TestCase
# App Imports
from .expirelinks import *
"""
Test cases for the functions in expirelinks
"""
class ExpireLinksTest(TestCase):
"""
Default test case, does not actually test anything
"""
def test_Django_Test(self):
self.assertEqual("Hello World!", "Hello World!")
...@@ -13,29 +13,39 @@ from go.models import RegisteredUser ...@@ -13,29 +13,39 @@ from go.models import RegisteredUser
register = template.Library() register = template.Library()
""" """
check if a user is registered Helper template function to check if a user is registered.
givenUser: The User object that we are checking to see if they are registered
or not.
""" """
@register.filter @register.filter
def is_registered(user): def is_registered(givenUser):
# try getting the RegisteredUser of the current user # try getting the RegisteredUser of the current user
try: try:
registered = RegisteredUser.objects.get(username=user.username) getRegisteredUser = RegisteredUser.objects.get(user=givenUser)
# if it works then the user is registered # if it works then the user is registered
return True return getRegisteredUser.registered
# This should never happen
except RegisteredUser.DoesNotExist as ex: except RegisteredUser.DoesNotExist as ex:
print(ex)
# if they don't exist then they are not registered # if they don't exist then they are not registered
return False return False
""" """
check if a user is approved Helper template function to check if a user is approved.
givenUser: The User object that we are checking to see if they are approved
or not.
""" """
@register.filter @register.filter
def is_approved(user): def is_approved(givenUser):
# try getting the RegisteredUser of the current user # try getting the RegisteredUser of the current user
try: try:
registered = RegisteredUser.objects.get(username=user.username) getRegisteredUser = RegisteredUser.objects.get(user=givenUser)
# if they exist, return whether or not they are approved (boolean) # if they exist, return whether or not they are approved (boolean)
return registered.approved return getRegisteredUser.approved
# This should never happen
except RegisteredUser.DoesNotExist as ex: except RegisteredUser.DoesNotExist as ex:
print(ex)
# if they don't exist then they are not approved # if they don't exist then they are not approved
return False return False
# Future Imports
from __future__ import unicode_literals, absolute_import, print_function, division
# Django Imports
from django.test import TestCase
from django.contrib.auth.models import User
# App Imports
from .go_extras import is_registered, is_approved
from go.models import RegisteredUser
"""
Test cases for the template helper functions in go_extras.py
"""
class GoExtrasTest(TestCase):
"""
Create a dummy user to be tested against.
"""
def setUp(self):
User.objects.create(username='dhaynes', password='password')
"""
Test the is_registered function to see if it gives correct false answers
"""
def test_is_registeredFalse(self):
getUser = User.objects.get(username='dhaynes')
getRegisteredUser = RegisteredUser.objects.get(user=getUser)
getRegisteredUser.registered = False
getRegisteredUser.save()
self.assertFalse(is_registered(getUser))
"""
Test the is_registered function to see if it gives correct true answers
"""
def test_is_registeredTrue(self):
getUser = User.objects.get(username='dhaynes')
getRegisteredUser = RegisteredUser.objects.get(user=getUser)
getRegisteredUser.registered = True
getRegisteredUser.save()
self.assertTrue(is_registered(getUser))
"""
Test the is_registered function to see if it gives correct false answers
"""
def test_is_approvedFalse(self):
getUser = User.objects.get(username='dhaynes')
getRegisteredUser = RegisteredUser.objects.get(user=getUser)
getRegisteredUser.approved = False
getRegisteredUser.save()
self.assertFalse(is_approved(getUser))
"""
Test the is_registered function to see if it gives correct true answers
"""
def test_is_approvedTrue(self):
getUser = User.objects.get(username='dhaynes')
getRegisteredUser = RegisteredUser.objects.get(user=getUser)
getRegisteredUser.approved = False
getRegisteredUser.save()
self.assertFalse(is_approved(getUser))
# Future Imports
from __future__ import unicode_literals, absolute_import, print_function, division
# Django Imports
from django.test import TestCase
# App Imports
from go.cas_callbacks import pfparse, pfinfo, create_user
"""
Test cases for the functions in call_callbacks.
"""
class CasCallbacksTest(TestCase):
"""
Presently enrolled student who has been added to peoplefinder
"""
def test_pf_peoplefinder_method(self):
actual = pfinfo('dhaynes3')
expected = ['David', 'Haynes']
self.assertEqual(expected, actual)
"""
Test the parsing method to ensure that first and last names are seperated
accordingly and correctly.
"""
def test_pfparse_peoplefinder_method(self):
actual = pfparse("Haynes, David M")
expected = ['David', 'Haynes']
self.assertEqual(expected, actual)
"""
student no longer in peoplefinder, or who hasn't yet been added
"""
def test_pfinfo_ldap_method(self):
actual = pfinfo('lfaraone')
expected = ['Luke W', 'Faraone']
self.assertEqual(expected, actual)
"""
student employees will have their staff info return before their student info
"""
def test_pfinfo_employee_method(self):
actual = pfinfo('nander13')
expected = ['Nicholas', 'Anderson']
self.assertEqual(expected, actual)
"""
a name not found for either (should never happen, but gracefully handle anyway)
"""
def test_pfinfo_dne(self):
actual = pfinfo('bobama')
expected = ['', '']
self.assertEqual(expected, actual)
# Future Imports
from __future__ import unicode_literals, absolute_import, print_function, division
# Django Imports
from django.test import TestCase
# App Imports
from go.forms import *
"""
Test cases for the URL form
"""
class URLFormTest(TestCase):
"""
Default test case, does not actually test anything
"""
def test_Django_Test(self):
self.assertEqual("Hello World!", "Hello World!")
"""
Test cases for the Signup form
"""
class SignupForm(TestCase):
"""
Default test case, does not actually test anything
"""
def test_Django_Test(self):
self.assertEqual("Hello World!", "Hello World!")
...@@ -8,19 +8,17 @@ from django.contrib.auth.models import User ...@@ -8,19 +8,17 @@ from django.contrib.auth.models import User
# App Imports # App Imports
from go.models import URL, RegisteredUser from go.models import URL, RegisteredUser
"""
Test cases for the URL Model
"""
class URLTest(TestCase):
"""
Default test case, does not actually test anything
"""
def test_Django_Test(self):
self.assertEqual("Hello World!", "Hello World!")
""" """
Test cases for the RegisteredUser Model Test cases for the RegisteredUser Model
- check if RegisteredUsers are actually made
- check approval and registration status flipping
- check blocking
- check printing
- add in description
- check organization field
- check full name field
- check print(RegisteredUser)
""" """
class RegisteredUserTest(TestCase): class RegisteredUserTest(TestCase):
...@@ -31,3 +29,23 @@ class RegisteredUserTest(TestCase): ...@@ -31,3 +29,23 @@ class RegisteredUserTest(TestCase):
getUser = User.objects.get(username='dhaynes') getUser = User.objects.get(username='dhaynes')
getRegisteredUser = RegisteredUser.objects.get(user=getUser) getRegisteredUser = RegisteredUser.objects.get(user=getUser)
self.assertTrue(getRegisteredUser) self.assertTrue(getRegisteredUser)
def test_checkPrint(self):
# expected = '<Registered User: %s - Approval Status: %s>' % (self.user, self.approved)
self.assertTrue(True)
"""
Test cases for the URL Model
- check if URL's are actually created
- modify clicks (social, qr, normal)
- check expiration date creation
- check print function
"""
class URLTest(TestCase):
"""
Default test case, does not actually test anything
"""
def test_Django_Test(self):
self.assertEqual("Hello World!", "Hello World!")
# Future Imports
from __future__ import unicode_literals, absolute_import, print_function, division
# Django Imports
from django.test import TestCase
# App Imports
from go.views import *
"""
Test cases for the index view
"""
class IndexTest(TestCase):
"""
Default test case, does not actually test anything
"""
def test_Django_Test(self):
self.assertEqual("Hello World!", "Hello World!")
"""
Test cases for the "view" view
"""
class ViewTest(TestCase):
"""
Default test case, does not actually test anything
"""
def test_Django_Test(self):
self.assertEqual("Hello World!", "Hello World!")
"""
Test cases for the my_links view
"""
class MyLinksTest(TestCase):
"""
Default test case, does not actually test anything
"""
def test_Django_Test(self):
self.assertEqual("Hello World!", "Hello World!")
"""
Test cases for the delete view
"""
class DeleteTest(TestCase):
"""
Default test case, does not actually test anything
"""
def test_Django_Test(self):
self.assertEqual("Hello World!", "Hello World!")
"""
Test cases for the signup view
"""
class SignupTest(TestCase):
"""
Default test case, does not actually test anything
"""
def test_Django_Test(self):
self.assertEqual("Hello World!", "Hello World!")
"""
Test cases for the redirection view
"""
class RedirectionTest(TestCase):
"""
Default test case, does not actually test anything
"""
def test_Django_Test(self):
self.assertEqual("Hello World!", "Hello World!")
"""
Test cases for the useradmin view
"""
class UserAdminTest(TestCase):
"""
Default test case, does not actually test anything
"""
def test_Django_Test(self):
self.assertEqual("Hello World!", "Hello World!")
...@@ -63,7 +63,6 @@ def my_links(request): ...@@ -63,7 +63,6 @@ def my_links(request):
@ratelimit(key='user', rate='3/m', method='POST', block=True) @ratelimit(key='user', rate='3/m', method='POST', block=True)
@ratelimit(key='user', rate='25/d', method='POST', block=True) @ratelimit(key='user', rate='25/d', method='POST', block=True)
def post(request): def post(request):
# Now we initialize the form again but this time we have the POST # Now we initialize the form again but this time we have the POST
# request # request
url_form = URLForm(request.POST, host = request.META.get('HTTP_HOST')) url_form = URLForm(request.POST, host = request.META.get('HTTP_HOST'))
...@@ -162,7 +161,6 @@ def index(request): ...@@ -162,7 +161,6 @@ def index(request):
}, },
) )
""" """
This view deletes a URL if you have the permission to. User must be This view deletes a URL if you have the permission to. User must be
logged in and registered, and must also be the owner of the URL. logged in and registered, and must also be the owner of the URL.
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
from . import secret from . import secret
import os import os
AUTH_MODE = "CAS"
BASE_DIR = os.path.dirname(os.path.dirname(__file__)) BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# DEBUG mode is used to view more details when errors occur # DEBUG mode is used to view more details when errors occur
...@@ -137,52 +135,25 @@ AUTHENTICATION_BACKENDS = ( ...@@ -137,52 +135,25 @@ AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend', 'django.contrib.auth.backends.ModelBackend',
) )
CAS_SERVER_URL = os.environ['cas_url']
CAS_LOGOUT_COMPLETELY = True
CAS_PROVIDE_URL_TO_LOGOUT = True
if AUTH_MODE.lower() == 'ldap': AUTHENTICATION_BACKENDS += (
import ldap 'cas.backends.CASBackend',
)
AUTHENTICATION_BACKENDS += (
'django_auth_ldap.backend.LDAPBackend',
)
AUTH_LDAP_SERVER_URI = "ldaps://directory.gmu.edu:636" # server url
AUTH_LDAP_BIND_DN = "ou=people,o=gmu.edu" # bind DN
AUTH_LDAP_BIND_AS_AUTHENTICATING_USER = True # use the user
AUTH_LDAP_USER_DN_TEMPLATE = "uid=%(user)s,ou=people,o=gmu.edu"
AUTH_LDAP_GLOBAL_OPTIONS = { # ignore UAC cert.
ldap.OPT_X_TLS: ldap.OPT_X_TLS_DEMAND,
ldap.OPT_X_TLS_REQUIRE_CERT: ldap.OPT_X_TLS_NEVER,
}
AUTH_LDAP_USER_ATTR_MAP = {
"first_name": "givenName",
"last_name": "sn",
"email": "mail"
}
AUTH_LDAP_ALWAYS_UPDATE_USER = True
elif AUTH_MODE.lower() == 'cas':
CAS_SERVER_URL = os.environ['cas_url']
CAS_LOGOUT_COMPLETELY = True
CAS_PROVIDE_URL_TO_LOGOUT = True
AUTHENTICATION_BACKENDS += (
'cas.backends.CASBackend',
)
CAS_RESPONSE_CALLBACKS = (
'go.cas_callbacks.create_user',
)
INSTALLED_APPS += ( CAS_RESPONSE_CALLBACKS = (
'cas', 'go.cas_callbacks.create_user',
) )
MIDDLEWARE_CLASSES += ( INSTALLED_APPS += (
'cas.middleware.CASMiddleware', 'cas',
) )
# PIWIK_SITE_ID = secret.PIWIK_SITE_ID MIDDLEWARE_CLASSES += (
# PIWIK_URL = secret.PIWIK_URL 'cas.middleware.CASMiddleware',
)
CRISPY_TEMPLATE_PACK = 'bootstrap3' CRISPY_TEMPLATE_PACK = 'bootstrap3'
......
...@@ -3,8 +3,6 @@ from . import secret ...@@ -3,8 +3,6 @@ from . import secret
import os import os
import sys import sys
AUTH_MODE = "CAS"
BASE_DIR = os.path.dirname(os.path.dirname(__file__)) BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# DEBUG mode is used to view more details when errors occur # DEBUG mode is used to view more details when errors occur
...@@ -148,49 +146,25 @@ AUTHENTICATION_BACKENDS = ( ...@@ -148,49 +146,25 @@ AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend', 'django.contrib.auth.backends.ModelBackend',
) )
CAS_SERVER_URL = "https://login.gmu.edu"
CAS_LOGOUT_COMPLETELY = True
CAS_PROVIDE_URL_TO_LOGOUT = True
if AUTH_MODE.lower() == 'ldap': AUTHENTICATION_BACKENDS += (
import ldap 'cas.backends.CASBackend',
)
AUTHENTICATION_BACKENDS += (
'django_auth_ldap.backend.LDAPBackend',
)
AUTH_LDAP_SERVER_URI = "ldaps://directory.gmu.edu:636" # server url
AUTH_LDAP_BIND_DN = "ou=people,o=gmu.edu" # bind DN
AUTH_LDAP_BIND_AS_AUTHENTICATING_USER = True # use the user
AUTH_LDAP_USER_DN_TEMPLATE = "uid=%(user)s,ou=people,o=gmu.edu"
AUTH_LDAP_GLOBAL_OPTIONS = { # ignore UAC cert.
ldap.OPT_X_TLS: ldap.OPT_X_TLS_DEMAND,
ldap.OPT_X_TLS_REQUIRE_CERT: ldap.OPT_X_TLS_NEVER,
}
AUTH_LDAP_USER_ATTR_MAP = {
"first_name": "givenName",
"last_name": "sn",
"email": "mail"
}
AUTH_LDAP_ALWAYS_UPDATE_USER = True
elif AUTH_MODE.lower() == 'cas':
CAS_SERVER_URL = "https://login.gmu.edu"
CAS_LOGOUT_COMPLETELY = True
CAS_PROVIDE_URL_TO_LOGOUT = True
AUTHENTICATION_BACKENDS += (