Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,9 @@ services:
- SMTP_USER=${SMTP_USER}
- SMTP_PASS=${SMTP_PASS}
- SMTP_FROM=${SMTP_FROM}
- SMTP_SOCKS_HOST=${SMTP_SOCKS_HOST}
- SMTP_SOCKS_PORT=${SMTP_SOCKS_PORT}
- SMTP_PROXY_ENABLED=${SMTP_PROXY_ENABLED}
- TOKEN_ISSUER_URL=${KC_ISSUER_URL}
- OTP_CODE_RESPONSE_ENABLED=${OTP_CODE_RESPONSE_ENABLED}
depends_on:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package co.nilin.opex.otp.app.config

import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Profile
import org.springframework.core.io.Resource
import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories
import org.springframework.r2dbc.core.DatabaseClient

@Configuration
@EnableR2dbcRepositories(basePackages = ["co.nilin.opex"])
@Profile("!test")
class PostgresConfig(
db: DatabaseClient,
@Value("classpath:schema.sql") private val schemaResource: Resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import jakarta.mail.internet.MimeMessage
import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Component


@Component
class EmailSender(
@Value("\${otp.email.host}")
Expand All @@ -19,7 +20,13 @@ class EmailSender(
@Value("\${otp.email.password}")
private val password: String,
@Value("\${otp.email.from}")
private val from: String
private val from: String,
@Value("\${otp.email.proxy.enabled}")
private val proxyIsEnabled: Boolean,
@Value("\${otp.email.proxy.host}")
private val proxyHost: String?,
@Value("\${otp.email.proxy.port}")
private val proxyPort: String?
) : MessageSender {

private val logger by LoggerDelegate()
Expand All @@ -34,6 +41,11 @@ class EmailSender(
properties["mail.smtp.starttls.enable"] = "true"
properties["mail.smtp.from"] = from
properties["mail.smtp.ssl.protocols"] = "TLSv1.2"
if (proxyIsEnabled) {
properties["mail.smtp.socks.host"] = proxyHost
properties["mail.smtp.socks.port"] = proxyPort
}

val session = Session.getDefaultInstance(properties)

return try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package co.nilin.opex.otp.app.conttroller


import co.nilin.opex.otp.app.service.message.EmailSender
import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test


class EmailSenderIT {
@Disabled("Manual test: requires real SMTP + proxy")
@Test
fun `should send email via real smtp`() = runBlocking {

val sender = EmailSender(
host = requireEnv("SMTP_HOST"),
port = requireEnv("SMTP_PORT"),
username = requireEnv("SMTP_USER"),
password = requireEnv("SMTP_PASS"),
from = requireEnv("SMTP_FROM"),
proxyIsEnabled = true,
proxyHost = requireEnv("SMTP_SOCKS_HOST"),
proxyPort = requireEnv("SMTP_SOCKS_PORT")
)

val result = sender.send(
receiver = requireEnv("SMTP_RECEIVER"),
message = "<h1>Integration Test</h1>",
metadata = emptyMap()
)

Assertions.assertTrue(result)
}

private fun requireEnv(key: String): String =
System.getenv(key) ?: error("Missing env: $key")
}
42 changes: 42 additions & 0 deletions otp/otp-app/src/test/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
spring:
main:
web-application-type: none

# 🚫 disable everything noisy
autoconfigure:
exclude:
- org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
- org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration
- org.springframework.boot.autoconfigure.r2dbc.R2dbcAutoConfiguration

cloud:
consul:
enabled: false
config:
enabled: false

vault:
enabled: false

kafka:
bootstrap-servers: ""
otp:
response-enabled: ${OTP_CODE_RESPONSE_ENABLED:false}
sms:
provider:
url: ${SMS_PROVIDER_URL}
api-key: ${SMS_PROVIDER_API_KEY}
template: ${SMS_PROVIDER_TEMPLATE}
email:
host: ${SMTP_HOST}
port: ${SMTP_PORT}
username: ${SMTP_USER}
password: ${SMTP_PASS}
from: ${SMTP_FROM}
proxy:
enabled: ${SMTP_PROXY_ENABLED:false}
host: ${SMTP_PROXY_HOST}
port: ${SMTP_PROXY_PORT}
custom-message:
enabled: ${CUSTOM_MESSAGE_ENABLED:false}
base-url: ${CUSTOM_MESSAGE_URL}
23 changes: 23 additions & 0 deletions otp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,29 @@
<artifactId>logbook-spring-boot-webflux-autoconfigure</artifactId>
<version>3.9.0</version>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>1.18.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.4.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<dependencyManagement>
Expand Down
Loading