public void TestPublishFilesImpersonate() { var project = DebugProject.OpenProject(@"Python.VS.TestData\HelloWorld.sln"); try { string subDir = Guid.NewGuid().ToString(); project.Properties.Item("PublishUrl").Value = Path.Combine(TestSharePrivate, subDir); string dir = Path.Combine(TestSharePrivate, subDir); var app = new VisualStudioApp(VsIdeTestHostContext.Dte); app.OpenSolutionExplorer(); var window = app.SolutionExplorerTreeView; // find Program.py, send copy & paste, verify copy of file is there var programPy = window.FindItem("Solution 'HelloWorld' (1 project)", "HelloWorld"); programPy.SetFocus(); ThreadPool.QueueUserWorkItem(x => VsIdeTestHostContext.Dte.ExecuteCommand("Build.PublishSelection")); var creds = new CredentialsDialog(app.WaitForDialog()); creds.UserName = PrivateShareUser; creds.Password = PrivateSharePassword; creds.Ok(); System.Threading.Thread.Sleep(2000); using (var impHelper = new ImpersonationHelper(new System.Net.NetworkCredential(PrivateShareUser.Split('\\')[1], PrivateSharePassword, PrivateShareUser.Split('\\')[0]))) { for (int i = 0; i < 10 && !Directory.Exists(dir); i++) { System.Threading.Thread.Sleep(1000); } var files = Directory.GetFiles(dir); Assert.AreEqual(files.Length, 1); Assert.AreEqual(Path.GetFileName(files[0]), "Program.py"); Directory.Delete(dir, true); } } finally { project.Properties.Item("PublishUrl").Value = ""; } }
public void TestPublishFilesImpersonateWrongCredentials() { var project = DebugProject.OpenProject(@"Python.VS.TestData\HelloWorld.sln"); try { string subDir = Guid.NewGuid().ToString(); project.Properties.Item("PublishUrl").Value = Path.Combine(TestSharePrivate, subDir); string dir = Path.Combine(TestSharePrivate, subDir); var app = new VisualStudioApp(VsIdeTestHostContext.Dte); app.OpenSolutionExplorer(); var window = app.SolutionExplorerTreeView; // find Program.py, send copy & paste, verify copy of file is there var programPy = window.FindItem("Solution 'HelloWorld' (1 project)", "HelloWorld"); programPy.SetFocus(); ThreadPool.QueueUserWorkItem(x => VsIdeTestHostContext.Dte.ExecuteCommand("Build.PublishSelection")); var creds = new CredentialsDialog(app.WaitForDialog()); creds.UserName = PrivateShareUser; creds.Password = PrivateSharePasswordIncorrect; creds.Ok(); System.Threading.Thread.Sleep(2000); var statusBar = (IVsStatusbar)VsIdeTestHostContext.ServiceProvider.GetService(typeof(SVsStatusbar)); string text; ErrorHandler.ThrowOnFailure(statusBar.GetText(out text)); const string expected = "Publish failed: Incorrect user name or password: "******"Expected '{0}', got '{1}'", expected, text); } finally { project.Properties.Item("PublishUrl").Value = ""; } }