コード例 #1
0
        public async Task WhenCredentialsInvalid_ThenErrorIsShownAndWindowIsClosed(
            [WindowsInstance] ResourceTask <InstanceLocator> testInstance,
            [Credential(Role = PredefinedRole.IapTunnelUser)] ResourceTask <ICredential> credential)
        {
            var locator = await testInstance;

            using (var tunnel = RdpTunnel.Create(
                       locator,
                       await credential))
            {
                var settings = VmInstanceConnectionSettings.CreateNew(
                    locator.ProjectId,
                    locator.Name);
                settings.Username.StringValue                 = "wrong";
                settings.Password.Value                       = SecureStringExtensions.FromClearText("wrong");
                settings.AuthenticationLevel.EnumValue        = RdpAuthenticationLevel.NoServerAuthentication;
                settings.UserAuthenticationBehavior.EnumValue = RdpUserAuthenticationBehavior.AbortOnFailure;
                settings.DesktopSize.EnumValue                = RdpDesktopSize.ClientSize;

                var rdpService = new RemoteDesktopConnectionBroker(this.serviceProvider);
                var session    = rdpService.Connect(
                    locator,
                    "localhost",
                    (ushort)tunnel.LocalPort,
                    settings);

                AwaitEvent <ConnectionFailedEvent>();
                Assert.IsNotNull(this.ExceptionShown);
                Assert.IsInstanceOf(typeof(RdpDisconnectedException), this.ExceptionShown);
                Assert.AreEqual(2055, ((RdpDisconnectedException)this.ExceptionShown).DisconnectReason);
            }
        }
コード例 #2
0
        private async Task <IRemoteDesktopSession> Connect(
            RdpTunnel tunnel,
            InstanceLocator vmInstanceReference)
        {
            using (var gceAdapter = new ComputeEngineAdapter(this.serviceProvider.GetService <IAuthorizationAdapter>()))
            {
                var credentials = await gceAdapter.ResetWindowsUserAsync(
                    vmInstanceReference,
                    CreateRandomUsername(),
                    TimeSpan.FromSeconds(60),
                    CancellationToken.None);

                var settings = VmInstanceConnectionSettings.CreateNew(vmInstanceReference);
                settings.Username.Value            = credentials.UserName;
                settings.Password.Value            = credentials.SecurePassword;
                settings.AuthenticationLevel.Value = RdpAuthenticationLevel.NoServerAuthentication;
                settings.BitmapPersistence.Value   = RdpBitmapPersistence.Disabled;
                settings.DesktopSize.Value         = RdpDesktopSize.ClientSize;

                var rdpService = new RemoteDesktopConnectionBroker(this.serviceProvider);
                return(rdpService.Connect(
                           vmInstanceReference,
                           "localhost",
                           (ushort)tunnel.LocalPort,
                           settings));
            }
        }
コード例 #3
0
        public async Task WhenConnected_ThenActiveSessionIsSetAndTryActivateReturnsTrue(
            [WindowsInstance(MachineType = MachineTypeForRdp)] ResourceTask <InstanceLocator> testInstance,
            [Credential(Role = PredefinedRole.IapTunnelUser)] ResourceTask <ICredential> credential)
        {
            var locator = await testInstance;

            using (var tunnel = RdpTunnel.Create(
                       locator,
                       await credential))
                using (var gceAdapter = new ComputeEngineAdapter(this.serviceProvider.GetService <IAuthorizationAdapter>()))
                {
                    var credentials = await gceAdapter.ResetWindowsUserAsync(
                        locator,
                        CreateRandomUsername(),
                        TimeSpan.FromSeconds(60),
                        CancellationToken.None);

                    var settings = VmInstanceConnectionSettings.CreateNew(
                        locator.ProjectId,
                        locator.Name);
                    settings.Username.StringValue = credentials.UserName;
                    settings.Password.Value       = credentials.SecurePassword;

                    var broker  = new RemoteDesktopConnectionBroker(this.serviceProvider);
                    var session = broker.Connect(
                        locator,
                        "localhost",
                        (ushort)tunnel.LocalPort,
                        settings);

                    AwaitEvent <ConnectionSuceededEvent>();
                    Assert.IsNull(this.ExceptionShown);

                    Assert.IsTrue(broker.IsConnected(locator));
                    Assert.AreSame(session, broker.ActiveSession);
                    Assert.IsTrue(broker.TryActivate(locator));

                    Assert.IsFalse(broker.TryActivate(SampleLocator));
                    Assert.IsFalse(broker.IsConnected(SampleLocator));

                    ConnectionClosedEvent expectedEvent = null;

                    this.serviceProvider.GetService <IEventService>()
                    .BindHandler <ConnectionClosedEvent>(e =>
                    {
                        expectedEvent = e;
                    });
                    session.Close();

                    Assert.IsNotNull(expectedEvent);
                }
        }
