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

Am/feature inactivity timeout #1572

Merged
merged 6 commits into from
Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 4 additions & 1 deletion install.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ def create_environment_json(path):
"static": "static_root",
"secret-key": secret_key,
"test_visible": False,
"debug": True
"debug": True,
"session_security_expire_at_browser_close" : True,
davidpofo marked this conversation as resolved.
Show resolved Hide resolved
"session_security_warn_after" : 1200,
"session_security_expire_after" : 1800
}
# Create local directory
if not os.path.exists('local'):
Expand Down
3 changes: 3 additions & 0 deletions requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,6 @@ markupsafe==1.1.1 # BSD 3

# Excel exports
openpyxl # MIT License

# Session timeout & security
django-session-security
965 changes: 134 additions & 831 deletions requirements.txt

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions siteapp/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os, os.path, json
from platform import uname, system
from django.core.exceptions import ValidationError
#from system_settings.models import SystemSettings
azharem marked this conversation as resolved.
Show resolved Hide resolved
# What's the name of the app containing this file? That determines
# the module for the main URLconf etc.
primary_app = os.path.basename(os.path.dirname(__file__))
Expand Down Expand Up @@ -98,6 +99,7 @@ def make_secret_key():
'django.contrib.messages',
'django.contrib.humanize',
'django.contrib.admindocs',
'session_security',

]
THIRD_PARTY_APPS = [
Expand Down Expand Up @@ -141,6 +143,7 @@ def make_secret_key():
'simple_history.middleware.HistoryRequestMiddleware',
'pyinstrument.middleware.ProfilerMiddleware',
#'django.middleware.cache.FetchFromCacheMiddleware',
'session_security.middleware.SessionSecurityMiddleware',
]
# The cache connection to use for the cache middleware.
#CACHE_MIDDLEWARE_ALIAS='default'
Expand Down Expand Up @@ -403,6 +406,17 @@ def make_secret_key():
SECURE_CONTENT_TYPE_NOSNIFF = True
X_FRAME_OPTIONS = 'DENY' # don't allow site to be embedded in iframes

# Session security and inactivity timeout. Logout user after certain period of inactivity.
# By default user is warned at 20 minutes that session is about to expire and if user does not perform any mouse/keyboard activity
# the session expires 10 minutes later (total of 30 minutes).
warn_after = 85800
expire_after = 86400
expire_at_browser_close = True

SESSION_EXPIRE_AT_BROWSER_CLOSE = environment['session_security_expire_at_browser_close'] if not DEBUG else expire_at_browser_close
SESSION_SECURITY_WARN_AFTER = environment['session_security_warn_after'] if not DEBUG else warn_after
SESSION_SECURITY_EXPIRE_AFTER = environment['session_security_expire_after'] if not DEBUG else expire_after
azharem marked this conversation as resolved.
Show resolved Hide resolved

# Put static files in the virtual path "/static/". When the "static"
# environment setting is present, then it's a local directory path
# where "collectstatic" will put static files.
Expand Down
12 changes: 12 additions & 0 deletions siteapp/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from django.test.client import RequestFactory

import selenium.webdriver
from selenium.webdriver.remote.command import Command
from django.urls import reverse
from selenium.common.exceptions import WebDriverException
from django.contrib.auth.models import Permission
Expand Down Expand Up @@ -259,6 +260,9 @@ def test_supportpage_customize(self):
self.assertInNodeText("support@govready.com", "#support_content")

class LandingSiteFunctionalTests(SeleniumTest):
def setUp(self):
super().setUp()

def test_homepage(self):
self.browser.get(self.url("/"))
self.assertRegex(self.browser.title, "Welcome to Compliance Automation")
Expand Down Expand Up @@ -499,6 +503,14 @@ def test_static_pages(self):
wait_for_sleep_after(lambda: self.browser.get(self.url("/love-assessments")))
wait_for_sleep_after(lambda: self.assertRegex(self.browser.title, "Love Assessments"))

def test_session_timeout(self):
self._login()
ping_url = self.url("/session_security/ping/?idleFor=0")
response = self.client_get(ping_url)
#self.browser.get(ping_url)
azharem marked this conversation as resolved.
Show resolved Hide resolved
self.assertTrue(response.status_code==200)
self.assertTrue(response.content==b'0')

def test_simple_module(self):
# Log in and create a new project and start its task.
self._login()
Expand Down
1 change: 1 addition & 0 deletions siteapp/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
url(r'^tags/_save$', views.create_tag),
url(r'^tags/(\d+)/_delete$', views.delete_tag),
url(r'^tags/$', views.list_tags),
url(r'session_security/', include('session_security.urls')),
azharem marked this conversation as resolved.
Show resolved Hide resolved
]

if 'django.contrib.auth.backends.ModelBackend' in settings.AUTHENTICATION_BACKENDS:
Expand Down
2 changes: 1 addition & 1 deletion templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ <h4 class="modal-title" id="invitation_modal_title">...</h4>
}
</script>
{% endif %}

{% include 'session_security/all.html' %}
{% block scripts %}
{% endblock %}
</body>
Expand Down