From d3e29a6a1d1ae200c43c66710ed960c63e731b9b Mon Sep 17 00:00:00 2001 From: Tim Ryan Date: Tue, 13 Aug 2019 18:45:02 -0400 Subject: [PATCH] Don't allow interval to be set with 0 or negative values. (#92) --- .../alerting/core/model/Schedule.kt | 4 ++++ .../alerting/core/model/ScheduleTest.kt | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/model/Schedule.kt b/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/model/Schedule.kt index 938aa02f..f669c2de 100644 --- a/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/model/Schedule.kt +++ b/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/model/Schedule.kt @@ -249,6 +249,10 @@ data class IntervalSchedule( if (!SUPPORTED_UNIT.contains(unit)) { throw IllegalArgumentException("Timezone $unit is not supported expected $SUPPORTED_UNIT") } + + if (interval <= 0) { + throw IllegalArgumentException("Interval is not allowed to be 0 or negative") + } } @Transient diff --git a/core/src/test/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/model/ScheduleTest.kt b/core/src/test/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/model/ScheduleTest.kt index a6765898..5c8670b3 100644 --- a/core/src/test/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/model/ScheduleTest.kt +++ b/core/src/test/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/model/ScheduleTest.kt @@ -336,5 +336,9 @@ class ScheduleTest : XContentTestBase { assertFailsWith(IllegalArgumentException::class, "Expected IllegalArgumentException") { IntervalSchedule(1, ChronoUnit.MONTHS) } + + assertFailsWith(IllegalArgumentException::class, "Expected IllegalArgumentException") { + IntervalSchedule(-1, ChronoUnit.MINUTES) + } } }