Fix validation issues (#53)

* Remove username format validator
* Avoid issues with default HTTP ports in resource validation
This commit is contained in:
Francisco de la Vega 2020-03-13 12:01:34 +01:00 committed by GitHub
parent 5341906767
commit da521ebad8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 28 additions and 27 deletions

View File

@ -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

View File

@ -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';"

View File

@ -1,3 +1,8 @@
#!/usr/bin/env bash
echo "Starting Jetty"
sudo service jetty8 restart
sudo netstat -ntlp
python setup.py nosetests

View File

@ -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

View File

@ -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'})

View File

@ -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([

View File

@ -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',

View File

@ -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.'),