diff --git a/product/dropkick.tests/Tasks/WinService/PasswordPromptSpecs.cs b/product/dropkick.tests/Tasks/WinService/PasswordPromptSpecs.cs index 48236a3b..f1156d55 100644 --- a/product/dropkick.tests/Tasks/WinService/PasswordPromptSpecs.cs +++ b/product/dropkick.tests/Tasks/WinService/PasswordPromptSpecs.cs @@ -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"); diff --git a/product/dropkick/Tasks/Topshelf/LocalTopshelfTask.cs b/product/dropkick/Tasks/Topshelf/LocalTopshelfTask.cs index 855ed731..c2a011d4 100644 --- a/product/dropkick/Tasks/Topshelf/LocalTopshelfTask.cs +++ b/product/dropkick/Tasks/Topshelf/LocalTopshelfTask.cs @@ -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(); + } + } } \ No newline at end of file diff --git a/product/dropkick/Tasks/WinService/WinServiceCreateTask.cs b/product/dropkick/Tasks/WinService/WinServiceCreateTask.cs index 448a2c79..ceedb5d2 100644 --- a/product/dropkick/Tasks/WinService/WinServiceCreateTask.cs +++ b/product/dropkick/Tasks/WinService/WinServiceCreateTask.cs @@ -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(); } } } \ No newline at end of file diff --git a/product/dropkick/WindowsAuthentication.cs b/product/dropkick/WindowsAuthentication.cs new file mode 100644 index 00000000..07458336 --- /dev/null +++ b/product/dropkick/WindowsAuthentication.cs @@ -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; + } + } +} diff --git a/product/dropkick/dropkick.csproj b/product/dropkick/dropkick.csproj index 1075831d..806498af 100644 --- a/product/dropkick/dropkick.csproj +++ b/product/dropkick/dropkick.csproj @@ -312,6 +312,7 @@ +