forked from opensearch-project/notifications
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Email test for security integration test (opensearch-project#462)
* Fix Email test for security integration test Signed-off-by: Ashish Agrawal <[email protected]>
- Loading branch information
Showing
3 changed files
with
100 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
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 |
---|---|---|
|
@@ -12,6 +12,7 @@ import org.opensearch.integtest.PluginRestTestCase | |
import org.opensearch.notifications.NotificationPlugin.Companion.PLUGIN_BASE_URI | ||
import org.opensearch.rest.RestRequest | ||
import org.opensearch.rest.RestStatus | ||
import org.springframework.integration.test.mail.TestMailServer | ||
|
||
internal class SendTestMessageRestHandlerIT : PluginRestTestCase() { | ||
@Suppress("EmptyFunctionBlock") | ||
|
@@ -209,4 +210,84 @@ internal class SendTestMessageRestHandlerIT : PluginRestTestCase() { | |
val error = sendResponse.get("error").asJsonObject | ||
Assert.assertNotNull(error.get("reason").asString) | ||
} | ||
|
||
@Suppress("EmptyFunctionBlock") | ||
fun `test send test smtp email message for localhost successfully`() { | ||
if (isLocalHost()) { | ||
val smtpPort = 10255 | ||
val smtpServer = TestMailServer.smtp(smtpPort) | ||
|
||
val sampleSmtpAccount = SmtpAccount( | ||
"localhost", | ||
smtpPort, | ||
MethodType.NONE, | ||
"[email protected]" | ||
) | ||
// Create smtp account notification config | ||
val smtpAccountCreateRequestJsonString = """ | ||
{ | ||
"config":{ | ||
"name":"this is a sample smtp", | ||
"description":"this is a sample smtp description", | ||
"config_type":"smtp_account", | ||
"is_enabled":true, | ||
"smtp_account":{ | ||
"host":"${sampleSmtpAccount.host}", | ||
"port":"${sampleSmtpAccount.port}", | ||
"method":"${sampleSmtpAccount.method}", | ||
"from_address":"${sampleSmtpAccount.fromAddress}" | ||
} | ||
} | ||
} | ||
""".trimIndent() | ||
val createResponse = executeRequest( | ||
RestRequest.Method.POST.name, | ||
"$PLUGIN_BASE_URI/configs", | ||
smtpAccountCreateRequestJsonString, | ||
RestStatus.OK.status | ||
) | ||
val smtpAccountConfigId = createResponse.get("config_id").asString | ||
Assert.assertNotNull(smtpAccountConfigId) | ||
Thread.sleep(1000) | ||
|
||
val emailCreateRequestJsonString = """ | ||
{ | ||
"config":{ | ||
"name":"email config name", | ||
"description":"email description", | ||
"config_type":"email", | ||
"is_enabled":true, | ||
"email":{ | ||
"email_account_id":"$smtpAccountConfigId", | ||
"recipient_list":[ | ||
{"recipient":"[email protected]"} | ||
], | ||
"email_group_id_list":[] | ||
} | ||
} | ||
} | ||
""".trimIndent() | ||
|
||
val emailCreateResponse = executeRequest( | ||
RestRequest.Method.POST.name, | ||
"$PLUGIN_BASE_URI/configs", | ||
emailCreateRequestJsonString, | ||
RestStatus.OK.status | ||
) | ||
val emailConfigId = emailCreateResponse.get("config_id").asString | ||
Assert.assertNotNull(emailConfigId) | ||
Thread.sleep(1000) | ||
|
||
// send test message | ||
val sendResponse = executeRequest( | ||
RestRequest.Method.GET.name, | ||
"$PLUGIN_BASE_URI/feature/test/$emailConfigId", | ||
"", | ||
RestStatus.OK.status | ||
) | ||
|
||
smtpServer.stop() | ||
smtpServer.resetServer() | ||
} | ||
} | ||
} |