Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RDISCROWD-6284 Block database details from API response #868

Merged
merged 1 commit into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pybossa/error/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import json
from flask import Response
from flask import current_app, request
from flask_babel import gettext


class ErrorStatus(object):
Expand Down Expand Up @@ -69,6 +70,9 @@ def format_exception(self, e, target, action, message=None):
'Conflict'):
if message is None:
message = e.description
elif exception_cls in ('DataError'):
if message is None:
message = gettext('Your request was invalid. Please check your arguments.')
else:
if message is None:
message = str(e)
Expand Down
4 changes: 3 additions & 1 deletion pybossa/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from werkzeug.exceptions import NotFound, BadRequest

__all__ = ['SUCCESS', 'ERROR', 'WARNING', 'FORBIDDEN', 'NOTFOUND', 'BADREQUEST',
'INFO', 'NOTFOUND', 'INTERNALSERVERERROR', 'UNAUTHORIZED']
'INFO', 'FAILED', 'NOTFOUND', 'INTERNALSERVERERROR', 'UNAUTHORIZED']

SUCCESS = "success"

Expand All @@ -44,6 +44,8 @@

INFO = "info"

FAILED = "failed"

FORBIDDEN = Forbidden.description

NOTFOUND = NotFound.description
Expand Down
14 changes: 14 additions & 0 deletions test/test_api/test_api_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from test import db, with_context
from test.test_api import TestAPI
from pybossa.core import project_repo
from pybossa.messages import *

from test.factories import ProjectFactory, TaskFactory, TaskRunFactory, UserFactory

Expand Down Expand Up @@ -475,3 +476,16 @@ def test_api_app_access_with_secure_app_access_disabled(self):
assert "Statistics" in res.data.decode()
assert 'id="percent-completed"' in res.data.decode()
assert "<div>100%</div>" in res.data.decode()

@with_context
def test_request_with_invalid_filter_query(self):
"""Test API response status code upon invalid request with filter query"""

user = UserFactory.create()
# owners_ids is missing curly braces
bad_url_query = '/api/project?owners_ids=9999&api_key=' + user.api_key
res = self.app_get_json(bad_url_query)
data = json.loads(res.data)
assert data.get('status') == FAILED
assert data.get('status_code') == 415
assert data.get('exception_msg') == 'Your request was invalid. Please check your arguments.'
Loading