Skip to content

Commit

Permalink
Fix Email test for security integration test
Browse files Browse the repository at this point in the history
Signed-off-by: Ashish Agrawal <ashisagr@amazon.com>
  • Loading branch information
lezzago committed May 20, 2022
1 parent 395d68d commit 964e384
Showing 1 changed file with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@
* SPDX-License-Identifier: Apache-2.0
*/

package org.opensearch.notifications.core.integTest
package org.opensearch.notifications.core.smtp

import org.junit.After
import org.junit.jupiter.api.Test
import org.opensearch.notifications.core.NotificationCoreImpl
import org.opensearch.notifications.core.transport.DestinationTransportProvider
import org.opensearch.notifications.core.transport.SmtpDestinationTransport
import org.opensearch.notifications.spi.model.MessageContent
import org.opensearch.notifications.spi.model.destination.DestinationType
import org.opensearch.notifications.spi.model.destination.SmtpDestination
import org.opensearch.rest.RestStatus
import org.opensearch.test.rest.OpenSearchRestTestCase
import org.springframework.integration.test.mail.TestMailServer
import kotlin.test.assertEquals

internal class SmtpEmailIT : OpenSearchRestTestCase() {
class SmtpEmailTests {

private val smtpServer: TestMailServer.SmtpServer
private val smtpPort = 10255 // use non-standard port > 1024 to avoid permission issue

init {
smtpServer = TestMailServer.smtp(smtpPort)
internal companion object {
private const val smtpPort = 10255 // use non-standard port > 1024 to avoid permission issue
private val smtpServer = TestMailServer.smtp(smtpPort)
}

@After
Expand All @@ -28,6 +30,7 @@ internal class SmtpEmailIT : OpenSearchRestTestCase() {
smtpServer.resetServer()
}

@Test
fun `test send email to one recipient over smtp server`() {
val smtpDestination = SmtpDestination(
"testAccountName",
Expand All @@ -46,11 +49,13 @@ internal class SmtpEmailIT : OpenSearchRestTestCase() {
"VGVzdCBtZXNzYWdlCgo=",
"application/octet-stream",
)
DestinationTransportProvider.destinationTransportMap = mapOf(DestinationType.SMTP to SmtpDestinationTransport())
val response = NotificationCoreImpl.sendMessage(smtpDestination, message, "ref")
assertEquals("Success", response.statusText)
assertEquals(RestStatus.OK.status, response.statusCode)
}

@Test
fun `test send email with non-available host`() {
val smtpDestination = SmtpDestination(
"testAccountName",
Expand All @@ -69,6 +74,7 @@ internal class SmtpEmailIT : OpenSearchRestTestCase() {
"VGVzdCBtZXNzYWdlCgo=",
"application/octet-stream",
)
DestinationTransportProvider.destinationTransportMap = mapOf(DestinationType.SMTP to SmtpDestinationTransport())
val response = NotificationCoreImpl.sendMessage(smtpDestination, message, "ref")
assertEquals(
"sendEmail Error, status:Couldn't connect to host, port: invalidHost, $smtpPort; timeout -1",
Expand Down

0 comments on commit 964e384

Please sign in to comment.