Exemplo n.º 1
0
        public async Task WhenKeyUnknown_ThenErrorIsShownAndWindowIsClosed(
            [LinuxInstance] ResourceTask <InstanceLocator> instanceLocatorTask)
        {
            var instanceLocator = await instanceLocatorTask;

            using (var key = new RsaSshKey(new RSACng()))
            {
                ConnectionFailedEvent deliveredEvent = null;
                this.eventService.BindHandler <ConnectionFailedEvent>(e => deliveredEvent = e);

                var broker = new SshTerminalConnectionBroker(
                    this.serviceProvider);
                await broker.ConnectAsync(
                    instanceLocator,
                    new IPEndPoint(await PublicAddressFromLocator(instanceLocator), 22),
                    AuthorizedKey.ForMetadata(key, "test", true, null))
                .ConfigureAwait(true);

                Assert.IsNotNull(deliveredEvent, "Event fired");
                Assert.IsInstanceOf(typeof(SshNativeException), this.ExceptionShown);
                Assert.AreEqual(
                    LIBSSH2_ERROR.AUTHENTICATION_FAILED,
                    ((SshNativeException)this.ExceptionShown).ErrorCode);
            }
        }
Exemplo n.º 2
0
        private async Task <SshTerminalPane> ConnectSshTerminalPane(
            InstanceLocator instanceLocator,
            ICredential credential)
        {
            var authorization = new Mock <IAuthorization>();

            authorization
            .SetupGet(a => a.Email)
            .Returns("*****@*****.**");
            var authorizationAdapter = new Mock <IAuthorizationAdapter>();

            authorizationAdapter
            .Setup(a => a.Authorization)
            .Returns(authorization.Object);

            using (var key = new RsaSshKey(new RSACng()))
                using (var keyAdapter = new AuthorizedKeyService(
                           authorizationAdapter.Object,
                           new ComputeEngineAdapter(credential),
                           new ResourceManagerAdapter(credential),
                           new Mock <IOsLoginService>().Object))
                {
                    var authorizedKey = await keyAdapter.AuthorizeKeyAsync(
                        instanceLocator,
                        key,
                        TimeSpan.FromMinutes(10),
                        null,
                        AuthorizeKeyMethods.InstanceMetadata,
                        CancellationToken.None)
                                        .ConfigureAwait(true);

                    // Connect and wait for event
                    ConnectionSuceededEvent connectedEvent = null;
                    this.eventService.BindHandler <ConnectionSuceededEvent>(e => connectedEvent = e);

                    var broker = new SshTerminalConnectionBroker(
                        this.serviceProvider);
                    var pane = await broker.ConnectAsync(
                        instanceLocator,
                        new IPEndPoint(await PublicAddressFromLocator(instanceLocator), 22),
                        authorizedKey)
                               .ConfigureAwait(true);

                    Assert.IsNotNull(connectedEvent, "ConnectionSuceededEvent event fired");
                    PumpWindowMessages();

                    return((SshTerminalPane)pane);
                }
        }
Exemplo n.º 3
0
        public async Task WhenWrongPort_ThenErrorIsShownAndWindowIsClosed()
        {
            using (var key = new RsaSshKey(new RSACng()))
            {
                ConnectionFailedEvent deliveredEvent = null;
                this.eventService.BindHandler <ConnectionFailedEvent>(e => deliveredEvent = e);

                var broker = new SshTerminalConnectionBroker(
                    this.serviceProvider);
                await broker.ConnectAsync(
                    new InstanceLocator("project-1", "zone-1", "instance-1"),
                    NonSshEndpoint,
                    AuthorizedKey.ForMetadata(key, "test", true, null))
                .ConfigureAwait(true);

                Assert.IsNotNull(deliveredEvent, "Event fired");
                Assert.IsInstanceOf(typeof(SocketException), this.ExceptionShown);
                Assert.AreEqual(
                    SocketError.ConnectionRefused,
                    ((SocketException)this.ExceptionShown).SocketErrorCode);
            }
        }