diff --git a/.travis.yml b/.travis.yml index d675e03..b1043a9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,7 @@ env: services: - redis-server - postgresql + - xvfb addons: firefox: "60.1.0esr" before_install: @@ -20,7 +21,6 @@ install: - bash bin/travis-build.bash before_script: - "export DISPLAY=:99.0" - - "sh -e /etc/init.d/xvfb start" - sleep 3 # give xvfb some time to start script: - sh bin/travis-run.sh diff --git a/bin/travis-build.bash b/bin/travis-build.bash index 682932d..3768e66 100755 --- a/bin/travis-build.bash +++ b/bin/travis-build.bash @@ -16,18 +16,21 @@ python setup.py develop sed -i "s|psycopg2==2.4.5|psycopg2==2.7.1|g" requirements.txt -pip install -r requirements.txt --allow-all-external -pip install -r dev-requirements.txt --allow-all-external +pip install -r requirements.txt +pip install -r dev-requirements.txt cd - +echo "Checking solr" +ls -la /etc/ + echo "Setting up Solr..." # solr is multicore for tests on ckan master now, but it's easier to run tests # on Travis single-core still. # see https://github.com/ckan/ckan/issues/2972 -sed -i -e 's/solr_url.*/solr_url = http:\/\/127.0.0.1:8983\/solr/' ckan/test-core.ini -printf "NO_START=0\nJETTY_HOST=127.0.0.1\nJETTY_PORT=8983\nJAVA_HOME=$JAVA_HOME" | sudo tee /etc/default/jetty +sed -i -e 's/solr_url.*/solr_url = http:\/\/127.0.0.1:8080\/solr/' ckan/test-core.ini +printf "NO_START=0\nJETTY_HOST=127.0.0.1\nJETTY_PORT=8080\nJAVA_HOME=$JAVA_HOME" | sudo tee /etc/default/jetty sudo cp ckan/ckan/config/solr/schema.xml /etc/solr/conf/schema.xml -sudo service jetty restart +sudo service jetty8 restart echo "Creating the PostgreSQL user and database..." sudo -u postgres psql -c "CREATE USER ckan_default WITH PASSWORD 'pass';" diff --git a/bin/travis-run.sh b/bin/travis-run.sh index d3ba879..e7031b1 100755 --- a/bin/travis-run.sh +++ b/bin/travis-run.sh @@ -1,3 +1,8 @@ #!/usr/bin/env bash +echo "Starting Jetty" +sudo service jetty8 restart + +sudo netstat -ntlp + python setup.py nosetests \ No newline at end of file diff --git a/ckanext/privatedatasets/converters_validators.py b/ckanext/privatedatasets/converters_validators.py index 26ea1c4..4d99c9b 100644 --- a/ckanext/privatedatasets/converters_validators.py +++ b/ckanext/privatedatasets/converters_validators.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # Copyright (c) 2014 CoNWeT Lab., Universidad Politécnica de Madrid +# Copyright (c) 2019 Future Internet Consulting and Development Solutions S.L. # This file is part of CKAN Private Dataset Extension. @@ -74,7 +75,6 @@ def allowed_users_convert(key, data, errors, context): else: for num, allowed_user in zip(count(current_index + 1), allowed_users): allowed_user = allowed_user.strip() - toolkit.get_validator('name_validator')(allowed_user, context) # User name should be validated data[(key[0], num)] = allowed_user diff --git a/ckanext/privatedatasets/parsers/fiware.py b/ckanext/privatedatasets/parsers/fiware.py index 5ea9894..03867e2 100644 --- a/ckanext/privatedatasets/parsers/fiware.py +++ b/ckanext/privatedatasets/parsers/fiware.py @@ -52,12 +52,18 @@ class FiWareNotificationParser(object): parsed_url = urlparse(resource['url']) dataset_name = re.findall('^/dataset/([^/]+).*$', parsed_url.path) + resource_url = parsed_url.netloc + if ':' in my_host and ':' not in resource_url: + # Add the default port depending on the protocol + default_port = '80' if parsed_url.protocol == 'http' else '443' + resource_url = resource_url + default_port + if len(dataset_name) == 1: - if parsed_url.netloc == my_host: + if resource_url == my_host: datasets.append(dataset_name[0]) else: - raise tk.ValidationError({'message': 'Dataset %s is associated with the CKAN instance located at %s' - % (dataset_name[0], parsed_url.netloc)}) + raise tk.ValidationError({'message': 'Dataset %s is associated with the CKAN instance located at %s, expected %s' + % (dataset_name[0], resource_url, my_host)}) else: raise tk.ValidationError({'message': 'Invalid resource format'}) diff --git a/ckanext/privatedatasets/tests/test_converters_validators.py b/ckanext/privatedatasets/tests/test_converters_validators.py index 8895c42..8700502 100644 --- a/ckanext/privatedatasets/tests/test_converters_validators.py +++ b/ckanext/privatedatasets/tests/test_converters_validators.py @@ -127,10 +127,6 @@ class ConvertersValidatorsTest(unittest.TestCase): def test_allowed_user_convert(self, users, previous_users, expected_users): key_str = 'allowed_users_str' key = 'allowed_users' - - # Configure mock - name_validator = MagicMock() - conv_val.toolkit.get_validator = MagicMock(return_value=name_validator) # Fullfill the data dictionary # * list should be included in the allowed_users filed @@ -151,7 +147,6 @@ class ConvertersValidatorsTest(unittest.TestCase): # Check that the users are set properly for i in range(previous_users, previous_users + len(expected_users)): - name_validator.assert_any_call(expected_users[i - previous_users], context) self.assertEquals(expected_users[i - previous_users], data[(key, i)]) @parameterized.expand([ diff --git a/ckanext/privatedatasets/tests/test_fiware_parser.py b/ckanext/privatedatasets/tests/test_fiware_parser.py index 7c29399..f93eb73 100644 --- a/ckanext/privatedatasets/tests/test_fiware_parser.py +++ b/ckanext/privatedatasets/tests/test_fiware_parser.py @@ -39,26 +39,26 @@ TEST_CASES = { 'error': { 'host': 'localhost', 'json': {"customer_name": "test", "resources": [{"url": "http://localhosta/dataset/ds1"}]}, - 'error': 'Dataset ds1 is associated with the CKAN instance located at localhosta', + 'error': 'Dataset ds1 is associated with the CKAN instance located at localhosta, expected localhost', }, 'error_one_ds': { 'host': 'localhost', 'json': {"customer_name": "test", "resources": [{"url": "http://localhosta/dataset/ds1"}, {"url": "http://localhost/dataset/ds2"}]}, - 'error': 'Dataset ds1 is associated with the CKAN instance located at localhosta', + 'error': 'Dataset ds1 is associated with the CKAN instance located at localhosta, expected localhost', }, 'two_errors': { 'host': 'localhost', 'json': {"customer_name": "test", "resources": [{"url": "http://localhosta/dataset/ds1"}, {"url": "http://localhostb/dataset/ds2"}]}, - 'error': 'Dataset ds1 is associated with the CKAN instance located at localhosta', + 'error': 'Dataset ds1 is associated with the CKAN instance located at localhosta, expected localhost', }, 'two_errors_two_ds': { 'host': 'example.com', 'json': {"customer_name": "test", "resources": [{"url": "http://localhosta/dataset/ds1"}, {"url": "http://example.es/dataset/ds2"}, {"url": "http://example.com/dataset/ds3"}, {"url": "http://example.com/dataset/ds4"}]}, - 'error': 'Dataset ds1 is associated with the CKAN instance located at localhosta', + 'error': 'Dataset ds1 is associated with the CKAN instance located at localhosta, expected example.com', }, 'no_customer_name': { 'host': 'localhost', diff --git a/ckanext/privatedatasets/tests/test_selenium.py b/ckanext/privatedatasets/tests/test_selenium.py index 251d61f..090b133 100644 --- a/ckanext/privatedatasets/tests/test_selenium.py +++ b/ckanext/privatedatasets/tests/test_selenium.py @@ -337,14 +337,6 @@ class TestSelenium(unittest.TestCase): self.check_acquired(pkg_name, url, acquired, private) @parameterized.expand([ - (['upm', 'a'], 'http://upm.es', 'Allowed users: Must be at least 2 characters long'), - (['upm', 'a a a'], 'http://upm.es', 'Allowed users: Must be purely lowercase alphanumeric (ascii) characters and these symbols: -_'), - (['upm', 'a?-vz'], 'http://upm.es', 'Allowed users: Must be purely lowercase alphanumeric (ascii) characters and these symbols: -_'), - ( - ['thisisaveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryverylongname'], - 'http://upm.es', - 'Allowed users: Name must be a maximum of 100 characters long' - ), (['conwet'], 'ftp://google.es', 'Acquire URL: The URL "ftp://google.es" is not valid.'), (['conwet'], 'google', 'Acquire URL: The URL "google" is not valid.'), (['conwet'], 'http://google', 'Acquire URL: The URL "http://google" is not valid.'),