Skip to content
This repository has been archived by the owner on Aug 5, 2024. It is now read-only.

Commit

Permalink
Do not allow to search if no read permission on collection or bucket (f…
Browse files Browse the repository at this point in the history
…ixes #7)
  • Loading branch information
leplatrem committed May 23, 2017
1 parent 705dab8 commit 4e80c71
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Changelog
**Bug fixes**

- Only index records if the storage transaction is committed (fixes #15)
- Do not allow to search if no read permission on collection or bucket (fixes #7)


0.0.1 (2017-05-22)
Expand Down
4 changes: 3 additions & 1 deletion kinto_elasticsearch/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import elasticsearch
from kinto.core import authorization
from kinto.core import Service
from kinto.core import utils


logger = logging.getLogger(__name__)
Expand All @@ -11,7 +12,8 @@
class RouteFactory(authorization.RouteFactory):
def __init__(self, request):
super().__init__(request)
self.permission_object_id = request.path.replace("/search", "/records")
records_plural = utils.strip_uri_prefix(request.path.replace("/search", "/records"))
self.permission_object_id = records_plural
self.required_permission = "read"


Expand Down
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def __init__(self, *args, **kwargs):
self.headers.update(get_user_headers('mat'))

def tearDown(self):
super().tearDown()
self.app.app.registry.indexer.flush()

@classmethod
Expand Down
2 changes: 2 additions & 0 deletions tests/test_elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ def test_response_is_served_if_indexer_fails(self):

class SearchView(BaseWebTest, unittest.TestCase):
def test_search_response_is_empty_if_indexer_fails(self):
self.app.put("/buckets/bid", headers=self.headers)
self.app.put("/buckets/bid/collections/cid", headers=self.headers)
with mock.patch("kinto_elasticsearch.indexer.Indexer.search",
side_effect=elasticsearch.ElasticsearchException):
resp = self.app.post("/buckets/bid/collections/cid/search",
Expand Down

0 comments on commit 4e80c71

Please sign in to comment.