Added support for title in get-Credential, and message set to optional.#1904
Added support for title in get-Credential, and message set to optional.#1904lzybkr merged 14 commits intoPowerShell:masterfrom McAndersDK:patch-1
Conversation
Added possibility to add title to the credential prompt window. Added possibility to only supply username without giving a message.
|
Hi @McAndersDK, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution! TTYL, MSBOT; |
|
@McAndersDK, Thanks for signing the contribution license agreement so quickly! Actual humans will now validate the agreement and then evaluate the PR. |
Missing ) and changed or to ||
|
Your code does not compile. Please fix before we review this PR. |
|
it build on my machine? |
|
@McAndersDK you can see logs from the build server by clicking on the build status in your PR (red cross) For example, here The compilation error message |
Fixed wrong caps in username
|
Thanks @vors for some reason appveyor only showed the first 200 lines here. |
Fix Scoping on caption.
|
@McAndersDK it should not be the case in general, but could be a one-off problem with AppVeyor. |
|
Thanks for fixing the build errors. Before accepting this PR, we'll need some tests. I was going to accept this PR without tests because @JamesWTruher has ported our After that PR is accepted, I'll ask you to add some tests for your new functionality. |
| else { | ||
| caption = UtilsStrings.PromptForCredential_DefaultCaption; | ||
| } | ||
|
|
There was a problem hiding this comment.
if only -Title is specified, the code path seems cannot get to this.Host.UI.PromptForCredential
|
@daxian-dbw Thanks for input, I will make sure this will go into the PR with the test for the changes. |
| protected override void BeginProcessing() | ||
| { | ||
| if (!string.IsNullOrEmpty(this.Message)) | ||
| string caption; |
There was a problem hiding this comment.
Looks like this code based uses a space between the if keyword and the opening paren. To be consistent with the rest of the code, you should add the space.
|
Can you add a test to test\powershell\Modules\Microsoft.PowerShell.Security\GetCredential.Tests.ps1 and fix the formatting as @rkeithhill suggested (though we'd fix that with a tool later anyway). |
|
yeah I will. Should I create a new PR with both file in it or just create a new one with the test separate? |
|
I'm fine with opening another issue to make the host ensure the prompt is unambiguously coming from PowerShell. @McAndersDK - I think this is ready merge unless you're adding a test to verify the title is passed correctly to the host. Such a test would be nice but not required as it's still insufficient in validating the title gets displayed, the only way to validate that would require an |
|
Yeah i need to add some more tests with the streams. Please give me some days to add them in. |
|
Awesome - thanks for being responsive to our feedback. |
Also added test for empty username.
|
Travis just timed out? |
| $netcred.Password | Should be "this is a test" | ||
| # Resx file only include english language, this should be changed to reflect Current Culture if title change by language. | ||
| $th.ui.Streams.Prompt[-1] | should be "Credential:Windows PowerShell credential request.:Foo" | ||
| } |
There was a problem hiding this comment.
We do run tests on localized builds of Windows, so this test would fail on those builds.
In some tests, if the message is important, we'll actually load the resource to get the text - that works on localized builds as well. We might not have any examples of that pattern in out pester tests though.
|
@lzybkr That did not work. we need to test the invoke for credential object?, if none throw? |
|
The problem with not using a script block is that if it doesn't throw, the test passes but should fail. Adding the change I suggested exposed the fact that no exception was thrown, so failing the test is correct. I think this test might not make sense. Looking at the console host - we prompt for the username if it's null or empty. Other hosts might do that or throw, but we don't really control other hosts. I'd say just remove this test. |
Change test to work on any culture
|
Set "message" to optional is not best practice, from https://msdn.microsoft.com/en-us/library/dd878348%28v=vs.85%29.aspx : Set both "message" and "title" to optional open a way to "anonymous" request of credential. That is bad. This provokes writing bad code. |
|
Before this change, you could call The current experience (after this PR) with |
Get-Credential with no parameters set message to default "Enter you credentials". Message is in another parameter set and that is another experience. |

Added possibility to add title to the credential prompt window.
Added possibility to only supply username without giving a message.