Skip to content

Commit

Permalink
Allow blank password with username option (resolves Topshelf#285);
Browse files Browse the repository at this point in the history
  * Whilst ensuring specified when username is.
  • Loading branch information
ianbattersby authored and phatboyg committed May 3, 2016
1 parent b050d7c commit 86fc9f0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions src/Topshelf.Tests/CommandLine_Specs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,34 @@ public void Extensible_the_command_line_should_be_yet_again()
Assert.AreEqual("11", volumeLevel);
}

[Test]
public void Should_require_password_option_when_specifying_username()
{
Assert.Throws<Topshelf.HostConfigurationException>(() =>
{
Host host = HostFactory.New(x =>
{
x.Service<MyService>();
x.ApplyCommandLine("install -username \"Joe\"");
});
});
}

[Test]
public void Will_allow_blank_password_when_specifying_username()
{
Host host = HostFactory.New(x =>
{
x.Service<MyService>();
x.ApplyCommandLine("install -username \"Joe\" -password \"\"");
});

Assert.IsInstanceOf<InstallHost>(host);
var installHost = (InstallHost)host;
Assert.AreEqual("Joe", installHost.InstallSettings.Username);
Assert.AreEqual("", installHost.InstallSettings.Password);
}

class MyService : ServiceControl
{
public bool Start(HostControl hostControl)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public IEnumerable<ValidateResult> Validate()
{
if (string.IsNullOrEmpty(Username))
yield return this.Failure("Username", "must be specified for a User account type");
if (string.IsNullOrEmpty(Password))
if (Password == null)
yield return this.Failure("Password", "must be specified for a User account type");
}
}
Expand Down

0 comments on commit 86fc9f0

Please sign in to comment.