Commit b62982f1 authored by Joern jkuensem's avatar Joern jkuensem

TMSS-155: Decorate OIDC tests as integrations tests.

parent 72007968
......@@ -190,8 +190,8 @@ if "TMSS_LDAPCREDENTIALS" in os.environ.keys():
import ldap
REST_FRAMEWORK['DEFAULT_AUTHENTICATION_CLASSES'].append('rest_framework.authentication.BasicAuthentication')
#REST_FRAMEWORK['DEFAULT_AUTHENTICATION_CLASSES'].append('rest_framework.authentication.SessionAuthentication')
#REST_FRAMEWORK['DEFAULT_PERMISSION_CLASSES'].append('rest_framework.permissions.IsAuthenticated')
REST_FRAMEWORK['DEFAULT_AUTHENTICATION_CLASSES'].append('rest_framework.authentication.SessionAuthentication')
REST_FRAMEWORK['DEFAULT_PERMISSION_CLASSES'].append('rest_framework.permissions.IsAuthenticated')
# LDAP
ldap_creds_name = os.environ.get('TMSS_LDAPCREDENTIALS', 'tmss_ldap')
......
......@@ -37,16 +37,20 @@ from lofar.sas.tmss.test.tmss_test_environment_unittest_setup import *
from lofar.sas.tmss.test.tmss_test_data_rest import TMSSRESTTestDataCreator
test_data_creator = TMSSRESTTestDataCreator(BASE_URL, AUTH)
from lofar.sas.tmss.util import TMSSsession
from lofar.common.test_utils import integration_test
# todo: figure out why csrftoken is missing when using the TMSSRESTTestDataCreator while it is present when...
# todo: ...running tmss manually and referring to that by overriding BASE_URL here:
# BASE_URL = 'http://localhost:8008/api'
from lofar.sas.tmss.util import TMSSsession
class LDAPSession(unittest.TestCase):
def test_failure_using_no_credentials(self):
with requests.Session() as session:
import time
time.sleep(20)
session.verify = False
r = session.get(BASE_URL + '/task_draft/?format=api')
self.assertEqual(r.status_code, 401)
......@@ -68,8 +72,10 @@ class LDAPSession(unittest.TestCase):
self.assertEqual(r.status_code, 200)
self.assertTrue("Task Draft List" in r.content.decode('utf8'))
@integration_test
class OIDCSession(unittest.TestCase):
@integration_test
def test_failure_without_authentication(self):
with requests.Session() as session:
session.verify = False
......@@ -77,6 +83,7 @@ class OIDCSession(unittest.TestCase):
self.assertEqual(r.status_code, 401)
self.assertTrue("Authentication credentials were not provided" in r.content.decode('utf8'))
@integration_test
def test_failure_using_wrong_credentials(self):
with self.assertRaises(ValueError) as err:
with TMSSsession(AUTH.username, 'wrong', BASE_URL.replace('/api', '')) as session:
......@@ -84,6 +91,7 @@ class OIDCSession(unittest.TestCase):
self.assertTrue('The username and/or password you specified are not correct' in str(err.exception))
@integration_test
def test_success_using_correct_credentials(self):
with TMSSsession(AUTH.username, AUTH.password, BASE_URL.replace('/api', '')) as session:
r = session.get(BASE_URL + '/task_draft/?format=api')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment