-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement simple query time range limit
In order to guard the system against accidental queries covering a large time range, the "query_time_range_limit" setting now provides a limit for those queries. If a search query exceeeds the time range given in "query_time_range_limit", the query is modified to fit within that limit by adjusting the starting time.
- Loading branch information
Jochen Schalanda
committed
Feb 12, 2016
1 parent
b202265
commit 821fcde
Showing
9 changed files
with
170 additions
and
13 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
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
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
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
89 changes: 89 additions & 0 deletions
89
graylog2-server/src/test/java/org/graylog2/rest/resources/search/SearchResourceTest.java
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,89 @@ | ||
/** | ||
* This file is part of Graylog. | ||
* | ||
* Graylog is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Graylog is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Graylog. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.graylog2.rest.resources.search; | ||
|
||
import org.graylog2.indexer.searches.Searches; | ||
import org.graylog2.indexer.searches.timeranges.AbsoluteRange; | ||
import org.graylog2.indexer.searches.timeranges.TimeRange; | ||
import org.joda.time.DateTime; | ||
import org.joda.time.DateTimeZone; | ||
import org.joda.time.Duration; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.MockitoJUnit; | ||
import org.mockito.junit.MockitoRule; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class SearchResourceTest { | ||
@Rule | ||
public final MockitoRule mockitoRule = MockitoJUnit.rule(); | ||
|
||
@Mock | ||
private Searches searches; | ||
|
||
private SearchResource searchResource; | ||
private Duration timeRangeLimit; | ||
|
||
@Before | ||
public void setUp() { | ||
timeRangeLimit = Duration.standardDays(1L); | ||
searchResource = new SearchResource(searches, timeRangeLimit) { | ||
}; | ||
} | ||
|
||
@Test | ||
public void restrictTimeRangeReturnsGivenTimeRangeWithinLimit() { | ||
final DateTime from = new DateTime(2015, 1, 15, 12, 0, DateTimeZone.UTC); | ||
final DateTime to = from.plusHours(1); | ||
final TimeRange timeRange = AbsoluteRange.create(from, to); | ||
|
||
final TimeRange restrictedTimeRange = searchResource.restrictTimeRange(timeRange); | ||
assertThat(restrictedTimeRange).isNotNull(); | ||
assertThat(restrictedTimeRange.getFrom()).isEqualTo(from); | ||
assertThat(restrictedTimeRange.getTo()).isEqualTo(to); | ||
} | ||
|
||
@Test | ||
public void restrictTimeRangeReturnsGivenTimeRangeIfNoLimitHasBeenSet() { | ||
final SearchResource resource = new SearchResource(searches, null) { | ||
}; | ||
|
||
final DateTime from = new DateTime(2015, 1, 15, 12, 0, DateTimeZone.UTC); | ||
final DateTime to = from.plusYears(1); | ||
final TimeRange timeRange = AbsoluteRange.create(from, to); | ||
|
||
final TimeRange restrictedTimeRange = resource.restrictTimeRange(timeRange); | ||
assertThat(restrictedTimeRange).isNotNull(); | ||
assertThat(restrictedTimeRange.getFrom()).isEqualTo(from); | ||
assertThat(restrictedTimeRange.getTo()).isEqualTo(to); | ||
} | ||
|
||
@Test | ||
public void restrictTimeRangeReturnsLimitedTimeRange() { | ||
final DateTime from = new DateTime(2015, 1, 15, 12, 0, DateTimeZone.UTC); | ||
final DateTime to = from.plus(timeRangeLimit.multipliedBy(2L)); | ||
final TimeRange timeRange = AbsoluteRange.create(from, to); | ||
final TimeRange restrictedTimeRange = searchResource.restrictTimeRange(timeRange); | ||
|
||
assertThat(restrictedTimeRange).isNotNull(); | ||
assertThat(restrictedTimeRange.getFrom()).isEqualTo(to.minus(timeRangeLimit)); | ||
assertThat(restrictedTimeRange.getTo()).isEqualTo(to); | ||
} | ||
} |
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