Skip to content
Snippets Groups Projects
Commit f3749ef3 authored by Jörn Künsemöller's avatar Jörn Künsemöller
Browse files

TMSS-453: fix test for TMSSsession to work when test env is hosted on 127.0.0.1

parent 84255891
No related branches found
No related tags found
3 merge requests!634WIP: COBALT commissioning delta,!481Draft: SW-971 SW-973 SW-975: Various fixes to build LOFAR correctly.,!476Resolve TMSS-453
......@@ -85,18 +85,23 @@ class OIDCSession(unittest.TestCase):
if "OIDC_RP_CLIENT_ID" not in os.environ.keys():
raise unittest.SkipTest("Cannot run OIDCSession-test when OIDC_RP_CLIENT_ID is not set in the environment to configure django settings")
# Fix the base url if required, since our test Keycloak expects localhost and not 127.0.0.1
self.BASE_URL_fixed = BASE_URL.replace('127.0.0.1', 'localhost')
self.hostname = urllib.parse.urlparse(self.BASE_URL_fixed).hostname
self.port = urllib.parse.urlparse(self.BASE_URL_fixed).port
@integration_test
def test_failure_without_authentication(self):
with requests.Session() as session:
session.verify = False
r = session.get(BASE_URL + '/task_draft/?format=api')
r = session.get(self.BASE_URL_fixed + '/task_draft/?format=api')
self.assertEqual(r.status_code, 401)
self.assertIn("Authentication credentials were not provided", r.content.decode('utf8'))
@integration_test
def test_failure_using_wrong_credentials(self):
with self.assertRaises(ValueError) as err:
with TMSSsession('nouser', 'wrongpassword', urllib.parse.urlparse(BASE_URL).hostname, urllib.parse.urlparse(BASE_URL).port):
with TMSSsession('nouser', 'wrongpassword', self.hostname, self.port):
pass
self.assertIn('The username and/or password you specified are not correct', str(err.exception))
......@@ -106,15 +111,11 @@ class OIDCSession(unittest.TestCase):
'''
Note: This test expects the test env AUTH credentials to work against the OpenID provider in use.
If that is not the case, set working credentials via OIDC_USERNAME and OIDC_PASSWORD env vars.
todo: fix this test for Keycloak. We can login and get redirected back to TMSS as expected,
but unexpectedly get a 401 then, i.e. the session is not authenticated even though it should be.
The callback looks the same as when the credentials are posted with the browser, and there we end up with
an authenticated session. (Not sure if this is somehow cookie-related or so, but Keycloak seems happy...)
'''
username = os.environ.get('OIDC_USERNAME', AUTH.username)
password = os.environ.get('OIDC_PASSWORD', AUTH.password)
with TMSSsession(username, password, urllib.parse.urlparse(BASE_URL).hostname, urllib.parse.urlparse(BASE_URL).port) as tmss_session:
r = tmss_session.session.get(BASE_URL + '/task_draft/')
with TMSSsession(username, password, self.hostname, self.port) as tmss_session:
r = tmss_session.session.get(self.BASE_URL_fixed + '/task_draft/')
self.assertEqual(r.status_code, 200)
self.assertIn('results', r.json())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment