PollMessageAsync() public method

public PollMessageAsync ( int count ) : Task
count int
return Task
Beispiel #1
0
        public void NegotiateStream_EchoServer_NTLM_ClientWriteRead_Successive_Async_Success()
        {
            if (!_isNtlmAvailable)
            {
                _output.WriteLine("skipping NegotiateStream_EchoServer_NTLM_ClientWriteRead_Successive_Async_Success");
                return;
            }

            byte[] firstRecvBuffer  = new byte[_firstMessage.Length];
            byte[] secondRecvBuffer = new byte[_secondMessage.Length];

            VirtualNetwork network = new VirtualNetwork();

            using (var clientStream = new VirtualNetworkStream(network, isServer: false))
                using (var serverStream = new VirtualNetworkStream(network, isServer: true))
                    using (var client = new NegotiateStream(clientStream))
                        using (var server = new UnixGssFakeNegotiateStream(serverStream))
                        {
                            Assert.False(client.IsAuthenticated, "client.IsAuthenticated");
                            Assert.False(server.IsAuthenticated, "server.IsAuthenticated");

                            string            user       = string.Format("{0}@{1}", TestConfiguration.NtlmUser, TestConfiguration.Domain);
                            NetworkCredential credential = new NetworkCredential(user, TestConfiguration.NtlmPassword);
                            Task[]            auth       = new Task[] {
                                client.AuthenticateAsClientAsync(credential, TestConfiguration.HostTarget),
                                server.AuthenticateAsServerAsync()
                            };

                            bool finished = Task.WaitAll(auth, TestConfiguration.PassingTestTimeoutMilliseconds);
                            Assert.True(finished, "Handshake completed in the allotted time");

                            //clearing message queue
                            byte[] junkBytes  = new byte[5];
                            int    j          = clientStream.Read(junkBytes, 0, 5);
                            Task   serverTask = server.PollMessageAsync(2);

                            Task[] msgTasks = new Task[] {
                                client.WriteAsync(_firstMessage, 0, _firstMessage.Length).ContinueWith((t) =>
                                                                                                       client.WriteAsync(_secondMessage, 0, _secondMessage.Length)).Unwrap(),
                                ReadAllAsync(client, firstRecvBuffer, 0, firstRecvBuffer.Length).ContinueWith((t) =>
                                                                                                              ReadAllAsync(client, secondRecvBuffer, 0, secondRecvBuffer.Length)).Unwrap(),
                                serverTask
                            };

                            finished = Task.WaitAll(msgTasks, TestConfiguration.PassingTestTimeoutMilliseconds);
                            Assert.True(finished, "Messages sent and received in the allotted time");
                            Assert.True(_firstMessage.SequenceEqual(firstRecvBuffer), "The first message received is as expected");
                            Assert.True(_secondMessage.SequenceEqual(secondRecvBuffer), "The second message received is as expected");
                        }
        }
        public async Task NegotiateStream_EchoServer_ClientWriteRead_Successive_Async_Success()
        {
            if (!_isKrbAvailable)
            {
                _output.WriteLine("skipping NegotiateStream_EchoServer_ClientWriteRead_Successive_Async_Success");
                return;
            }

            VirtualNetwork network = new VirtualNetwork();

            byte[] firstRecvBuffer  = new byte[_firstMessage.Length];
            byte[] secondRecvBuffer = new byte[_secondMessage.Length];

            using (var clientStream = new VirtualNetworkStream(network, isServer: false))
                using (var serverStream = new VirtualNetworkStream(network, isServer: true))
                    using (var client = new NegotiateStream(clientStream))
                        using (var server = new UnixGssFakeNegotiateStream(serverStream))
                        {
                            Assert.False(client.IsAuthenticated, "client is not authenticated before AuthenticateAsClient call");

                            string            user       = string.Format("{0}@{1}", TestConfiguration.KerberosUser, TestConfiguration.Realm);
                            string            target     = string.Format("{0}@{1}", TestConfiguration.HostTarget, TestConfiguration.Realm);
                            NetworkCredential credential = new NetworkCredential(user, _fixture.password);
                            Task[]            auth       = new Task[] {
                                client.AuthenticateAsClientAsync(credential, target),
                                server.AuthenticateAsServerAsync()
                            };

                            await TestConfiguration.WhenAllOrAnyFailedWithTimeout(auth);

                            Task   serverTask = server.PollMessageAsync(2);
                            Task[] msgTasks   = new Task[] {
                                client.WriteAsync(_firstMessage, 0, _firstMessage.Length).ContinueWith((t) =>
                                                                                                       client.WriteAsync(_secondMessage, 0, _secondMessage.Length)).Unwrap(),
                                ReadAllAsync(client, firstRecvBuffer, 0, firstRecvBuffer.Length).ContinueWith((t) =>
                                                                                                              ReadAllAsync(client, secondRecvBuffer, 0, secondRecvBuffer.Length)).Unwrap(),
                                serverTask
                            };

                            await TestConfiguration.WhenAllOrAnyFailedWithTimeout(msgTasks);

                            Assert.True(_firstMessage.SequenceEqual(firstRecvBuffer), "The first message received is as expected");
                            Assert.True(_secondMessage.SequenceEqual(secondRecvBuffer), "The second message received is as expected");
                        }
        }
        public async Task NegotiateStream_EchoServer_NTLM_ClientWriteRead_Successive_Sync_Success()
        {
            if (!_isNtlmAvailable)
            {
                _output.WriteLine("skipping NegotiateStream_EchoServer_NTLM_ClientWriteRead_Successive_Sync_Success");
                return;
            }

            byte[] firstRecvBuffer  = new byte[_firstMessage.Length];
            byte[] secondRecvBuffer = new byte[_secondMessage.Length];

            VirtualNetwork network = new VirtualNetwork();

            using (var clientStream = new VirtualNetworkStream(network, isServer: false))
                using (var serverStream = new VirtualNetworkStream(network, isServer: true))
                    using (var client = new NegotiateStream(clientStream))
                        using (var server = new UnixGssFakeNegotiateStream(serverStream))
                        {
                            Assert.False(client.IsAuthenticated, "client.IsAuthenticated");
                            Assert.False(server.IsAuthenticated, "server.IsAuthenticated");

                            string            user       = string.Format("{0}@{1}", TestConfiguration.NtlmUser, TestConfiguration.Domain);
                            NetworkCredential credential = new NetworkCredential(user, TestConfiguration.NtlmPassword);
                            Task[]            auth       = new Task[] {
                                client.AuthenticateAsClientAsync(credential, TestConfiguration.HostTarget),
                                server.AuthenticateAsServerAsync()
                            };
                            await TestConfiguration.WhenAllOrAnyFailedWithTimeout(auth);

                            //clearing message queue
                            byte[] junkBytes  = new byte[5];
                            int    j          = clientStream.Read(junkBytes, 0, 5);
                            Task   svrMsgTask = server.PollMessageAsync(2);

                            client.Write(_firstMessage, 0, _firstMessage.Length);
                            client.Write(_secondMessage, 0, _secondMessage.Length);
                            client.Read(firstRecvBuffer, 0, firstRecvBuffer.Length);
                            client.Read(secondRecvBuffer, 0, secondRecvBuffer.Length);
                            Assert.True(_firstMessage.SequenceEqual(firstRecvBuffer), "first message received is as expected");
                            Assert.True(_secondMessage.SequenceEqual(secondRecvBuffer), "second message received is as expected");
                            await svrMsgTask.TimeoutAfter(TestConfiguration.PassingTestTimeoutMilliseconds);
                        }
        }
