forked from druids/django-security
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: get partitioned doc from semi-partitioned index
- there was issue in case that we have indexes which are partitioned and not partitioned at once e.g. input-requests-log, input-requests-log-2023-01-01 - I tackle this issue with searching over all indexes with Search API on exact term - internal ID, response time will be slower, but it should be enough
- Loading branch information
Tomáš Daniel
committed
Nov 27, 2023
1 parent
4e6efef
commit 26090a2
Showing
4 changed files
with
60 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
from .celery_log import CeleryLogTestCase | ||
from .command_log import CommandLogTestCase | ||
from .commands import CommandTestCase | ||
from .input_request_log import InputRequestLogTestCase | ||
from .output_request_log import OutputRequestLogTestCase | ||
from .commands import CommandTestCase | ||
from .partitioned_log import PartitionedLogTestCase | ||
from .utils import UtilsTestCase |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import time | ||
|
||
from django.test import override_settings | ||
|
||
from germanium.test_cases.client import ClientTestCase | ||
from security.backends.elasticsearch.tests import store_elasticsearch_log | ||
from security.backends.elasticsearch.models import Log, PartitionedLog | ||
from security.backends.testing import capture_security_logs | ||
from .base import BaseTestCaseMixin | ||
|
||
|
||
class TestNonPartitionedLog(Log): | ||
class Index: | ||
name = "test-log" | ||
|
||
|
||
class TestPartitionedLog(PartitionedLog): | ||
class Index: | ||
name = "test-log*" | ||
|
||
|
||
@override_settings(SECURITY_BACKEND_WRITERS={}) | ||
class PartitionedLogTestCase(BaseTestCaseMixin, ClientTestCase): | ||
|
||
@store_elasticsearch_log() | ||
def test_save_and_retrieve_from_semi_partitioned_index(self): | ||
with capture_security_logs(): | ||
TestNonPartitionedLog.init() | ||
doc_nonpartitioned = TestNonPartitionedLog(slug="test") | ||
doc_nonpartitioned.save() | ||
time.sleep(1) # Wait for reindex | ||
|
||
TestPartitionedLog.init() | ||
doc_partitioned = TestPartitionedLog(slug="test_2") | ||
doc_partitioned.save() | ||
|
||
time.sleep(1) | ||
|
||
# Check that we are able to retrieve document before and after partitioning | ||
retrieved_doc = TestPartitionedLog.get(id=doc_nonpartitioned.pk) | ||
assert retrieved_doc | ||
retrieved_doc = TestPartitionedLog.get(id=doc_partitioned.pk) | ||
assert retrieved_doc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters