-
Notifications
You must be signed in to change notification settings - Fork 0
feat: allow pass hostname in docker env #157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: qodo_claude_vs_qodo_base_feat_allow_pass_hostname_in_docker_env_pr6
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,8 @@ | |
| from email.mime.multipart import MIMEMultipart | ||
| from email.mime.text import MIMEText | ||
|
|
||
| from configs import dify_config | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
|
|
@@ -19,20 +21,19 @@ def __init__( | |
| self.opportunistic_tls = opportunistic_tls | ||
|
|
||
| def send(self, mail: dict): | ||
| smtp = None | ||
| smtp: smtplib.SMTP | None = None | ||
| local_host = dify_config.SMTP_LOCAL_HOSTNAME or "" | ||
| try: | ||
| if self.use_tls: | ||
| if self.opportunistic_tls: | ||
| smtp = smtplib.SMTP(self.server, self.port, timeout=10) | ||
| # Send EHLO command with the HELO domain name as the server address | ||
| smtp.ehlo(self.server) | ||
| smtp.starttls() | ||
| # Resend EHLO command to identify the TLS session | ||
| smtp.ehlo(self.server) | ||
| else: | ||
| smtp = smtplib.SMTP_SSL(self.server, self.port, timeout=10) | ||
| else: | ||
| smtp = smtplib.SMTP(self.server, self.port, timeout=10) | ||
| # Use ternary to select SMTP class based on TLS mode | ||
| smtp = (smtplib.SMTP_SSL if (self.use_tls and not self.opportunistic_tls) else smtplib.SMTP)( | ||
| self.server, self.port, timeout=10, local_hostname=local_host or None | ||
| ) | ||
|
|
||
| assert smtp is not None | ||
| if self.use_tls and self.opportunistic_tls: | ||
| smtp.ehlo(local_host) | ||
| smtp.starttls() | ||
| smtp.ehlo(local_host) | ||
|
Comment on lines
+24
to
+36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2. Smtpclient config side effects libs.smtp.SMTPClient now depends on the global dify_config to determine HELO/EHLO hostname, which forces config initialization when importing the SMTP utility and makes the local hostname process-global rather than instance-level. This increases coupling and can break callers that want to use SMTPClient without the full app config stack or need different hostnames per client instance. Agent Prompt
|
||
|
|
||
| # Only authenticate if both username and password are non-empty | ||
| if self.username and self.password and self.username.strip() and self.password.strip(): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| from unittest.mock import MagicMock, patch | ||
| from unittest.mock import ANY, MagicMock, patch | ||
|
|
||
| import pytest | ||
|
|
||
|
|
@@ -17,7 +17,7 @@ def test_smtp_plain_success(mock_smtp_cls: MagicMock): | |
| client = SMTPClient(server="smtp.example.com", port=25, username="", password="", _from="noreply@example.com") | ||
| client.send(_mail()) | ||
|
|
||
| mock_smtp_cls.assert_called_once_with("smtp.example.com", 25, timeout=10) | ||
| mock_smtp_cls.assert_called_once_with("smtp.example.com", 25, timeout=10, local_hostname=ANY) | ||
| mock_smtp.sendmail.assert_called_once() | ||
|
Comment on lines
+20
to
21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 3. Hostname override untested Unit tests were updated to accept any value for the new local_hostname argument, but they do not assert that SMTP_LOCAL_HOSTNAME is actually propagated into the SMTP handshake behavior. This can allow future regressions where the env/config value is ignored while tests still pass. Agent Prompt
|
||
| mock_smtp.quit.assert_called_once() | ||
|
|
||
|
|
@@ -38,7 +38,7 @@ def test_smtp_tls_opportunistic_success(mock_smtp_cls: MagicMock): | |
| ) | ||
| client.send(_mail()) | ||
|
|
||
| mock_smtp_cls.assert_called_once_with("smtp.example.com", 587, timeout=10) | ||
| mock_smtp_cls.assert_called_once_with("smtp.example.com", 587, timeout=10, local_hostname=ANY) | ||
| assert mock_smtp.ehlo.call_count == 2 | ||
| mock_smtp.starttls.assert_called_once() | ||
| mock_smtp.login.assert_called_once_with("user", "pass") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1. feature/init.py exceeds 800
📘 Rule violation⛯ ReliabilityAgent Prompt
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools