public void WhenParseStringCreatedByToString_ResultIsSame()
        {
            var settings = InstanceConnectionSettings.CreateNew("project-1", "instance-1");

            settings.RdpUsername.Value                     = "user";
            settings.RdpDomain.Value                       = "domain";
            settings.RdpConnectionBar.Value                = RdpConnectionBarState.Off;
            settings.RdpDesktopSize.Value                  = RdpDesktopSize.ScreenSize;
            settings.RdpAuthenticationLevel.Value          = RdpAuthenticationLevel.RequireServerAuthentication;
            settings.RdpColorDepth.Value                   = RdpColorDepth.TrueColor;
            settings.RdpAudioMode.Value                    = RdpAudioMode.PlayOnServer;
            settings.RdpRedirectClipboard.Value            = RdpRedirectClipboard.Disabled;
            settings.RdpCredentialGenerationBehavior.Value = RdpCredentialGenerationBehavior.Disallow;

            var url = new IapRdpUrl(
                new InstanceLocator("project-1", "us-central1-a", "instance-1"),
                settings.ToUrlQuery());

            var copy = InstanceConnectionSettings.FromUrl(url);

            Assert.AreEqual("user", copy.RdpUsername.Value);
            Assert.AreEqual("domain", copy.RdpDomain.Value);
            Assert.AreEqual(RdpConnectionBarState.Off, copy.RdpConnectionBar.Value);
            Assert.AreEqual(RdpDesktopSize.ScreenSize, copy.RdpDesktopSize.Value);
            Assert.AreEqual(RdpAuthenticationLevel.RequireServerAuthentication, copy.RdpAuthenticationLevel.Value);
            Assert.AreEqual(RdpColorDepth.TrueColor, copy.RdpColorDepth.Value);
            Assert.AreEqual(RdpAudioMode.PlayOnServer, copy.RdpAudioMode.Value);
            Assert.AreEqual(RdpRedirectClipboard.Disabled, copy.RdpRedirectClipboard.Value);
            Assert.AreEqual(RdpCredentialGenerationBehavior.Disallow, copy.RdpCredentialGenerationBehavior.Value);
        }
        public void WhenQueryStringContainsValidUserOrDomain_ThenSettingsUseDecodedValues()
        {
            var url = IapRdpUrl.FromString("iap-rdp:///my-project/us-central1-a/my-instance?" +
                                           "userNAME=John%20Doe&PassworD=ignore&Domain=%20%20mydomain&");
            var settings = InstanceConnectionSettings.FromUrl(url);

            Assert.AreEqual("John Doe", settings.RdpUsername.Value);
            Assert.IsNull(settings.RdpPassword.Value);
            Assert.AreEqual("  mydomain", settings.RdpDomain.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 = InstanceConnectionSettings.FromUrl(url);

            Assert.AreEqual(RdpConnectionBarState.Pinned, settings.RdpConnectionBar.Value);
            Assert.AreEqual(RdpDesktopSize.ScreenSize, settings.RdpDesktopSize.Value);
            Assert.AreEqual(RdpAuthenticationLevel.AttemptServerAuthentication, settings.RdpAuthenticationLevel.Value);
            Assert.AreEqual(RdpColorDepth.DeepColor, settings.RdpColorDepth.Value);
            Assert.AreEqual(RdpAudioMode.DoNotPlay, settings.RdpAudioMode.Value);
            Assert.AreEqual(RdpRedirectClipboard.Disabled, settings.RdpRedirectClipboard.Value);
            Assert.AreEqual(RdpCredentialGenerationBehavior.Allow, settings.RdpCredentialGenerationBehavior.Value);
            Assert.AreEqual(13389, settings.RdpPort.Value);
        }
        public void WhenQueryStringContainsNonsense_ThenSettingsUsesDefaults()
        {
            var url      = IapRdpUrl.FromString("iap-rdp:///my-project/us-central1-a/my-instance?a=b&user=wrongcase&_");
            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);
        }
        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);
        }
Ejemplo n.º 6
0
        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);
        }