Fix validation issues (#53)
* Remove username format validator * Avoid issues with default HTTP ports in resource validation
This commit is contained in:
parent
5341906767
commit
da521ebad8
|
@ -9,6 +9,7 @@ env:
|
||||||
services:
|
services:
|
||||||
- redis-server
|
- redis-server
|
||||||
- postgresql
|
- postgresql
|
||||||
|
- xvfb
|
||||||
addons:
|
addons:
|
||||||
firefox: "60.1.0esr"
|
firefox: "60.1.0esr"
|
||||||
before_install:
|
before_install:
|
||||||
|
@ -20,7 +21,6 @@ install:
|
||||||
- bash bin/travis-build.bash
|
- bash bin/travis-build.bash
|
||||||
before_script:
|
before_script:
|
||||||
- "export DISPLAY=:99.0"
|
- "export DISPLAY=:99.0"
|
||||||
- "sh -e /etc/init.d/xvfb start"
|
|
||||||
- sleep 3 # give xvfb some time to start
|
- sleep 3 # give xvfb some time to start
|
||||||
script:
|
script:
|
||||||
- sh bin/travis-run.sh
|
- sh bin/travis-run.sh
|
||||||
|
|
|
@ -16,18 +16,21 @@ python setup.py develop
|
||||||
|
|
||||||
sed -i "s|psycopg2==2.4.5|psycopg2==2.7.1|g" requirements.txt
|
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 requirements.txt
|
||||||
pip install -r dev-requirements.txt --allow-all-external
|
pip install -r dev-requirements.txt
|
||||||
cd -
|
cd -
|
||||||
|
|
||||||
|
echo "Checking solr"
|
||||||
|
ls -la /etc/
|
||||||
|
|
||||||
echo "Setting up Solr..."
|
echo "Setting up Solr..."
|
||||||
# solr is multicore for tests on ckan master now, but it's easier to run tests
|
# solr is multicore for tests on ckan master now, but it's easier to run tests
|
||||||
# on Travis single-core still.
|
# on Travis single-core still.
|
||||||
# see https://github.com/ckan/ckan/issues/2972
|
# 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
|
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=8983\nJAVA_HOME=$JAVA_HOME" | sudo tee /etc/default/jetty
|
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 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..."
|
echo "Creating the PostgreSQL user and database..."
|
||||||
sudo -u postgres psql -c "CREATE USER ckan_default WITH PASSWORD 'pass';"
|
sudo -u postgres psql -c "CREATE USER ckan_default WITH PASSWORD 'pass';"
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
echo "Starting Jetty"
|
||||||
|
sudo service jetty8 restart
|
||||||
|
|
||||||
|
sudo netstat -ntlp
|
||||||
|
|
||||||
python setup.py nosetests
|
python setup.py nosetests
|
|
@ -1,6 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright (c) 2014 CoNWeT Lab., Universidad Politécnica de Madrid
|
# 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.
|
# This file is part of CKAN Private Dataset Extension.
|
||||||
|
|
||||||
|
@ -74,7 +75,6 @@ def allowed_users_convert(key, data, errors, context):
|
||||||
else:
|
else:
|
||||||
for num, allowed_user in zip(count(current_index + 1), allowed_users):
|
for num, allowed_user in zip(count(current_index + 1), allowed_users):
|
||||||
allowed_user = allowed_user.strip()
|
allowed_user = allowed_user.strip()
|
||||||
toolkit.get_validator('name_validator')(allowed_user, context) # User name should be validated
|
|
||||||
data[(key[0], num)] = allowed_user
|
data[(key[0], num)] = allowed_user
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -52,12 +52,18 @@ class FiWareNotificationParser(object):
|
||||||
parsed_url = urlparse(resource['url'])
|
parsed_url = urlparse(resource['url'])
|
||||||
dataset_name = re.findall('^/dataset/([^/]+).*$', parsed_url.path)
|
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 len(dataset_name) == 1:
|
||||||
if parsed_url.netloc == my_host:
|
if resource_url == my_host:
|
||||||
datasets.append(dataset_name[0])
|
datasets.append(dataset_name[0])
|
||||||
else:
|
else:
|
||||||
raise tk.ValidationError({'message': 'Dataset %s is associated with the CKAN instance located at %s'
|
raise tk.ValidationError({'message': 'Dataset %s is associated with the CKAN instance located at %s, expected %s'
|
||||||
% (dataset_name[0], parsed_url.netloc)})
|
% (dataset_name[0], resource_url, my_host)})
|
||||||
else:
|
else:
|
||||||
raise tk.ValidationError({'message': 'Invalid resource format'})
|
raise tk.ValidationError({'message': 'Invalid resource format'})
|
||||||
|
|
||||||
|
|
|
@ -127,10 +127,6 @@ class ConvertersValidatorsTest(unittest.TestCase):
|
||||||
def test_allowed_user_convert(self, users, previous_users, expected_users):
|
def test_allowed_user_convert(self, users, previous_users, expected_users):
|
||||||
key_str = 'allowed_users_str'
|
key_str = 'allowed_users_str'
|
||||||
key = 'allowed_users'
|
key = 'allowed_users'
|
||||||
|
|
||||||
# Configure mock
|
|
||||||
name_validator = MagicMock()
|
|
||||||
conv_val.toolkit.get_validator = MagicMock(return_value=name_validator)
|
|
||||||
|
|
||||||
# Fullfill the data dictionary
|
# Fullfill the data dictionary
|
||||||
# * list should be included in the allowed_users filed
|
# * list should be included in the allowed_users filed
|
||||||
|
@ -151,7 +147,6 @@ class ConvertersValidatorsTest(unittest.TestCase):
|
||||||
|
|
||||||
# Check that the users are set properly
|
# Check that the users are set properly
|
||||||
for i in range(previous_users, previous_users + len(expected_users)):
|
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)])
|
self.assertEquals(expected_users[i - previous_users], data[(key, i)])
|
||||||
|
|
||||||
@parameterized.expand([
|
@parameterized.expand([
|
||||||
|
|
|
@ -39,26 +39,26 @@ TEST_CASES = {
|
||||||
'error': {
|
'error': {
|
||||||
'host': 'localhost',
|
'host': 'localhost',
|
||||||
'json': {"customer_name": "test", "resources": [{"url": "http://localhosta/dataset/ds1"}]},
|
'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': {
|
'error_one_ds': {
|
||||||
'host': 'localhost',
|
'host': 'localhost',
|
||||||
'json': {"customer_name": "test", "resources": [{"url": "http://localhosta/dataset/ds1"},
|
'json': {"customer_name": "test", "resources": [{"url": "http://localhosta/dataset/ds1"},
|
||||||
{"url": "http://localhost/dataset/ds2"}]},
|
{"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': {
|
'two_errors': {
|
||||||
'host': 'localhost',
|
'host': 'localhost',
|
||||||
'json': {"customer_name": "test", "resources": [{"url": "http://localhosta/dataset/ds1"},
|
'json': {"customer_name": "test", "resources": [{"url": "http://localhosta/dataset/ds1"},
|
||||||
{"url": "http://localhostb/dataset/ds2"}]},
|
{"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': {
|
'two_errors_two_ds': {
|
||||||
'host': 'example.com',
|
'host': 'example.com',
|
||||||
'json': {"customer_name": "test", "resources": [{"url": "http://localhosta/dataset/ds1"},
|
'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.es/dataset/ds2"}, {"url": "http://example.com/dataset/ds3"},
|
||||||
{"url": "http://example.com/dataset/ds4"}]},
|
{"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': {
|
'no_customer_name': {
|
||||||
'host': 'localhost',
|
'host': 'localhost',
|
||||||
|
|
|
@ -337,14 +337,6 @@ class TestSelenium(unittest.TestCase):
|
||||||
self.check_acquired(pkg_name, url, acquired, private)
|
self.check_acquired(pkg_name, url, acquired, private)
|
||||||
|
|
||||||
@parameterized.expand([
|
@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'], 'ftp://google.es', 'Acquire URL: The URL "ftp://google.es" is not valid.'),
|
||||||
(['conwet'], 'google', 'Acquire URL: The URL "google" 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.'),
|
(['conwet'], 'http://google', 'Acquire URL: The URL "http://google" is not valid.'),
|
||||||
|
|
Loading…
Reference in New Issue