Commit graph

55 commits

Author SHA1 Message Date
1bfec504ed
Add new SMTP test cases for various failure scenarios
This commit introduces multiple test cases to handle SMTP failure scenarios such as invalid host, newline in addresses, EHLO/HELO failures, and malformed data injections. Additionally, it includes improvements in error handling for these specific conditions.
2024-11-11 17:12:15 +01:00
87accd289e
Fix formatting in smtp_test.go and add new test cases
Corrected indentation inconsistencies in the smtp_test.go file. Added multiple test cases to verify the failure scenarios for `SendMail` under various conditions including invalid hostnames, newlines in the address fields, and server failures during EHLO/HELO, STARTTLS, and authentication stages.
2024-11-11 16:41:44 +01:00
c6da393676
Add echo buffer to SMTP server tests
Refactored SMTP server tests to use an echo buffer for capturing responses. This allows for better validation of command responses without relying on error messages. Additionally, added a new test case to validate a full SendMail transaction with TLS and authentication.
2024-11-11 13:31:25 +01:00
e9c7bdbb4e
Refactor TLS config initialization in tests
Replace repetitive TLS configuration code with a reusable `getTLSConfig` helper function for consistency and maintainability. Additionally, update port configuration and add new tests for mail data transmission.
2024-11-11 12:54:10 +01:00
75bfdd2855
Update smtp tests to use t.Fatalf for critical failures
Changed `t.Errorf` to `t.Fatalf` in multiple instances within the test cases. This ensures that the tests halt immediately upon a critical failure, improving test reliability and debugging clarity.
2024-11-11 12:28:52 +01:00
d446b491e2
Add client cleanup to SMTP tests and new TestClient_Rcpt
Update SMTP tests to use t.Cleanup for client cleanup to ensure proper resource release. Introduce a new test, TestClient_Rcpt, to verify recipient address handling under various conditions.
2024-11-10 14:31:18 +01:00
0d8d097ae1
Add tests for DSN, 8BITMIME, and SMTPUTF8 support in SMTP
Introduce new test cases to verify the SMTP server's ability to handle DSN, 8BITMIME, and SMTPUTF8 features. These tests ensure correct response behavior when these features are supported by the server.
2024-11-10 14:10:50 +01:00
0df228178a
Add extensive client tests for Mail, Verify, and Auth commands
Introduce new tests for the SMTP client covering scenarios for Mail, Verify, and Auth commands to ensure correct behavior under various conditions. Updated `simpleSMTPServer` implementation to handle more cases including VRFY and SMTPUTF8.
2024-11-10 14:06:05 +01:00
b7ffce62aa
Add TLS connection state tests for SMTP client
Introduce tests to verify TLS connection state handling in the SMTP client. Ensure that normal TLS connections return a valid state, and non-TLS connections do not wrongly indicate a TLS state.
2024-11-09 15:22:23 +01:00
8f28babc47
Add tests for Client StartTLS functionality
Introduce new tests to cover the Client's behavior when initiating a STARTTLS session under different conditions: normal operation, failure on EHLO/HELO, and a server not supporting STARTTLS. This ensures robustness in handling STARTTLS interactions.
2024-11-09 14:58:23 +01:00
50505e1339
Add test for Client cmd failure on textproto command
This commit introduces a new test case for the `Client`'s `cmd` method to ensure it fails correctly when the `textproto` command encounters a broken writer. It also adds a `failWriter` struct that simulates a write failure to facilitate this testing scenario.
2024-11-09 14:26:44 +01:00
af7964450a
Add test cases for invalid HELO/EHLO commands
Add tests to ensure HELO/EHLO commands fail with empty name, newline in name, and double execution. This improves validation and robustness of the SMTP client implementation.
2024-11-09 14:01:02 +01:00
cefaa0d4ee
Refactor SMTP test cases for improved clarity and coverage
Consolidate and organize SMTP test cases by removing obsolete tests and adding focused, detailed tests for CRAM-MD5 and new client behaviors. This ensures clearer test structure and better coverage of edge cases.
2024-11-09 13:44:14 +01:00
92ab51b13d
Add comprehensive tests for scramAuth error handling
Introduce new test cases to validate the error handling of the scramAuth methods. These tests cover scenarios such as invalid characters in usernames, empty inputs, and edge cases like broken rand.Reader.
2024-11-09 00:06:33 +01:00
d4c6cb506c
Add SCRAM authentication tests to smtp package
Added comprehensive unit tests for SCRAM-SHA-1, SCRAM-SHA-256, and their PLUS variants. Implemented a test server to simulate various SCRAM authentication scenarios and validate both success and failure cases.
2024-11-08 16:53:09 +01:00
c656226fd3
Add XOAuth2 authentication tests to SMTP package
Introduces two tests for XOAuth2 authentication in the SMTP package. The first test ensures successful authentication with valid credentials, while the second test verifies that authentication fails with incorrect settings.
2024-11-08 15:51:17 +01:00
1af17f14e1
Add cleanup to close client connections in tests
This commit enhances the cleanup process in the SMTP tests by adding t.Cleanup to close client connections. Additionally, it rewrites the TestXOAuth2 function to include more detailed sub-tests, enhancing test granularity and readability.
2024-11-08 15:11:47 +01:00
b03fbb4ae8
Add test server for SMTP authentication
Added a simple SMTP test server with basic features like PLAIN, LOGIN, and NOENC authentication. It can start, handle connections, and simulate authentication success or failure. Included support for TLS with a generated localhost certificate.
2024-11-07 22:42:23 +01:00
4221d48644
Update login authentication test cases in smtp_test.go
Renamed the test functions and improved the test structure for login authentication checks. Added subtests to provide clear descriptions and enhance error checking.
2024-11-07 21:31:24 +01:00
410343496c
Refactor and expand TestLoginAuth
Rename and uncomment TestLoginAuth with more test cases, ensuring coverage for successful and failed authentication scenarios, including checks for unencrypted logins and server response errors. This improves test robustness and coverage.
2024-11-07 21:14:52 +01:00
3cfd20576d
Rename and expand TestPlainAuth_noEnc with additional checks
Refactor the test function `TestPlainAuth_noEnc` to include subtests for better organization and add more comprehensive error handling. This improves clarity and robustness by verifying various authentication scenarios and expected outcomes.
2024-11-03 16:13:54 +01:00
99c4378107
Refactor and streamline authentication tests
Improved the structure and readability of the authentication tests by using subtests for each scenario, ensuring better isolation and clearer failure reporting. Removed unnecessary imports and redundant code, reducing complexity and enhancing maintainability.
2024-11-01 19:22:28 +01:00
8353b4b255
Follow upstream for HELO during Quit bug
I reported the bug I fixed in 74fa3f6f62 to Go upstream. They fixed simpler by just ignoring the error (See: https://go.dev/cl/622476). We follow this patch accordingly. The upstream test has been adopted as well.
2024-10-25 09:33:45 +02:00
df1a141368
Handle client close errors in SMTP tests
Update defer statements to log errors if client fails to close in smtp_test.go. Additionally, add a return statement to avoid further errors after a failed SendMail operation.
2024-10-22 16:02:43 +02:00
e2ed5b747a
Add tests for PlainAuth and LoginAuth without encryption
Introduced new test functions TestAuthPlainNoEnc and TestAuthLoginNoEnc in smtp_test.go to verify behaviors of PlainAuth and LoginAuth without TLS encryption. These tests ensure that authentication mechanisms handle non-encrypted and diverse server configurations correctly.
2024-10-22 15:50:18 +02:00
2bd950469a
Add 'skipTLS' parameter to auth functions in tests
Updated PlainAuth and LoginAuth calls in smtp_test.go and example_test.go to include a 'skipTLS' boolean parameter. This ensures consistent function signatures throughout the test cases and examples.
2024-10-22 15:44:40 +02:00
f120485c98
Correct typo in comment
Fix a typo in smtp_test.go's comment from "challanges" to "challenges" to improve readability and accuracy of documentation. This change does not affect the code's functionality.
2024-10-16 10:37:13 +02:00
3234c13277
Add tests for SetLogAuthData method
Introduced TestClient_SetLogAuthData to verify the proper behavior of the SetLogAuthData method in both client and SMTP tests. This ensures that logAuthData is enabled or disabled as expected, increasing code reliability.
2024-10-15 20:02:24 +02:00
476130d6e3
Fumpt files to make golangci-lint happy 2024-10-05 11:43:50 +02:00
159c1bf850
Add tests for new tls and connection handling methods
This commit introduces tests for various TLS-related methods such as GetTLSConnectionState, HasConnection, SetDSNMailReturnOption, SetDSNRcptNotifyOption, and UpdateDeadline. It also modifies the error handling logic in smtp.go to include new error types and improves the mutex handling in UpdateDeadline.
2024-10-05 10:55:25 +02:00
711ce2ac65
Add support for SCRAM-SHA-1-PLUS and SCRAM-SHA-256-PLUS
Extended SMTP tests to include SCRAM-SHA-1-PLUS and SCRAM-SHA-256-PLUS authentication mechanisms. Adjusted the `startSMTPServer` function to accept a hashing function and modified the server logic to handle TLS channel binding.
2024-10-04 18:31:58 +02:00
4c8c0d855e
Handle read errors in SMTP authentication flow
Add checks to handle errors when reading client messages. This ensures that an appropriate error message is sent back to the client if reading fails, improving the robustness of the SMTP authentication process.
2024-10-03 12:38:39 +02:00
03062c5183
Add SCRAM-SHA authentication tests for SMTP
Introduce new unit tests to verify SCRAM-SHA-1 and SCRAM-SHA-256 authentication for the SMTP client. These tests cover both successful and failing authentication cases, and include a mock SMTP server to facilitate testing.
2024-10-03 12:32:06 +02:00
a8e89a1258
Add support for SCRAM-SHA authentication mechanisms
Introduced new test cases for SCRAM-SHA-1, SCRAM-SHA-256, and their PLUS variants in `smtp_test.go`. Updated the authTest structure to include a `hasNonce` flag and implemented logic to handle nonce validation and success message processing.
2024-10-02 18:02:46 +02:00
93752280aa
Update smtp_test.go to add more authentication test cases
Enhanced the LoginAuth test coverage by adding new scenarios with different sequences and invalid cases. This ensures more robust validation and better handling of edge cases in authentication testing.
2024-10-02 12:54:32 +02:00
071ad66035
Sync with upstream
This PR syncs our smtp package with the upstream `net/smtp` changes introduced via bf91eb3a8b
2024-05-24 18:50:27 +02:00
07783d24e5
Update format string in Debugf method calls in tests
The format string for the Debugf method calls within the smtp_test.go file have been updated. Previously, the format string was empty, but it has now been changed to "%s" to align with the standard formatting expectations, improving the correctness of the tests.
2024-04-06 17:13:45 +02:00
7a549242ae
Update Go version and clean up SMTP test suite
The Go version has been updated to 1.22 in the .golangci.toml file for compatibility reasons. Additionally, unnecessary white space has been removed from the smtp/smtp_test.go file to maximize code efficiency and readability.
2024-02-08 16:51:25 +01:00
James Elliott
a73a914fb2
feat(smtp): auth login extension draft support
This adds support for the auth login extension draft.
2024-01-07 13:34:33 +11:00
1c5c1e318c
#136: Refactor logging for clearer messaging direction
The logging system in the smtp.go and log package has been refactored. A new custom log type `Log` was introduced, that includes the message direction, format and arguments. The `Logger` interface and the `Stdlog` implementation were modified to accept this new type. This change provides a clearer understanding of message direction inside logs, allowing for easier debugging and reduced complexity. This change does not affect features or disrupt user functionality. Additionally, it allows for custom implementations of the log.Logger interface to without being forced to use the C --> S/C <-- S direction logging.
2023-08-02 11:43:45 +02:00
Nicola Murino
61b9e59dd2 oauth2: add more test cases 2023-06-04 10:47:19 +02:00
Nicola Murino
8673addaf0 OAuth2: remove variants
Microsoft also accept the same protocol used for Google servers
2023-05-29 18:19:01 +02:00
Nicola Murino
6e4b348ccf add Oauth2 support
fixes #129
2023-05-28 14:31:04 +02:00
912797c782
#126: sync upstream changes to net/smtp
Related: https://github.com/golang/go/issues/58141
Resolves #126
2023-04-12 09:54:26 +02:00
13d0add21c
#121: Remove defer from for loops
Fixes #121. `defer` in for loops can possibly lead to leaks.

The whole handling including the defer are now moved into anonymous functions outside the for loop and are called form the loop instead. This way the defer is handle when the inline function finishes
2023-03-15 18:42:25 +01:00
6633591b51
Implement Logger interface
As stated in https://github.com/wneessen/go-mail/pull/102#issuecomment-1411956040 it would be beneficial if, instead of forcing the Go stdlib logger on the user to provide a simple interface and use that for logging purposes.

This PR implements this simple log.Logger interface as well as a standard logger that satisfies this interface. If no custom logger is provided, the Stdlog will be used (which makes use of the Go stdlib again).

Accordingly, a `Client.WithLogger` and `Client.SetLogger` have been implemented. Same applies for the smtp counterparts.
2023-02-03 10:19:26 +01:00
e36511e90e
Fix tests to not log authentication data
We don't want to expose SMTP authentication details in tests, therefore the tests have been adjusted a bit
2023-01-14 13:05:04 +01:00
34b432a985
Implement debug logging in SMTP client
Resolves #101.

Since we now have full control over the SMTP client we can also access the message input and output.

This PR introduces a new debug logging feature. Via the `Client.WithDebugLog` the user can enable this feature. It will then make use of the new `smtp/Client.SetDebugLog` method. Once the flag is set to true, the SMTP client will start logging incoming and outgoing messages to os.Stderr.

Log directions will be output accordingly
2023-01-14 12:47:51 +01:00
7cb34856a3
Adjusting license headers and including original LICENSE file from the Go project into the smtp/ directory as suggested in https://github.com/wneessen/go-mail/issues/97#issuecomment-1381046444 2023-01-13 16:54:55 +01:00
820d1c25d8
Fork net/smpt into go-mail
Implemented negative check for AuthLogin Auth method
2023-01-11 20:35:22 +01:00