Skip to content
Snippets Groups Projects
Commit b093dfc9 authored by Jorrit Schaap's avatar Jorrit Schaap
Browse files

SW-415: fixed tests with broken mock-ldap

parent a92f1655
No related branches found
No related tags found
1 merge request!87Lsmr epic
...@@ -147,7 +147,7 @@ AUTH_LDAP_CONNECTION_OPTIONS = { ldap.OPT_X_TLS_REQUIRE_CERT : ldap.OPT_X_TLS_NE ...@@ -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 # AUTH_LDAP_BIND_PASSWORD = '' # our LDAP is open
protocol = 'ldaps://' protocol = 'ldaps://'
if 'test' in ldap_creds_name: 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://' protocol = 'ldap://'
AUTH_LDAP_SERVER_URI = "%s%s:%s" % (protocol, django_ldap_credentials.host, django_ldap_credentials.port) 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" AUTH_LDAP_USER_DN_TEMPLATE="cn=%(user)s,ou=Users,o=lofar,c=eu"
......
#!/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
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
# todo: behavior in a controlled way. # todo: behavior in a controlled way.
# todo: We should probably also fully test behavior wrt mandatory and nullable fields. # todo: We should probably also fully test behavior wrt mandatory and nullable fields.
import os
import unittest import unittest
import requests import requests
import json import json
...@@ -39,16 +39,9 @@ from t_lsmrapp_specification_functional import BASE_URL, _call_API_and_assert_ex ...@@ -39,16 +39,9 @@ from t_lsmrapp_specification_functional import BASE_URL, _call_API_and_assert_ex
from requests.auth import HTTPBasicAuth from requests.auth import HTTPBasicAuth
from lofar.common import dbcredentials from lofar.common import dbcredentials
# Read Login credentials (todo: when we authorize functionality based on specific users, we need sth better than this) # 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.
# this requires a config file .lofar/dbcredentials/lsmr.ini, with contents as such (adapt as needed): ldap_credentials = dbcredentials.DBCredentials().get(os.environ.get('LSMR_LDAPCREDENTIALS', 'lsmr_ldap_test'))
#
# [database:lsmr_ldap]
# user = ldapuser
# password = ldappass
#
dbc = dbcredentials.DBCredentials()
ldap_credentials = dbc.get("lsmr_ldap_test")
print('Using ldap credentials', ldap_credentials.stringWithHiddenPassword()) print('Using ldap credentials', ldap_credentials.stringWithHiddenPassword())
class TaskTemplateTestCase(unittest.TestCase): class TaskTemplateTestCase(unittest.TestCase):
......
#!/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
......
...@@ -41,8 +41,10 @@ import logging ...@@ -41,8 +41,10 @@ import logging
DJANGO_PORT=os.environ.get('DJANGO_TEST_PORT', 0) DJANGO_PORT=os.environ.get('DJANGO_TEST_PORT', 0)
BASE_URL = 'http://localhost:%s' % (DJANGO_PORT,) BASE_URL = 'http://localhost:%s' % (DJANGO_PORT,)
dbc = dbcredentials.DBCredentials() # read ldap_credentials from ~/.lofar/dbcredentials/<ldap_creds_filename.ini>
ldap_credentials = dbc.get("lsmr_ldap_test") # 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): def _call_API_and_assert_expected_response(self, url, call, data, expected_code, expected_content):
""" """
......
...@@ -10,20 +10,32 @@ function setup { ...@@ -10,20 +10,32 @@ function setup {
# write test credentials to file # write test credentials to file
mkdir -p ~/.lofar/dbcredentials 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'`" echo "creating test db credentials file: $DJANGO_TEST_DATABASE_CREDENTIALS_PATH"
CREDENTIALS_PATH="$HOME/.lofar/dbcredentials/$DJANGO_TEST_DATABASE_NAME.ini"
echo "creating test credentials file: $CREDENTIALS_PATH"
echo "[database:$DJANGO_TEST_DATABASE_NAME] echo "[database:$DJANGO_TEST_DATABASE_NAME]
host=localhost host=localhost
type=postgres type=postgres
database=$DJANGO_TEST_DATABASE_NAME database=$DJANGO_TEST_DATABASE_NAME
port=$DB_PORT port=$DJANGO_TEST_DATABASE_PORT
user=lsmr user=lsmr
password=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 #keep track of helper application pids to kill in teardown
PIDS= PIDS=
...@@ -32,7 +44,7 @@ function setup { ...@@ -32,7 +44,7 @@ function setup {
export DJANGO_TEST_PORT=$DJANGO_TEST_PORT export DJANGO_TEST_PORT=$DJANGO_TEST_PORT
export LSMR_DBCREDENTIALS=$DJANGO_TEST_DATABASE_NAME 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 upon signals and upon normal exit.
trap 'STATUS=$?; teardown; exit $STATUS' SIGHUP SIGINT SIGQUIT SIGKILL SIGTERM trap 'STATUS=$?; teardown; exit $STATUS' SIGHUP SIGINT SIGQUIT SIGKILL SIGTERM
...@@ -50,8 +62,11 @@ function teardown { ...@@ -50,8 +62,11 @@ function teardown {
kill -TERM $PID kill -TERM $PID
done done
echo "removing test credentials file: $CREDENTIALS_PATH" echo "removing test db credentials file: $DJANGO_TEST_DATABASE_CREDENTIALS_PATH"
rm $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 { ...@@ -59,23 +74,32 @@ function setup_with_test_lsmr {
setup setup
# fire up a postgres test database # fire up a postgres test database
echo
echo "Starting Django test database server..."
lsmr_testdatabase -C $DJANGO_TEST_DATABASE_NAME & lsmr_testdatabase -C $DJANGO_TEST_DATABASE_NAME &
PIDS="$! $PIDS" PIDS="$! $PIDS"
sleep 5 sleep 5
echo "Started Django test database server\n\n" echo "Started Django test database server"
echo
# fire up a test LDAP service # fire up a test LDAP service
echo
echo "Starting test LDAP server..."
lsmr_testldap -C $LSMR_LDAPCREDENTIALS & lsmr_testldap -C $LSMR_LDAPCREDENTIALS &
PIDS="$! $PIDS" PIDS="$! $PIDS"
sleep 5 sleep 5
echo "Started test LDAP server\n\n" echo "Started test LDAP server"
echo
# Run Django test instance # Run Django test instance
echo
echo "Starting lsmr django server..."
export LSMR_RAISE_ON_SIGNALS="True" export LSMR_RAISE_ON_SIGNALS="True"
lsmr -p $DJANGO_TEST_PORT -C $DJANGO_TEST_DATABASE_NAME & lsmr -p $DJANGO_TEST_PORT -C $DJANGO_TEST_DATABASE_NAME &
PIDS="$! $PIDS" PIDS="$! $PIDS"
sleep 5 sleep 5
echo "Started lsmr django server\n\n" echo "Started lsmr django server"
echo
} }
function run_test { function run_test {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment