Commit graph

1124 commits

Author SHA1 Message Date
127cfdf2bc
Fix error variable declaration in eml.go
The error variable declaration has been corrected from "if err := parseEML(...)" to "if err = parseEML(...)". This change ensures consistency with the rest of the error handling code in the file.
2024-10-24 13:20:09 +02:00
7ed23bf01b
Remove outdated client test cases
Removed obsolete and redundant client test cases that were no longer relevant. This cleanup improves code maintainability and readability by eliminating excessive, unused test methods.
2024-10-24 12:53:37 +02:00
0310527eb5
Completed client.go tests
We've now covered 96% of all code. Everything else is not testable for us at this point.
2024-10-24 12:25:13 +02:00
1399a3331a
Refactor and extend client email tests
Refactor existing email sending tests by organizing multiple edge cases and adding robust test coverage. This includes adding checks for invalid sender/recipient addresses, handling DSN support, and ensuring proper client server interactions during failures like DATA init, DATA close, and MAIL FROM.
2024-10-24 12:03:56 +02:00
45ebcb95b3
Remove redundant connection check in send function.
The connection check is performed in the c.Reset call just before the c.checkconn call, making this redundant. Removing it simplifies the code and eliminates unnecessary error handling for connection status. This change helps improve code maintainability.
2024-10-24 12:02:57 +02:00
1519522e5d
Reduce sleep duration in client tests
Decreased sleep time from 300ms to 30ms across multiple tests to improve test execution speed. Added a new test `TestClient_sendSingleMsg` to connect and send an email message, ensuring the robustness of the sending functionality.
2024-10-24 10:50:17 +02:00
3bf1992cab
Improve test conciseness and concurrency handling
Simplified repeated message initialization by introducing a helper function `testMessage(t)`. Enhanced existing tests by adding robust concurrency tests and refined the structure of email sending scenarios.
2024-10-24 10:45:05 +02:00
4a8ac76636
Add nil check for smtpClient in checkConn function
Previously, if smtpClient was nil, the checkConn function would not handle that case. This update ensures that an appropriate error is returned when smtpClient is nil, enhancing the robustness of the client connection checks.
2024-10-24 10:44:40 +02:00
5e3ebcc1a6
Remove redundant connection check in auth function
The checkConn call in the auth function was redundant because the connection is already managed appropriately elsewhere. Removing this unnecessary check simplifies the code and avoids potential duplication of error handling.
2024-10-24 10:12:57 +02:00
040289cea4
Remove hardcoded test credentials and add new auth tests.
Replaced hardcoded SMTP credentials with generic placeholders for improved security. Added new test cases to handle unsupported authentication methods and connections without TLS.
2024-10-24 10:12:43 +02:00
2a2176d700
Add tests for various SMTP authentication methods
Implemented new test cases for different SMTP authentication methods including PLAIN, LOGIN, XOAUTH2, and various SCRAM mechanisms. These tests ensure that the client can correctly handle both successful and failing authentication scenarios, as well as unsupported authentication types.
2024-10-24 09:59:31 +02:00
e442419c18
Remove redundant connection check in tls function
The `tls` function in `client.go` no longer checks for an active connection before executing. This simplifies the code since the connection check is either redundant or already handled elsewhere in the flow.
2024-10-24 09:19:08 +02:00
28dc629674
Refactor and expand client dial-and-send tests
Renamed TestClient_DialAndSend to TestClient_DialAndSendWithContext and reorganized message setup. Added multiple test cases to cover different failure points in the DialAndSendWithContext method.
2024-10-24 00:50:16 +02:00
84ca70083a
Add test for DialAndSend functionality
Introduce a new test `TestClient_DialAndSend` to validate the process of dialing and sending an email using the SMTP client. This includes setting up a mock SMTP server and verifying the process from message creation to sending.
2024-10-24 00:30:57 +02:00
06f6fd3692
Add client reset functionality tests
Introduce tests for the client reset functionality, including scenarios to test successful reset, reset on a disconnected client, and reset with server failure. This ensures robustness and reliability of the client reset feature under various conditions.
2024-10-24 00:22:33 +02:00
2710250baa
Add *testing.T to simpleSMTPServer and logging improvements
Pass `*testing.T` to `simpleSMTPServer` for enhanced test logging and helper methods. This allows better integration with the testing framework, converting standard log outputs to `t.Logf` for improved test diagnostics and error reporting.
2024-10-24 00:11:58 +02:00
7f3cd8dc38
Merge branch 'main' into feature/overhaul-tests 2024-10-23 23:52:13 +02:00
cf1246d9ea
Remove redundant DialWithContext test cases
Deleted two test functions for DialWithContext that tested invalid HELO and authentication scenarios. These tests were deemed redundant as the error handling for these cases is covered elsewhere.
2024-10-23 23:34:13 +02:00
c63b8b124e
Add STARTTLS and SSL test cases for SMTP client
Extended test cases to include scenarios for STARTTLS and SSL connections. This includes handling TLS configurations, testing certificate handling, and tests for various authentication methods under TLS.
2024-10-23 23:33:33 +02:00
563ccbab4a
Fix typo in comment within Quit function
Corrected grammar in a comment to enhance code readability and maintain consistency. This change does not affect the functionality of the `Quit` method.
2024-10-23 22:26:08 +02:00
ea57644a8e
Add debug logging to client creation in tests
Introduce `WithDebugLog()` in client creation for enhanced logging during tests. Correct handling of certain SMTP command errors by replacing `return` with `break` in switch cases for proper loop continuation.
2024-10-23 22:20:32 +02:00
74fa3f6f62
Fix Quit handling when initial HELO fails
Ensure QUIT command can be sent even if initial HELO fails. Added a check to skip retrying HELO if it already failed, allowing for proper closing of the connection. This prevents potential hangs or errors during connection termination.
2024-10-23 21:54:06 +02:00
572751ac10
Add test for invalid HELO handling in SMTP client
Introduce a new test case to ensure the SMTP client fails gracefully when an invalid HELO command is used. This includes validating error handling and maintaining the client connection integrity. Also, optimize EHLO/HELO command handling by enhancing syntax checking and error response generation.
2024-10-23 18:20:52 +02:00
d281f838d4
Add integration tests for invalid host and HELO failure
Add test cases to validate client behavior on connecting with an invalid host and encountering a HELO failure. This helps ensure the client handles these error scenarios correctly, maintaining robustness and reliability.
2024-10-23 18:08:30 +02:00
0db1383940
Refactor buffer initialization in client tests
Replaced &bytes.Buffer{} with bytes.NewBuffer(nil) for buffer initialization in various client tests. This change ensures more idiomatic and consistent creation of byte buffers throughout the test cases.
2024-10-23 17:58:08 +02:00
21184e60b9
Switch to using bytes.NewBuffer(nil) in tests
Refactored the test code to initialize buffers using bytes.NewBuffer(nil) instead of &bytes.Buffer{}. This change ensures a consistent and idiomatic initialization of byte buffers throughout the test cases.
2024-10-23 17:57:09 +02:00
12695385e8
Refactor SMTP server test setup to use serverProps struct
Consolidate server configuration properties into a new serverProps struct for better code clarity and future extensibility. This change involves updating simpleSMTPServer and test cases to use the new struct, allowing more control over server behavior during tests.
2024-10-23 17:55:31 +02:00
8a6cd2b448
Add and update client tests
Reintroduces and enhances several client tests including `SetLogAuthData`, `Close`, `DialWithContext`, and others. Deprecated and non-functional tests are removed, and a new log parsing method is added for enhanced logging validation.
2024-10-23 17:34:23 +02:00
ae7160ddba
Refactor SMTP Auth unit test with table-driven approach
Replaced the single test case for setting custom SMTP authentication with a table-driven approach. This refactor improves test coverage by including multiple authentication methods such as CRAM-MD5, LOGIN, PLAIN, SCRAM, and XOAUTH2.
2024-10-23 16:46:18 +02:00
d4dc212dd3
Refactor client tests and add SetSMTPAuthCustom test
Removed outdated tests for TLSConfig, Username, Password, and SMTPAuth that were commented out. Added a new test for the SetSMTPAuthCustom method, specifically for PLAIN authentication, ensuring proper behavior and type checks.
2024-10-23 16:14:05 +02:00
17cb590a45
Add test for Client.SetSMTPAuth function
Introduce a new test to validate the functionality of the Client.SetSMTPAuth method. This test covers various SMTP authentication types and ensures that the method correctly sets the expected authentication type while also verifying the override behavior for different custom and default authentications.
2024-10-23 15:44:21 +02:00
cec7e38332
Merge pull request #345 from wneessen/dependabot/github_actions/github/codeql-action-3.27.0
Bump github/codeql-action from 3.26.13 to 3.27.0
2024-10-23 15:32:09 +02:00
c946f74ad2
Add unit tests for Client TLS, Username, and Password methods
Introduced unit tests for Client's SetTLSConfig, SetUsername, and SetPassword methods. The tests cover various scenarios, including setting valid configurations, handling nil inputs, and overriding previous settings. This improves our test coverage and ensures the reliability of these methods.
2024-10-23 15:31:00 +02:00
dependabot[bot]
9ad77012e3
Bump github/codeql-action from 3.26.13 to 3.27.0
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.26.13 to 3.27.0.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](f779452ac5...662472033e)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-10-23 13:16:56 +00:00
68bc5dde72
Add comprehensive tests for Client TLS and debugging features
Implemented detailed test cases for various TLS policies and settings, port configurations, and SSL options. Also added tests for debugging functionalities of the Client, enabling robust validation of different scenarios.
2024-10-23 15:15:59 +02:00
3efd2b529f
Set fallbackPort to 0 in SetTLSPortPolicy
The default fallback port should be reset to 0 when setting the TLS port policy. This ensures the fallbackPort does not retain an incorrect value when switching policies.
2024-10-23 14:39:28 +02:00
c5b57543c1
Update client tests to add context support and new checks
Introduced `context` package for new tests. Added checks for `WithDialContextFunc`, `WithLogAuthData`, and TLS policy assertions. Improved test failure handling and removed obsolete tests.
2024-10-23 14:08:19 +02:00
ab8fc3e4fc
Add DSN and dial context func options to client tests
Expanded the client test cases to include DSN mail return types and multiple DSN recipient notify types. Also added tests for setting dial context functions using both net.Dialer and tls.Dialer, including error handling for invalid options.
2024-10-23 13:51:48 +02:00
35f92f2ddc
Add error handling for nil DialContextFunc
Introduce ErrDialContextFuncIsNil to handle cases where the dial context function is not provided. Update WithDialContextFunc to return this error when a nil function is passed.
2024-10-23 13:51:31 +02:00
3251d74c36
Refactor client test to enhance coverage and clarity
Reorganized and refactored tests for `NewClient` by adding individual test cases for different client creation scenarios, including various options and validation. Improved clarity and coverage by isolating cases, enhancing error messages, and removing redundancy.
2024-10-23 13:23:01 +02:00
1c8b2904f5
Add error check for nil SMTP authentication method
Ensure that the SMTP authentication method is not nil by adding a corresponding error check in the WithSMTPAuthCustom function. Introduced a new error, ErrSMTPAuthMethodIsNil, to handle this validation.
2024-10-23 13:10:13 +02:00
ab835b7870
Uncomment seed data in FuzzBase64LineBreaker
The previously commented-out empty byte array is now uncommented to include an empty string as part of the test cases. This change ensures that the FuzzBase64LineBreaker function properly handles an empty input scenario.
2024-10-23 11:36:06 +02:00
0bac51746d
Add error handling for base64 decoding in test
This commit adds a check for errors when decoding base64 strings in the b64linebreaker_test.go file. If an error occurs, it logs a meaningful error message, improving the test's robustness and clarity.
2024-10-23 11:29:04 +02:00
b31c7cf3a7
Add licenses for logo SVG files
These files specify the copyright and licensing information for the logo assets. They ensure that our usage of these images complies with the CC-BY-ND-4.0 license.
2024-10-23 11:26:42 +02:00
854361090a
Add coverage files to .gitignore
This change ensures that coverage data files are not tracked by Git. The addition helps keep the repository clean from auto-generated coverage reports.
2024-10-23 11:21:03 +02:00
421451f179
Add base64-encoded logo.svg to testdata
This commit introduces a new file, logo.svg.base64, into the testdata directory. This encoded SVG logo will be useful for testing purposes.
2024-10-23 11:20:24 +02:00
bdfe13dc93
Overhauled Base64LineBreaker test suite
Improved the test suite for the Base64LineBreaker. Tests are now written more consistently. Maintainability and readability have been improved as well.
2024-10-23 11:19:58 +02:00
946d9888d6
Refactor error handling in Base64LineBreaker
Switched ErrNoOutWriter from a string constant to an error object for improved error handling consistency. This change enhances clarity and reduces the risk of error handling inconsistencies in the future.
2024-10-23 11:16:09 +02:00
2088796049
Remove testdata directory and extra newline from .gitignore
The testdata directory entry was incorrect and has been removed. Additionally, an extra newline at the end of the file was removed for consistency.
2024-10-23 11:15:32 +02:00
55e5a1536e
Merge pull request #344 from wneessen/feature/342_allow-bypass-plain-auth-tls-check
Allow unencrypted PLAIN and LOGIN smtp authentication
2024-10-22 17:39:04 +02:00