Beispiel #1
0
        public void No_supported_authentication_methods_should_throw()
        {
            var         stream = new BufferReadOnlyStream(5, 0, 0);
            Func <Task> act    = () => Greeting.ReadFromAsync(stream, this._bufferPool);

            act.Should().Throw <InvalidDataException>().And.Message.Should().ContainEquivalentOf("authentication methods");
        }
Beispiel #2
0
        public async Task No_authentication_should_work()
        {
            var stream   = new BufferReadOnlyStream(5, 1, 0);
            var greeting = await Greeting.ReadFromAsync(stream, this._bufferPool).ConfigureAwait(true);

            greeting.SupportedAuthenticationMethods.Should().Equal(AuthenticationMethod.None);
        }
Beispiel #3
0
        public void Wrong_protocol_version_should_throw()
        {
            var         stream = new BufferReadOnlyStream(4, 1, 0);
            Func <Task> act    = () => Greeting.ReadFromAsync(stream, this._bufferPool);

            act.Should().Throw <InvalidDataException>().And.Message.Should().ContainEquivalentOf("version");
        }
Beispiel #4
0
        public async Task All_authentication_methods_supported()
        {
            var stream = new BufferReadOnlyStream(
                new[] { 5, 255 }
                .Concat(Enumerable.Range(0, 255))
                .Select(x => (byte)x)
                .ToArray());

            var greeting = await Greeting
                           .ReadFromAsync(stream, this._bufferPool)
                           .ConfigureAwait(true);

            greeting.SupportedAuthenticationMethods
            .Should()
            .Equal(Enumerable.Range(0, 255).Select(x => (AuthenticationMethod)x));
        }
        async Task <bool> TryNegotiateSupportedAuthenticationMethodAsync()
        {
            var greeting = await Greeting
                           .ReadFromAsync(this._clientStream, this._bufferPool)
                           .ConfigureAwait(false);

            if (greeting.SupportedAuthenticationMethods.All(x => x != AuthenticationMethod.None))
            {
                this._log.LogError("Client does not support no authentication.");
                await new GreetingReply(AuthenticationMethod.NoAcceptableMethods)
                .WriteToAsync(this._clientStream, this._bufferPool)
                .ConfigureAwait(false);
                return(false);
            }

            await new GreetingReply(AuthenticationMethod.None)
            .WriteToAsync(this._clientStream, this._bufferPool)
            .ConfigureAwait(false);
            return(true);
        }