This repository has been archived by the owner on Aug 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support host deny list for Destinations (#353)
* Support deny list for destinations * Support deny list for destinations * Addressed comments and added integ tests
- Loading branch information
1 parent
8f1b7d5
commit a359247
Showing
12 changed files
with
204 additions
and
29 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
60 changes: 60 additions & 0 deletions
60
...src/test/kotlin/com/amazon/opendistroforelasticsearch/alerting/util/AlertingUtilsTests.kt
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,60 @@ | ||
package com.amazon.opendistroforelasticsearch.alerting.util | ||
|
||
import com.amazon.opendistroforelasticsearch.alerting.destination.message.BaseMessage | ||
import com.amazon.opendistroforelasticsearch.alerting.destination.message.CustomWebhookMessage | ||
import org.elasticsearch.test.ESTestCase | ||
import java.util.HashMap | ||
|
||
class AlertingUtilsTests : ESTestCase() { | ||
|
||
private val HOST_DENY_LIST = listOf( | ||
"127.0.0.0/8", | ||
"10.0.0.0/8", | ||
"172.16.0.0/12", | ||
"192.168.0.0/16", | ||
"0.0.0.0/8", | ||
"9.9.9.9" // ip | ||
) | ||
|
||
fun `test ips in denylist`() { | ||
val ips = listOf( | ||
"127.0.0.1", // 127.0.0.0/8 | ||
"10.0.0.1", // 10.0.0.0/8 | ||
"10.11.12.13", // 10.0.0.0/8 | ||
"172.16.0.1", // "172.16.0.0/12" | ||
"192.168.0.1", // 192.168.0.0/16" | ||
"0.0.0.1", // 0.0.0.0/8 | ||
"9.9.9.9" | ||
) | ||
for (ip in ips) { | ||
val bm = createMessageWithHost(ip) | ||
assertEquals(true, bm.isHostInDenylist(HOST_DENY_LIST)) | ||
} | ||
} | ||
|
||
fun `test url in denylist`() { | ||
val urls = listOf("https://www.amazon.com", "https://mytest.com", "https://mytest.com") | ||
for (url in urls) { | ||
val bm = createMessageWithURl(url) | ||
assertEquals(false, bm.isHostInDenylist(HOST_DENY_LIST)) | ||
} | ||
} | ||
|
||
private fun createMessageWithHost(host: String): BaseMessage { | ||
return CustomWebhookMessage.Builder("abc") | ||
.withHost(host) | ||
.withPath("incomingwebhooks/383c0e2b-d028-44f4-8d38-696754bc4574") | ||
.withMessage("{\"Content\":\"Message test\"}") | ||
.withMethod("POST") | ||
.withQueryParams(HashMap<String, String>()).build() | ||
} | ||
|
||
private fun createMessageWithURl(url: String): BaseMessage { | ||
return CustomWebhookMessage.Builder("abc") | ||
.withUrl(url) | ||
.withPath("incomingwebhooks/383c0e2b-d028-44f4-8d38-696754bc4574") | ||
.withMessage("{\"Content\":\"Message test\"}") | ||
.withMethod("POST") | ||
.withQueryParams(HashMap<String, String>()).build() | ||
} | ||
} |
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
Oops, something went wrong.