コード例 #4
0
        public void WhenWrongPort_ThenErrorIsShownAndWindowIsClosed()
        {
            var rdpService = new RemoteDesktopConnectionBroker(this.serviceProvider);

            rdpService.Connect(
                this.instanceReference,
                "localhost",
                135,    // That one will be listening, but it is RPC, not RDP.
                new VmInstanceConnectionSettings());

            AwaitEvent <ConnectionFailedEvent>();
            Assert.IsInstanceOf(typeof(RdpDisconnectedException), this.ExceptionShown);
            Assert.AreEqual(2308, ((RdpDisconnectedException)this.ExceptionShown).DisconnectReason);
        }
コード例 #5
0
        public void WhenServerInvalid_ThenErrorIsShownAndWindowIsClosed()
        {
            var rdpService = new RemoteDesktopConnectionBroker(this.serviceProvider);

            rdpService.Connect(
                this.instanceReference,
                "invalid.corp",
                3389,
                new VmInstanceConnectionSettings());

            AwaitEvent <ConnectionFailedEvent>();
            Assert.IsInstanceOf(typeof(RdpDisconnectedException), this.ExceptionShown);
            Assert.AreEqual(260, ((RdpDisconnectedException)this.ExceptionShown).DisconnectReason);
        }
コード例 #6
0
        public void WhenPortNotListening_ThenErrorIsShownAndWindowIsClosed()
        {
            var rdpService = new RemoteDesktopConnectionBroker(this.serviceProvider);

            rdpService.Connect(
                this.instanceReference,
                "localhost",
                1,
                new VmInstanceConnectionSettings()
            {
                ConnectionTimeout = 5
            });

            AwaitEvent <ConnectionFailedEvent>();
            Assert.IsInstanceOf(typeof(RdpDisconnectedException), this.ExceptionShown);
            Assert.AreEqual(516, ((RdpDisconnectedException)this.ExceptionShown).DisconnectReason);
        }
コード例 #7
0
        public async Task WhenSigningOutPerSendKeys_ThenWindowIsClosed(
            [WindowsInstance(ImageFamily = WindowsInstanceAttribute.WindowsServer2019)]
            ResourceTask <InstanceLocator> testInstance,
            [Credential(Role = PredefinedRole.IapTunnelUser)] ResourceTask <ICredential> credential)
        {
            var locator = await testInstance;

            using (var tunnel = RdpTunnel.Create(
                       locator,
                       await credential))
                using (var gceAdapter = new ComputeEngineAdapter(this.serviceProvider.GetService <IAuthorizationAdapter>()))
                {
                    var credentials = await gceAdapter.ResetWindowsUserAsync(
                        locator,
                        CreateRandomUsername(),
                        TimeSpan.FromSeconds(60),
                        CancellationToken.None);

                    var settings = VmInstanceConnectionSettings.CreateNew(
                        locator.ProjectId,
                        locator.Name);
                    settings.Username.StringValue          = credentials.UserName;
                    settings.Password.Value                = credentials.SecurePassword;
                    settings.AuthenticationLevel.EnumValue = RdpAuthenticationLevel.NoServerAuthentication;
                    settings.BitmapPersistence.EnumValue   = RdpBitmapPersistence.Disabled;
                    settings.DesktopSize.EnumValue         = RdpDesktopSize.ClientSize;

                    var rdpService = new RemoteDesktopConnectionBroker(this.serviceProvider);
                    var session    = (RemoteDesktopPane)rdpService.Connect(
                        locator,
                        "localhost",
                        (ushort)tunnel.LocalPort,
                        settings);

                    AwaitEvent <ConnectionSuceededEvent>();

                    Thread.Sleep(5000);
                    session.ShowSecurityScreen();
                    Thread.Sleep(1000);
                    session.SendKeys(Keys.Menu, Keys.S); // Sign out.

                    AwaitEvent <ConnectionClosedEvent>();
                    Assert.IsNull(this.ExceptionShown);
                }
        }
