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

Fix missing product validation and API queries specifying products #1189

Open
wants to merge 1 commit into
base: lockhart
Choose a base branch
from
Open
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
50 changes: 50 additions & 0 deletions features/news_api_search.feature
Original file line number Diff line number Diff line change
Expand Up @@ -673,3 +673,53 @@ Feature: News API News Search
{"body_html": "Once upon a time there was a aardvark that could not swim"}
]}
"""

Scenario: search by not allowed product raises error
Given "products"
"""
[{"name": "A Product",
"decsription": "a product for text",
"companies" : [
"#companies._id#"
],
"query": "aardvark",
"product_type": "news_api"
}]
"""
When we get "news/search?start_date=now-10d&products=111111111111111111111111"
Then we get response code 400

Scenario: search by not empty product raises error
Given "products"
"""
[{"name": "A Product",
"decsription": "a product for text",
"companies" : [
"#companies._id#"
],
"query": "aardvark",
"product_type": "news_api"
}]
"""
Given "items"
"""
[
{
"body_html": "Three aardvark story",
"versioncreated": "#DATE-3#",
"headline": "Headline 1",
"products": [
{
"code": "#products._id#",
"name": "A Product"
},
{
"code": "1234",
"name": "Product b"
}
]
}
]
"""
When we get "news/search?start_date=now-10d&products="
Then we get response code 400
11 changes: 11 additions & 0 deletions newsroom/news_api/news/search_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,17 @@ def validate_request(self, search):
if not search.company:
raise SuperdeskApiError.forbiddenError()

# Check if 'products' argument is has been passed
products_arg = search.args.get('products')
if products_arg:
valid_product_ids = {str(c.get('_id')) for c in search.products}
requested_products = products_arg.split(',')
if not all(product in valid_product_ids for product in requested_products):
raise BadParameterValueError('Bad product value')
# Make sure it has a value
elif products_arg == '':
raise BadParameterValueError('Bad product value')

self.validate_page(search)

def validate_include_exclude_fields(self, search):
Expand Down
Loading