Skip to content

Added support for title in get-Credential, and message set to optional.#1904

Merged
lzybkr merged 14 commits intoPowerShell:masterfrom
McAndersDK:patch-1
Sep 16, 2016
Merged

Added support for title in get-Credential, and message set to optional.#1904
lzybkr merged 14 commits intoPowerShell:masterfrom
McAndersDK:patch-1

Conversation

@McAndersDK
Copy link
Copy Markdown
Contributor

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

Added possibility to add title to the credential prompt window.
Added possibility to only supply username without giving a message.
@msftclas
Copy link
Copy Markdown

Hi @McAndersDK, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!

In order for us to evaluate and accept your PR, we ask that you sign a contribution license agreement. It's all electronic and will take just minutes. I promise there's no faxing. https://cla.microsoft.com.

TTYL, MSBOT;

@msftclas
Copy link
Copy Markdown

@McAndersDK, Thanks for signing the contribution license agreement so quickly! Actual humans will now validate the agreement and then evaluate the PR.

Thanks, MSBOT;

Missing ) and changed or to ||
@McAndersDK McAndersDK changed the title Update CredentialCommands.cs Added support for title in get-Credential, and message set to optional. Aug 18, 2016
@daxian-dbw daxian-dbw added the WG-Cmdlets general cmdlet issues label Aug 18, 2016
@lzybkr
Copy link
Copy Markdown
Contributor

lzybkr commented Aug 18, 2016

Your code does not compile. Please fix before we review this PR.

@McAndersDK
Copy link
Copy Markdown
Contributor Author

it build on my machine?
I cant see in the build details what is wrong? @lzybkr

@vors
Copy link
Copy Markdown
Collaborator

vors commented Aug 19, 2016

@McAndersDK you can see logs from the build server by clicking on the build status in your PR (red cross)

For example, here
https://ci.appveyor.com/project/PowerShell/powershell/build/6.0.0-alpha.9-36#L276

The compilation error message

C:\projects\powershell\src\Microsoft.PowerShell.Security\security\CredentialCommands.cs(122,83): error CS1061: 'GetCredentialCommand' does not contain a definition for 'Username' and no extension method 'Username' accepting a 
first argument of type 'GetCre
dentialCommand' could be found (are you missing a using directive or an assembly reference?)
C:\projects\powershell\src\Microsoft.PowerShell.Security\security\CredentialCommands.cs(124,40): error CS1061: 'GetCredentialCommand' does not contain a definition for 'Username' and no extension method 'Username' accepting a 
first argument of type 'GetCre
dentialCommand' could be found (are you missing a using directive or an assembly reference?)
C:\projects\powershell\src\Microsoft.PowerShell.Security\security\CredentialCommands.cs(129,67): error CS0103: The name 'caption' does not exist in the current context

Fixed wrong caps in username
@McAndersDK
Copy link
Copy Markdown
Contributor Author

Thanks @vors for some reason appveyor only showed the first 200 lines here.
I had to download the log to see the complete output.

Fix Scoping on caption.
@vors
Copy link
Copy Markdown
Collaborator

vors commented Aug 19, 2016

@McAndersDK it should not be the case in general, but could be a one-off problem with AppVeyor.

@lzybkr
Copy link
Copy Markdown
Contributor

lzybkr commented Aug 19, 2016

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 Get-Credential is a bit harder to test than some cmdlets, but...

@JamesWTruher has ported our Get-Credential to Pester, hopefully we'll see a PR from him today.

After that PR is accepted, I'll ask you to add some tests for your new functionality.

else {
caption = UtilsStrings.PromptForCredential_DefaultCaption;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if only -Title is specified, the code path seems cannot get to this.Host.UI.PromptForCredential

@McAndersDK
Copy link
Copy Markdown
Contributor Author

@daxian-dbw Thanks for input, I will make sure this will go into the PR with the test for the changes.

@jpsnover
Copy link
Copy Markdown
Contributor

We should have done this a long time ago. Thanks!
542

protected override void BeginProcessing()
{
if (!string.IsNullOrEmpty(this.Message))
string caption;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@lzybkr
Copy link
Copy Markdown
Contributor

lzybkr commented Aug 22, 2016

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).

@McAndersDK
Copy link
Copy Markdown
Contributor Author

yeah I will. Should I create a new PR with both file in it or just create a new one with the test separate?

@lzybkr
Copy link
Copy Markdown
Contributor

lzybkr commented Aug 25, 2016

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 expect like test.

@McAndersDK
Copy link
Copy Markdown
Contributor Author

Yeah i need to add some more tests with the streams.

Please give me some days to add them in.

@lzybkr
Copy link
Copy Markdown
Contributor

lzybkr commented Aug 25, 2016

Awesome - thanks for being responsive to our feedback.

Also added test for empty username.
@McAndersDK
Copy link
Copy Markdown
Contributor Author

Travis just timed out?
How do we rerun travis? except to do a push?

$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"
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@McAndersDK
Copy link
Copy Markdown
Contributor Author

@lzybkr That did not work. we need to test the invoke for credential object?, if none throw?
but why change this? it worked before? atleast the test did not fail, I have not tryed the other way around

@lzybkr
Copy link
Copy Markdown
Contributor

lzybkr commented Sep 1, 2016

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.

@lzybkr lzybkr merged commit 5738f37 into PowerShell:master Sep 16, 2016
@lzybkr lzybkr added this to the 6.0.0-alpha.11 milestone Sep 16, 2016
@iSazonov
Copy link
Copy Markdown
Collaborator

Set "message" to optional is not best practice, from https://msdn.microsoft.com/en-us/library/dd878348%28v=vs.85%29.aspx :
•Each parameter set must have at least one unique parameter. If possible, make this parameter a mandatory parameter.

Set both "message" and "title" to optional open a way to "anonymous" request of credential. That is bad. This provokes writing bad code.

@lzybkr
Copy link
Copy Markdown
Contributor

lzybkr commented Sep 19, 2016

Before this change, you could call Get-Credential with no parameters, so I thought the change was necessary to keep that behavior. Maybe it wasn't.

The current experience (after this PR) with Get-Credential and no additional parameters is broken - it prompts twice (see #2306). So maybe we need to revert the change on the Message parameter.

@iSazonov
Copy link
Copy Markdown
Collaborator

iSazonov commented Sep 22, 2016

Before this change, you could call Get-Credential with no parameters

Get-Credential with no parameters set message to default "Enter you credentials". Message is in another parameter set and that is another experience.
So I think we should follow the msdn recommendations above mentioned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

WG-Cmdlets general cmdlet issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants