diff --git a/SAS/LSMR/src/lsmr/settings.py b/SAS/LSMR/src/lsmr/settings.py index 1350635ff2dd8d6046ae29c0a1b9f5beb802fb54..40ce53ce928ae56bd55b5680721f374c600fc6ac 100644 --- a/SAS/LSMR/src/lsmr/settings.py +++ b/SAS/LSMR/src/lsmr/settings.py @@ -147,7 +147,7 @@ AUTH_LDAP_CONNECTION_OPTIONS = { ldap.OPT_X_TLS_REQUIRE_CERT : ldap.OPT_X_TLS_NE # AUTH_LDAP_BIND_PASSWORD = '' # our LDAP is open protocol = 'ldaps://' if 'test' in ldap_creds_name: - logging.info('Test credentials detected, using insecure connection') # mock LDAP does not support ldaps:// + logging.warning('Test ldap credentials detected, using insecure connection for ldap autenthication') # mock LDAP does not support ldaps:// protocol = 'ldap://' AUTH_LDAP_SERVER_URI = "%s%s:%s" % (protocol, django_ldap_credentials.host, django_ldap_credentials.port) AUTH_LDAP_USER_DN_TEMPLATE="cn=%(user)s,ou=Users,o=lofar,c=eu" diff --git a/SAS/LSMR/test/t_lsmrapp_scheduling_django.run b/SAS/LSMR/test/t_lsmrapp_scheduling_django.run index 2f0b3cd8eeb1a52737e0dfd22eba99e9847a67b7..cef966bd134339dc6621f438f2ccba7cabbc17ae 100755 --- a/SAS/LSMR/test/t_lsmrapp_scheduling_django.run +++ b/SAS/LSMR/test/t_lsmrapp_scheduling_django.run @@ -1,6 +1,9 @@ -#!/bin/sh +#!/bin/bash -$LOFARROOT/lib*/python*/site-packages/lofar/sas/lsmr/manage.py test --pattern="t_lsmrapp_scheduling_django.py" --testrunner=postgres_testrunner.PostgresqlTestRunner +. test_funcs.sh + +setup +run_test $LOFARROOT/lib*/python*/site-packages/lofar/sas/lsmr/manage.py test --pattern="t_lsmrapp_scheduling_django.py" --testrunner=postgres_testrunner.PostgresqlTestRunner diff --git a/SAS/LSMR/test/t_lsmrapp_scheduling_functional.py b/SAS/LSMR/test/t_lsmrapp_scheduling_functional.py index 4f29a734984ef098e3166fedd9dbfb029736efb3..f33821d523a3ea8ace81c53ed5da79a1fd18dc04 100755 --- a/SAS/LSMR/test/t_lsmrapp_scheduling_functional.py +++ b/SAS/LSMR/test/t_lsmrapp_scheduling_functional.py @@ -27,7 +27,7 @@ # todo: behavior in a controlled way. # todo: We should probably also fully test behavior wrt mandatory and nullable fields. - +import os import unittest import requests import json @@ -39,16 +39,9 @@ from t_lsmrapp_specification_functional import BASE_URL, _call_API_and_assert_ex from requests.auth import HTTPBasicAuth from lofar.common import dbcredentials -# Read Login credentials (todo: when we authorize functionality based on specific users, we need sth better than this) - -# this requires a config file .lofar/dbcredentials/lsmr.ini, with contents as such (adapt as needed): -# -# [database:lsmr_ldap] -# user = ldapuser -# password = ldappass -# -dbc = dbcredentials.DBCredentials() -ldap_credentials = dbc.get("lsmr_ldap_test") +# read ldap_credentials from ~/.lofar/dbcredentials/<ldap_creds_filename.ini> +# such a file is created automagically in the test_funcs.sh and passed to this test via the LSMR_LDAPCREDENTIALS environment variable. +ldap_credentials = dbcredentials.DBCredentials().get(os.environ.get('LSMR_LDAPCREDENTIALS', 'lsmr_ldap_test')) print('Using ldap credentials', ldap_credentials.stringWithHiddenPassword()) class TaskTemplateTestCase(unittest.TestCase): diff --git a/SAS/LSMR/test/t_lsmrapp_specification_django.run b/SAS/LSMR/test/t_lsmrapp_specification_django.run index 833baf2385f7229ce2a31e8023851d106d549db2..81450aa2a5ddfa91204be0aae358f944e6a06eb4 100755 --- a/SAS/LSMR/test/t_lsmrapp_specification_django.run +++ b/SAS/LSMR/test/t_lsmrapp_specification_django.run @@ -1,6 +1,9 @@ -#!/bin/sh +#!/bin/bash -$LOFARROOT/lib*/python*/site-packages/lofar/sas/lsmr/manage.py test --pattern="t_lsmrapp_specification_django.py" --testrunner=postgres_testrunner.PostgresqlTestRunner +. test_funcs.sh + +setup +run_test $LOFARROOT/lib*/python*/site-packages/lofar/sas/lsmr/manage.py test --pattern="t_lsmrapp_specification_django.py" --testrunner=postgres_testrunner.PostgresqlTestRunner diff --git a/SAS/LSMR/test/t_lsmrapp_specification_functional.py b/SAS/LSMR/test/t_lsmrapp_specification_functional.py index 5b52af117d37737dd8cd3d69e3928f19ae2a82b2..70493441c1abfe490cf4d87b4fa6feb256139d1d 100755 --- a/SAS/LSMR/test/t_lsmrapp_specification_functional.py +++ b/SAS/LSMR/test/t_lsmrapp_specification_functional.py @@ -41,8 +41,10 @@ import logging DJANGO_PORT=os.environ.get('DJANGO_TEST_PORT', 0) BASE_URL = 'http://localhost:%s' % (DJANGO_PORT,) -dbc = dbcredentials.DBCredentials() -ldap_credentials = dbc.get("lsmr_ldap_test") +# read ldap_credentials from ~/.lofar/dbcredentials/<ldap_creds_filename.ini> +# such a file is created automagically in the test_funcs.sh and passed to this test via the LSMR_LDAPCREDENTIALS environment variable. +ldap_credentials = dbcredentials.DBCredentials().get(os.environ.get('LSMR_LDAPCREDENTIALS', 'lsmr_ldap_test')) +print('Using ldap credentials', ldap_credentials.stringWithHiddenPassword()) def _call_API_and_assert_expected_response(self, url, call, data, expected_code, expected_content): """ diff --git a/SAS/LSMR/test/test_funcs.sh b/SAS/LSMR/test/test_funcs.sh index 8b0d5866ebf68101e280ebff4f8c353700cb1d4d..ff9d756dbcbbb0849a0cdc1009ada78fb580304f 100755 --- a/SAS/LSMR/test/test_funcs.sh +++ b/SAS/LSMR/test/test_funcs.sh @@ -10,20 +10,32 @@ function setup { # write test credentials to file mkdir -p ~/.lofar/dbcredentials - DB_PORT=$(get_free_port 7654) + DJANGO_TEST_DATABASE_PORT=$(get_free_port 7531) + DJANGO_TEST_DATABASE_NAME="lsmr_test_db_`uuidgen | sed 's/-/_/g'`" + DJANGO_TEST_DATABASE_CREDENTIALS_PATH="$HOME/.lofar/dbcredentials/$DJANGO_TEST_DATABASE_NAME.ini" - DJANGO_TEST_DATABASE_NAME="lsmr_test_`uuidgen | sed 's/-/_/g'`" - CREDENTIALS_PATH="$HOME/.lofar/dbcredentials/$DJANGO_TEST_DATABASE_NAME.ini" - - echo "creating test credentials file: $CREDENTIALS_PATH" + echo "creating test db credentials file: $DJANGO_TEST_DATABASE_CREDENTIALS_PATH" echo "[database:$DJANGO_TEST_DATABASE_NAME] host=localhost type=postgres database=$DJANGO_TEST_DATABASE_NAME - port=$DB_PORT + port=$DJANGO_TEST_DATABASE_PORT user=lsmr password=lsmr - " > "$CREDENTIALS_PATH" + " > "$DJANGO_TEST_DATABASE_CREDENTIALS_PATH" + + + DJANGO_TEST_LDAP_PORT=$(get_free_port 8642) + DJANGO_TEST_LDAP_NAME="lsmr_test_ldap_`uuidgen | sed 's/-/_/g'`" + DJANGO_TEST_LDAP_CREDENTIALS_PATH="$HOME/.lofar/dbcredentials/$DJANGO_TEST_LDAP_NAME.ini" + + echo "creating test ldap credentials file: $DJANGO_TEST_LDAP_CREDENTIALS_PATH" + echo "[database:$DJANGO_TEST_LDAP_NAME] + port=$DJANGO_TEST_LDAP_PORT + user=lsmr_test_ldap_user + password=lsmr_test_ldap_password + " > "$DJANGO_TEST_LDAP_CREDENTIALS_PATH" + #keep track of helper application pids to kill in teardown PIDS= @@ -32,7 +44,7 @@ function setup { export DJANGO_TEST_PORT=$DJANGO_TEST_PORT export LSMR_DBCREDENTIALS=$DJANGO_TEST_DATABASE_NAME - export LSMR_LDAPCREDENTIALS="lsmr_ldap_test" + export LSMR_LDAPCREDENTIALS=$DJANGO_TEST_LDAP_NAME ## Trap upon signals and upon normal exit. trap 'STATUS=$?; teardown; exit $STATUS' SIGHUP SIGINT SIGQUIT SIGKILL SIGTERM @@ -50,8 +62,11 @@ function teardown { kill -TERM $PID done - echo "removing test credentials file: $CREDENTIALS_PATH" - rm $CREDENTIALS_PATH + echo "removing test db credentials file: $DJANGO_TEST_DATABASE_CREDENTIALS_PATH" + rm $DJANGO_TEST_DATABASE_CREDENTIALS_PATH + + echo "removing test ldap credentials file: $DJANGO_TEST_LDAP_CREDENTIALS_PATH" + rm $DJANGO_TEST_LDAP_CREDENTIALS_PATH } @@ -59,23 +74,32 @@ function setup_with_test_lsmr { setup # fire up a postgres test database + echo + echo "Starting Django test database server..." lsmr_testdatabase -C $DJANGO_TEST_DATABASE_NAME & PIDS="$! $PIDS" sleep 5 - echo "Started Django test database server\n\n" + echo "Started Django test database server" + echo # fire up a test LDAP service + echo + echo "Starting test LDAP server..." lsmr_testldap -C $LSMR_LDAPCREDENTIALS & PIDS="$! $PIDS" sleep 5 - echo "Started test LDAP server\n\n" + echo "Started test LDAP server" + echo # Run Django test instance + echo + echo "Starting lsmr django server..." export LSMR_RAISE_ON_SIGNALS="True" lsmr -p $DJANGO_TEST_PORT -C $DJANGO_TEST_DATABASE_NAME & PIDS="$! $PIDS" sleep 5 - echo "Started lsmr django server\n\n" + echo "Started lsmr django server" + echo } function run_test {