public async Task WhenLinuxInstanceCreated_ThenReportContainsInstanceAndLicenseInfoFromItsDisk(
            [LinuxInstance] InstanceRequest testInstance,
            [Credential(Roles = new[] {
            PredefinedRole.ComputeViewer,
            PredefinedRole.LogsViewer
        })] CredentialRequest credential)
        {
            await testInstance.AwaitReady();

            var instanceRef = await testInstance.GetInstanceAsync();

            var startDate = DateTime.UtcNow.AddDays(-1);
            var builder   = new AuditLogReportBuilder(
                new AuditLogAdapter(await credential.GetCredentialAsync()),
                new ComputeEngineAdapter(await credential.GetCredentialAsync()),
                new[] { TestProject.ProjectId },
                startDate);
            var report = await builder.BuildAsync(CancellationToken.None);

            var instance = report.History.Instances.First(i => i.Reference == instanceRef);

            Assert.IsTrue(report.IsInstanceAnnotatedAs(
                              instance,
                              OperatingSystemTypes.Linux,
                              LicenseTypes.Unknown));
        }
Ejemplo n.º 2
0
        public async Task WhenSetClientConnectionEncryptionLevelSetToLow_ThenConnectionSucceeds(
            [WindowsInstance(InitializeScript = @"
                & reg add ""HKLM\SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services"" /t REG_DWORD /v MinEncryptionLevel /d 1 /f | Out-Default
            ")] InstanceRequest testInstance,
            [Credential] CredentialRequest credential)
        {
            await testInstance.AwaitReady();

            using (var tunnel = RdpTunnel.Create(
                       testInstance.Locator,
                       await credential.GetCredentialAsync()))
            {
                var session = await Connect(tunnel, testInstance.Locator);

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

                RemoteDesktopWindowClosedEvent expectedEvent = null;

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

                Delay(TimeSpan.FromSeconds(5));
                session.Close();

                Assert.IsNotNull(expectedEvent);
            }
        }
        public async Task WhenCredentialsInvalid_ThenErrorIsShownAndWindowIsClosed(
            [WindowsInstance] InstanceRequest testInstance,
            [Credential] CredentialRequest credential)
        {
            await testInstance.AwaitReady();

            using (var tunnel = RdpTunnel.Create(
                       testInstance.Locator,
                       await credential.GetCredentialAsync()))
            {
                var rdpService = new RemoteDesktopService(this.serviceProvider);
                var session    = rdpService.Connect(
                    testInstance.Locator,
                    "localhost",
                    (ushort)tunnel.LocalPort,
                    new VmInstanceConnectionSettings()
                {
                    Username                   = "******",
                    Password                   = SecureStringExtensions.FromClearText("wrong"),
                    AuthenticationLevel        = RdpAuthenticationLevel.NoServerAuthentication,
                    UserAuthenticationBehavior = RdpUserAuthenticationBehavior.AbortOnFailure,
                    DesktopSize                = RdpDesktopSize.ClientSize
                });

                AwaitEvent <RemoteDesktopConnectionFailedEvent>();
                Assert.IsNotNull(this.ExceptionShown);
                Assert.IsInstanceOf(typeof(RdpDisconnectedException), this.ExceptionShown);
                Assert.AreEqual(2055, ((RdpDisconnectedException)this.ExceptionShown).DisconnectReason);
            }
        }
Ejemplo n.º 4
0
        public async Task WhenUsingInvalidProjectId_ThenListEventsAsyncThrowsException(
            [Credential(Role = PredefinedRole.LogsViewer)] CredentialRequest credential)
        {
            var startDate = DateTime.UtcNow.AddDays(-30);
            var request   = new ListLogEntriesRequest()
            {
                ResourceNames = new[]
                {
                    "projects/invalid"
                },
                Filter = $"resource.type=\"gce_instance\" " +
                         $"AND protoPayload.methodName:{InsertInstanceEvent.Method} " +
                         $"AND timestamp > {startDate:yyyy-MM-dd}",
                PageSize = 1000,
                OrderBy  = "timestamp desc"
            };

            var adapter = new AuditLogAdapter(await credential.GetCredentialAsync());

            AssertEx.ThrowsAggregateException <GoogleApiException>(
                () => adapter.ListEventsAsync(
                    request,
                    _ => { },
                    new Apis.Util.ExponentialBackOff(),
                    CancellationToken.None).Wait());
        }
Ejemplo n.º 5
0
        public async Task WhenServerClosesConnectionAfterSingleHttpRequest_ThenRelayEnds(
            [LinuxInstance(InitializeScript = InstallApache)] InstanceRequest vm,
            [Credential] CredentialRequest credential)
        {
            await vm.AwaitReady();

            var stream = ConnectToWebServer(
                vm.Locator,
                await credential.GetCredentialAsync());

            byte[] request = new ASCIIEncoding().GetBytes(
                "GET / HTTP/1.0\r\n\r\n");
            await stream.WriteAsync(request, 0, request.Length, this.tokenSource.Token);

            byte[] buffer = new byte[stream.MinReadSize];

            var response = new HttpResponseAccumulator();
            int bytesRead;

            while ((bytesRead = await stream.ReadAsync(buffer, 0, buffer.Length, this.tokenSource.Token)) > 0)
            {
                response.Accumulate(buffer, 0, bytesRead);
            }

            await stream.CloseAsync(this.tokenSource.Token);

            Assert.AreEqual(response.ExpectedBytes, response.TotalBytesRead);
        }
        public async Task WhenUserNotInRole_ThenGetImageThrowsResourceAccessDeniedException(
            [Credential(Role = PredefinedRole.IapTunnelUser)] CredentialRequest credential)
        {
            var adapter = new ComputeEngineAdapter(await credential.GetCredentialAsync());

            AssertEx.ThrowsAggregateException <ResourceAccessDeniedException>(
                () => adapter.GetImageAsync(
                    new ImageLocator(TestProject.ProjectId, "someimage"),
                    CancellationToken.None).Wait());
        }
Ejemplo n.º 7
0
        public async Task WhenUserNotInRole_ThenIsGrantedPermissionReturnsFalse(
            [Credential(Role = PredefinedRole.ComputeViewer)] CredentialRequest credential)
        {
            var adapter = new ResourceManagerAdapter(await credential.GetCredentialAsync());

            var result = await adapter.IsGrantedPermission(
                TestProject.ProjectId,
                "compute.disks.create");

            Assert.IsFalse(result);
        }
Ejemplo n.º 8
0
        public async Task WhenSwitchingToCloudNode_ThenControlsAreDisabled(
            [Credential(Role = PredefinedRole.ComputeViewer)] CredentialRequest credential)
        {
            var viewModel = CreateViewModel(await credential.GetCredentialAsync());
            var node      = new Mock <IProjectExplorerCloudNode>();
            await viewModel.SwitchToModelAsync(node.Object);

            Assert.IsFalse(viewModel.IsEnableTailingButtonEnabled);
            Assert.IsFalse(viewModel.IsOutputBoxEnabled);
            StringAssert.Contains(SerialOutputViewModel.DefaultWindowTitle, viewModel.WindowTitle);
        }
Ejemplo n.º 9
0
        public async Task WhenApiReturns404_ThenExecuteAsStreamOrThrowAsyncThrowsException(
            [Credential(Role = PredefinedRole.ComputeViewer)] CredentialRequest credential
            )
        {
            var computeService = new ComputeService(new BaseClientService.Initializer
            {
                HttpClientInitializer = await credential.GetCredentialAsync()
            });

            AssertEx.ThrowsAggregateException <GoogleApiException>(
                () => computeService.Instances.Get("invalid", "invalid", "invalid")
                .ExecuteAsStreamOrThrowAsync(CancellationToken.None).Wait());
        }
Ejemplo n.º 10
0
        public async Task WhenSwitchingToStoppedInstanceNode_ThenControlsAreDisabled(
            [WindowsInstance] InstanceRequest testInstance,
            [Credential(Role = PredefinedRole.ComputeViewer)] CredentialRequest credential)
        {
            var viewModel = CreateViewModel(await credential.GetCredentialAsync());
            var node      = await CreateNode(testInstance, false);

            await viewModel.SwitchToModelAsync(node);

            Assert.IsFalse(viewModel.IsEnableTailingButtonEnabled);
            Assert.IsFalse(viewModel.IsOutputBoxEnabled);
            StringAssert.Contains(SerialOutputViewModel.DefaultWindowTitle, viewModel.WindowTitle);
        }
Ejemplo n.º 11
0
        public async Task WhenBlocked_ThenEnableHasNoImpactOnTailing(
            [WindowsInstance] InstanceRequest testInstance,
            [Credential(Role = PredefinedRole.ComputeViewer)] CredentialRequest credential)
        {
            var viewModel = CreateViewModel(await credential.GetCredentialAsync());
            var node      = await CreateNode(testInstance, true);

            await viewModel.SwitchToModelAsync(node);

            viewModel.IsTailBlocked = true;
            viewModel.IsTailEnabled = true;

            Assert.IsNull(viewModel.TailCancellationTokenSource, "not tailing yet");
        }
Ejemplo n.º 12
0
        public async Task WhenInstanceCreated_ThenListInstanceEventsAsyncCanFeedHistorySetBuilder(
            [LinuxInstance] InstanceRequest testInstance,
            [Credential(Roles = new[] {
            PredefinedRole.ComputeViewer,
            PredefinedRole.LogsViewer
        })] CredentialRequest credential)
        {
            await testInstance.AwaitReady();

            var instanceRef = await testInstance.GetInstanceAsync();

            var instanceBuilder = new InstanceSetHistoryBuilder(
                DateTime.UtcNow.AddDays(-7),
                DateTime.UtcNow);

            var computeAdapter = new ComputeEngineAdapter(await credential.GetCredentialAsync());

            instanceBuilder.AddExistingInstances(
                await computeAdapter.ListInstancesAsync(TestProject.ProjectId, CancellationToken.None),
                await computeAdapter.ListDisksAsync(TestProject.ProjectId, CancellationToken.None),
                TestProject.ProjectId);

            var adapter = new AuditLogAdapter(await credential.GetCredentialAsync());

            await adapter.ListInstanceEventsAsync(
                new[] { TestProject.ProjectId },
                null,  // all zones.
                null,  // all instances.
                instanceBuilder.StartDate,
                instanceBuilder,
                CancellationToken.None);

            var set = instanceBuilder.Build();
            var testInstanceHistory = set.Instances.FirstOrDefault(i => i.Reference == instanceRef);

            Assert.IsNotNull(testInstanceHistory, "Instance found in history");
        }
Ejemplo n.º 13
0
        public async Task WhenSendingMessagesToEchoServer_MessagesAreReceivedVerbatim(
            [LinuxInstance(InitializeScript = InstallEchoServer)] InstanceRequest vm,
            [Credential] CredentialRequest credential,
            [Values(
                 1,
                 (int)DataMessage.MaxDataLength - 1,
                 (int)DataMessage.MaxDataLength,
                 (int)DataMessage.MaxDataLength + 1,
                 (int)DataMessage.MaxDataLength * 10)] int length,
            [Values(1, 3)] int count)
        {
            var message = new byte[length];

            FillArray(message);

            await vm.AwaitReady();

            var stream = ConnectToEchoServer(
                vm.Locator,
                await credential.GetCredentialAsync());

            for (int i = 0; i < count; i++)
            {
                await stream.WriteAsync(message, 0, message.Length, this.tokenSource.Token);

                var response       = new byte[length];
                int totalBytesRead = 0;
                while (true)
                {
                    var bytesRead = await stream.ReadAsync(
                        response,
                        totalBytesRead,
                        response.Length - totalBytesRead,
                        this.tokenSource.Token);

                    totalBytesRead += bytesRead;

                    if (bytesRead == 0 || totalBytesRead >= length)
                    {
                        break;
                    }
                }

                Assert.AreEqual(length, totalBytesRead);
                Assert.AreEqual(message, response);
            }

            await stream.CloseAsync(this.tokenSource.Token);
        }
        public async Task WhenUserNotInRole_ThenGetInstanceAsyncThrowsResourceAccessDeniedException(
            [LinuxInstance] InstanceRequest testInstance,
            [Credential(Role = PredefinedRole.IapTunnelUser)] CredentialRequest credential)
        {
            await testInstance.AwaitReady();

            var instanceRef = await testInstance.GetInstanceAsync();

            var adapter = new ComputeEngineAdapter(await credential.GetCredentialAsync());

            AssertEx.ThrowsAggregateException <ResourceAccessDeniedException>(
                () => adapter.GetInstanceAsync(
                    testInstance.Locator,
                    CancellationToken.None).Wait());
        }
Ejemplo n.º 15
0
        public async Task WhenInstanceCreated_ThenListLogEntriesReturnsInsertEvent(
            [LinuxInstance] InstanceRequest testInstance,
            [Credential(Role = PredefinedRole.LogsViewer)] CredentialRequest credential)
        {
            await testInstance.AwaitReady();

            var instanceRef = await testInstance.GetInstanceAsync();

            var startDate = DateTime.UtcNow.AddDays(-30);
            var endDate   = DateTime.UtcNow;

            var adapter = new AuditLogAdapter(await credential.GetCredentialAsync());
            var request = new ListLogEntriesRequest()
            {
                ResourceNames = new[]
                {
                    "projects/" + TestProject.ProjectId
                },
                Filter = $"resource.type=\"gce_instance\" " +
                         $"AND protoPayload.methodName:{InsertInstanceEvent.Method} " +
                         $"AND timestamp > {startDate:yyyy-MM-dd}",
                PageSize = 1000,
                OrderBy  = "timestamp desc"
            };

            var events          = new List <EventBase>();
            var instanceBuilder = new InstanceSetHistoryBuilder(startDate, endDate);

            // Creating the VM might be quicker than the logs become available.
            for (int retry = 0; retry < 4 && !events.Any(); retry++)
            {
                await adapter.ListEventsAsync(
                    request,
                    events.Add,
                    new Apis.Util.ExponentialBackOff(),
                    CancellationToken.None);

                if (!events.Any())
                {
                    await Task.Delay(20 * 1000);
                }
            }

            var insertEvent = events.OfType <InsertInstanceEvent>()
                              .First(e => e.InstanceReference == instanceRef);

            Assert.IsNotNull(insertEvent);
        }
Ejemplo n.º 16
0
        public async Task WhenSwitchingToRunningInstanceNode_ThenOutputIsPopulated(
            [WindowsInstance] InstanceRequest testInstance,
            [Credential(Role = PredefinedRole.ComputeViewer)] CredentialRequest credential)
        {
            var viewModel = CreateViewModel(await credential.GetCredentialAsync());
            var node      = await CreateNode(testInstance, true);

            await viewModel.SwitchToModelAsync(node);

            Assert.IsTrue(viewModel.IsEnableTailingButtonEnabled);
            Assert.IsTrue(viewModel.IsOutputBoxEnabled);
            StringAssert.Contains("Instance setup finished", viewModel.Output);

            StringAssert.Contains(SerialOutputViewModel.DefaultWindowTitle, viewModel.WindowTitle);
            StringAssert.Contains(testInstance.Locator.Name, viewModel.WindowTitle);
        }
        public async Task WhenUserNotInRole_ThenIsGrantedPermissionReturnsFalse(
            [LinuxInstance] InstanceRequest testInstance,
            [Credential(Role = PredefinedRole.ComputeViewer)] CredentialRequest credential)
        {
            await testInstance.AwaitReady();

            var instanceRef = await testInstance.GetInstanceAsync();

            var adapter = new ResourceManagerAdapter(await credential.GetCredentialAsync());

            var result = await adapter.IsGrantedPermission(
                TestProject.ProjectId,
                "iam.serviceAccounts.actAs");

            Assert.IsFalse(result);
        }
Ejemplo n.º 18
0
        public async Task WhenImageNotFound_ThenAnnotationNotAdded(
            [Credential(Role = PredefinedRole.ComputeViewer)] CredentialRequest credential)
        {
            var annotatedSet = CreateSet(
                new ImageLocator("unknown", "beos"));

            Assert.AreEqual(0, annotatedSet.LicenseAnnotations.Count());

            var computeEngineAdapter = new ComputeEngineAdapter(
                await credential.GetCredentialAsync());
            await LicenseLoader.LoadLicenseAnnotationsAsync(
                annotatedSet,
                computeEngineAdapter,
                CancellationToken.None);

            Assert.AreEqual(0, annotatedSet.LicenseAnnotations.Count());
        }
Ejemplo n.º 19
0
        public async Task WhenServerNotListening_ThenReadReturnsZero(
            [LinuxInstance] InstanceRequest vm,
            [Credential] CredentialRequest credential)
        {
            await vm.AwaitReady();

            var stream = ConnectToWebServer(
                vm.Locator,
                await credential.GetCredentialAsync());

            byte[] request = new ASCIIEncoding().GetBytes(
                $"GET / HTTP/1.1\r\nHost:www\r\nConnection: keep-alive\r\n\r\n");
            await stream.WriteAsync(request, 0, request.Length, CancellationToken.None);

            byte[] buffer = new byte[stream.MinReadSize];
            Assert.AreEqual(0, stream.ReadAsync(buffer, 0, buffer.Length, CancellationToken.None).Result);
        }
Ejemplo n.º 20
0
        public async Task WhenLoadAsyncCompletes_ThenOutputContainsExistingData(
            [WindowsInstance] InstanceRequest testInstance,
            [Credential(Role = PredefinedRole.ComputeViewer)] CredentialRequest credential)
        {
            await testInstance.AwaitReady();

            var model = await SerialOutputModel.LoadAsync(
                "display-name",
                new ComputeEngineAdapter(await credential.GetCredentialAsync()),
                await testInstance.GetInstanceAsync(),
                SerialPortStream.ConsolePort,
                CancellationToken.None);

            Assert.IsFalse(string.IsNullOrWhiteSpace(model.Output));
            Assert.AreEqual("display-name", model.DisplayName);
            StringAssert.Contains("Instance setup finished", model.Output);
        }
Ejemplo n.º 21
0
        public async Task WhenInstanceExistsAndIsListening_ThenProbeSucceeds(
            [WindowsInstance] InstanceRequest testInstance,
            [Credential] CredentialRequest credential)
        {
            await testInstance.AwaitReady();

            using (var stream = new SshRelayStream(
                       new IapTunnelingEndpoint(
                           await credential.GetCredentialAsync(),
                           testInstance.Locator,
                           3389,
                           IapTunnelingEndpoint.DefaultNetworkInterface,
                           TestProject.UserAgent)))
            {
                await stream.TestConnectionAsync(TimeSpan.FromSeconds(10));
            }
        }
Ejemplo n.º 22
0
 public async Task WhenInstanceDoesntExist_ThenProbeFailsWithUnauthorizedException(
     [Credential] CredentialRequest credential)
 {
     using (var stream = new SshRelayStream(
                new IapTunnelingEndpoint(
                    await credential.GetCredentialAsync(),
                    new InstanceLocator(
                        TestProject.ProjectId,
                        TestProject.Zone,
                        "invalid"),
                    80,
                    IapTunnelingEndpoint.DefaultNetworkInterface,
                    TestProject.UserAgent)))
     {
         AssertEx.ThrowsAggregateException <UnauthorizedException>(() =>
                                                                   stream.TestConnectionAsync(TimeSpan.FromSeconds(10)).Wait());
     }
 }
        public async Task WhenUserInViewerRole_ThenListInstancesAsyncReturnsInstances(
            [LinuxInstance] InstanceRequest testInstance,
            [Credential(Role = PredefinedRole.ComputeViewer)] CredentialRequest credential)
        {
            // Make sure there is at least one instance.
            await testInstance.AwaitReady();

            var instanceRef = await testInstance.GetInstanceAsync();

            var adapter = new ComputeEngineAdapter(await credential.GetCredentialAsync());

            var instances = await adapter.ListInstancesAsync(
                TestProject.ProjectId,
                CancellationToken.None);

            Assert.Greater(instances.Count(), 1);
            Assert.IsNotNull(instances.FirstOrDefault(i => i.Name == instanceRef.Name));
        }
Ejemplo n.º 24
0
        public async Task WhenInstanceExistsButNotListening_ThenProbeFailsWithNetworkStreamClosedException(
            [WindowsInstance] InstanceRequest testInstance,
            [Credential] CredentialRequest credential)
        {
            await testInstance.AwaitReady();

            using (var stream = new SshRelayStream(
                       new IapTunnelingEndpoint(
                           await credential.GetCredentialAsync(),
                           testInstance.Locator,
                           22,
                           IapTunnelingEndpoint.DefaultNetworkInterface,
                           TestProject.UserAgent)))
            {
                AssertEx.ThrowsAggregateException <NetworkStreamClosedException>(() =>
                                                                                 stream.TestConnectionAsync(TimeSpan.FromSeconds(5)).Wait());
            }
        }
        public async Task WhenLoadAsyncCompletes_ThenPropertiesArePopulated(
            [WindowsInstance] InstanceRequest testInstance,
            [Credential(Role = PredefinedRole.ComputeViewer)] CredentialRequest credential)
        {
            await testInstance.AwaitReady();

            var model = await InstanceDetailsModel.LoadAsync(
                await testInstance.GetInstanceAsync(),
                new ComputeEngineAdapter(await credential.GetCredentialAsync()),
                CancellationToken.None);

            Assert.AreEqual(testInstance.Locator.Name, model.InstanceName);
            Assert.IsNull(model.Hostname);
            Assert.AreEqual("RUNNING", model.Status);
            Assert.IsNotNull(model.InternalIp);
            Assert.IsNotNull(model.ExternalIp);
            Assert.IsNotNull(model.Licenses);
            Assert.IsFalse(model.IsSoleTenant);
        }
Ejemplo n.º 26
0
        public async Task WhenBufferIsTiny_ThenReadingFailsWithIndexOutOfRangeException(
            [LinuxInstance(InitializeScript = InstallApache)] InstanceRequest vm,
            [Credential] CredentialRequest credential)
        {
            await vm.AwaitReady();

            var stream = ConnectToWebServer(vm.Locator, await credential.GetCredentialAsync());

            byte[] request = new ASCIIEncoding().GetBytes(
                "GET / HTTP/1.0\r\n\r\n");
            await stream.WriteAsync(request, 0, request.Length, CancellationToken.None);

            byte[] buffer = new byte[64];

            AssertEx.ThrowsAggregateException <IndexOutOfRangeException>(() =>
            {
                stream.ReadAsync(buffer, 0, buffer.Length, CancellationToken.None).Wait();
            });
        }
        public async Task WhenSigningOutPerSendKeys_ThenWindowIsClosed(
            [WindowsInstance(ImageFamily = WindowsInstanceAttribute.WindowsServer2019)]
            InstanceRequest testInstance,
            [Credential] CredentialRequest credential)
        {
            await testInstance.AwaitReady();

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

                    var rdpService = new RemoteDesktopService(this.serviceProvider);
                    var session    = (RemoteDesktopPane)rdpService.Connect(
                        testInstance.Locator,
                        "localhost",
                        (ushort)tunnel.LocalPort,
                        new VmInstanceConnectionSettings()
                    {
                        Username            = credentials.UserName,
                        Password            = credentials.SecurePassword,
                        AuthenticationLevel = RdpAuthenticationLevel.NoServerAuthentication,
                        BitmapPersistence   = RdpBitmapPersistence.Disabled,
                        DesktopSize         = RdpDesktopSize.ClientSize
                    });

                    AwaitEvent <RemoteDesktopConnectionSuceededEvent>();

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

                    AwaitEvent <RemoteDesktopWindowClosedEvent>();
                    Assert.IsNull(this.ExceptionShown);
                }
        }
Ejemplo n.º 28
0
        public async Task WhenServerNotListening_ThenReadFails(
            [LinuxInstance] InstanceRequest vm,
            [Credential] CredentialRequest credential)
        {
            await vm.AwaitReady();

            var stream = ConnectToWebServer(
                vm.Locator,
                await credential.GetCredentialAsync());

            byte[] request = new ASCIIEncoding().GetBytes(
                $"GET / HTTP/1.1\r\nHost:www\r\nConnection: keep-alive\r\n\r\n");
            await stream.WriteAsync(request, 0, request.Length, CancellationToken.None);

            AssertEx.ThrowsAggregateException <WebSocketStreamClosedByServerException>(() =>
            {
                byte[] buffer = new byte[stream.MinReadSize];
                stream.ReadAsync(buffer, 0, buffer.Length, CancellationToken.None).Wait();
            });
        }
Ejemplo n.º 29
0
        public async Task WhenAllowUsersToConnectRemotelyByUsingRdsIsOff_ThenErrorIsShownAndWindowIsClosed(
            [WindowsInstance(InitializeScript = @"
                # Disable Policy
                & reg add ""HKLM\SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services"" /t REG_DWORD /v fDenyTSConnections /d 1 /f | Out-Default
            ")] InstanceRequest testInstance,
            [Credential] CredentialRequest credential)
        {
            await testInstance.AwaitReady();

            using (var tunnel = RdpTunnel.Create(
                       testInstance.Locator,
                       await credential.GetCredentialAsync()))
            {
                var session = await Connect(tunnel, testInstance.Locator);

                AwaitEvent <RemoteDesktopConnectionFailedEvent>();
                Assert.IsNotNull(this.ExceptionShown);
                Assert.IsInstanceOf(typeof(RdpDisconnectedException), this.ExceptionShown);
                Assert.AreEqual(264, ((RdpDisconnectedException)this.ExceptionShown).DisconnectReason);
            }
        }
Ejemplo n.º 30
0
        public async Task WhenImageNotFoundButFromWindowsProject_ThenAnnotationIsAdded(
            [Credential(Role = PredefinedRole.ComputeViewer)] CredentialRequest credential)
        {
            var annotatedSet = CreateSet(
                new ImageLocator("windows-cloud", "windows-95"));

            Assert.AreEqual(0, annotatedSet.LicenseAnnotations.Count());

            var computeEngineAdapter = new ComputeEngineAdapter(
                await credential.GetCredentialAsync());
            await LicenseLoader.LoadLicenseAnnotationsAsync(
                annotatedSet,
                computeEngineAdapter,
                CancellationToken.None);

            Assert.AreEqual(1, annotatedSet.LicenseAnnotations.Count());

            var annotation = annotatedSet.LicenseAnnotations.Values.First();

            Assert.AreEqual(OperatingSystemTypes.Windows, annotation.OperatingSystem);
            Assert.AreEqual(LicenseTypes.Spla, annotation.LicenseType);
        }