citrusframework / citrus

Framework for automated integration tests with focus on messaging integration
https://citrusframework.org
Apache License 2.0
453 stars 134 forks source link

Citrus 4: MailServer only binds to loopback interface #1199

Closed ghost closed 1 week ago

ghost commented 1 month ago

Citrus Version 4.x

Expected behavior Mailserver binds to all interfaces, as in Citrus 3.x, or host is configurable

Actual behavior Mailserver binds to loopback interface only and the host is not configurable

Test case sample SMTP interception on a host which has its mail port bound to a non loopback interface. Upgrade from Citrus 3.x to 4.x.

When we upgraded from Citrus 3 to Citrus 4, our mail tests did not work anymore. The problem was due to the default behaviour of subethasmtp vs. GreenMail. In subethasmtp, when no host is given, the mail server binds to all interfaces, whereas GreenMail will bind only to loopback per default.

As the Citrus MailServerBuilder does not have functions to set the host manually, and the MailServer initialises the GreenMail server with a hardcoded host value of null, the Citrus MailServer will only bind to the loopback interface and not receive Mails from another interfaces. This can be fixed by adding a host method to the MailServerBuilder and setting the host value instead of null for the GreenMail initialisation in the MailServer startup() function

On a side note: it also seems that if you use the smtp(GreenMail smtpServer) method from the MailServerBuilder, the given GreenMail server is overwritten in the MailServer startup() function as there is a missing null check before initialising a new GreenMail instance.

bbortt commented 1 month ago

thanks for the report! definitely two bugs:

do you want to work on these and submit a PR or should I try and fix it if I find some time?