diff --git a/Dockerfile b/Dockerfile index 853f56bcd319b5ed2337d90c51b5c2b9154d4097..ee2a9f8371287857f119ba09705bf74cfd3a977f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.7-slim as base +FROM python:3.8-slim as base # Install Python dependencies in an intermediate image # as some requires a compiler (psycopg2) @@ -37,6 +37,7 @@ RUN apt-get update \ COPY requirements.txt /requirements.txt RUN python -m venv /venv \ && . /venv/bin/activate \ + && pip install --no-cache-dir --upgrade pip \ && pip install --no-cache-dir -r /requirements.txt ARG CSENTRY_BUILD diff --git a/app/utils.py b/app/utils.py index 1995f55284d96d2e32c3b21d83e39060cde61d1a..f109ce22a9c75005ea590cea6ee1e64b4441b7be 100644 --- a/app/utils.py +++ b/app/utils.py @@ -186,7 +186,7 @@ def get_query(query, model, **kwargs): # Always apply filtering on the given model for key, value in kwargs.items(): query = query.filter(getattr(model, key) == value) - except (sa.exc.InvalidRequestError, AttributeError) as e: + except (sa.exc.InvalidRequestError, sa.exc.ArgumentError, AttributeError) as e: current_app.logger.warning(f"Invalid query arguments: {e}") raise CSEntryError("Invalid query arguments", status_code=422) return query diff --git a/requirements-to-freeze.txt b/requirements-to-freeze.txt index 042e8e5d4cec134d6fa5c65ba0602667be2ea2be..8ed87dadcc836ecf3ba9901b63432a0946bda496 100644 --- a/requirements-to-freeze.txt +++ b/requirements-to-freeze.txt @@ -19,11 +19,13 @@ python-dateutil pyyaml qrcode whitenoise -ansible-tower-cli -rq -rq-dashboard +ansible-tower-cli<3.3.9 +rq<1.0 +rq-dashboard<0.5.0 sentry-sdk +sqlalchemy<1.3 sqlalchemy-citext sqlalchemy-continuum openpyxl uwsgi +WTForms>=2.1,<2.2 diff --git a/requirements.txt b/requirements.txt index 21ed0ab57f002daf98129ce6fc048d19aedb0d3f..effc19c6bd88c373db189de7dc1c64ff5bc7d8a0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,54 +1,55 @@ -alembic==1.0.5 -ansible-tower-cli==3.3.0 -arrow==0.12.1 +alembic==1.4.3 +ansible-tower-cli==3.3.8 +arrow==0.17.0 blinker==1.4 -certifi==2018.11.29 +cachelib==0.1.1 +certifi==2020.6.20 chardet==3.0.4 -Click==7.0 -colorama==0.4.1 -elasticsearch==7.0.4 +click==7.1.2 +colorama==0.4.4 +elasticsearch==7.9.1 et-xmlfile==1.0.1 -Flask==1.0.2 -Flask-Admin==1.5.2 -Flask-Caching==1.4.0 -Flask-DebugToolbar==0.10.1 -Flask-JWT-Extended==3.13.1 +Flask==1.1.2 +Flask-Admin==1.5.6 +Flask-Caching==1.9.0 +Flask-DebugToolbar==0.11.0 +Flask-JWT-Extended==3.24.1 flask-ldap3-login==0.9.16 -Flask-Login==0.4.1 +Flask-Login==0.5.0 Flask-Mail==0.9.1 -Flask-Migrate==2.3.1 -Flask-Redis==0.3.0 -Flask-Session==0.3.1 -Flask-SQLAlchemy==2.3.2 -Flask-WTF==0.14.2 -idna==2.7 +Flask-Migrate==2.5.3 +flask-redis==0.4.0 +Flask-Session==0.3.2 +Flask-SQLAlchemy==2.4.4 +Flask-WTF==0.14.3 +idna==2.10 itsdangerous==1.1.0 -jdcal==1.4 -Jinja2==2.10 -ldap3==2.5.1 -Mako==1.0.7 -MarkupSafe==1.1.0 -openpyxl==2.5.12 -Pillow==5.3.0 -psycopg2==2.7.6.1 -pyasn1==0.4.4 -PyJWT==1.6.4 -python-dateutil==2.7.5 -python-editor==1.0.3 -PyYAML==3.13 -qrcode==6.0 -redis==2.10.6 -requests==2.20.1 -rq==0.12.0 -rq-dashboard==0.3.12 -sentry-sdk==0.7.10 -six==1.11.0 -SQLAlchemy==1.2.14 -sqlalchemy-citext==1.3.post0 -SQLAlchemy-Continuum==1.3.6 -SQLAlchemy-Utils==0.33.8 -urllib3==1.24.1 -uwsgi==2.0.18 -Werkzeug==0.14.1 -whitenoise==4.1.2 +jdcal==1.4.1 +Jinja2==2.11.2 +ldap3==2.8.1 +Mako==1.1.3 +MarkupSafe==1.1.1 +openpyxl==3.0.5 +Pillow==8.0.0 +psycopg2==2.8.6 +pyasn1==0.4.8 +PyJWT==1.7.1 +python-dateutil==2.8.1 +python-editor==1.0.4 +PyYAML==5.3.1 +qrcode==6.1 +redis==3.5.3 +requests==2.24.0 +rq==0.13.0 +rq-dashboard==0.4.0 +sentry-sdk==0.19.1 +six==1.15.0 +SQLAlchemy==1.2.19 +sqlalchemy-citext==1.7.0 +SQLAlchemy-Continuum==1.3.11 +SQLAlchemy-Utils==0.36.8 +urllib3==1.25.11 +uWSGI==2.0.19.1 +Werkzeug==1.0.1 +whitenoise==5.2.0 WTForms==2.1 diff --git a/tests/functional/test_api.py b/tests/functional/test_api.py index 8843e2adfa9d56d88616e1f3a87bfaabd66d4cf1..79b70b1fd2f55b6fa4c20a625f8cd5310d5c12dd 100644 --- a/tests/functional/test_api.py +++ b/tests/functional/test_api.py @@ -312,7 +312,7 @@ def test_create_generic_model(endpoint, client, user_token): response = post(client, f"{API_URL}/{endpoint}", data=data, token=user_token) check_response_message( response, - "(psycopg2.IntegrityError) duplicate key value violates unique constraint", + "(psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint", 422, ) response = post( @@ -320,7 +320,7 @@ def test_create_generic_model(endpoint, client, user_token): ) check_response_message( response, - "(psycopg2.IntegrityError) duplicate key value violates unique constraint", + "(psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint", 422, ) response = post( @@ -328,7 +328,7 @@ def test_create_generic_model(endpoint, client, user_token): ) check_response_message( response, - "(psycopg2.IntegrityError) duplicate key value violates unique constraint", + "(psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint", 422, ) data = {"name": "Bar", "description": "Bar description"} @@ -397,7 +397,7 @@ def test_create_item(client, user_token): response = post(client, f"{API_URL}/inventory/items", data=data2, token=user_token) check_response_message( response, - "(psycopg2.IntegrityError) duplicate key value violates unique constraint", + "(psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint", 422, ) @@ -543,7 +543,7 @@ def test_patch_item_integrity_error(client, user_token, item_factory): ) check_response_message( response, - "(psycopg2.IntegrityError) duplicate key value violates unique constraint", + "(psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint", 422, ) @@ -911,7 +911,7 @@ def test_create_network(client, admin_token, network_scope_factory): ) check_response_message( response, - "(psycopg2.IntegrityError) duplicate key value violates unique constraint", + "(psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint", 422, ) @@ -1318,7 +1318,7 @@ def test_create_interface(client, host, network_192_168_1, no_login_check_token) ) check_response_message( response, - "(psycopg2.IntegrityError) duplicate key value violates unique constraint", + "(psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint", 422, ) @@ -1510,7 +1510,7 @@ def test_create_mac(client, item_factory, user_token): response = post(client, f"{API_URL}/inventory/macs", data=data, token=user_token) check_response_message( response, - "(psycopg2.IntegrityError) duplicate key value violates unique constraint", + "(psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint", 422, ) @@ -1567,7 +1567,7 @@ def test_create_ansible_group(client, admin_token): response = post(client, f"{API_URL}/network/groups", data=data, token=admin_token) check_response_message( response, - "(psycopg2.IntegrityError) duplicate key value violates unique constraint", + "(psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint", 422, ) @@ -1784,7 +1784,7 @@ def test_create_host(client, device_type_factory, user_token): response = post(client, f"{API_URL}/network/hosts", data=data, token=user_token) check_response_message( response, - "(psycopg2.IntegrityError) duplicate key value violates unique constraint", + "(psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint", 422, ) @@ -1932,7 +1932,7 @@ def test_create_domain(client, admin_token): response = post(client, f"{API_URL}/network/domains", data=data, token=admin_token) check_response_message( response, - "(psycopg2.IntegrityError) duplicate key value violates unique constraint", + "(psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint", 422, ) @@ -2906,7 +2906,7 @@ def test_delete_network_scope_with_network_fail( ) check_response_message( response, - '(psycopg2.IntegrityError) null value in column "scope_id" violates not-null constraint', + '(psycopg2.errors.NotNullViolation) null value in column "scope_id" violates not-null constraint', 422, ) @@ -2930,7 +2930,7 @@ def test_delete_network_with_host_fail( ) check_response_message( response, - '(psycopg2.IntegrityError) null value in column "network_id" violates not-null constraint', + '(psycopg2.errors.NotNullViolation) null value in column "network_id" violates not-null constraint', 422, ) @@ -2962,7 +2962,7 @@ def test_delete_domain_with_network_fail(client, domain, network_factory, admin_ ) check_response_message( response, - '(psycopg2.IntegrityError) null value in column "domain_id" violates not-null constraint', + '(psycopg2.errors.NotNullViolation) null value in column "domain_id" violates not-null constraint', 422, )