public async Task WhenConnectingByUrlWithUsernameAndCredentialsExist_ThenConnectionIsMadeWithUsernameFromUrl() { var settings = InstanceConnectionSettings.CreateNew("project", "instance-1"); settings.RdpUsername.Value = "existinguser"; settings.RdpPassword.Value = SecureStringExtensions.FromClearText("password"); var settingsService = this.serviceRegistry.AddMock <IConnectionSettingsService>(); settingsService.Setup(s => s.GetConnectionSettings( It.IsAny <IProjectModelNode>())) .Returns( settings.ToPersistentSettingsCollection(s => Assert.Fail("should not be called"))); var vmNode = new Mock <IProjectModelInstanceNode>(); vmNode.SetupGet(n => n.Instance) .Returns(new InstanceLocator("project-1", "zone-1", "instance-1")); this.serviceRegistry.AddMock <ICredentialPrompt>() .Setup(p => p.ShowCredentialsPromptAsync( It.IsAny <IWin32Window>(), It.IsAny <InstanceLocator>(), It.IsAny <ConnectionSettingsBase>(), It.IsAny <bool>())); this.serviceRegistry.AddMock <IProjectModelService>() .Setup(p => p.GetNodeAsync( It.IsAny <ResourceLocator>(), It.IsAny <CancellationToken>())) .ReturnsAsync(vmNode.Object); var remoteDesktopService = new Mock <IRemoteDesktopSessionBroker>(); remoteDesktopService.Setup(s => s.Connect( It.IsAny <InstanceLocator>(), "localhost", It.IsAny <ushort>(), It.IsAny <InstanceConnectionSettings>())).Returns <IRemoteDesktopSession>(null); this.serviceRegistry.AddSingleton <IRemoteDesktopSessionBroker>(remoteDesktopService.Object); var service = new RdpConnectionService(this.serviceRegistry); await service.ActivateOrConnectInstanceAsync( IapRdpUrl.FromString("iap-rdp:///project/us-central-1/instance-1?username=john%20doe")); remoteDesktopService.Verify(s => s.Connect( It.IsAny <InstanceLocator>(), "localhost", It.IsAny <ushort>(), It.Is <InstanceConnectionSettings>(i => i.RdpUsername.StringValue == "john doe")), Times.Once); settingsService.Verify(s => s.GetConnectionSettings( It.IsAny <IProjectModelNode>()), Times.Once); }
public async Task ActivateOrConnectInstanceWithCredentialPromptAsync( IWin32Window owner, IapRdpUrl url) { if (this.remoteDesktopService.TryActivate(url.Instance)) { // RDP session was active, nothing left to do. return; } int selectedOption = this.taskDialog.ShowOptionsTaskDialog( owner, UnsafeNativeMethods.TD_INFORMATION_ICON, "Credentials", $"Would you like to generate credentials for {url.Instance.InstanceName} first?", null, null, new[] { "Yes, generate new credentials", // Same as pressing 'OK' "Enter existing credentials" // Same as pressing 'Cancel' }, null, out bool donotAskAgain); if (selectedOption == 0) { // Generate new credentials. var credentials = await this.credentialsService.GenerateCredentialsAsync( owner, url.Instance, MakeNullIfEmpty(url.Settings.Username)); if (credentials != null) { // Amend settings. url.Settings.Domain = credentials.Domain; url.Settings.Username = credentials.UserName; url.Settings.Password = credentials.SecurePassword; } else { // Aborted. return; } } else if (selectedOption == 1) { // Cancel - just continue connecting. } await ConnectInstanceAsync(url.Instance, url.Settings); }
public async Task ActivateOrConnectInstanceWithCredentialPromptAsync( IWin32Window owner, IapRdpUrl url) { if (this.remoteDesktopService.TryActivate(url.Instance)) { // RDP session was active, nothing left to do. return; } // Create an ephemeral settings editor. We do not persist // any changes. var settingsEditor = new ConnectionSettingsEditor( url.Settings, _ => { }, null); int selectedOption = this.taskDialog.ShowOptionsTaskDialog( owner, UnsafeNativeMethods.TD_INFORMATION_ICON, "Credentials", $"Would you like to generate credentials for {url.Instance.Name} first?", null, null, new[] { "Yes, generate new credentials", // Same as pressing 'OK' "Enter existing credentials" // Same as pressing 'Cancel' }, null, out bool donotAskAgain); if (selectedOption == 0) { // Generate new credentials using the ephemeral settings editor. await this.credentialsService.GenerateCredentialsAsync( owner, url.Instance, settingsEditor, MakeNullIfEmpty(url.Settings.Username)) .ConfigureAwait(true); } else if (selectedOption == 1) { // Cancel - just continue connecting. } await ConnectInstanceAsync( url.Instance, settingsEditor.CreateConnectionSettings(url.Instance.Name)) .ConfigureAwait(true); }
public void WhenQueryStringContainsValidSettings_ThenSettingsUseDecodedValues() { var url = IapRdpUrl.FromString("iap-rdp:///my-project/us-central1-a/my-instance?" + "ConnectionBar=1&DesktopSize=1&AuthenticationLevel=0&ColorDepth=2&" + "AudioMode=2&RedirectClipboard=0"); var settings = url.Settings; Assert.AreEqual(RdpConnectionBarState.Pinned, settings.ConnectionBar); Assert.AreEqual(RdpDesktopSize.ScreenSize, settings.DesktopSize); Assert.AreEqual(RdpAuthenticationLevel.AttemptServerAuthentication, settings.AuthenticationLevel); Assert.AreEqual(RdpColorDepth.DeepColor, settings.ColorDepth); Assert.AreEqual(RdpAudioMode.DoNotPlay, settings.AudioMode); Assert.AreEqual(RdpRedirectClipboard.Disabled, settings.RedirectClipboard); }
public async Task WhenConnectingByUrlWithUsernameAndCredentialsExist_ThenConnectionIsMadeWithExistingCredentials() { var settings = new VmInstanceConnectionSettings() { Username = "******", Password = SecureStringExtensions.FromClearText("password") }; var vmNode = new Mock <IProjectExplorerVmInstanceNode>(); vmNode.SetupGet(n => n.SettingsEditor) .Returns(new ConnectionSettingsEditor( settings, _ => { }, null)); vmNode.SetupGet(n => n.Reference) .Returns(new InstanceLocator("project-1", "zone-1", "instance-1")); this.serviceRegistry.AddMock <ICredentialPrompt>() .Setup(p => p.ShowCredentialsPromptAsync( It.IsAny <IWin32Window>(), It.IsAny <InstanceLocator>(), It.IsAny <ConnectionSettingsEditor>(), It.IsAny <bool>())); this.serviceRegistry.AddMock <IProjectExplorer>() .Setup(p => p.TryFindNode( It.IsAny <InstanceLocator>())) .Returns(vmNode.Object); var remoteDesktopService = new Mock <IRemoteDesktopService>(); remoteDesktopService.Setup(s => s.Connect( It.IsAny <InstanceLocator>(), "localhost", It.IsAny <ushort>(), It.IsAny <VmInstanceConnectionSettings>())).Returns <IRemoteDesktopSession>(null); this.serviceRegistry.AddSingleton <IRemoteDesktopService>(remoteDesktopService.Object); var service = new IapRdpConnectionService(this.serviceRegistry); await service.ActivateOrConnectInstanceAsync( IapRdpUrl.FromString("iap-rdp:///project/us-central-1/instance?username=john%20doe")); remoteDesktopService.Verify(s => s.Connect( It.IsAny <InstanceLocator>(), "localhost", It.IsAny <ushort>(), It.Is <VmInstanceConnectionSettings>(i => i.Username == "existinguser")), Times.Once); }
public void WhenQueryStringContainsNonsense_ThenSettingsUsesDefaults() { var url = IapRdpUrl.FromString("iap-rdp:///my-project/us-central1-a/my-instance?a=b&user=wrongcase&_"); var settings = url.Settings; Assert.IsNull(settings.Username); Assert.IsNull(settings.Password); Assert.IsNull(settings.Domain); Assert.AreEqual(RdpConnectionBarState._Default, settings.ConnectionBar); Assert.AreEqual(RdpDesktopSize._Default, settings.DesktopSize); Assert.AreEqual(RdpAuthenticationLevel._Default, settings.AuthenticationLevel); Assert.AreEqual(RdpColorDepth._Default, settings.ColorDepth); Assert.AreEqual(RdpAudioMode._Default, settings.AudioMode); Assert.AreEqual(RdpRedirectClipboard._Default, settings.RedirectClipboard); }
public void WhenSettingsContainsEscapableChars_ThenToStringEscapesThem() { var url = new IapRdpUrl( new VmInstanceReference("project-1", "us-central1-a", "instance-1"), new VmInstanceConnectionSettings() { Username = "******", Domain = "\"?\"" }); Assert.AreEqual( "iap-rdp:///project-1/us-central1-a/instance-1?" + "Username=Tom+%26+Jerry%3f&Domain=%22%3f%22&" + "ConnectionBar=0&DesktopSize=2&AuthenticationLevel=3&ColorDepth=1&AudioMode=0&RedirectClipboard=1", url.ToString()); }
public void WhenQueryStringMissing_ThenSettingsUsesDefaults() { var url = IapRdpUrl.FromString("iap-rdp:///my-project/us-central1-a/my-instance"); var settings = VmInstanceConnectionSettings.FromUrl(url); Assert.IsNull(settings.Username.Value); Assert.IsNull(settings.Password.Value); Assert.IsNull(settings.Domain.Value); Assert.AreEqual(RdpConnectionBarState._Default, settings.ConnectionBar.Value); Assert.AreEqual(RdpDesktopSize._Default, settings.DesktopSize.Value); Assert.AreEqual(RdpAuthenticationLevel._Default, settings.AuthenticationLevel.Value); Assert.AreEqual(RdpColorDepth._Default, settings.ColorDepth.Value); Assert.AreEqual(RdpAudioMode._Default, settings.AudioMode.Value); Assert.AreEqual(RdpRedirectClipboard._Default, settings.RedirectClipboard.Value); Assert.AreEqual(RdpCredentialGenerationBehavior._Default, settings.CredentialGenerationBehavior.Value); }
public void WhenQueryStringContainsValidSettings_ThenSettingsUseDecodedValues() { var url = IapRdpUrl.FromString("iap-rdp:///my-project/us-central1-a/my-instance?" + "ConnectionBar=1&DesktopSize=1&AuthenticationLevel=0&ColorDepth=2&" + "AudioMode=2&RedirectClipboard=0&CredentialGenerationBehavior=0&Rdpport=13389"); var settings = VmInstanceConnectionSettings.FromUrl(url); Assert.AreEqual(RdpConnectionBarState.Pinned, settings.ConnectionBar.Value); Assert.AreEqual(RdpDesktopSize.ScreenSize, settings.DesktopSize.Value); Assert.AreEqual(RdpAuthenticationLevel.AttemptServerAuthentication, settings.AuthenticationLevel.Value); Assert.AreEqual(RdpColorDepth.DeepColor, settings.ColorDepth.Value); Assert.AreEqual(RdpAudioMode.DoNotPlay, settings.AudioMode.Value); Assert.AreEqual(RdpRedirectClipboard.Disabled, settings.RedirectClipboard.Value); Assert.AreEqual(RdpCredentialGenerationBehavior.Allow, settings.CredentialGenerationBehavior.Value); Assert.AreEqual(13389, settings.RdpPort.Value); }
public void WhenSettingsContainsEscapableChars_ThenToStringEscapesThem() { var settings = VmInstanceConnectionSettings.CreateNew("project-1", "instance-1"); settings.Username.Value = "Tom & Jerry?"; settings.Domain.Value = "\"?\""; var url = new IapRdpUrl( new InstanceLocator("project-1", "us-central1-a", "instance-1"), settings.ToUrlQuery()); Assert.AreEqual( "iap-rdp:///project-1/us-central1-a/instance-1?" + "Username=Tom+%26+Jerry%3f&Domain=%22%3f%22", url.ToString()); }
public void WhenQueryStringContainsOutOfRangeValues_ThenSettingsUsesDefaults() { var url = IapRdpUrl.FromString("iap-rdp:///my-project/us-central1-a/my-instance?" + "ConnectionBar=-1&DesktopSize=a&AuthenticationLevel=null&ColorDepth=&" + "AudioMode=9999&RedirectClipboard=b&RedirectClipboard=c"); var settings = url.Settings; Assert.IsNull(settings.Username); Assert.IsNull(settings.Password); Assert.IsNull(settings.Domain); Assert.AreEqual(RdpConnectionBarState._Default, settings.ConnectionBar); Assert.AreEqual(RdpDesktopSize._Default, settings.DesktopSize); Assert.AreEqual(RdpAuthenticationLevel._Default, settings.AuthenticationLevel); Assert.AreEqual(RdpColorDepth._Default, settings.ColorDepth); Assert.AreEqual(RdpAudioMode._Default, settings.AudioMode); Assert.AreEqual(RdpRedirectClipboard._Default, settings.RedirectClipboard); }
public async Task ActivateOrConnectInstanceAsync(IapRdpUrl url) { if (this.remoteDesktopService.TryActivate(url.Instance)) { // RDP session was active, nothing left to do. return; } VmInstanceConnectionSettings settings; if (this.projectExplorer.TryFindNode(url.Instance) is IProjectExplorerVmInstanceNode vmNode) { // We have a full set of settings for this VM, so use that as basis settings = this.settingsService.GetConnectionSettingsEditor(vmNode) .CreateConnectionSettings(vmNode.Reference.Name) .OverlayBy(url.Settings); } else { settings = url.Settings; } // We do not know anything other than what's in the URL. // Create an ephemeral settings editor. We do not persist // any changes. var settingsEditor = new ConnectionSettingsEditor( settings, _ => { }, null); await this.credentialPrompt.ShowCredentialsPromptAsync( this.window, url.Instance, settingsEditor, false) .ConfigureAwait(true); await ConnectInstanceAsync( url.Instance, settingsEditor.CreateConnectionSettings(url.Instance.Name)) .ConfigureAwait(true); }
public void WhenQueryStringContainsOutOfRangeValues_ThenSettingsUsesDefaults() { var url = IapRdpUrl.FromString("iap-rdp:///my-project/us-central1-a/my-instance?" + "ConnectionBar=-1&DesktopSize=a&AuthenticationLevel=null&ColorDepth=&" + "AudioMode=9999&RedirectClipboard=b&RedirectClipboard=c&" + "CredentialGenerationBehavior=-11"); var settings = InstanceConnectionSettings.FromUrl(url); Assert.IsNull(settings.RdpUsername.Value); Assert.IsNull(settings.RdpPassword.Value); Assert.IsNull(settings.RdpDomain.Value); Assert.AreEqual(RdpConnectionBarState._Default, settings.RdpConnectionBar.Value); Assert.AreEqual(RdpDesktopSize._Default, settings.RdpDesktopSize.Value); Assert.AreEqual(RdpAuthenticationLevel._Default, settings.RdpAuthenticationLevel.Value); Assert.AreEqual(RdpColorDepth._Default, settings.RdpColorDepth.Value); Assert.AreEqual(RdpAudioMode._Default, settings.RdpAudioMode.Value); Assert.AreEqual(RdpRedirectClipboard._Default, settings.RdpRedirectClipboard.Value); Assert.AreEqual(RdpCredentialGenerationBehavior._Default, settings.RdpCredentialGenerationBehavior.Value); }
internal void ConnectToUrl(IapRdpUrl url) { var rdcService = this.serviceProvider .GetService <RemoteDesktopConnectionService>(); var vmNode = this.serviceProvider .GetService <IProjectExplorer>() .TryFindNode(url.Instance); try { if (vmNode != null) { // We have a full set of settings for this VM, so use that. rdcService .ActivateOrConnectInstanceWithCredentialPromptAsync(this, vmNode) .ContinueWith(t => this.serviceProvider .GetService <IExceptionDialog>() .Show(this, "Failed to connect to VM instance", t.Exception), CancellationToken.None, TaskContinuationOptions.OnlyOnFaulted, TaskScheduler.FromCurrentSynchronizationContext()); } else { // We do not know anything other than what's in the URL. rdcService .ActivateOrConnectInstanceWithCredentialPromptAsync(this, url) .ContinueWith(t => this.serviceProvider .GetService <IExceptionDialog>() .Show(this, "Failed to connect to VM instance", t.Exception), CancellationToken.None, TaskContinuationOptions.OnlyOnFaulted, TaskScheduler.FromCurrentSynchronizationContext()); } } catch (OperationCanceledException) { // The user cancelled, nervemind. } }
internal void ConnectToUrl(IapRdpUrl url) { if (this.urlHandler != null) { try { this.urlHandler .ActivateOrConnectInstanceAsync(url) .ContinueWith(t => this.serviceProvider .GetService <IExceptionDialog>() .Show(this, "Failed to connect to VM instance", t.Exception), CancellationToken.None, TaskContinuationOptions.OnlyOnFaulted, TaskScheduler.FromCurrentSynchronizationContext()); } catch (Exception e) when(e.IsCancellation()) { // The user cancelled, nervemind. } } }
private static IapRdpUrl ParseCommandLine(string[] args) { if (args.Length == 0) { // No arguments passed. return(null); } else if (args.Length > 1 && args[0] == "/url") { // Certain legacy browsers do not properly quote URLs when passing them // as command line arguments. If the URL contains a space, it might be // delivered as two separate arguments. var url = string.Join(" ", args.Skip(1)).Trim(); try { return(IapRdpUrl.FromString(url)); } catch (UriFormatException e) { MessageBox.Show( "Invalid command line options.\n\n" + e.Message, "IAP Desktop", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show( "Invalid command line options.", "IAP Desktop", MessageBoxButtons.OK, MessageBoxIcon.Error); } Environment.Exit(1); return(null); }
public async Task ActivateOrConnectInstanceAsync(IapRdpUrl url) { if (this.sessionBroker.TryActivate(url.Instance)) { // RDP session was active, nothing left to do. return; } InstanceConnectionSettings settings; var existingNode = await this.projectModelService .GetNodeAsync(url.Instance, CancellationToken.None) .ConfigureAwait(true); if (existingNode is IProjectModelInstanceNode vmNode) { // We have a full set of settings for this VM, so use that as basis settings = (InstanceConnectionSettings) this.settingsService.GetConnectionSettings(vmNode).TypedCollection; // Apply parameters from URL on top. settings.ApplyUrlQuery(url.Parameters); } else { settings = InstanceConnectionSettings.FromUrl(url); } await this.credentialPrompt.ShowCredentialsPromptAsync( this.window, url.Instance, settings, false) .ConfigureAwait(true); await ConnectInstanceAsync( url.Instance, settings) .ConfigureAwait(true); }
public async Task WhenConnectingByUrlWithUsernameAndNoCredentialsExist_ThenConnectionIsMadeWithThisUsername() { var settingsService = this.serviceRegistry.AddMock <IConnectionSettingsService>(); this.serviceRegistry.AddMock <ICredentialPrompt>() .Setup(p => p.ShowCredentialsPromptAsync( It.IsAny <IWin32Window>(), It.IsAny <InstanceLocator>(), It.IsAny <ConnectionSettingsBase>(), It.IsAny <bool>())); // Nop -> Connect without configuring credentials. this.serviceRegistry.AddMock <IProjectModelService>() .Setup(p => p.GetNodeAsync( It.IsAny <ResourceLocator>(), It.IsAny <CancellationToken>())) .ReturnsAsync((IProjectModelNode)null); // Not found var remoteDesktopService = new Mock <IRemoteDesktopSessionBroker>(); remoteDesktopService.Setup(s => s.Connect( It.IsAny <InstanceLocator>(), "localhost", It.IsAny <ushort>(), It.IsAny <InstanceConnectionSettings>())).Returns <IRemoteDesktopSession>(null); this.serviceRegistry.AddSingleton <IRemoteDesktopSessionBroker>(remoteDesktopService.Object); var service = new RdpConnectionService(this.serviceRegistry); await service.ActivateOrConnectInstanceAsync( IapRdpUrl.FromString("iap-rdp:///project/us-central-1/instance?username=john%20doe")); remoteDesktopService.Verify(s => s.Connect( It.IsAny <InstanceLocator>(), "localhost", It.IsAny <ushort>(), It.Is <InstanceConnectionSettings>(i => i.RdpUsername.StringValue == "john doe")), Times.Once); settingsService.Verify(s => s.GetConnectionSettings( It.IsAny <IProjectModelNode>()), Times.Never); }
public async Task WhenConnectingByUrlWithoutUsername_ThenConnectionIsMadeWithoutUsername() { var taskDialog = new Mock <ITaskDialog>(); this.serviceRegistry.AddSingleton <ITaskDialog>(taskDialog.Object); taskDialog.Setup(t => t.ShowOptionsTaskDialog( It.IsAny <IWin32Window>(), It.IsAny <IntPtr>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <IList <string> >(), It.IsAny <string>(), out It.Ref <bool> .IsAny)).Returns(1); // Enter existing credentials var remoteDesktopService = new Mock <IRemoteDesktopService>(); remoteDesktopService.Setup(s => s.Connect( It.IsAny <VmInstanceReference>(), "localhost", It.IsAny <ushort>(), It.IsAny <VmInstanceConnectionSettings>())).Returns <IRemoteDesktopSession>(null); this.serviceRegistry.AddSingleton <IRemoteDesktopService>(remoteDesktopService.Object); var service = new RemoteDesktopConnectionService(this.serviceRegistry); await service.ActivateOrConnectInstanceWithCredentialPromptAsync( null, IapRdpUrl.FromString("iap-rdp:///project/us-central-1/instance")); remoteDesktopService.Verify(s => s.Connect( It.IsAny <VmInstanceReference>(), "localhost", It.IsAny <ushort>(), It.Is <VmInstanceConnectionSettings>(i => i.Username == null)), Times.Once); }
public async Task ActivateOrConnectInstanceAsync(IapRdpUrl url) { if (this.remoteDesktopService.TryActivate(url.Instance)) { // RDP session was active, nothing left to do. return; } VmInstanceConnectionSettings settings; if (this.projectExplorer.TryFindNode(url.Instance) is IProjectExplorerVmInstanceNode vmNode) { // We have a full set of settings for this VM, so use that as basis settings = (VmInstanceConnectionSettings) this.settingsService.GetConnectionSettings(vmNode); // Apply parameters from URL on top. settings.ApplyUrlQuery(url.Parameters); } else { settings = VmInstanceConnectionSettings.FromUrl(url); } await this.credentialPrompt.ShowCredentialsPromptAsync( this.window, url.Instance, settings, false) .ConfigureAwait(true); await ConnectInstanceAsync( url.Instance, settings) .ConfigureAwait(true); }
public static CommandLineOptions Parse(string[] args) { var options = new CommandLineOptions(); for (int i = 0; i < args.Length; i++) { if (args[i] == "/debug") { options.IsLoggingEnabled = true; } else if (args[i] == "/url" && i + 1 < args.Length) { // Certain legacy browsers do not properly quote URLs when passing them // as command line arguments. If the URL contains a space, it might be // delivered as two separate arguments. var url = string.Join(" ", args[++i]).Trim(); try { options.StartupUrl = IapRdpUrl.FromString(url); } catch (UriFormatException e) { throw new InvalidCommandLineException( "Invalid startup URL:\n\n" + e.Message); } } else { throw new InvalidCommandLineException( $"Unrecognized command line option '{args[0]}'"); } } return(options); }
public async Task WhenConnectingByUrlWithoutUsernameAndNoCredentialsExist_ThenConnectionIsMadeWithoutUsername() { var settingsService = this.serviceRegistry.AddMock <IConnectionSettingsService>(); this.serviceRegistry.AddMock <ICredentialPrompt>() .Setup(p => p.ShowCredentialsPromptAsync( It.IsAny <IWin32Window>(), It.IsAny <InstanceLocator>(), It.IsAny <ConnectionSettingsEditor>(), It.IsAny <bool>())); // Nop -> Connect without configuring credentials. this.serviceRegistry.AddMock <IProjectExplorer>() .Setup(p => p.TryFindNode( It.IsAny <InstanceLocator>())) .Returns <VmInstanceNode>(null); // Not found var remoteDesktopService = new Mock <IRemoteDesktopConnectionBroker>(); remoteDesktopService.Setup(s => s.Connect( It.IsAny <InstanceLocator>(), "localhost", It.IsAny <ushort>(), It.IsAny <VmInstanceConnectionSettings>())).Returns <IRemoteDesktopSession>(null); this.serviceRegistry.AddSingleton <IRemoteDesktopConnectionBroker>(remoteDesktopService.Object); var service = new IapRdpConnectionService(this.serviceRegistry); await service.ActivateOrConnectInstanceAsync( IapRdpUrl.FromString("iap-rdp:///project/us-central-1/instance")); remoteDesktopService.Verify(s => s.Connect( It.IsAny <InstanceLocator>(), "localhost", It.IsAny <ushort>(), It.Is <VmInstanceConnectionSettings>(i => i.Username == null)), Times.Once); settingsService.Verify(s => s.GetConnectionSettingsEditor( It.IsAny <IProjectExplorerNode>()), Times.Never); }
public async Task WhenConnectingByUrlWithUsername_ThenSuggestedUsernameForCredentialGenerationIsThisUsername() { var taskDialog = new Mock <ITaskDialog>(); this.serviceRegistry.AddSingleton <ITaskDialog>(taskDialog.Object); taskDialog.Setup(t => t.ShowOptionsTaskDialog( It.IsAny <IWin32Window>(), It.IsAny <IntPtr>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <IList <string> >(), It.IsAny <string>(), out It.Ref <bool> .IsAny)).Returns(0); // Generate new credentials var credentialsService = new Mock <ICredentialsService>(); credentialsService.Setup(s => s.GenerateCredentialsAsync( It.IsAny <IWin32Window>(), It.IsAny <InstanceLocator>(), It.IsAny <ConnectionSettingsEditor>(), It.IsAny <string>())).Returns(Task.FromResult(new NetworkCredential("user", "password"))); this.serviceRegistry.AddSingleton <ICredentialsService>(credentialsService.Object); var service = new RemoteDesktopConnectionService(this.serviceRegistry); await service.ActivateOrConnectInstanceWithCredentialPromptAsync( null, IapRdpUrl.FromString("iap-rdp:///project/us-central-1/instance?username=john%20doe")); credentialsService.Verify(s => s.GenerateCredentialsAsync( It.IsAny <IWin32Window>(), It.IsAny <InstanceLocator>(), It.IsAny <ConnectionSettingsEditor>(), It.Is <string>(user => user == "john doe")), Times.Once); }
public void WhenZoneIdIsIsInvalid_ThenFromStringThrowsIapRdpUrlFormatException() { Assert.Throws <IapRdpUrlFormatException>(() => IapRdpUrl.FromString("iap-rdp:///my-project/__/my-instance")); }
public void WhenInstanceNameIsIsInvalid_ThenFromStringThrowsIapRdpUrlFormatException() { Assert.Throws <IapRdpUrlFormatException>(() => IapRdpUrl.FromString("iap-rdp:///my-project/us-central1-a/__")); }
public void WhenProjectIdIsIsInvalid_ThenFromStringThrowsIapRdpUrlFormatException() { Assert.Throws <IapRdpUrlFormatException>(() => IapRdpUrl.FromString("iap-rdp:///__/us-central1-a/my-instance")); }
public void WhenLeadingSlashMissing_ThenFromStringThrowsIapRdpUrlFormatException() { Assert.Throws <IapRdpUrlFormatException>(() => IapRdpUrl.FromString("iap-rdp:my-project/us-central1-a/my-instance")); }
public void WhenHostNotEmpty_ThenFromStringThrowsIapRdpUrlFormatException() { Assert.Throws <IapRdpUrlFormatException>(() => IapRdpUrl.FromString("iap-rdp://host/my-project/us-central1-a/my-instance")); }
public void WhenSchemeIsWrong_ThenFromStringThrowsIapRdpUrlFormatException() { Assert.Throws <IapRdpUrlFormatException>(() => IapRdpUrl.FromString("http://www/")); }
public void WhenStringIsNotAUri_ThenFromStringThrowsUriFormatException() { Assert.Throws <UriFormatException>(() => IapRdpUrl.FromString("::")); }