Skip to content

Commit

Permalink
TopShelf task should not prompt for password when using a built-in ac…
Browse files Browse the repository at this point in the history
…count
  • Loading branch information
laazyj committed Aug 2, 2011
1 parent e32316c commit 0ae1889
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ public void It_should_not_prompt_for_password()
_result.Results.Where(x => x.Message.Contains("prompt for a password")).Count().ShouldBeEqualTo(0);
}

public void It_should_prompt_for_password_if_not_supplied()
{

}

public override void Context()
{
_task = new WinServiceCreateTask("localhost", "test");
Expand Down
87 changes: 46 additions & 41 deletions product/dropkick/Tasks/Topshelf/LocalTopshelfTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,52 +17,57 @@ namespace dropkick.Tasks.Topshelf
using FileSystem;
using Prompting;

public class LocalTopshelfTask :
BaseTask
{
readonly LocalCommandLineTask _task;
readonly PromptService _prompt = new ConsolePromptService();
public class LocalTopshelfTask :
BaseTask
{
private readonly LocalCommandLineTask _task;
private readonly PromptService _prompt = new ConsolePromptService();

public LocalTopshelfTask(string exeName, string location, string instanceName, string username, string password)
{
string args = string.IsNullOrEmpty(instanceName)
? ""
: " /instance:" + instanceName;
public LocalTopshelfTask(string exeName, string location, string instanceName, string username, string password)
{
string args = string.IsNullOrEmpty(instanceName)
? ""
: " /instance:" + instanceName;

if (username != null && password != null)
{
var user = username;
var pass = password;
if (username.ShouldPrompt())
user = _prompt.Prompt("Win Service '{0}' UserName".FormatWith(exeName));
if (password.ShouldPrompt())
pass = _prompt.Prompt("Win Service '{0}' For User '{1}' Password".FormatWith(exeName, username));
if (username != null && password != null)
{
var user = username;
var pass = password;
if (username.ShouldPrompt())
user = _prompt.Prompt("Win Service '{0}' UserName".FormatWith(exeName));
if (shouldPromptForPassword(username, password))
pass = _prompt.Prompt("Win Service '{0}' For User '{1}' Password".FormatWith(exeName, username));

args += " /username:{0} /password:{1}".FormatWith(user, pass);
}
args += " /username:{0} /password:{1}".FormatWith(user, pass);
}

_task = new LocalCommandLineTask(new DotNetPath(), exeName)
{
Args = "install " + args,
ExecutableIsLocatedAt = location,
WorkingDirectory = location
};
}
_task = new LocalCommandLineTask(new DotNetPath(), exeName)
{
Args = "install " + args,
ExecutableIsLocatedAt = location,
WorkingDirectory = location
};
}

public override string Name
{
get { return "[topshelf] local Installing"; }
}
public override string Name
{
get { return "[topshelf] local Installing"; }
}

public override DeploymentResult VerifyCanRun()
{
return _task.VerifyCanRun();
}
public override DeploymentResult VerifyCanRun()
{
return _task.VerifyCanRun();
}

public override DeploymentResult Execute()
{
Logging.Coarse("[topshelf] Installing a local Topshelf service.");
return _task.Execute();
}
}
public override DeploymentResult Execute()
{
Logging.Coarse("[topshelf] Installing a local Topshelf service.");
return _task.Execute();
}

private bool shouldPromptForPassword(string username, string password)
{
return !WindowsAuthentication.IsBuiltInUsername(username) && password.ShouldPrompt();
}
}
}
8 changes: 1 addition & 7 deletions product/dropkick/Tasks/WinService/WinServiceCreateTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,7 @@ public override DeploymentResult Execute()

private bool shouldPromptForPassword()
{
return !isBuiltInUsername(UserName) && Password.ShouldPrompt();
}

private bool isBuiltInUsername(string userName)
{
const string ntAuthorityPrefix = @"NT AUTHORITY\";
return String.Compare(ntAuthorityPrefix, 0, userName, 0, ntAuthorityPrefix.Length, true) == 0;
return !WindowsAuthentication.IsBuiltInUsername(UserName) && Password.ShouldPrompt();
}
}
}
12 changes: 12 additions & 0 deletions product/dropkick/WindowsAuthentication.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace dropkick
{
public static class WindowsAuthentication
{
public static bool IsBuiltInUsername(string username)
{
const string ntAuthorityPrefix = @"NT AUTHORITY\";

return string.Compare(ntAuthorityPrefix, 0, username, 0, ntAuthorityPrefix.Length, true) == 0;
}
}
}
1 change: 1 addition & 0 deletions product/dropkick/dropkick.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@
<Compile Include="Engine\Runner.cs" />
<Compile Include="Configuration\Dsl\ProtoTask.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="WindowsAuthentication.cs" />
<Compile Include="Wmi\ErrorControl.cs" />
<Compile Include="Wmi\ProcessReturnCode.cs" />
<Compile Include="Wmi\ServiceReturnCode.cs" />
Expand Down

0 comments on commit 0ae1889

Please sign in to comment.