GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Enable Send-MailMessage on CoreCLR by jeffbi · Pull Request #3869 · PowerShell/PowerShell ConversationContributes to the completion of #2123 and #2240. Now that the requisite components are implemented in corefx, compilation of the Send-MailMessage cmdlet has been enabled. This PR includes a test script that allows the cmdlet to be tested against a working local SMTP server, but only on Linux and under specific conditions. A separate issue will be opened for improving test coverage and including additional platforms.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Collaborator
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Collaborator
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was an error while loading. Please reload this page.
|
jeffbi The tests is skipped on both CI - I believe we should remove its at all. Maybe we can merge without tests if the cmdlet passes manual tests locally. Related https://github.com/tedious/DovecotTesting/blob/master/resources/Scripts/Provision.sh#L28 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Ilya (@iSazonov) I would guess that the test is being marked as Pending due to the machine name not matching the one specified in the test script. The test does require some pretty specific configuration. I have been able to manually send mail to myself on Linux with the cmdlet. I don't have an SMTP server for my Windows box to test with. James Truher (@JamesWTruher), Steve Lee (@SteveL-MSFT), do you have thoughts on this? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Ilya (@iSazonov) So you know, when the CI checks failed, the error was pointing to |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I did not saw problem with test/powershell/engine/Remoting/SSHRemotingAPI.Tests.ps1 - I saw only failed DefaultCommands.Tests.ps1 that is expected. I believe it is very expensive install a mail server on CI VMs. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| It @PesterArgs { | ||
| $body = "Greetings from me." | ||
| $subject = "Test message" |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
shouldn't you also validate the subject?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
|
|
||
| $user = "jeff" | ||
| $inPassword = Select-String "^${user}:" /etc/passwd -ErrorAction SilentlyContinue |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
seems like user 'jeff' will almost always not exist so this test is always pending?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Changed to current user
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| return | ||
| } | ||
|
|
||
| $domain = "Chinstrap" |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
similar to above, this will almost always fail and thus be Pending, seems like if mail is installed you should be able to rely on root@computername?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
What it actually should be is current_user$computername. While the test takes steps to avoid deleting an existing mailbox, it still made me nervous, so I left those hard-coded names in, partially to call attention to the situation.
To use root@computername, the test would need to be running as root in order to access root's mailbox. Is that what the CI environment is?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
current user is probably correct
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Changed to current user on current machine
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| $PesterArgs["Name"] += " (pending: mailbox not empty)" | ||
| return | ||
| } | ||
| $alreadyHasMail = $false |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this, you set $alreadyHasMail to $true above and then it's always set to $false here
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This is one of those steps to avoid deleting an existing mailbox. In the AfterAll block, the $alreadyHasMail variable is checked before deleting the mailbox. The early return at line 104 keeps that set to $true if the mailbox is not empty.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| $PesterArgs = @{ Name = "Can send mail message from user to self"} | ||
| $alreadyHasMail = $true | ||
|
|
||
| if (-not $IsLinux) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
do we need to check if a smtp server is installed or is that always the case on Linux/Mac?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
On Linux, an SMTP server is not installed by default, since there are at least two to choose from, perhaps more.
I'll have to look into how to detect from PowerShell if anyone's listening on port 25.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
the important check to be added is to be sure that an SMTP server is installed and running on the system
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| return | ||
| } | ||
|
|
||
| $user = "jeff" |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
make this testuser please. I'm using this account name in another upcoming PR
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Is testuser the username the CI tests will run as?
The permission bits on a user's mailbox are rw------- so a test might be able to send mail to another user, but it won't be able to read the mailbox to verify that the mail was sent.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
We could use an environment variables:
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| return | ||
| } | ||
| $alreadyHasMail = $false | ||
| Set-Content -Value "" -Path $mailBox -Force -ErrorAction SilentlyContinue |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
do permissions need to be set on this mailbox? I seem to remember that the permissions for mailbox files are special
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
They don't seem to be special, just rw-------
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| It @PesterArgs { | ||
| $body = "Greetings from me." | ||
| $subject = "Test message" | ||
| Send-MailMessage -To $address -From $address -Subject $subject -Body $body -SmtpServer 127.0.0.1 |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
one more check needed above to be sure that there's an smtp server running on localhost
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Fixed
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| AfterAll { | ||
| if (-not $alreadyHasMail) | ||
| { | ||
| Set-Content -Value "" -Path $mailBox -Force -ErrorAction SilentlyContinue |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
should this just be delete the file?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Unless we're running as root or as a member of the mail group, we can write to the file but we cannot delete it.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
* Add check for SMTP server * Send mail to/from currently logged-in user on currently-named machine * Do not try to clear/create the mailbox before the test * Add validation of Subject
|
Can we use .Net Fake SMTP Server ? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| @@ -0,0 +1,147 @@ | |||
| Describe "Basic Send-MailMessage tests" -Tags CI { | |||
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Does this test require Administrator on Windows or root on all non-Windows platforms?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Currently this test runs only on Linux. So long as the sender/receiver of the email is the currently logged-in user, running as root is not required.
I've been looking into ways to make tests more cross-platform, using a suggestion from Ilya (@iSazonov), but it's going to take some effort.
My personal feeling is that I'd like to create a separate issue for testing Send-MailMessage and have this PR be taken as-is, but I don't know if that works with testing policies.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
jeffbi create a separate issue for that and link it to this
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Steve Lee (@SteveL-MSFT) James Truher (@JamesWTruher) Have all of you concerns been addressed? Do you have any additional comments? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
James Truher (@JamesWTruher) Do you have any additional comments? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
LGTM |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
* Enable Send-MailMessage for PowerShell Core * Update cmdlet entry in DefaultCommands.Tests.ps1 * Changes per code review: * Add check for SMTP server * Send mail to/from currently logged-in user on currently-named machine * Do not try to clear/create the mailbox before the test * Add validation of Subject
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.