コード例 #8
0
        public void WhenPortNotListening_ThenErrorIsShownAndWindowIsClosed()
        {
            var settings = VmInstanceConnectionSettings.CreateNew(this.SampleLocator);

            settings.ConnectionTimeout.IntValue = 5;

            var rdpService = new RemoteDesktopConnectionBroker(this.serviceProvider);

            rdpService.Connect(
                this.SampleLocator,
                "localhost",
                1,
                settings);

            AwaitEvent <ConnectionFailedEvent>();
            Assert.IsInstanceOf(typeof(RdpDisconnectedException), this.ExceptionShown);
            Assert.AreEqual(516, ((RdpDisconnectedException)this.ExceptionShown).DisconnectReason);
        }
コード例 #9
0
        public async Task WhenCredentialsValid_ThenConnectingSucceeds(
            [Values(RdpConnectionBarState.AutoHide, RdpConnectionBarState.Off, RdpConnectionBarState.Pinned)]
            RdpConnectionBarState connectionBarState,

            [Values(RdpDesktopSize.ClientSize, RdpDesktopSize.ScreenSize)]
            RdpDesktopSize desktopSize,

            [Values(RdpAudioMode.DoNotPlay, RdpAudioMode.PlayLocally, RdpAudioMode.PlayOnServer)]
            RdpAudioMode audioMode,

            [Values(RdpRedirectClipboard.Disabled, RdpRedirectClipboard.Enabled)]
            RdpRedirectClipboard redirectClipboard,

            // Use a slightly larger machine type as all this RDP'ing consumes a fair
            // amount of memory.
            [WindowsInstance(MachineType = "n1-standard-2")] ResourceTask <InstanceLocator> testInstance,
            [Credential(Role = PredefinedRole.IapTunnelUser)] ResourceTask <ICredential> credential)
        {
            var locator = await testInstance;

            using (var tunnel = RdpTunnel.Create(
                       locator,
                       await credential))
                using (var gceAdapter = new ComputeEngineAdapter(this.serviceProvider.GetService <IAuthorizationAdapter>()))
                {
                    var credentials = await gceAdapter.ResetWindowsUserAsync(
                        locator,
                        CreateRandomUsername(),
                        TimeSpan.FromSeconds(60),
                        CancellationToken.None);

                    var settings = VmInstanceConnectionSettings.CreateNew(
                        locator.ProjectId,
                        locator.Name);
                    settings.Username.StringValue          = credentials.UserName;
                    settings.Password.Value                = credentials.SecurePassword;
                    settings.ConnectionBar.EnumValue       = connectionBarState;
                    settings.DesktopSize.EnumValue         = desktopSize;
                    settings.AudioMode.EnumValue           = audioMode;
                    settings.RedirectClipboard.EnumValue   = redirectClipboard;
                    settings.AuthenticationLevel.EnumValue = RdpAuthenticationLevel.NoServerAuthentication;
                    settings.BitmapPersistence.EnumValue   = RdpBitmapPersistence.Disabled;

                    var rdpService = new RemoteDesktopConnectionBroker(this.serviceProvider);
                    var session    = rdpService.Connect(
                        locator,
                        "localhost",
                        (ushort)tunnel.LocalPort,
                        settings);

                    AwaitEvent <ConnectionSuceededEvent>();
                    Assert.IsNull(this.ExceptionShown);


                    ConnectionClosedEvent expectedEvent = null;

                    this.serviceProvider.GetService <IEventService>()
                    .BindHandler <ConnectionClosedEvent>(e =>
                    {
                        expectedEvent = e;
                    });
                    session.Close();

                    Assert.IsNotNull(expectedEvent);
                }
        }