Beispiel #4
0
        public void NegotiateStream_EchoServer_ClientWriteRead_Successive_Sync_Success()
        {
            if (!_isKrbAvailable)
            {
                _output.WriteLine("skipping NegotiateStream_EchoServer_ClientWriteRead_Successive_Sync_Success");
                return;
            }

            VirtualNetwork network = new VirtualNetwork();

            byte[] firstRecvBuffer  = new byte[_firstMessage.Length];
            byte[] secondRecvBuffer = new byte[_secondMessage.Length];

            using (var clientStream = new VirtualNetworkStream(network, isServer: false))
                using (var serverStream = new VirtualNetworkStream(network, isServer: true))
                    using (var client = new NegotiateStream(clientStream))
                        using (var server = new UnixGssFakeNegotiateStream(serverStream))
                        {
                            Assert.False(client.IsAuthenticated, "client is not authenticated before AuthenticateAsClient call");

                            string            user       = string.Format("{0}@{1}", TestConfiguration.KerberosUser, TestConfiguration.Realm);
                            string            target     = string.Format("{0}@{1}", TestConfiguration.HostTarget, TestConfiguration.Realm);
                            NetworkCredential credential = new NetworkCredential(user, _fixture.password);
                            Task[]            auth       = new Task[] {
                                client.AuthenticateAsClientAsync(credential, target),
                                server.AuthenticateAsServerAsync()
                            };
                            bool finished = Task.WaitAll(auth, TestConfiguration.PassingTestTimeoutMilliseconds);
                            Assert.True(finished, "Handshake completed in the allotted time");

                            Task svrMsgTask = server.PollMessageAsync(2);

                            client.Write(_firstMessage, 0, _firstMessage.Length);
                            client.Write(_secondMessage, 0, _secondMessage.Length);
                            client.Read(firstRecvBuffer, 0, firstRecvBuffer.Length);
                            client.Read(secondRecvBuffer, 0, secondRecvBuffer.Length);
                            Assert.True(_firstMessage.SequenceEqual(firstRecvBuffer), "first message received is as expected");
                            Assert.True(_secondMessage.SequenceEqual(secondRecvBuffer), "second message received is as expected");
                            finished = svrMsgTask.Wait(TestConfiguration.PassingTestTimeoutMilliseconds);
                            Assert.True(finished, "Message roundtrip completed in the allotted time");
                        }
        }